var fields = new Array();
fields.push(new Array("txt","#form_subject","Please select a subject"));
fields.push(new Array("txt","#form_name","Please enter your first name"));
fields.push(new Array("txt","#form_lastname","Please enter your last name"));
fields.push(new Array("mail","#form_email","Please enter a correct email"));
fields.push(new Array("mail2","#form_email","Please enter the same adresse"));
fields.push(new Array('txt','#form_tel','Please enter your phone number'));
fields.push(new Array('txt','#form_comments','Please enter your comments'));

var fieldsSugar = new Array();
fieldsSugar.push(new Array('txt','#product_c','Please select a product'));
fieldsSugar.push(new Array('txt','#arrival_c','Please enter an arrival date'));
fieldsSugar.push(new Array('txt','#departure_c','Please enter an departure date'));
fieldsSugar.push(new Array('txt','#a0_c','Please enter the number of adults'));
fieldsSugar.push(new Array('txt','#type_of_group_c','Please select you type of group'));




function checkFormQuote(){
	for (var i = 0; i < fields.length; i++) {
			if(!checkField(fields[i][0],fields[i][1],fields[i][2])){return false;}
	}
	if($('#sendToSugar').val()== 1){
		for (var i = 0; i < fieldsSugar.length; i++) {
			if(!checkField(fieldsSugar[i][0],fieldsSugar[i][1],fieldsSugar[i][2])){return false;}
		}
		if($('#product_c').val()=="hotel"){
			if(!checkField('int','#a1_c','Please enter the number of adults')){return false;}
		}
		if($('#product_c').val()=="apartment"){
			if(!checkField('int','#a0_c','Please enter the number of adults')){return false;}
		}
	}

	return true;
}


function checkField(type,nameField,alertMessage){

	toReturn = true;

	switch (type) {
		case 'txt':
			if($(nameField).val()==""){
				alert(alertMessage);
				$(nameField).focus();
				toReturn = false;
			}
		break;

		case 'int':
			if($(nameField).val()==0){
				alert(alertMessage);
				$(nameField).focus();
				toReturn = false;
			}
		break;

		case 'mail':
			if(!checkMail($(nameField).val())){
					alert(alertMessage);
					$(nameField).focus();
					toReturn = false;
			}
		break;

		case 'mail2':
			if($(nameField).val()!=$(nameField+'2').val()){
				alert(alertMessage);
				$('#email_address_c').focus();
				return false;
			}
		break;
	}
	return toReturn;


}
function checkMail(email){
	var regexEmail = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	return regexEmail.test(email);
}
$().ready(function(){

	$('#arrival_c').datepicker({
		dateFormat: 'dd-mm-yy',
		firstDay: 1 ,
		constrainInput: true,
		showOn: 'button',
		buttonImage: '/images/calendar.jpg',
		buttonImageOnly: true
	});
	$('#departure_c').datepicker({
		dateFormat: 'dd-mm-yy',
		firstDay: 1,
		constrainInput: true,
		showOn: 'button',
		buttonImage: '/images/calendar.jpg',
		buttonImageOnly: true
	});
	$('#arrival_c').change( function() {
		$('#departure_c').datepicker('setDate' , new Date($('#arrival_c').datepicker( 'getDate' ).getTime() + 86400000));
	});
	$('#form_subject').change(function(){
		if($('#form_subject').val()=="Reservation Inquiries"){
			$('#sendToSugar').val(1);
			$('#sugarInfos').show();
			$('#destination_c_1').hide();

		}else{
			$('#sendToSugar').val(0);
			$('#sugarInfos').hide();
			$('#destination_c_1').show();
			$('#Apartment').hide();
			$('#hotel').hide();
			$('#product_c').val("");
		}
	});

	$('#product_c').change(function(){
		if($('#product_c').val()==""){
			$('#Apartment').hide();
			$('#hotel').hide();
		}
		else{
			if($('#product_c').val()=="apartment" || $('#product_c').val()=="ticket" ){
				$('#Apartment').show();
				$('#hotel').hide();
				$('#a1_c').val(0);
				$('#c1_c').val(0);
				$('#cage1_c').val("");
				$('#a2_c').val(0);
				$('#c2_c').val(0);
				$('#cage2_c').val("");


			}else{
				$('#hotel').show();
				$('#Apartment').hide();
				$('#a0_c').val(0);
				$('#c0_c').val(0);
				$('#cage_c').val("");

			}
		}
		
	});

	$('#addRoom').click(function(){
		$('#addRoom').hide();
		$('.room2Title').show();
		$('#room2Details').show();
		$('#room2Ages').show();
		$('#removeRoom').show();

	});
	
	$('#removeRoom').click(function(){
		$('#addRoom').show();
		$('.room2Title').hide();
		$('#room2Details').hide();
		$('#room2Ages').hide();
		$('#removeRoom').hide();

	});

	$('#form_subject').change();
	$('#product_c').change();
	if($('#a2_c').val()!=0){
		$('#addRoom').click();
	}
});

/* Conact Form*/



