function AutoComplete(){}
AutoComplete.divName = '';

function initRequest() {
	   if (window.XMLHttpRequest) {
			 return new XMLHttpRequest();
       } else if (window.ActiveXObject) {
			isIE = true;
           return new ActiveXObject("Microsoft.XMLHTTP");
       }
   }

	function setAirportLocation(locationType, locationString) 
	{
		if(document.forms["main"].elements[locationType])
			document.forms["main"].elements[locationType].value = locationString;
		if(document.getElementById(locationType))
			document.getElementById(locationType).value = locationString;
	}
 	
   function showLocationAirportCode(DD,locationValue,locationType, productType, index) 
   { 
	   var req;
       if (locationValue.value == "" || locationValue.length == 0) 
	   {
		    var i = locationType.substring(locationType.length -1);
			locationType = locationType.substring(0, locationType.length-1);
			locationType = locationType.concat("Airport").concat(i);
	
			var divTag = document.getElementById(locationType);	
         	divTag.innerHTML = "";
            divTag.style.visibility = "hidden";
            return;
       } 
       else if(locationValue.length >= 3)
	   {   
	       var url = "PrepareAirportNameList?DD="+escape(DD)+"&"+escape(locationType)+"="+ escape(locationValue)+"&product="+escape(productType);
           var req = initRequest();
		  
           req.onreadystatechange = function() 
		   {
				if (req.readyState == 4) 
				{
					if (req.status == 200) 
					{  
						parseMessages(req.responseText,locationType, index);
					}		
	            }
           };
		req.open("GET", url, true);
		req.send(null);
       }
   }

   function showFromLocationAirportCode(DD,fromLocation, productType) 
   {
	   var req;
       if (fromLocation.value == "" || fromLocation.length == 0) 
	   {
          document.getElementById("displayFromLocationAirportNames").innerHTML = "";
          document.getElementById("displayFromLocationAirportNames").style.visibility = "hidden";
          return;
       } 
       else if( fromLocation.length >= 3)
	   {
	       var url = "PrepareAirportNameList?DD="+escape(DD)+"&fromLocation="+escape(fromLocation)+"&product="+escape(productType);
           var req = initRequest();
		  
           req.onreadystatechange = function() 
		   {
				if (req.readyState == 4) 
				{
					if (req.status == 200) 
					{
						parseFromMessages(req.responseText);
					}		
	            }
           };
		req.open("GET", url, true);
		req.send(null);
       }
   }

  function showToLocationAirportCode(DD,toLocation,productType) 
  {    
  	   var req;
       if (toLocation.value == "" || toLocation.length == 0 ) 
	   {
      	  document.getElementById("displayToLocationAirportNames").innerHTML = "";	
          document.getElementById("displayToLocationAirportNames").style.visibility="hidden";
          return;
       } 
       else if(toLocation.length >= 3)
	   {
	       var url = "PrepareAirportNameList?DD="+escape(DD)+"&toLocation="+escape(toLocation)+"&product="+escape(productType);
           var req = initRequest();
		  
           req.onreadystatechange = function() 
		   {
				if (req.readyState == 4) 
				{
					if (req.status == 200) 
					{
						parseToMessages(req.responseText);
					}		
	            }
           };
		req.open("GET", url, true);
		req.send(null);
       }
   }


function parseMessages(responseText, locationType, index) 
{    
		if(AutoComplete.divName != index){ 
			return false;
		}
		var i = locationType.substring(locationType.length -1);
		locationType = locationType.substring(0, locationType.length-1);
		locationType = locationType.concat("Airport").concat(i);
	
		var divTag = document.getElementById(locationType);
		var iframeTag = document.getElementById(index);
		iframeTag.style.display = "block";
		divTag.style.visibility = "visible";
		
		if(responseText != "")
		{
			divTag.innerHTML =responseText
		}
		else
		{
			divTag.innerHTML = "";
			divTag.style.visibility = "hidden";
		}
}

function parseFromMessages(responseText) 
{
		if(AutoComplete.divName != 'iframeId1'){
			return false;
		}
		var divTag = document.getElementById("displayFromLocationAirportNames");
		var iframeTag = document.getElementById("iframeId1");
		iframeTag.style.display = "block";
		divTag.style.visibility = "visible";
		if(responseText != "")
		{
			divTag.innerHTML =responseText
		}
		else
		{	
			divTag.innerHTML = "";
			divTag.style.visibility = "hidden";
		}
}

function parseToMessages(responseText) 
{
		if(AutoComplete.divName != 'iframeId2'){
			return false;
		}
		var divTag = document.getElementById("displayToLocationAirportNames");
		var iframeTag = document.getElementById("iframeId2");
		iframeTag.style.display = "block";
		divTag.style.visibility = "visible";
		if(responseText != "")
		{
			divTag.innerHTML =responseText;
		}
		else
		{	
			divTag.innerHTML = "";
			divTag.style.visibility = "hidden";
		}
}

