// ########## CAMPOS ##########

ORIGEN = "<div><label>Origen<br /><div class='inputorigen'><input type='text' name='origen' id='origen' autocomplete='off' class='textinput'/></div></label></div>";
ORIGEN_ = "<label></label>";
FLIGHTTYPE = "<tr id='flightTypeTr'><td><input type='radio' name='flightType' value='oneway' id='oneway' onclick='flightFields(this.value)' /><label>S&#243;lo ida</label></td><td><input type='radio' name='flightType' value='return' id='return' onclick='flightFields(this.value)' checked='checked' /><label>Ida y vuelta</label></td></tr>";
FLIGHTTYPE_ = "<tr id='flightTypeTr'><td></td></tr>";
NUMEROHAB = "<tr id='numeroDeHabitaciones'><td colspan='2'><label>N&#250;mero de habitaciones <input type='hidden' id='hab' value='1'/></label><select name='habitaciones' id='habitaciones'><option value='1'>1</option><option value='2'>2</option></select></td></tr>";

NUMEROHAB.resp = "<tr id='numeroDeHabitaciones'><td colspan='2'><label>N&#250;mero de habitaciones <input type='hidden' id='hab' value='1' /></label><select name='habitaciones' id='habitaciones'><option value='1'>1</option><option value='2'>2</option><option value='3'>3</option><option value='4'>4</option><option value='5'>5</option></select></td></tr>";

NUMEROHAB_ = "<tr id='numeroDeHabitaciones'><td colspan='2'></td></tr>";
HORAS = "<option value='-1'>Cualquiera</option><option value='0'>00:00</option><option value='1'>01:00</option><option value='2'>02:00</option><option value='3'>03:00</option><option value='4'>04:00</option><option value='5'>05:00</option><option value='6'>06:00</option><option value='7'>07:00</option><option value='8'>08:00</option><option value='9'>09:00</option><option value='10'>10:00</option><option value='11'>11:00</option><option value='12'>12:00</option><option value='13'>13:00</option><option value='14'>14:00</option><option value='15'>15:00</option><option value='16'>16:00</option><option value='17'>17:00</option><option value='18'>18:00</option><option value='19'>19:00</option><option value='20'>20:00</option><option value='21'>21:00</option><option value='22'>22:00</option><option value='23'>23:00</option>";

HORASALIDA = "<tr id='horaSalida'><td><label>Hora<br /><input type=\"hidden\" name=\"iHora\" id=\"iHora\" /><select name='iHoraS' id='iHoraS' class='hora'>" + HORAS + "</select></label></td></tr>";
HORASALIDA_= "<tr id='horaSalida'><td></td></tr>";

HORAREGRESO ="<tr id='horaRegreso'><td><label>Hora<br /><input type=\"hidden\" name=\"fHora\" id=\"fHora\" /><select name='fHoraS' id='fHoraS' class='hora'>" + HORAS + "</select></label></td></tr>";
HORAREGRESO_="<tr id='horaRegreso'><td></td></tr>";
HOTELNAME = "<tr id='hotelNametr'><td colspan='2'><label>Nombre del Hotel <input type='text' name='hotelName' id='hotelName' class='textinput' /></label></td></tr>";
HOTELNAME_ = "<tr id='hotelNametr'><td colspan='2'></td></tr>";
PROMOCODE = "<tr id='promotionCodetr'><td colspan='2'><label>C&#243;digo de la promoci&#243;n<br /><input type='text' name='promoCode' id='promoCode' class='textinput' /></label></td></tr>";
PROMOCODE_= "<tr id='promotionCodetr'><td colspan='2'></td></tr>";
DIRECTFLIGHT = "<tr id='directFlighttr'><td colspan='2'><input type='checkbox' name='directFlight' id='directFlight' /><label>Vuelo directo</label></td></tr>";
DIRECTFLIGHT_ = "<tr id='directFlighttr'><td colspan='2'></td></tr>";
BUSQUEDAA="<table cellspacing='0' cellpadding='0' id='advancedSearch'><tr id='directFlighttr'><td colspan='2'></td></tr><tr id='hotelNametr'><td colspan='2'></td></tr></table>";
CHILDRENPANEL_="<table id='childrenPanel' cellspacing='0' cellpadding='0'></table>";
GUESTS = "<table id='guest'><tr id='guests_row0'><td><div>Adultos</div> <div><input type=\"hidden\" name='noAdultos_0' id='noAdultos_0' value='1'/> <select name='SnoAdultos_0' id='SnoAdultos_0' class='selectinput'><option value='1' selected='selected'>1</option><option value='2'>2</option><option value='3'>3</option></select></div></td><td><div>Ni&#241;os </div><div><input type=\"hidden\" name='noChildren_0' id='noChildren_0' value='0'/> <select name='SnoChildren_0' id='SnoChildren_0'><option value='0' selected='selected'>0</option><option value='1'>1</option><option value='2'>2</option><option value='3'>3</option><option value='4'>4</option></select><input type='hidden' name='childrenAge_0' id='childrenAge_0' value='0' /></div></td></tr></table>";

