/*#############################################################################

FILE:	SB/contact.js

	Copyright (c) 2005 Navitaire Inc. All rights reserved.

	This source code is (i) proprietary to and a trade secret of Navitaire Inc.
	and (ii) protected by copyright law and international treaties.
	Unauthorized disclosure, reproduction, distribution or alteration of this
	source code, or any portion of it, may result in severe civil and criminal
	penalties and will be prosecuted to the maximum extent possible under
	the law.

	www.navitaire.com

DESCRIPTION:

	Contains javascript for the search form.  Note that this file relies on
	javascript from the jContact.wld template.

#############################################################################*/

var contactPrefs = new Object();
captureContactPrefs(contactPrefs);

/*####################################################
#
# Function: onLoadContact()
#
# Description:
#	This is the on load event for the contact page.
#
*/
function onLoadContact()
{
	if ( contactPrefs.EZREZ_ENABLED == "true" )
	{
		if ( contactPrefs.CAR_ENABLED == "true" )
		{
			showSSRs('carBody', document.skylightsForm.findCar.checked);
			if (contactPrefs.ACTIVE_CAR_VENDOR == "TRAVEL_COMMERCE")
			{
				setSourceCodeValues(tc_car_source_country, 'Car');
			}
		}

		if ( contactPrefs.HOTEL_ENABLED == "true" )
		{
			showSSRs('hotelBody', document.skylightsForm.findHotel.checked);
			if (contactPrefs.ACTIVE_HOTEL_VENDOR == "TRAVEL_COMMERCE")
			{
				setSourceCodeValues(tc_hotel_source_country, 'Hotel');
			}
		}

		if ( contactPrefs.ACTIVITY_ENABLED == "true" )
		{
			showSSRs('activityBody', document.skylightsForm.findActivity.checked);
		}
	}

	//setStateValues(state);
	//setCountryValues(country);
}

/*####################################################
#
# Function: submitForm()
#
# Description:
#	Sends the contact information for submission.
#	Goes to the Passenger page.
#
# Parameters:
#	action*	- the form action to submit to. If no
#			action is passed, the form action already
#			set in the form will be used.
#
*/
function submitForm(action)
{
	if ( verifyFormData() )
	{
		if (action)
		{
			document.skylightsForm.action		= action;
		}
		document.skylightsForm.page.value		= 'CONTACT';
		document.skylightsForm.module.value		= 'SB';
		document.skylightsForm.event.value 		= 'contact';
		// Ganalytix
	  action = document.skylightsForm.action;
		if (action.indexOf('step') == -1){
		  action = action  + '?step=3';
		}
		document.skylightsForm.action = action;
		document.skylightsForm.submit();
	}
}


/*####################################################
#
# Function: showSSRs()
#
# Description:
#	Displays and hide the services search options.
#
# Parameters:
#	whichBox - The service type.
#	bool	 - 0 - hide
#		   1 - show
#
*/
function showSSRs( whichBox, bool )
{

	if(!document.getElementById || !document.createTextNode)
	{
		return true;
	}

	var ds = document['SkySales'];
	var hotelSearch	= document.getElementById(whichBox);

	if ( bool )
	{
		hotelSearch.style.display = "block";
	}else{
		hotelSearch.style.display = "none";
	}
}

/*####################################################
#
# Function: setStateValues()
#
# Description:
#	Sets the correct defaut value in the state field.
#
# Parameters:
#	state - The state to set as default.
#
*/
function setStateValues( state )
{
}

/*####################################################
#
# Function: setCountryValues()
#
# Description:
#	Sets the correct defaut value in the country field.
#
# Parameters:
#	country - The state to set as default.
#
*/
function setCountryValues( country )
{
	if (contactPrefs.USE_COUNTRY_LIST == "false")
	{
		document.skylightsForm.country.value = country;
	}
	else
	{
		for ( i = 0; i < document.skylightsForm.country.length; i++)
		{
			if ( document.skylightsForm.country.options[i].value == country && country != "" )
			{
				document.skylightsForm.country.selectedIndex	= i;
				break;
			}
		}
		if ( i+1 == document.skylightsForm.country.length )
		{
			document.skylightsForm.country.selectedIndex = 0;
		}
	}
}

/*####################################################
#
# Function: setSourceCodeValues()
#
# Description:
#	Sets the correct defaut value in the source country
#		field in the Travel Commerce search section.
#
# Parameters:
#	country - The 2 letter country code to set as default.
#
*/
function setSourceCodeValues( country, searchtype )
{
	var sourceCodeKey = eval("document.skylightsForm.sourceSelect" + searchtype);
	var TCDefaultIndex = 0;
	var defaultFound = false;
	
	if (sourceCodeKey != null)
	{
		for ( i = 0; i < sourceCodeKey.length; i++)
		{
			if ( sourceCodeKey.options[i].value == country && country != "" )
			{
				sourceCodeKey.selectedIndex	= i;
				defaultFound = true;
				break;
			}

			if ( sourceCodeKey.options[i].value == "INT" )
			{
				TCDefaultIndex = i;
			}
		}

		// If the country of the flight origin city is not among the list of valid
		// countries returned by Travel Commerce, set the default source country to be 
		// the Travel Commerce default country.
		//
		if (!defaultFound)
		{
			sourceCodeKey.selectedIndex = TCDefaultIndex;
		}
	}
}