function startHide(id)
{  
    if(document.getElementById(id))
	document.getElementById(id).style.visibility="hidden"
}

function hideDiv()
{
	var fromLocation = document.getElementById("displayFromLocationAirportNames")
	if(fromLocation != null)
	{
		fromLocation.style.visibility="hidden"
		var toLocation = document.getElementById("displayToLocationAirportNames")
		if(toLocation)
		toLocation.style.visibility="hidden"	
		
		var hotelLocation=document.getElementById("hotelLocatioAirportn")	
		if(hotelLocation)
		hotelLocation.style.visibility="hidden"
		
		var fromLocation1 = document.getElementById("fromLocationAirport1")
		if(fromLocation1)
		fromLocation1.style.visibility='hidden'
		var toLocation1 = document.getElementById("toLocationAirport1")
		if(toLocation1)
		toLocation1.style.visibility='hidden'
		
		var fromLocation2 = document.getElementById("fromLocationAirport2")
		if(fromLocation2)
		fromLocation2.style.visibility='hidden'
		var toLocation2 = document.getElementById("toLocationAirport2")
		if(toLocation2)
		toLocation2.style.visibility='hidden'
		
		var fromLocation3 = document.getElementById("fromLocationAirport3")
		if(fromLocation3)
		fromLocation3.style.visibility='hidden'
		var toLocation3 = document.getElementById("toLocationAirport3")
		if(toLocation3)
		toLocation3.style.visibility='hidden'
		
		var fromLocation4 = document.getElementById("fromLocationAirport4")
		if(fromLocation4)
		fromLocation4.style.visibility='hidden'
		var toLocation4 = document.getElementById("toLocationAirport4")
		if(toLocation4)
		toLocation4.style.visibility='hidden'
		
		var fromLocation5 = document.getElementById("fromLocationAirport5")
		if(fromLocation5)
		fromLocation5.style.visibility='hidden'
		var toLocation5 = document.getElementById("toLocationAirport5")
		if(toLocation5)
		toLocation5.style.visibility='hidden'
		
		var fromLocation6 = document.getElementById("fromLocationAirport6")
		if(fromLocation6)
		fromLocation6.style.visibility='hidden'
		var toLocation6 = document.getElementById("toLocationAirport6")
		if(toLocation6)
		toLocation6.style.visibility='hidden'
	}
}

function highlight(item,bcolor,textcolor )
{

	if (document.all||document.getElementById)
	{
		item.style.backgroundColor=bcolor;
		item.style.width="auto";
		item.style.color =textcolor;
	}
}

function underline(item, line )
{
	if (document.all||document.getElementById)
	{
		item.style.textDecoration = line;
	}
}

function productType()
{
	var product = "";
  	if (document.main.products != null)	
	{
		for (var i=0; i < document.main.products.length; i++)
		{
			if(document.main.products[i].checked)
			{
				var product = document.main.products[i].value;
				break;
			}
		}
                if(product == "")
                {
                  product = document.main.products.value;
                }
		return product;
	}
}

   function getHotelLocation(DD,locationValue) 
   { 
       var req;
       if(locationValue.length >= 3)
       {   
	   var url = "PrepareAirportNameList?DD="+escape(DD)+"&product="+escape('H')+"&hotelLocation="+locationValue;
           var req = initRequest();
		  
           req.onreadystatechange = function() 
		   {
				if (req.readyState == 4) 
				{
					if (req.status == 200) 
					{  
						document.getElementById("displayFromLocationAirportNames").innerHTML = req.responseText;
						document.getElementById("displayFromLocationAirportNames").visibility = "visible";
						//parseMessages(req.responseText,locationType, index);
					}		
	                        }
	           }
	   req.open("GET", url, true);
	   req.send(null);
       }
   }
   
      function showLocationAirportCode1(DD,locationValue,locationType, productType, index) 
   { 
	   var req;
	   locationValue = Field.trim(locationValue);
       if (Field.isWhite(locationValue)) 
	   {
		    var i = locationType.substring(locationType.length -1);
			locationType = locationType.substring(0, locationType.length-1);
			locationType = locationType.concat("Airport").concat(i);
	
			var divTag = document.getElementById(locationType);	
         	divTag.innerHTML = "";
            divTag.style.visibility = "hidden";
            return;
       } 
       else if(locationValue.length >= 3 && Field.isAlphaNumericSpace(locationValue))
	   {   
	       var url = "PrepareAirportNameList?DD="+escape(DD)+"&"+escape(locationType)+"="+ escape(locationValue)+"&product="+escape(productType);
           var req = initRequest();
		  
           req.onreadystatechange = function() 
		   {
				if (req.readyState == 4) 
				{
					if (req.status == 200) 
					{  
						parseMessages(req.responseText,locationType, index);
					}		
	            }
           };
		req.open("GET", url, true);
		req.send(null);
       }
   }
   