CPMESSAGE= "<table id='childrenPanelMessage' cellpadding='0' cellspacing='7'><tr><td>Edades de los ni&#241;os:</td></tr><tr><td></td></tr><tr><td>Los impuestos o tarifas aplicables a ni&#241;os menores a dos a&#241;os deber&#225;n ser pagados en el aeropuerto de origen.</td></tr></table>";
CPMESSAGE_= "<table id='childrenPanelMessage' cellpadding='0' cellspacing='0'><tr><td></td></tr><tr><td></td></tr><tr><td></td></tr></table>";
SPINNER= "<div id='hidepage' style='z-index:1004; position: fixed; left:0px; top:0px; background-color: #FFFFFF;text-align:center; background-color: #FFFFFF; height: 100%; width: 100%;'><table width='100%' height='100%' ><tr><td align='center'><object height='394px' width='717px' align='middle' id='loader2' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0' classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000'><param value='" + configForm.spinerURL +"' name='movie'/><embed height='394px' width='717px' align='middle' pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' allowscriptaccess='sameDomain' name='loader' wmode='transparent' quality='high' src='" + configForm.spinerURL +"' class='spinner'/></object><br/><span class='spinnerText'>Por favor, espera mientras buscamos tu viaje...</span></td></tr></table></div>";
CAMPOSREGRESO = "<table cellspacing=\"0\" cellpadding=\"0\" id=\"camposRegreso\"><tbody><tr><td><label>Regreso<br /><input type=\"text\" readonly=\"readonly\" class=\"fecha date-pick\" id=\"fecha-Fin\" name=\"y\"/><input type=\"hidden\" id=\"fechaFin\" name=\"fechaFin\" value=\"\"/></label></td></tr>" + HORAREGRESO +"</tbody></table>";
CAMPOSREGRESO_ = "<table cellspacing=\"0\" cellpadding=\"0\" id=\"camposRegreso\"><tr><td><input type=\"hidden\" id=\"fecha-Fin\"/><input type=\"hidden\" id=\"fechaFin\" name=\"fechaFin\" value=\"\"/></td></tr></table>";
//-----------------------------

// ###########################  OBJETO DE CONFIGURACION #################################

function submitForm(){
	if (validateFields()){
		$('#form1').attr("action", configForm.myLocation);
		document.form1.submit();
		$('#titleCerrar').addClass("notShow");
		$('#ctp-content').addClass("notShow");
		minispinner();
	}
}

function initialize(){
	setOfferedProducts();
	setChecked(document.getElementsByName("viaje"), configForm.defautlProduct)
	configureFields(getCheckedValue(document.getElementsByName("viaje")));
	$('#hotelNametr').replaceWith(HOTELNAME_);
	$('#directFlighttr').replaceWith(DIRECTFLIGHT_);
	$(document).pngFix();
	$('#destino').selectbox({input2update:'destinoHidden'});
	
}

