/*#############################################################################

FILE:	SB/serviceSearch.js

	Copyright (c) 2006 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 service search forms.

#############################################################################*/

var serviceSearchPrefs	= new Object();
var serviceSearchText	= new Object();
captureServiceSearchPrefs(serviceSearchPrefs);
captureServiceSearchText(serviceSearchText);


/* JavaScript for Hotel Search Form */
/*##############################################
#
# Function: hotelSubmitForm()
#
# Parameter: 
#		beginDate : Start date search parameter
#		
#			
# Description: 
#	       Submits the form with the hotel search parameter 
#	       for a given date.
#	       
#*/
function hotelSubmitForm(beginDate)
{
	var okay		= verifyPassengerData();
	if( okay && verifyHotelData() && verifyHotelDates(beginDate) )
	{
		document.skylightsForm.page.value		= 'CONTACT';
		document.skylightsForm.module.value		= 'SB';
		document.skylightsForm.event.value		= 'hotel';
		document.skylightsForm.submit();
	}
}

/*##############################################
#
# Function: verifyPassengerData()
#
# Parameter: 
#		
#			
# Description: 
#	       Validate if there are no numbers of pax referred
#	       before a availabilty search can proceed
#
# Return  : 
#	      True: > 0 pax
#	      False: <= 0 pax 
#*/
function verifyPassengerData()
{
	var adult		= document.skylightsForm.adult.options[ document.skylightsForm.adult.selectedIndex ].value;
	var child		= 0;
	var okay		= true;

	if ( serviceSearchPrefs.OFFER_CHILDREN == "true" ) {
		child		= document.skylightsForm.adult.options[ document.skylightsForm.child.selectedIndex ].value;
	}
	if ( adult + child <= 0 )
	{
		alert( serviceSearchText.setHotelPaxCount );
		okay		= false;
	}
	return okay;
}

/*##############################################
#
# Function: verifyHotelData()
#
# Parameter: 
#		
#			
# Description: 
#	       Validate if there are no selected city 
#	       in the city field.
#
# Return  : 
#	      True: there is a city selected
#	      False: no city selected
#*/
function verifyHotelData()
{
	if( document.skylightsForm.hotelCity.value == "???" )
	{
		return false;
	}
	else
	{
		return true;
	}
}

/*##############################################
#
# Function: verifyHotelDates()
#
# Parameter: 
#		beginDate : Start date search parameter
#			
# Description: 
#	       Validate if the date provided overlaps
#	       with the departure or return date.
#
# Return  : 
#	      True: date is valid
#	      False: date overlaps with either departure or return date
#*/
function verifyHotelDates(beginDate)
{
	var is_valid			= true;

	//set Hotel specific errors
	dateText.datesOverlapDepart = dateText.datesOverlapDepartHotel;
	dateText.datesOverlapReturn = dateText.datesOverlapReturnHotel;

	// first check that dates are valid calandar dates
	if(!validateCalendarDate("checkinDay1", "checkinMonth1", true, true))
	{
		is_valid = false;
	}
	else if(!validateCalendarDate("checkoutDay1", "checkoutMonth1", true, true))
	{
		is_valid = false;
	}
	else if(!validateFutureDate("checkinDay1", "checkinMonth1", beginDate, true, true))
	{
		is_valid = false;
	}
	else if ( !validateDateOverlap("checkinDay1", "checkinMonth1", "checkoutDay1", "checkoutMonth1", true, true) )
	{
		is_valid		= false;
	}

	return is_valid;
}


