/*#############################################################################

FILE:	C3/lookup.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 PNR lookup page.

#############################################################################*/
// edited by yogesh sharma


// Begin PNR Lookup Submit Form javascript
   var searchPrefs	= new Object();  
   captureSearchPrefs(searchPrefs);
function getDest()
{
  var ori=document.getElementById("origin_city");
  alert('origin '+ori.value);
  
}
function resetDest_LookUp(  )
			{
			 
       var fromList                        = document.getElementById( "origin_city" );
			//one roundtrip, this is called for market2, but we have hidden the controls
			if (!fromList)
			{
			return;
			}

			var toList                              = document.getElementById("destination_city" );
			var orig                 = fromList.options[ fromList.selectedIndex ].value;
			
			while (toList.hasChildNodes()) {
			   toList.removeChild(toList.firstChild);
		          	}
			toList.length       = 1;
			toList.options[0] = new Option("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 ( fromList.selectedIndex == 0 )
      
      else
      {
   
			var notinternational = 0  ;
			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;
			var opt;
			var opt2;

			if ( searchPrefs.DISPLAY_AIRPORT_CITY_CODES == 'true' )
			{
			opt_str                 +=  " (" + dest_air.code + ")";
			}

          
			if( eval("searchPrefs."+dest_air.code+"ValidINTCITYRTT")  == 'true' )
			{
			opt         = document.createElement("option");
			opt.value              = dest_air.code;
			opt.appendChild(document.createTextNode(opt_str));
			opt.setAttribute('style', 'font-size: .98em;color: #c42db8;font-weight: bold;padding-left:0px;padding-top:2px;padding-bottom:2px;');
			toList.appendChild(opt);
			}
			else
			{
			opt          = document.createElement("option");
			opt.value              = dest_air.code;
			opt.appendChild(document.createTextNode(opt_str));
			opt.setAttribute('style', 'font-size: .98em;color: #1d3d90;padding:0px;border:none');
			toList.appendChild(opt);
			}
			}
		       }
		      

}



	/*function submitLookup(fields)
	{
		alert(fields);
		if ( validateFields())
		{
			document.skylightsForm.event.value = 'lookup';
			document.skylightsForm.submit();
		}
	}

	function validateFields()
	{
		return true;
	}*/
	

	var Airports	= buildAirports();
	/*##############################################
	#
	# Function: airport()
	#	
	# Parameter: 
	#		m: mac airport 
	#		c: origin Airport code
	#		n: origin airport name
	#		d: destination city
	#
	# Description: 
	#	       Collects the airport information and
	#	       stores it in a single string.
	#	       
	#*/
	function airport(m, c, n, d)
	{
		this.mac		= m;
		this.code	= c;
		this.name	= n;
		this.dests	= d;

		this.display	= function ()
		{
			var msg		=  "Airport: "
						+ "\n   code: " + this.code
						+ "\n   name: " + this.name
						+ "\n   dests: ";
			for (var i=0; i < this.dests.length; i++)
			{
				msg		+= "'" + this.dests[i] + "', ";
			}
			alert( msg );
		};
	}
	/*##############################################
	#
	# Function: getAirport()
	#	
	# Parameter: 
	#		code: mac airport 
	#		
	#
	# Description: 
	#	       Returns the hash information of a specific airport requested.
	#	       
	#*/
	function getAirport( code )
	{
		var air;
		for (var i=0; i < Airports.length; i++)
		{
			if ( Airports[i].code == code )
			{
				air		= Airports[i];
				break;
			}
		}
		return air;
	}