function setOfferedProducts(){
	if (configForm.productsOffered.indexOf("|H|")  >= 0) $('#viaje_0').parent().addClass("show-inline"); else $('#viaje_0').parent().remove();
	if (configForm.productsOffered.indexOf("|F|")  >= 0) $('#viaje_1').parent().addClass("show-inline"); else $('#viaje_1').parent().remove();
	if (configForm.productsOffered.indexOf("|HF|") >= 0) $('#viaje_2').parent().addClass("show-inline"); else $('#viaje_2').parent().remove();
}

function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	for(var i = 0; i < radioObj.length; i++)
		if(radioObj[i].checked)
			return radioObj[i].value;
	return "";
}

function setChecked(radioObj, Value) {
	if(!radioObj)
		return;
	for(var i = 0; i < radioObj.length; i++)
		if(radioObj[i].value == Value) {
			radioObj[i].checked = 'checked';
			return;
		}
}
//-----------------------------------------------------------------------------------------


//	#################### 	FUNCION PARA LIMPIAR LOS CAMPOS		################################

function clearForm(){
	$('#origen').val('');
	$('#origenHidden').val('');
	$('#destino').val('');
	$('#destinoHidden').val('');
	$('#fecha-Inicio').val('');
	$('#fecha-Fin').val('');
	$('#fechaInicio').val('');
	$('#fechaFin').val('');
	$('#noAdultos_0').get(0).selectedIndex = 0;
	$('#noChildren_0').get(0).selectedIndex = 0;
	$('#childrenPanel').replaceWith(CHILDRENPANEL_);
	$('#guest').replaceWith(GUESTS);
	$('#SnoAdultos_0').selectbox({input2update:'noAdultos_0'});
	$('#SnoChildren_0').selectbox({input2update:'noChildren_0',onchange:'modifyChildren(0, this.value)'});
	$('#origen').removeClass('missingField');
	$('#destino').parent().removeClass('missingField');
	$('#fecha-Inicio').parent().parent().removeClass('missingField');
	$('#fecha-Fin').removeClass('missingField');
	$('#errors div').parent().remove();
}


//------------------------------------------------------------------------------------------

// #################  FUNCIONES MOSTRAR y/o OCULTAR CAMPOS DEPENDIENDO DE LA BUSQUEDA ###########


function configureFields(searchType){	
	configForm.selectedProduct = searchType;
	$('#jSuggestContainerorigen').remove();
	$('#jSuggestContainerdestino').remove();
	switch (searchType){
		case 'HF'	:	$('#flightTypeTr').replaceWith(FLIGHTTYPE_);
						$('#origentr').children(":eq(0)").children(":eq(0)").replaceWith(ORIGEN);
						autocomplete_origen();
						$('#numeroDeHabitaciones').replaceWith(NUMEROHAB);
						$('#camposRegreso').replaceWith(CAMPOSREGRESO);
						$('#horaSalida').replaceWith(HORASALIDA);
						$('#horaRegreso').replaceWith(HORAREGRESO);
						$('#promotionCodetr').replaceWith(PROMOCODE);
						//if ($("#advanced").get(0).checked){
						//	$('#hotelNametr').replaceWith(HOTELNAME);
						//	$('#directFlighttr').replaceWith(DIRECTFLIGHT);
						//}
						
						configForm.autocompleteOrigenMode = 'airport';
						configForm.autocompleteDestinoMode = 'city';
						configForm.iAge = configForm.PackageInfantMaxAge;
						configForm.cAge = configForm.PackageChildMaxAge;
						
						setHF();
						break;
		case 'F'	:	$('#flightTypeTr').replaceWith(FLIGHTTYPE);
						$('#origentr').children(":eq(0)").children(":eq(0)").replaceWith(ORIGEN);
						autocomplete_origen();
						$('#numeroDeHabitaciones').replaceWith(NUMEROHAB_);
						$('#camposRegreso').replaceWith(CAMPOSREGRESO);
						$('#horaSalida').replaceWith(HORASALIDA);
						$('#horaRegreso').replaceWith(HORAREGRESO);
						$('#promotionCodetr').replaceWith(PROMOCODE_);
						
						//if ($("#advanced").get(0).checked){
						//	$('#hotelNametr').replaceWith(HOTELNAME_);
						//	$('#directFlighttr').replaceWith(DIRECTFLIGHT);
						//}
						
						configForm.autocompleteOrigenMode = 'city';
						configForm.autocompleteDestinoMode = 'airport';
						configForm.iAge = configForm.AirInfantMaxAge;
						configForm.cAge = configForm.AirChildMaxAge;
						
						
						setF();
						break ;
		case 'H'	:	$('#flightTypeTr').replaceWith(FLIGHTTYPE_);
						$('#origentr').children(":eq(0)").children(":eq(0)").replaceWith(ORIGEN_);
						$('#numeroDeHabitaciones').replaceWith(NUMEROHAB);
						$('#camposRegreso').replaceWith(CAMPOSREGRESO);
						$('#horaSalida').replaceWith(HORASALIDA_);
						$('#horaRegreso').replaceWith(HORAREGRESO_);
						$('#promotionCodetr').replaceWith(PROMOCODE);
						
						//if ($("#advanced").get(0).checked){
						//	$('#hotelNametr').replaceWith(HOTELNAME);
						//	$('#directFlighttr').replaceWith(DIRECTFLIGHT_);	
						//}
						
						configForm.autocompleteOrigenMode = 'city';
						configForm.autocompleteDestinoMode = 'city';
						configForm.iAge = configForm.HotelInfantMaxAge;
						configForm.cAge = configForm.HotelChildMaxAge;
						setHF();
	}
	clearForm();
	calendarios();
	$('#iHoraS').selectbox({input2update:'iHora'});
	$('#fHoraS').selectbox({input2update:'fHora'});
	$('#habitaciones').selectbox({input2update:'hab',onchange:'modifyHab(this.value)'});
}

