/*
------------------------------------------------------------------------
	update: 09/04/10
	
	This script defined inquiry functions.
------------------------------------------------------------------------
*/

(function() {
	var _inquirySubmit, _inquiryReset, _data = {}, _chkFlg = true;
	var nameMap = {
		subject: '件名',
		mail: 'メールアドレス',
		body: 'お問合せ内容'
	};
	
	//send inquiry function.
	_inquirySubmit = function() {
		$( '#inquiryForm input, #inquiryForm textarea' ).each(function() {
			_data[$( this ).attr( 'name' )] = $( this ).val();
			if( $( this ).val() === '' ) {
				var that = this;
				new $pop( nameMap[$( this ).attr( 'name' )] + 'を記入してください。', { type: 'warning', modal: true, effect: 'normal', YES:function() {
					$( that ).focus();
				}} );
				_chkFlg = false;
				return false;
			}
		});
		
		if( _chkFlg ) {
			$.post( $( '#inquiryForm' ).attr( 'action' ), _data, function() {
				var hash = 'thanks';
				// moves to a new page. 
				// pageload is called at once. 
				$.historyLoad( hash );
			});
		}
		
		return false;
	}
	
	//Reset form function.
	_inquiryReset = function() {
		$( '#inquiryForm input, #inquiryForm textarea' ).val( '' );
	}
	
	$( '#submit' ).live( 'click', function() {
		_inquirySubmit();
	});
	
	$( '#reset' ).live( 'click', function() {
		_inquiryReset();
	});
	
})();