// JavaScript Document
$(document).ready(function(){
	
	var urlPost = (("https:" == document.location.protocol) ? "https://www.cancuntransportationfamar.com" : "http://www.cancuntransportationfamar.com");

	$("ul.subnav").parent().append("<span></span>"); //Only shows drop down trigger when js is enabled (Adds empty span tag after ul.subnav*)

	$("ul.topnav li span").click(function() { //When trigger is clicked...

		//Following events are applied to the subnav itself (moving subnav up and down)
		$(this).parent().find("ul.subnav").slideDown('fast').show(); //Drop down the subnav on click

		$(this).parent().hover(function() {
		}, function(){
			$(this).parent().find("ul.subnav").slideUp('slow'); //When the mouse hovers out of the subnav, move it back up
		});

		//Following events are applied to the trigger (Hover events for the trigger)
		}).hover(function() {
			$(this).addClass("subhover"); //On hover over, add class "subhover"
		}, function(){	//On Hover Out
			$(this).removeClass("subhover"); //On hover out, remove class "subhover"
	});
	
		
	/*CODIGO PARA EL MOTOR*/	   	
			$("#txtFrom").autocomplete(urlPost+"/index.php/ajax/cargarDestino", {
				width: 260,
				selectFirst: false
			});
			
			$("#txtFrom").result(function(event, data, formatted) {
				if (data)				
					$("#txtClaveFrom").val(data[1]);					
			});
			
			$("#txtTo").autocomplete(urlPost+"/index.php/ajax/cargarDestino", {
				width: 260,
				selectFirst: false
			});
			
			$("#txtTo").result(function(event, data, formatted) {
				if (data)				
					$("#txtClaveTo").val(data[1]);					
			});	

			$('#txtFechaIn').datepicker({
					inline:false,
					//minDate:'+2d',  //d m w y
					//defaultDate:'+2d',
					'dateFormat': 'mm/dd/yy',
					onClose: function(input) {						
						startDate = $("#txtFechaIn").datepicker('getDate');
				        
				        if (startDate != null) {
				            startDate.setDate(startDate.getDate()+1);				            
				            $("#txtFechaOut").datepicker('option', 'minDate',startDate);
				        }
					} 
			});
			
			var startDate = "";

			$('#txtFechaOut').datepicker({
					inline:false,
					minDate:'+1d',  //d m w y
					defaultDate:'+1d',
					'dateFormat': 'mm/dd/yy'
			});						
	/*FIN DEL CODIGO MOTOR*/
	
	//Codigo para el formulario del motor
	$("#frm_quick").submit(function(){
				
		if ($("#txtFrom").val()==""){
			alert("Por favor ingrese un destino");
			$("#txtFrom").focus();
			return false;
		}
		
		if ($("#txtTo").val()=="" || $("#txtClaveTo").val()=="Select"){
			alert("Por favor ingrese un destino");
			$("#txtTo").focus();
			return false;
		}		
		
		return true;
	});
	
	$("#txtTo").focus(function(){
		var texto = $(this).val();
		if(texto=="- - Choose your destination - - ")
		{
			$(this).val('');
		}

	});
	
	$("#txtTo").blur(function(){
		var texto = $(this).val();
		if(texto=="- - Choose your destination - - ")
		{
			$(this).val('');
		}

	});
	
	
	//Para reservar el transfer
	$(".booking").click( function(){

		var id = $(this).attr("title");
		var datos = $("#datos_reserva_" + id).val();
		
		var listaValores = datos.split("#");
	
		$("#frmSelectTransfer").find("input").each(function(indice,id){
			$(id).attr("value",listaValores[indice]);
		});
	
		$("#frmSelectTransfer").submit();
	});
	
	
	$(".txtViaje").click(function(){
		
		var viaje = $(this).attr("value");
		
		if (viaje=="rt")
			$("#litxtFechaOut").show();
		else
			$("#litxtFechaOut").hide();			
		
	});	
	
	$(".eliminarProducto").click(function(){		
		var id = $(this).attr("rel");
		$("#id").val(id);
		$("#frmVaciar").submit();		
	});	
	
	
	//Codigo para el formulario de pago
	$("#Informacion").submit(function(){
				
		if ($("#txtNombre").val()==""){
			alert("Please enter your First Name");
			$("#txtNombre").focus();
			return false;
		}
		
		if ($("#txtApellido").val()==""){
			alert("Please enter your Last Name");
			$("#txtApellido").focus();
			return false;
		}
		
		if ($("#txtEmail").val()==""){
			alert("Please enter your E-mail");
			$("#txtEmail").focus();
			return false;
		}

		if ($("#txtTel").val()==""){
			alert("Please enter your Telephone (Only numbers)");
			$("#txtTel").focus();
			return false;
		}
		
		if ($("#txtDir").val()==""){
			alert("Please enter your Address");
			$("#txtDir").focus();
			return false;
		}		

		if ($("#txtHotel").val()==""){
			alert("Please enter your Hotel stay");
			$("#txtHotel").focus();
			return false;
		}			
		
		return true;
	});
	

});