function flightFields (type){
	switch (type){
		case 'return' 	:	$('#camposRegreso').replaceWith(CAMPOSREGRESO);
							calendarios();
							$('#fHoraS').selectbox({input2update:'fHora'});
							break;
		case 'oneway'	:	$('#camposRegreso').replaceWith(CAMPOSREGRESO_);
	}
}

function advancedSearch(checkbox){
	if (!checkbox)
		return;
	$('#advancedSearch').replaceWith(BUSQUEDAA);
	if (checkbox.checked){
		switch (configForm.selectedProduct){
			case 'HF'	:	$('#hotelNametr').replaceWith(HOTELNAME);
							$('#directFlighttr').replaceWith(DIRECTFLIGHT);
							break;
			case 'F'	:	$('#hotelNametr').replaceWith(HOTELNAME_);
							$('#directFlighttr').replaceWith(DIRECTFLIGHT);
							break ;
			case 'H'	:	$('#hotelNametr').replaceWith(HOTELNAME);
							$('#directFlighttr').replaceWith(DIRECTFLIGHT_);
		}
	}
		
}

//--------------------------------------------------------------------------------------------------

// #############   FUNCIONES PARA VALIDACION DEL FORMULARIOS   #####################################

function validateFields(){
	var missingFields = '';
	
	if (configForm.selectedProduct == 'H'){
		if ($("#destino").val() == '' ){
			$('#destino_input').parent().parent().addClass('missingField');
			missingFields += '<li>Destino</li>';
		}else 
			$('#destino_input').removeClass('missingField');
	}else{
		if ($('#origenHidden').get(0).value.length < 3 ){
			$('#origen').parent().parent().addClass('missingField');
			missingFields += '<li>Origen</li>';
		}else 
			$('#origen').parent().parent().removeClass('missingField');
			
		if ($("#destinoHidden" ).val() == 'any' || $("#destinoHidden" ).val() == ''){
			$('#destino_input').parent().addClass('missingField');
			missingFields += '<li>Destino</li>';
		}else 
			$('#destino_input').parent().removeClass('missingField');
	}
	
	if ($('#fecha-Inicio').get(0).value.length < 8 ){
		$('#fecha-Inicio').parent().parent().addClass('missingField');
		missingFields += '<li>Salida</li>';
	}else $('#fecha-Inicio').parent().parent().removeClass('missingField');
	if ($('#fecha-Fin').get(0).value.length < 8 ){
		$('#fecha-Fin').parent().parent().addClass('missingField');
		missingFields += '<li>Regreso</li>';
	}else $('#fecha-Fin').parent().parent().removeClass('missingField');
					
	if (missingFields.length > 0){
		$('#errors div').parent().remove();
//		$('#errors').append('<fieldset><div class="errors">' + configForm.missingFieldMessage +'<ul>'+ missingFields + '</ul></div></fieldset>');
		$('#errors').append('<fieldset><div class="errors">' + configForm.missingFieldMessage +'</div></fieldset>');
		return false;
	}
	return true;
	
}

