/*#############################################################################

FILE:	util.js

	Copyright (c) 2005-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 ataGlance utility section.

#############################################################################*/
	
	var utilCustom 	= new Object();
	captureUtilCustom(utilCustom);
	
	/*###############################
	#
	# Function: changeUtilDiv()
	#
	# Parameter: 	'login' 		- shows the login form as long as the
	#								  user isn't logged in.
	#				'flifo'			- shows the flight form
	#				'checkin'		- shows the check in form
	#
	# Description: Handles the switching of forms in the ataGlanceUtil section
	#				This is done by showing and hiding divs.  The page is not 
	#				submitted when just changing the form to display.
	#
	#################################*/

	function changeUtilDiv( selection )
	{
		if(( selection == "login" ) && ( utilCustom.mpEnabled == "on" ))
		{		
			if( document.getElementById( "loginUtils" ) )
			{
				var parentDivId = document.getElementById("loginUtilsMenu").parentNode.parentNode.parentNode.getAttribute('id');
				document.getElementById("loginUtilsMenu").className = parentDivId + "On";
				document.getElementById("checkinUtilsMenu").className = "";
				showDiv( true, "loginUtils" );
				showDiv( false, "checkinUtils" );
				showDiv( false, "checkinUtils1" );
				
				
			}
			else if( document.getElementById( "checkinUtilsMenu" ) )
			{
				var parentDivId = document.getElementById("loginUtilsMenu").parentNode.parentNode.parentNode.getAttribute('id');
				document.getElementById("checkinUtilsMenu").className = parentDivId + "On";
				selection = "aglogin";
				showDiv( false, "loginUtils" );
				showDiv( true, "checkinUtils" );
				showDiv( false, "checkinUtils1" );
				
				
			}
			else
			{
						
			var parentDivId = document.getElementById("checkinUtilsMenu").parentNode.parentNode.parentNode.getAttribute('id');
			document.getElementById("checkinUtilsMenu1").className = parentDivId + "On";
			selection = "aglogin1";
			        showDiv( false, "loginUtils" );
			        showDiv( false, "checkinUtils" );
				showDiv( true, "checkinUtils1" );
			}
			
			
			
			
		}
		else if(( selection == "aglogin" ) && ( utilCustom.ciEnabled == "on" ))
		{
			if( document.getElementById( "loginUtils" ) )
			{
				showDiv( false, "loginUtils" );
			}
			var parentDivId = document.getElementById("checkinUtilsMenu").parentNode.parentNode.parentNode.getAttribute('id');
			document.getElementById("loginUtilsMenu").className = "";
			document.getElementById("checkinUtilsMenu").className = parentDivId + "On";
			
		                showDiv( false, "loginUtils" );
				showDiv( true, "checkinUtils" );
				showDiv( false, "checkinUtils1" );	
			
		}
		
		else if(( selection == "aglogin1" ) && ( utilCustom.ciEnabled == "on" ))
				{
					if( document.getElementById( "loginUtils" ) )
					{
						showDiv( false, "loginUtils" );
					}
					var parentDivId = document.getElementById("checkinUtilsMenu").parentNode.parentNode.parentNode.getAttribute('id');
					document.getElementById("loginUtilsMenu").className = "";
					document.getElementById("checkinUtilsMenu").className = "";
					document.getElementById("checkinUtilsMenu1").className = parentDivId + "On";
				 showDiv( false, "loginUtils" );
				 showDiv( false, "checkinUtils" );
				showDiv( true, "checkinUtils1" );
					
		}
		
		document.skylightsForm.selectedUtil.value = selection;
		balanceHeight("wrapper", "left", "right");
	}


	/*##############################################
	#
	# Function: checkData()
	#	
	# Parameter: 
	#		
	# Description: 
	#	       Returns true if the fields in FL page are valid.
	#	       
	#*/
	function checkData()
	{
		var result = false;
		var origCity = document.skylightsForm.orig.options[document.skylightsForm.orig.selectedIndex].value;
		var destCity = document.skylightsForm.dest.options[document.skylightsForm.dest.selectedIndex].value;

		if (document.skylightsForm.flightnum.value != '')
		{
			result = true;
		}

		if ( (origCity != 'XXX') && (destCity != 'XXX') )
	 	{
			result = true;
		}

		if (result == false)
		{
			alert( utilCustom.popup_flight_or_orig_dest );
			return result;
		}

		if (origCity == destCity && origCity != 'XXX')
		{
			alert( utilCustom.popup_invalid_city_pair );
			return false;
		}

		return true;
	}



	/*##############################################
	#
	# Function: submitFLIFO()
	#	
	# Parameter: 
	#		
	# Description: 
	#	       Stores the serch parameters in the hidden input boxes and submits it for search
	#	       to start.
	#*/
	function submitFLIFO()
	{
		if ( checkData() )
		{	
			document.skylightsForm.flight_key.value
				= "";
			document.skylightsForm.flight_number.value
				= document.skylightsForm.flightnum.value;			
			document.skylightsForm.depart_date.value
				= document.skylightsForm.date.options[document.skylightsForm.date.selectedIndex].value;
			document.skylightsForm.arrive_city.value
				= document.skylightsForm.dest.options[document.skylightsForm.dest.selectedIndex].value;
			document.skylightsForm.depart_city.value
				= document.skylightsForm.orig.options[document.skylightsForm.orig.selectedIndex].value;

			document.skylightsForm.module.value = "FL";
			document.skylightsForm.page.value = "RESULTS";

			document.skylightsForm.submit();
		}
	}
	

	/*##############################################
	#
	# Function: checkDataCheckin()
	#	
	# Parameter: 
	#
	# Description: 
	#	       Verifies that the necessary fields are properly filled up.
	#	       Returns true if all are valid, false if otherwise.
	#	       
	#*/
	function checkDataCheckin()
	{
		var result = false;
		var origCity = document.skylightsForm.departFrom.options[document.skylightsForm.departFrom.selectedIndex].value;

		if (document.skylightsForm.confNum.value != '')
		{
			result = true;
		}

		if ( (origCity != 'XXX') )
		{
			result = true;
		}

		if (result == false)
		{
			alert("\nUSER.CUSTOM.popup_flight_or_orig_dest\n");
			return result;
		}

		return true;
	}

	/*##############################################
	#
	# Function: submitCheckin()
	#	
	# Parameter: 
	#
	# Description: 
	#	       If all data are properly filled-up then it starts the 
	#	       check-in process.
	#	       
	#*/
	function submitCheckin()
	{
		if ( checkDataCheckin() )
		{
			document.checkinForm.CityCode.value = document.skylightsForm.departFrom.value;
			document.checkinForm.RL. value = document.skylightsForm.confNum.value;
			document.checkinForm.submit();
		}

	}
	
	/*####################################################
	#
	# Function: submitLogin()
	#
	# Description:
	#	Handles the event of a user logging in or logging out.
	# 
	# Parameters:
	#	event - action (login or logout)
	#	
	*/
	function submitLogin(event,httpsaction)
	{
		var okay = false;
		
		if (httpsaction)
				       		{
				       			document.skylightsForm.action		= httpsaction;
		}
		

		if (!event)
		{
			event = 'login';
		}
		if (event == 'login')
		{
			okay = checkLogin();
			document.skylightsForm.log_in.value = 1;
		}

		if (okay)
		{
			if( utilCustom.loginModule != "" )
			{
				document.skylightsForm.page.value = utilCustom.loginPage;
				document.skylightsForm.module.value = utilCustom.loginModule;
			}
			document.skylightsForm.event.value = event;
			document.skylightsForm.submit();
		}
	}