/* JavaScript for Car Search Form */
/*##############################################
#
# Function: carSubmitForm()
#
# Parameter: 
#		beginDate : Start date search parameter
#			
# Description: 
#	       Submits the form with the car search parameter 
#	       for a given date.
#
#*/
function carSubmitForm(beginDate)
{	
	if( verifyCarData() && verifyCarDates(beginDate))
	{
		document.skylightsForm.page.value		= 'CONTACT';
		document.skylightsForm.module.value		= 'SB';
		document.skylightsForm.event.value		= 'car';
		document.skylightsForm.submit();
	}
}
/*##############################################
#
# Function: verifyCarData()
#
# Parameter: 
#		beginDate : Start date search parameter
#			
# Description: 
#	       Varifies if there are no selected pickup date/time 
#	       for pick-up or drop-off fields
#
# Return :  true : fields have values
#           false: fields does not have valid values.
#*/
function verifyCarData(beginDate)
{
	if(document.skylightsForm.pickUp.value == "???" || document.skylightsForm.dropOff.value == "???")
	{
		return false;
	}
	else
	{
		return true;
	}
}
/*##############################################
#
# Function: verifyCarDates()
#
# Parameter: 
#		beginDate : Start date search parameter
#			
# Description: 
#	       Varifies if there are no overlaps from the pick-up or drop-ff dates
#	       wtih the depart or return dates.
#
# Return :  true : dates are valid
#           false: dates overlaps with either return or departure date.
#*/
function verifyCarDates(beginDate)
{
	var is_valid			= true;

	//set Car specific errors
	dateText.datesOverlapDepart = dateText.datesOverlapDepartCar;
	dateText.datesOverlapReturn = dateText.datesOverlapReturnCar;

	// first check that dates are valid calandar dates
	if(!validateCalendarDate("carPickupDay", "carPickupMonth", true, true))
	{
		is_valid = false;
	}
	else if(!validateCalendarDate("carDropoffDay", "carDropoffMonth", true, true))
	{
		is_valid = false;
	}
	else if(!validateFutureDate("carPickupDay", "carPickupMonth", beginDate, true, true))
	{
		is_valid = false;
	}
	else if ( !validateDateOverlap("carPickupDay", "carPickupMonth", "carDropoffDay", "carDropoffMonth", true, true) )
	{
		is_valid		= false;
	}
	else if ( validateSameDate("carPickupDay", "carPickupMonth", "carDropoffDay", "carDropoffMonth", false) )
	{
		if ( !validateFutureTime(document.skylightsForm.carPickupTime.value, document.skylightsForm.carDropoffTime.value, true) )
		{		
			is_valid = false;		
		}
	}		

	return is_valid;
}


/* JavaScript for Activity Search Form */
/*##############################################
#
# Function: activitySubmitForm()
#
# Parameter: 
#		beginDate : Start date search parameter
#			
# Description: 
#	       Submits the form with the activity search parameter 
#	       for a given date.
#
#*/
function activitySubmitForm(beginDate)
{			
	if( verifyActivityData() && verifyActivityDates(beginDate) )
	{
		document.skylightsForm.page.value		= 'CONTACT';
		document.skylightsForm.module.value		= 'SB';
		document.skylightsForm.event.value		= 'activity';
		document.skylightsForm.submit();
	}
}
/*##############################################
#
# Function: verifyActivityData()
#
# Parameter: 
#		
#			
# Description: 
#	       Verifies if the city field has a valid value
#	       
# Return: true: has valid city value
#	  false: has invalid city value
#*/
function verifyActivityData()
{
	if(document.skylightsForm.activityCity.value == "???" )
	{
		return false;
	}
	else
	{
		return true;
	}
}
/*##############################################
#
# Function: verifyActivityDates()
#
# Parameter: 
#		beginDate : Start date search parameter
#			
# Description: 
#	       arifies if there are no overlaps from the activity dates
#	       with the depart or return dates.
#	       
# Return: true: no date overlaps
#	  false: has date overlaps
#*/
function verifyActivityDates(beginDate)
{
	var is_valid			= true;

	//set Activity specific errors
	dateText.datesOverlapDepart = dateText.datesOverlapDepartAct;
	dateText.datesOverlapReturn = dateText.datesOverlapReturnAct;

	// first check that dates are valid calandar dates
	if(!validateCalendarDate("activityStartDay1", "activityStartMonth1", true, true))
	{
		is_valid = false;
	}
	else if(!validateCalendarDate("activityEndDay1", "activityEndMonth1", true, true))
	{
		is_valid = false;
	}
	else if(!validateFutureDate("activityStartDay1", "activityStartMonth1", beginDate, true, true))
	{
		is_valid = false;
	}
	else if ( !validateDateOverlap("activityStartDay1", "activityStartMonth1", "activityEndDay1", "activityEndMonth1", true, true) )
	{
		is_valid		= false;
	}

	return is_valid;
}