//-----------------------------------------------------------------------------------------------------------

//   ###########################	FUNCION PARA MOSTRAR EL SPINNER		############3########################

function waitFor() {
	$('body').children().remove();
	$('body').append(SPINNER);
	
}
//-----------------------------------------------------------------------------------------------------------
			

// #####################	FUNCIONES PARA HABITACIONES Y NIŅOS		#############################################
			
function modifyHab(number){
var id = document.getElementById("hab").value;
	id--;
	number--;
	while(id > number){
		removeFormField("#guests_row" + id);
		removeFormField("#cdph_" + id);
		id--;
	}
	while(id < number){
		id++;
		addFormField("#guest",id,"<tr id='guests_row" + id + "'><td><div>Adultos</div><div> <input type=\"hidden\" name='noAdultos_"+id+"' id='noAdultos_"+id+"' value='1'/><select name='SnoAdultos_"+id+"' id='SnoAdultos_" + id + "'><option value='1'>1</option><option value='2'>2</option><option value='3'>3</option></select></div></td><td><div>Ni&ntilde;os </div><div><input type=\"hidden\" name='noChildren_"+id+"' id='noChildren_"+id+"' value='0'/> <select name='SnoChildren_"+id+"' id='SnoChildren_"+id+"'><option value='0' selected='selected'>0</option><option value='1'>1</option><option value='2'>2</option><option value='3'>3</option><option value='4'>4</option></select></div></td></tr>");		
		addFormField("#guest",id,"<input type='hidden' name='childrenAge_"+id+"' id='childrenAge_"+id+"' value='0' />");
		$('#SnoAdultos_' + id).selectbox({input2update:'noAdultos_' + id});
		$('#SnoChildren_' + id).selectbox({input2update:'noChildren_' + id,onchange:'modifyChildren(' + id + ', this.value)'});
	}
	id++;
	document.getElementById("hab").value = id;
}
/*
id - indice de la fila
index - valor acual del numero de ninios
objValue - numero de ninios deseados
*/
function modifyChildren2(objId,objValue){
	var id=objId.substring(objId.indexOf('_')+1);
	var index=document.getElementById("childrenAge_"+id).value;
	var parent=($("#childrenPanel").children(":eq(0)").children(":eq("+id+")").children(":eq(1)"));

	if(objValue==0)
		$("#childrenPanel").children(":eq(0)").children(":eq("+id+")").removeClass("show").addClass("notShow");
	else 
		$("#childrenPanel").children(":eq(0)").children(":eq("+id+")").removeClass("notShow").addClass("show");
	parent.children().remove();
	index=0;
	while(index < objValue){
		index++;
		parent.append("<span>Ni&ntilde;o "+index+" <select name='childAge_"+id+"_"+index+"' id='childAge_"+id+"_"+index+"'></select></span>");
		for (var i= parseInt(configForm.iAge) +1 ; i <= configForm.cAge; i++ )
			$("#childAge_" + id + "_" + index).append("<option value='" + i +"'>"+ i +"</option>");
	}
	$("#childrenAge_"+id).val(index);
}