/*#############################################################################

FILE:	AG/login.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 Login form.  Note that this file relies on
	javascript from the AG/jLogin.wld template.

#############################################################################*/

var AGloginText2 = new Object();

captureAGLoginText2(AGloginText2);


/*####################################################
#
# Function: submitForm()
#
# Description:
#	Sends the agency ID and password for login.
#
*/
function submitaglogin(httpsaction)

{


if (httpsaction)
		       		{
		       			document.skylightsForm.action		= httpsaction;
		}

	if (! document.skylightsForm.iata.value)
	{
		alert("Please enter Agency ID");
	}
	else if (! document.skylightsForm.iata_pw.value)
		{
			alert("Please enter Password");
		}
	else if (document.skylightsForm.iata.value.substring(0, 1) == 'C' || document.skylightsForm.iata.value.substring(0, 1) == 'K' || document.skylightsForm.iata.value.substring(0, 2) == 'SC' || document.skylightsForm.iata.value.substring(0, 2) == 'TC' )
	{
	    alert("You are not authorized, Please try at CorporateTravel Partner Login");
	}	
	
	else if ((!filterFieldValue(document.skylightsForm.iata)) || (!filterPasswordValue(document.skylightsForm.iata_pw, 4, 8)))
	{
		return;
	}
	else
	{
		document.skylightsForm.iata.value = document.skylightsForm.iata.value.toUpperCase();
		document.skylightsForm.iata_pw.value = document.skylightsForm.iata_pw.value.toUpperCase();
		document.skylightsForm.event.value = "login";
		document.skylightsForm.log_in.value = "1";
		document.skylightsForm.module.value= "C3";
		document.skylightsForm.page.value= "PNR_LIST";
		
				
		document.skylightsForm.submit();
	}
}


