	var searchText 	= new Object();
	var searchPrefs	= new Object();
	captureSearchText(searchText);
	captureSearchPrefs(searchPrefs);
	function setDest( mkt )
	{
		var toList		= document.getElementById( "to" + mkt + "Select" );
		eval( "document.skylightsForm.toCity" + mkt + ".value = toList.value" );
	}
	function resetDest( mkt )
	{
		var fromList		= document.getElementById( "from" + mkt + "Select" );
		if (!fromList)
		{
			return;
		}
		var toList		= document.getElementById( "to" + mkt + "Select" );
		var orig		= fromList.options[ fromList.selectedIndex ].value;
		var dest		= eval( "document.skylightsForm.toCity" + mkt + ".value" );
		toList.length	= 1;
		//toList.options[0]		= new Option("Destination");
		toList.options[0] = new Option(searchText.destination);
		
		toList.options[0].value	= "???"
		if ( fromList.selectedIndex == 0 )
		{
			for (var i = 0; i < Airports.length; i++)
			{
				toList.length	+= 1;
				var l_ix		= toList.length - 1;
				var opt_str		= Airports[i].name;
				if ( searchPrefs.DISPLAY_AIRPORT_CITY_CODES == 'true' )
				{
					opt_str		+=  " (" + Airports[i].code + ")";
				}
				toList.options[l_ix]	= new Option( opt_str );
				toList.options[l_ix].value	= Airports[i].code;
				if ( dest == Airports[i].code )
				{
					toList.selectedIndex	= l_ix;
				}
			}
		}
		else
		{
			var air		= getAirport( orig );
			for (var i = 0; i < air.dests.length; i++)
			{
				dest_air		= getAirport( air.dests[i] );
				toList.length	+= 1;
				var l_ix		= toList.length - 1;
				var opt_str		= dest_air.name;
				if ( searchPrefs.DISPLAY_AIRPORT_CITY_CODES == 'true' )
				{
					opt_str		+=  " (" + dest_air.code + ")";
				}
				toList.options[l_ix]	= new Option( opt_str );
				toList.options[l_ix].value	= dest_air.code;
				if ( dest == dest_air.code )
				{
					toList.selectedIndex	= l_ix;
				}
			}
		}
		setDest( mkt );
	}
	function resetDates(checkDates)
	{
		var m1d_ix		= document.skylightsForm.departDay1.selectedIndex;
		var m1y_ix		= document.skylightsForm.departMonth1.selectedIndex;
		if ( checkDates ) {
			if ( m1y_ix > document.skylightsForm.departMonth2.selectedIndex ) {
				document.skylightsForm.departMonth2.selectedIndex	=  m1y_ix;
				document.skylightsForm.departDay2.selectedIndex	=  m1d_ix;
			}
			if ( ( (m1y_ix) == document.skylightsForm.departMonth2.selectedIndex )
			  && ( m1d_ix > document.skylightsForm.departDay2.selectedIndex ) ) {
				document.skylightsForm.departDay2.selectedIndex	=  m1d_ix;
			}
		}
	}
	function validCities()
	{
		var is_valid	= true;
		if ( document.skylightsForm.from1.selectedIndex == 0 )
		{
			alert( searchText.missingDepartCity );
			is_valid	= false;
		}
		else if ( document.skylightsForm.to1.selectedIndex == 0 && BanderitaPaginaIntermedia == false)
		{
			alert( searchText.missingArriveCity );
			is_valid	= false;
		}
		else if ((searchPrefs.OFFER_OPEN_JAW_ROUTES == "true") && (document.skylightsForm.travel[2].checked))
		{
			is_valid = validateOpenJawConnections();
		}
		return is_valid;
	}
	function validPax()
	{
		var adults = document.skylightsForm.ADULT.value;
		var infants = document.skylightsForm.INFANT.value;
		var paxTotal = 0;
		for (i = 0; i < searchPrefs.paxTypes.length; i++)
		{
			var paxType 	= searchPrefs.paxTypes[i];
			var paxSelect	= document.getElementById(paxType +"Select");
			paxTotal		= eval(paxTotal) + eval(paxSelect.options[paxSelect.selectedIndex].value);
		}
		if ((paxTotal > searchPrefs.MAX_PASSENGERS_ALLOWED) && ( searchPrefs.MAX_PASSENGERS_ALLOWED > 0 ))
		{
			alert("\n"	+ searchText.popup_max_passenger_amount_1
						+ searchPrefs.MAX_PASSENGERS_ALLOWED
						+ searchText.popup_max_passenger_amount_2 + "\n");
			return false;
		}
		if ( paxTotal < 1)
		{
			alert(searchText.popup_missing_passenger_amount);
			return false;
		}
		if ( (adults  / infants) < 1 )
		{
			alert(searchText.popup_too_many_infants);
			document.skylightsForm.INFANT.focus();
			return false;
		}
		return true;
	}
	function validDates(beginDate, endDate)
	{
		var is_valid			= true;
		var beginDateString		= new String (beginDate);
		var endDateString		= new String (endDate);
		var departDateString	= captureDateString("departDay1", "departMonth1");
		var arriveDateString	= captureDateString("departDay2", "departMonth2");
		date_message = searchText.popup_pre_flight_date_1 +
						searchText.popup_initial_flight_date +
						searchText.popup_pre_flight_date_2;
						
						//alert("fecha: " + departDateString + "   -   " + endDateString);
		if ( departDateString <= beginDateString )
		{
			alert( date_message );
			setDate( "departDay1", "departMonth1", beginDateString );
			if( isRoundTrip() && arriveDateString < beginDateString )
				setDate( "departDay2", "departMonth2", beginDateString );
			return false;
		}
		if ( searchPrefs.final_date_used )
		{
			if( departDateString >= endDateString )
			{
				is_valid = false;
				setDate( "departDay1", "departMonth1", endDateString );
			}
			if( isRoundTrip() && ( arriveDateString > endDateString ) )
			{
				is_valid = false;
				setDate( "departDay2", "departMonth2", endDateString );
			}
			if( !is_valid )
			{
				alert( searchText.popup_post_live_flight_date_1 +
						searchText.popup_final_flight_date +
						searchText.popup_post_live_flight_date_2 );
				return false;
			}
		}
		if(!validateCalendarDate("departDay1", "departMonth1", true, true))
		{
			if( isRoundTrip() || ( !isOneWay() && searchPrefs.OFFER_OPEN_JAW_ROUTES == 'true' ) )
			{
				validateCalendarDate("departDay2", "departMonth2", false, true);
			}
			return false;
		}
		if(	( isRoundTrip() || ( !isOneWay() && searchPrefs.OFFER_OPEN_JAW_ROUTES == 'true' ) ) && !validateCalendarDate("departDay2", "departMonth2", true, true) )
		{
			return false;
		}
		if ( isRoundTrip() || ( !isOneWay() && searchPrefs.OFFER_OPEN_JAW_ROUTES == 'true' ) )
		{
			if ( !validateDateOverlap("departDay1", "departMonth1", "departDay2", "departMonth2", true, true) )
			{
				return false;
			}
			else if ( searchText.sameDayWarning && arriveDateString == '' + departDateString )
			{
				alert(MensajeErrorFechasIguales);
				return false;
				is_valid		= confirm( searchText.sameDayWarning );
			}
		}
		return is_valid;
	}
	
	
	
	
	function formatDates()
	{
		document.skylightsForm.departDate1.value		= 		captureDateString("departDay1", "departMonth1");
		if ( document.skylightsForm.numberMarkets.value > 1 )
		{
			document.skylightsForm.departDate2.value	= captureDateString("departDay2", "departMonth2");
		}
	}
	function validateOpenJawConnections()
	{
		if ( ( ( document.skylightsForm.from1.value == document.skylightsForm.to2.value ) ||
				( document.skylightsForm.to1.value == document.skylightsForm.from2.value ) ) 
				&& ( document.skylightsForm.from2.value != '???') && ( document.skylightsForm.to2.value != '???'))
		{
			return true;
		}
		else
		{
			alert(searchText.popup_illogical_open_jaw);
			return false;
		}
	}
	function isOneWay()
	{
		return ( document.skylightsForm.travel[1].checked );
	}
	function isRoundTrip()
	{
		return ( document.skylightsForm.travel[0].checked );
	}
	function swapTravel()
	{
		if ( document.skylightsForm.travel[0].checked )
		{
			document.skylightsForm.numberMarkets.value			= 2;
			showDiv(true, 'dateSel2');
			if (searchPrefs.OFFER_OPEN_JAW_ROUTES == 'true')
			{
				showDiv(false, 'fromToSel2');
			}
		}
		else if ( document.skylightsForm.travel[1].checked )
		{
			document.skylightsForm.numberMarkets.value			= 1;
			showDiv(false, 'dateSel2');
			if (searchPrefs.OFFER_OPEN_JAW_ROUTES == 'true')
			{
				showDiv(false, 'fromToSel2');
			}
		}
		else
		{
			document.skylightsForm.numberMarkets.value			= 2;
			showDiv(true, 'dateSel2');
			showDiv(true, 'fromToSel2');
		}
		if (eval(document.skylightsForm.farePriority))
		{
			showDateFlex();
		}
		balanceHeight('wrapper', 'right', 'left');
	}
	function showDateFlex()
	{
		var option_val = document.skylightsForm.farePriority[document.skylightsForm.farePriority.selectedIndex].value;
		var elem_id;
		for (i = 1; i <= document.skylightsForm.numberMarkets.value; i++)
		{
			elem_id = "depart" + i + "FlexBySelect";
			if (option_val == 1) 
			{
			      showDiv(true, elem_id,'inline');
			}
			else  
			{
			      showDiv(false, elem_id );
			}
		}
	}
	function submitSearch(beginDate, endDate)
	{
		if ( validCities() && validDates(beginDate, endDate) && validPax())
		{
			finalDate();
			document.skylightsForm.page.value 	= 'SEARCH';
			document.skylightsForm.module.value	= 'SB';			
			document.skylightsForm.event.value 	= 'search';
			
			/**
			 * Muestra la capa de espera para la busqueda
			 */
			document.getElementById("EsperaPop").style.visibility="visible";
			document.getElementById("EsperaPop").focus();
			document.getElementById("contenedor").style.visibility="hidden";
			
			
			document.skylightsForm.submit();
		}
	}
	function onLoadAtaGlance()
	{
		swapTravel();
		for (i = 1; i <= document.skylightsForm.numberMarkets.value; i++)
		{
			resetDest(i);
		}
	}