function modifyChildren(objId,objValue){
	var id=objId;
	//var id=objId.substring(objId.indexOf('_')+1);
	var index=document.getElementById("childrenAge_"+id).value;
	var parent=$("#childrenPanel");
	var tds = parent.find('tr');
	var exist = 0;
	var brother = '';
	
	if (configForm.selectedProduct == 'H')
		return;
	
	if(objValue==0){
		$("#cdph_" + id).remove();
		if ($("#childrenPanel").find('tr').length < 1){
			$("#childrenPanelMessage").replaceWith(CPMESSAGE_);
		}
		return;
	}
	
	$("#childrenPanelMessage").replaceWith(CPMESSAGE);
	
	
	var newtr= "<tr id='cdph_" + id +"'><td class='hab'><div class='divhab'>Edades</div><div class='divhab'>Hab. " + (parseInt(id)+1) + "</div></td><td class='habTd'>"
	
	while(index < objValue){
		index++;
		newtr += "<span>Ni&ntilde;o "+index+" <input type=\"hidden\" name='childAge_"+id+"_"+index+"' id='childAge_"+id+"_"+index+"' value='2'/> <select name='SchildAge_"+id+"_"+index+"' id='SchildAge_"+id+"_"+index+"'>";
		for (var i= parseInt(configForm.iAge) +1 ; i <= configForm.cAge; i++ )
			newtr += "<option value='" + i +"'>"+ i +"</option>";
		newtr += "</select></span>";
		
	}
	
	newtr +="</td></tr>";
	
	tds.each(function(){
		hid = "cdph_" + id;
		if ($(this).attr("id") == hid & exist==0){
			exist=1;
		}
	});
	
	tds.each(function(){
		tdn = $(this).attr("id").substring($(this).attr("id").indexOf('_')+1);
		if (tdn < id){
			brother = $(this).attr("id");
		}
	});
	
	if (exist == 0 & brother == ''){
		parent.prepend(newtr);
	}else if (exist ==1){
		$("#cdph_" + id).replaceWith(newtr);
	}else{
		$("#" + brother ).after(newtr);
	}
	
	index=document.getElementById("childrenAge_"+id).value;
	while(index < objValue){
		index++;
		$('#SchildAge_' + id + '_' + index).selectbox({input2update:'childAge_' + id + '_' + index});
	}
	
	
}

function addFormField(parent,id, obj) {
	$(parent).append(obj);
}

function removeFormField(id) {
	$(id).remove();
}

//------------------------------------------------------------------------------------------------		

// ###################################### GOOGLE ANALYTICS #########################################

function analytics(){
	var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
	document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
	try {
		var pageTracker = _gat._getTracker(configForm.GoogleAnalyticsAccount);
		pageTracker._trackPageview();
	} catch(err) {}
}
//--------------------------------------------------------------------------------------------------


//------------------------------------------------------------------------------------------------		

// ###################################### CAMBIO DE LOCALIDADES #########################################

