/**
 * @author angel
 */


function showFormReservation(adults,kids,arrival,departure){
	parametros = 'modulo=reservaciones&accion=step2&isAjax=1';
	if(adults!=null) parametros+="&adults="+adults;
	if(kids!=null) parametros+="&kids="+kids;
	if(arrival!=null) parametros+="&arrival="+arrival;
	if(departure!=null) parametros+="&departure="+departure;	
	showWindowAjax('wReservacion',{width:380,height:500,title:'Make Reservation',maximizable:false,resizable:true,minimizable:false,zIndex:10},'reservacion_en.php',parametros,null,null,'post',true);
}


 function startReservation(){
 	 
	
	form = $('formReservacion');
	
	if (trim(form.fullname.value) == "") {
		alert("Please type your full name");
		return;
	}
	if (trim(form.email.value) == "") {
		alert("Please type your email");
		return;
	}	

	  if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(form.email.value)){
	   
	  } else {
	    alert("Your email address is invalid.");
	    return;
	  }
  
	if (trim(form.country.value) == "none") {
		alert("Please select your country");
		return;
	}

	if (trim(form.phone.value) == "none") {
		alert("Please type your phone number");
		return;
	}

	if (trim(form.arrival.value) == "") {
		alert("Please select your arrival date");
		return;
	}
	
	if (trim(form.departure.value) == "") {
		alert("Please select your departure date");
		return;
	}
	
	if (trim(form.departure.value) < trim(form.arrival.value)) {
		alert("Please select a valid departure date");
		return;
	}
		

	$('btreservationmake').disable();
	
	parametros = Form.serialize($('formReservacion'));
	var opt = {
		   parameters : parametros,
		   onFailure:function(){
				alert("Fallo el envio de datos");
			},
		 	onSuccess:function(t){
			 	if(t.responseXML.getElementsByTagName("respuesta")[0].firstChild.data == 1) {
					
				//	alert(t.responseXML.getElementsByTagName("mensaje")[0].firstChild.data);
					if($('wReservacion')){
						Windows.close('wReservacion');
					}
				alert("Thank you, we will contact you as soon as posible");
				//parent.window.location.href='http://www.holboxtravel.com/index.php?modulo=contenido&id=34';
			}else {
			 		alert(t.responseXML.getElementsByTagName("mensaje")[0].firstChild.data);
					$('btreservationback').enable();
					$('btreservationmake').enable();
			 	}
		 	}
		}
		
	var request = new Ajax.Request('doreservacion.php',opt);
}

function bookNow(form){
	if(form.arrival.value!="" && form.departure.value!=""){
	showFormReservation(form.adults.value,form.kids.value,form.arrival.value,form.departure.value)
	}else{
	 alert("Please select an arrival and departure date");
	}
}