/*#############################################################################

FILE:	AG/login.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 Login form.  Note that this file relies on
	javascript from the AG/jLogin.wld template.

#############################################################################*/

var AGloginText1 = new Object();

captureAGLoginText1(AGloginText1);


/*####################################################
#
# Function: submitForm()
#
# Description:
#	Sends the agency ID and password for login.
#
*/
function submitaglogin1(httpsaction)
{

if (httpsaction)
		       		{
		       			document.skylightsForm.action		= httpsaction;
		}
	if (! document.skylightsForm.iata1.value)
	{
		alert("Please enter Corp ID");
	}
	else if (! document.skylightsForm.iata_pw1.value)
	{
		alert("Please enter Password");
	}
	
	else if (document.skylightsForm.iata1.value.substring(0, 1) != 'C' &&  document.skylightsForm.iata1.value.substring(0, 1) != 'K' && document.skylightsForm.iata1.value.substring(0, 2) != 'SC' && document.skylightsForm.iata1.value.substring(0, 2) != 'TC' )
	{
	    alert("You are not authorized, Please try at Travel Partner Login");
	}
	else if ((!filterFieldValue(document.skylightsForm.iata1)) || (!filterPasswordValue(document.skylightsForm.iata_pw1, 4, 8)))
	{
		return;
	}
	else
	{
		document.skylightsForm.iata.value = document.skylightsForm.iata1.value.toUpperCase();
		document.skylightsForm.iata_pw.value = document.skylightsForm.iata_pw1.value.toUpperCase();
		document.skylightsForm.event.value = "login";
		document.skylightsForm.log_in.value = "1";
		if ( document.skylightsForm.iata.value.substring(0, 3) == 'TCX' )
							
		{		
		document.skylightsForm.module.value= "AG";
		document.skylightsForm.page.value= "AGENCY_PROFILE";
							
		}
		else if ( document.skylightsForm.iata.value  == 'CDEL001' )
					{
					
					document.skylightsForm.module.value= "SB";
					document.skylightsForm.page.value="SEARCH";
			}	
		
		else
		{
		document.skylightsForm.module.value= "C3";
		document.skylightsForm.page.value= "PNR_LIST";
		}
			
		
				
		document.skylightsForm.submit();
	}
}