var cityLocations = [ 
						{ valor: 'CITY_ACA_MX', 	texto: 'Acapulco'},
						{ valor: 'CITY_AGU_MX', 	texto: 'Aguascalientes'},
						{ valor: 'CITY_CUN_MX', 	texto: 'Cancun'},
						{ valor: 'CITY_CTM_MX', 	texto: 'Chetumal'},
						{ valor: 'CITY_CUU_MX', 	texto: 'Chihuahua'},
						{ valor: 'CITY_CME_MX', 	texto: 'Ciudad del Carmen'},
						{ valor: 'CITY_CJS_MX', 	texto: 'Ciudad Juarez'},
						{ valor: 'StaMxVeCoatz398', texto: 'Coatzacoalcos'},
						{ valor: 'CITY_CLQ_MX', 	texto: 'Colima'},
						{ valor: 'CITY_CZM_MX', 	texto: 'Cozumel'},
						{ valor: 'CITY_CUL_MX', 	texto: 'Culiacan'},
						{ valor: 'CITY_DGO_MX', 	texto: 'Durango'},
						{ valor: 'CITY_GDL_MX', 	texto: 'Guadalajara'},
						{ valor: 'CITY_HMO_MX', 	texto: 'Hermosillo'},
						{ valor: 'CITY_LAP_MX', 	texto: 'La Paz'},
						{ valor: 'REG_MX_LosCabo', 	texto: 'Cabo'},
						{ valor: 'CITY_MZT_MX', 	texto: 'Mazatlan'},
						{ valor: 'CITY_MXL_MX', 	texto: 'Mexicali'},
						{ valor: 'CITY_MEX_MX', 	texto: 'Ciudad de Mexico'},
						{ valor: 'CITY_LOV_MX', 	texto: 'Monclova'},
						{ valor: 'CITY_MTY_MX', 	texto: 'Monterrey'},
						{ valor: 'CITY_MLM_MX', 	texto: 'Morelia'},
						{ valor: 'CITY_NLD_MX', 	texto: 'Nuevo Laredo'},
						{ valor: 'CITY_OAX_MX', 	texto: 'Oaxaca'},
						{ valor: 'CITY_PAZ_MX', 	texto: 'Poza Rica'},
						{ valor: 'CITY_PBC_MX', 	texto: 'Puebla'},
						{ valor: 'CITY_PVR_MX', 	texto: 'Puerto Vallarta'},
						{ valor: 'CITY_QRO_MX', 	texto: 'Queretaro'},
						{ valor: 'CITY_REX_MX', 	texto: 'Reynosa'},
						{ valor: 'CITY_SLW_MX', 	texto: 'Saltillo'},
						{ valor: 'CITY_SLP_MX', 	texto: 'San Luis Potosi'},
						{ valor: 'CITY_TAM_MX', 	texto: 'Tampico'},
						{ valor: 'CITY_TIJ_MX', 	texto: 'Tijuana'},
						{ valor: 'CITY_TLC_MX', 	texto: 'Toluca'},
						{ valor: 'CITY_TRC_MX', 	texto: 'Torreon'},
						{ valor: 'CITY_TGZ_MX', 	texto: 'Tuxtla'},
						{ valor: 'CITY_VER_MX', 	texto: 'Veracruz'},
						{ valor: 'CITY_VSA_MX', 	texto: 'Villahermosa'},
						{ valor: 'CITY_BHZ_MG_BR', 	texto: 'Belo Horizonte'},
						{ valor: 'CITY_RIO_RJ_BR', 	texto: 'Rio de Janeiro'},
						{ valor: 'CITY_SAO_SP_BR', 	texto: 'Sao Paulo'},
						{ valor: 'CITY_BUE_BA_AR', 	texto: 'Buenos Aires'}
					];

var airLocations = [ 
						{ valor: 'AIR_ACA_MX', 		texto: 'Acapulco'},
						{ valor: 'AIR_AGU_MX', 		texto: 'Aguascalientes'},
						{ valor: 'AIR_CUN_MX', 		texto: 'Cancun'},
						{ valor: 'AIR_CTM_MX', 		texto: 'Chetumal'},
						{ valor: 'AIR_CUU_MX', 		texto: 'Chihuahua'},
						{ valor: 'AIR_CME_MX', 		texto: 'Ciudad del Carmen'},
						{ valor: 'AIR_CJS_MX', 		texto: 'Ciudad Juarez'},
						{ valor: 'AirMxMinatit419', texto: 'Coatzacoalcos'},
						{ valor: 'AirMxManzani054', texto: 'Colima'},
						{ valor: 'AIR_CZM_MX', 		texto: 'Cozumel'},
						{ valor: 'AIR_CUL_MX', 		texto: 'Culiacan'},
						{ valor: 'StaEsPaDuran429', texto: 'Durango'},
						{ valor: 'AIR_GDL_MX', 		texto: 'Guadalajara'},
						{ valor: 'AIR_HMO_MX', 		texto: 'Hermosillo'},
						{ valor: 'AIR_LAP_MX', 		texto: 'La Paz'},
						{ valor: 'AIR_SJD_MX', 		texto: 'Cabo'},
						{ valor: 'AIR_MZT_MX', 		texto: 'Mazatlan'},
						{ valor: 'AIR_MXL_MX', 		texto: 'Mexicali'},
						{ valor: 'AirMxBenitoJ875', texto: 'Ciudad de Mexico'},
						{ valor: 'AIR_LOV_MX', 		texto: 'Monclova'},
						{ valor: 'AirMx545', 		texto: 'Monterrey'},
						{ valor: 'AIR_MLM_MX', 		texto: 'Morelia'},
						{ valor: 'AIR_NLD_MX', 		texto: 'Nuevo Laredo'},
						{ valor: 'AIR_OAX_MX', 		texto: 'Oaxaca'},
						{ valor: 'AIR_PAZ_MX', 		texto: 'Poza Rica'},
						{ valor: 'AIR_TCN_MX', 		texto: 'Puebla'},
						{ valor: 'AIR_PVR_MX', 		texto: 'Puerto Vallarta'},
						{ valor: 'AIR_QRO_MX', 		texto: 'Queretaro'},
						{ valor: 'AIR_REX_MX', 		texto: 'Reynosa'},
						{ valor: 'AIR_SLW_MX', 		texto: 'Saltillo'},
						{ valor: 'AIR_SLP_MX', 		texto: 'San Luis Potosi'},
						{ valor: 'AIR_TAM_MX', 		texto: 'Tampico'},
						{ valor: 'AIR_TIJ_MX', 		texto: 'Tijuana'},
						{ valor: 'AIR_TLC_MX', 		texto: 'Toluca'},
						{ valor: 'AIR_TRC_MX', 		texto: 'Torreon'},
						{ valor: 'AirMxLlanoSa895', texto: 'Tuxtla'},
						{ valor: 'AirMxVeracru521', texto: 'Veracruz'},
						{ valor: 'AIR_VSA_MX', 		texto: 'Villahermosa'},
						{ valor: 'AIR_CNF_MG_BR', 	texto: 'Belo Horizonte'},
						{ valor: 'AIR_SDU_RJ_BR', 	texto: 'Rio de Janeiro'},
						{ valor: 'AIR_GRU_SP_BR', 	texto: 'Sao Paulo'},
						{ valor: 'AirArBa722', 		texto: 'Buenos Aires'}
					];
					
function setHF(){
	var sele = document.getElementById('destino');
	while (sele.options[1])
		sele.options[1] = null;
	for (i=0; cityLocations[i]; i++){
		opt = new Option(cityLocations[i].texto,cityLocations[i].valor);
		sele.options[sele.options.length] = opt;
	}
}

function setF(){
	var sele = document.getElementById('destino');
	while (sele.options[1])
		sele.options[1] = null;
	for (i=0; airLocations[i]; i++){
		opt = new Option(airLocations[i].texto,airLocations[i].valor);
		sele.options[sele.options.length] = opt;
	}
}

//--------------------------------------------------------------------------------------------------


function autocomplete_origen(){
	$('input#origen').jSuggest({
			url: 		configForm.ajaxURL + "?locationType=" + configForm.autocompleteOrigenMode + "&searchableOnly=false",
			type: 		"GET",
			data: 		"ajaxSearch", 
			autoChange:	false,
			id: 		"origen"
		});	
}

function autocomplete_destino(){
	$('input#destino').jSuggest({
			url: 		configForm.ajaxURL + "?locationType=" + configForm.autocompleteDestinoMode + "&searchableOnly=false",
			type: 		"GET",
			data: 		"ajaxSearch", 
			autoChange:	false,
			id: 		"destino"
		});	
}

function calendarios(){
	$('#fecha-Inicio').datePicker({clickInput:true,createButton:true});
	$('#fecha-Fin').datePicker({clickInput:true,createButton:true});
	$('.date-pick').datePickerMultiMonth({numMonths: 1});
	$('.date-pick').dpSetOffset(0, 0);
    $('.date-pick').dpSetPosition($.dpConst.POS_AUTO, $.dpConst.POS_AUTO);
}


function minispinner(){
	$('body').prepend('<div id="spinner"><img src="images/ajax-loader.gif"/><div class="spinner-message">Por favor espera mientras buscamos tu viaje.</div></div>');
}
