﻿// JScript File
var xmlHttpnew=null;
var _Curr = -1;
var _Currpcode=-1;
var NUMBER_OF_RESULTS = 10;
var NUMBER_OF_RESULTSpcode = 10;
var availableResults = 0;
var availableResultspcode = 0;
var CurrentEventName="";
var CurrentEventId="";
var GSearchstr="";
var resultspcode = new Array();
var results= new Array();
var resultIndex=new Array();
var CurrentCity="";
var CurrentCountry="";
var NoHide=1;
var chkEnter='y';
var city="";
var Country="";
var i=0;
var LocationNameArray = new Array();
var LocationNameArraySort = new Array();
var xmlDoc;
var j=0;
var k=0;
var j=0;
var k=0;
var result;
var GData;

function ReadXML()
{
	var url="myworldV2/AllXML/MasterList.xml";
	var XmlHTTP = null;
	var Possibles = {0: "XMLHttpRequest()", 1: "ActiveXObject('Microsoft.XMLHttp')", 2:"ActiveXObject('MSXML2.XMLHttp')", 3:"ActiveXObject('MSXML2.XMLHttp.3.0')", 4:"ActiveXObject('MSXML2.XMLHttp.4.0')", 5:"ActiveXObject('MSXML2.XMLHttp.5.0')", 6:"ActiveXObject('MSXML2.XMLHttp.6.0')", 7:""};
	var Option = 0;
	try
	{		
		while(XmlHTTP == null)
		{
			XmlHTTP = eval("new " + Possibles[Option]);
		}

		XmlHTTP.open("get", url, false);
		XmlHTTP.send("");
		xmlDoc = XmlHTTP.responseXML;
	}
	catch(exception)
	{
		xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
		xmlDoc.async=false;
		xmlDoc.load(url);
	}

	if(XmlHTTP === null)
		return false;


	for(var i=0;i<=1000;i++)
	{
		LocationNameArray[i]="";
	}

	var lenR=xmlDoc.getElementsByTagName("R").length;
	var agent = navigator.userAgent.toLowerCase();


	if ((agent.indexOf("msie") > -1))
	{
		for(var RIndex=0;RIndex<xmlDoc.childNodes[0].childNodes.length;RIndex++)
		{
			for(var CIndex=0;CIndex<xmlDoc.childNodes[0].childNodes[RIndex].childNodes.length;CIndex++)
			{
				var name=xmlDoc.childNodes[0].childNodes[RIndex].childNodes[CIndex].getAttribute("n");
				if(xmlDoc.childNodes[0].childNodes[RIndex].childNodes[CIndex].childNodes.length==0)
				{
					var LID=xmlDoc.childNodes[0].childNodes[RIndex].childNodes[CIndex].getAttribute("LID");
					LocationNameArray[parseInt(LID)] = name;
					LocationNameArraySort.push(name);
				}
				else
				{
					for(var LIndex=0;LIndex<xmlDoc.childNodes[0].childNodes[RIndex].childNodes[CIndex].childNodes.length;LIndex++)
					{
						name = xmlDoc.childNodes[0].childNodes[RIndex].childNodes[CIndex].childNodes[LIndex].getAttribute("n");
						var LID=xmlDoc.childNodes[0].childNodes[RIndex].childNodes[CIndex].childNodes[LIndex].getAttribute("LID");				
						LocationNameArray[parseInt(LID)] = name;					
						LocationNameArraySort.push(name);

					}
				}
			}
		}
	}

	else
	{

		for(var i=0;i<lenR*2-1;i++)
		{
			k=i+1;
			if(k%2!=0)
			{
				var n=0;
				for(var m=0;m<(xmlDoc.childNodes[0].childNodes[k].childNodes.length)-1;m++)
				{
					n=m+1;
					if(n%2!=0)
					{
						if(xmlDoc.childNodes[0].childNodes[k].childNodes[n].hasChildNodes())
						{						
							var q=0;
							for(p=0;p<(xmlDoc.childNodes[0].childNodes[k].childNodes[n].childNodes.length)-1;p++)
							{
								q=p+1;
								if(q%2!=0)
								{
									name=xmlDoc.childNodes[0].childNodes[k].childNodes[n].childNodes[q].getAttribute('n');		
									var LID=xmlDoc.childNodes[0].childNodes[k].childNodes[n].childNodes[q].getAttribute("LID");
									LocationNameArray[parseInt(LID)] = name;
									LocationNameArraySort.push(name);
								}
							}
						}	
						else
						{
							name=xmlDoc.childNodes[0].childNodes[k].childNodes[n].getAttribute('n');		
							var LID=xmlDoc.childNodes[0].childNodes[k].childNodes[n].getAttribute("LID");
							LocationNameArray[parseInt(LID)] = name;
							LocationNameArraySort.push(name);
						}	
					}
				}						
			}
		}
	}
}

ReadXML();

function GetXmlHttpObjectNew()
{                
	try   
	{ 
		xmlHttpnew=new ActiveXObject("Microsoft.XMLHTTP");
	}
	catch (e)
	{              
		try
		{
			xmlHttpnew=new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch (e)
		{
			// Firefox, Opera 8.0+, Safari
			xmlHttpnew=new XMLHttpRequest();

		}
	}

	if(!xmlHttpnew&&typeof XMLHttpRequest != 'undefined')
	{
		xmlHttpnew = new XMLHttpRequest();
	}

	return xmlHttpnew;
}


function reloadInfo(elem)
{
	elem.style.backgroundColor="Transparent";
	//elem.style.backgroundColor="white";
	elem.style.color="Maroon";
}

function fnSelectedElement(elem,tbxID)
{
	document.getElementById(tbxID).focus();
	elem.style.backgroundColor="#cccccc";
	//elem.style.color="#FFFFFF";
	elem.style.color="#000000";
}

function refillTextBox(currObj,tbxID){
	var tokens; 
	var tokenisedInput = "";
	tokenisedInput += stripTags(currObj.innerHTML);
	document.getElementById(tbxID).value = tokenisedInput;
	document.getElementById(tbxID).value=document.getElementById(tbxID).value.replace("&amp;", "&") ;
	document.getElementById(tbxID).focus();
}

function stripTags(str){
	var stripped = str.replace(/(<([^>]+)>)/ig,"");
	return stripped;
}
function fnClose(tbxID)
{
  if (NoHide==0)
  {
   clearDropDownList(tbxID);
  }
}

function clearDropDownList(tbxID){
  
	try{
	      document.getElementsByTagName("body")[0].removeChild(document.getElementById("tbxHint"+tbxID));
		
	}catch(e){}
	
}

function xstooltip_show(tooltipId, parentId, posX, posY,wdT)
{
    it = document.getElementById(tooltipId);
    
    if ((it.style.top == '' || it.style.top == 0) 
        && (it.style.left == '' || it.style.left == 0))
    {
       
        it.style.width = it.offsetWidth + 'px';
        it.style.height = it.offsetHeight + 'px';
        
		img = document.getElementById(parentId); 
        
        posY=img.offsetHeight ;        
       
        if (posX + it.offsetWidth > img.offsetWidth) posX = img.offsetWidth - it.offsetWidth;
        if (posX < 0 ) posX = 0;
        if(navigator.appName.indexOf("Exp")>=0) //IE
        {
            it.style.width=wdT;
            posX=1;
	      x = xstooltip_findPosX(img) + posX;
        y = xstooltip_findPosY(img) + posY;
        
        it.style.top = y+1 ;
        it.style.left = x ;
        }
	else
	{
        
         posX=0;
	   x = xstooltip_findPosX(img) + posX;
        y = xstooltip_findPosY(img) + posY;
        
        it.style.top = y + 'px';
        it.style.left = x + 'px';
        }

      
    }
    it.style.visibility = 'visible'; 
}
function xstooltip_findPosY(obj) 
{
    var curtop = 0;
    if (obj.offsetParent) 
    {
        while (obj.offsetParent) 
        {
            curtop += obj.offsetTop
            obj = obj.offsetParent;
        }
    }
    else if (obj.y)
        curtop += obj.y;
    return curtop;
}
function xstooltip_findPosX(obj) 
{
  var curleft = 0;
  if (obj.offsetParent) 
  {
    while (obj.offsetParent) 
        {
            curleft += obj.offsetLeft
            obj = obj.offsetParent;
        }
    }
    else if (obj.x)
        curleft += obj.x;
    return curleft;
}
function xstooltip_hide(id)
{
    it = document.getElementById(id); 
    it.style.visibility = 'hidden'; 
}


function suggesttbxLocationName(ev,charCdAsciVal,tbxID){
	var key = (window.event) ? window.event.keyCode : ev.keyCode;
	var ARRUP = 38;
	var TAB = 9;
	var ARRDN = 40;
	var ENTER = 13;
	var bubble = true;
     CurrentEventName="tbxHint"+tbxID;
     CurrentEventId="td"+tbxID;
  
    if (key==27) 
     return;

  
	switch(key){
		case ARRUP:
		if (document.getElementById("tbxHint"+tbxID).innerHTML!="")
		{
			changeSelectedElement("up",tbxID);
		}
			bubble = false;
			break;
		case ARRDN:
		if (document.getElementById("tbxHint"+tbxID).innerHTML!="")
		{
			changeSelectedElement("down",tbxID);
		}
			bubble = false;
			break;

	    case ENTER:     try{Obj =  document.getElementById("tbxHint"+tbxID);Validation=true;}catch(e){}
		           
                    if(Obj)
                    {
			           // document.getElementById("tbxLatitute").focus();
 				//document.getElementById("btnSearch").focus();
					document.getElementById(tbxID).focus();
			           
                    }  
			      break;
		default:
		         if (results.length==0)
                   fillresulttbxLocationName(tbxID);
                 else
				 {
			        getSuggestionstbxLocationName(document.getElementById(tbxID).value,charCdAsciVal,tbxID);
				 }
	}
	return bubble;
}

function changeSelectedElement(key,tbxID)
{
	var obj = false;
	try{obj = document.getElementById(CurrentEventName);}catch(e){}
	if(obj)
	{
			var currElem = CurrentEventId + "0";
			var currObj = false;
			try{currObj =  document.getElementById(currElem);}catch(e){}
			if(currObj)
			{
				var total=NUMBER_OF_RESULTS;

				for(var i=0; i<=total-1; i++)
				{
					try{
						reloadInfo(document.getElementById(CurrentEventId + i));
					}catch(e){}
				}

				if(key == "up")
				{
					if(document.getElementById("hdn"+tbxID).value != -1)
						document.getElementById("hdn"+tbxID).value = parseInt(document.getElementById("hdn"+tbxID).value) - 1;
				}
				else if(key == "down")
				{
					if(document.getElementById("hdn"+tbxID).value != total-1)
					{
						document.getElementById("hdn"+tbxID).value = parseInt(document.getElementById("hdn"+tbxID).value) + 1;
					}
				}
				currElem = CurrentEventId + document.getElementById("hdn"+tbxID).value;
				
				try{currObj = document.getElementById(currElem);}catch(e){}
				if(currObj)
				{   
					fnSelectedElement(currObj,tbxID);
					refillTextBox(currObj,tbxID);
				}
			}
			else
			{
				try{reloadInfo(document.getElementById(CurrentEventId + document.getElementById("hdn"+tbxID).value));}catch(e){}
				if(document.getElementById("hdn"+tbxID).value > 0)
				{
					document.getElementById("hdn"+tbxID).value = parseInt(document.getElementById("hdn"+tbxID).value) - 1;
				}
				else
				{
					document.getElementById("hdn"+tbxID).value = parseInt(document.getElementById("hdn"+tbxID).value) + 1;
				}
			}
	}
	
}
var FirstEv;
function fillresulttbxLocationName(tbxID)
{
   // FirstEv=ev;
   //alert("aaya in divList.js");
   // xmlHttpnew=GetXmlHttpObjectNew()
   // if (xmlHttpnew==null)
   // {
   //     alert ("Your browser does not support AJAX!");
   //     return;
   // } 
   // var dt =new Date();
//	var dtime=dt.getSeconds();
   // var url;
   
    //   url='DropdownCityName.aspx';
     //  url= url + "?dt="+dtime;   
    
    //xmlHttpnew.onreadystatechange=ShowtbxLocationNameSuggestions;
    //xmlHttpnew.open("GET",url,true);
    //xmlHttpnew.send(null);
    //alert("call server side code");
    ShowtbxLocationNameSuggestions(tbxID)    
}

var matchResult="";
function ShowtbxLocationNameSuggestions(tbxID)    
 {
	
	   
        //alert(GData);
// the one below is Matthew generated - why does it not work ?????
		
		
     var ajaxOpts = {
        type: "post",
        async:false,
        url: "chkTime.php",
        success: function(data)
		{
			result=data;
			GData=data;
//			alert(data);
		}};
 $.ajax(ajaxOpts);
 

		
		
		var GetData = GData.split("$$$");           // Split that value.
	   	
	    var newGetData,newGetDataIndexVal,tmpGetDataIndexVal;
	    
	    newGetData=GetData[0].split("$");           // Get City Name
	    matchResult=newGetData;
	    newGetDataIndexVal = GetData[1];            // Get Array index & length

	    tmpGetDataIndexVal = newGetDataIndexVal.split("$");       // Split data with ($) from str= 6565#0,5

	    // Now tmpGetDataIndexVal array contain array index with length like
	    // tmpGetDataIndexVal[0] = 6565#0,120;
	    // tmpGetDataIndexVal[1] = 6566#121,220;
	    // tmpGetDataIndexVal[2] = 6567#221,320;
	    // ............ 
	    // ............
	    // ............
	    // tmpGetDataIndexVal[n] = 6665#1221,1320;
	    // tmpGetDataIndexVal[n+1] = 6666#1321,1420;
	    // ............ 
	    // ............
	    // ............
	    
	    
	    var strFormul,DvdStr,RmdStr,tmpstrChr,tmpstrInterval;
	    for(var i=0;i<(tmpGetDataIndexVal.length);i++)
	    {
	        var IndexValues = tmpGetDataIndexVal[i].split("#");       // Split data with (#) from str= 6565#0,5 to 0,5
	        DvdStr = parseInt((IndexValues[0] - 6565) / 100);
	        RmdStr = (IndexValues[0] - 6565) % 100;

	        // Now this contain (6565 - 6565)/100 = 0 Means -- 0 index for AA
	        // (6665 - 6565)/100 = 1 Means -- 1 index for BA
	        // (6765 - 6565)/100 = 2 Means -- 2 index for CA   like this
	        
	        strFormul = (DvdStr * 26) + RmdStr;
	        resultIndex[parseInt(strFormul)]=IndexValues[1];
	    }
	    // This for loop create one array which use for index value called -->
	    // resultIndex[0] = 0,120
	    // resultIndex[1] = 121,220
	    // resultIndex[2] = 221,320
	    // ............ 
	    // ............
	    // ............
	    // resultIndex[n] = 1221,1320
	    // resultIndex[n] = 1321,1420
	    // ............ 
	    // ............
	    // ............
	    
	    var istbxLocationNamename=0;
        results = new Array();
        for (var i=0;i<newGetData.length;i++)  
        {
            results[i] = newGetData[i];        // newGetData array contain all location name;  Fill all location in results array
	       if (CurrentCity==trim(results[i]))
	       istbxLocationNamename=1;
        }
        availableResults = results.length;             // availableResults contain total length of all location 
        //document.getElementById('spnautofill').style.display='none'; 
        //document.getElementById('AddTrvLnk').style.display='block'; 
        if (results.length>0 && NoHide==1)
        {
			//alert(tbxID + "~" + "came in scope");
			if(tbxID)
			{
				getSuggestionstbxLocationName(document.getElementById(tbxID).value,"",tbxID);	
			}
        }
}
function getSuggestionstbxLocationName(str,charCdAsciVal,tbxID){
	//alert(str + "_" + results);
    var NewStr="";
    document.getElementById("hdn"+tbxID).value=-1;
    if (str.length==0)
      { 
          clearDropDownList(tbxID);
          return;
      }
        str=trim(str);
        //alert(results.length);
    
        if(str!="")
        {
		   var iIndex; 
		   for(iIndex=0;iIndex<txtArray.length;iIndex++)
		   {
			   if(tbxID!=txtArray[iIndex])
			   {
				  clearDropDownList(txtArray[iIndex]);
				  document.getElementById(txtArray[iIndex]).value="";
			   }
		   }
           createDropDown(results,tbxID,"tbxHint"+tbxID,"td"+tbxID,str,"155px","xstooltip",charCdAsciVal,tbxID);
        }
		
         
 }
 
 function gotonewPage(tbxID)
 {
	 //alert(tbxID);
	fnGoToSearch(tbxID);
 }
 
 var autoFillDivId;
 var myFilteredArray=new Array();
 function createDropDown(results, ParentName,ChildName,SubChild,str,ParentLeftPosition,ClassName,charCdAsciVal,tbxID)
 {
 	try
 	{
		document.getElementsByTagName("body")[0].removeChild(document.getElementById(ChildName));
	}
	catch(e){}
	var div = document.createElement("div");
	div.id = ChildName;
	autoFillDivId=ChildName;
	div.className=ClassName;
	div.setAttribute('onmouseout','javascript:fnClose('+tbxID+');');
	div.style.position = "absolute";
	div.style.overflow="auto";
	document.getElementsByTagName("body")[0].appendChild(div);
	div.innerHTML = "";
	
	xstooltip_show(ChildName, ParentName,0,0,ParentLeftPosition);
    var k=0; 
    
    str=str.toUpperCase();
   var show=false;
   var total;
   NUMBER_OF_RESULTS=25;
    if (ChildName=="tbxHint"+tbxID)
   	 total = NUMBER_OF_RESULTS >= availableResults ? availableResults : NUMBER_OF_RESULTS;
   
   var count=0;

    /***********************************************************************************/
    
    var charcodeVV,IndxVal,tmpIndexVal,DvdStr,RmdStr,strFormul;
            charcodeVV=charCdAsciVal;
            DvdStr = parseInt((parseInt(charcodeVV)-6565)/100);
	        RmdStr = (parseInt(charcodeVV)-6565)%100;
	        strFormul = (DvdStr * 26) + RmdStr;
	       IndxVal=resultIndex[parseInt(strFormul)];
    
      //  alert("me in create Div     :   "+charCdAsciVal+"   =   "+charcodeVV+"  ==  "+strFormul+"   Index val "+IndxVal);
	
	if(IndxVal!=null)
	{
		if(IndxVal.toString().indexOf(",")>0)
		{
			tmpIndexVal=IndxVal.split(",");	
		}
        	else
		{
			tmpIndexVal=IndxVal;
		}
 		var strtIndex,endIndex;
		if(tmpIndexVal.length>0)
		{
			strtIndex=parseInt(tmpIndexVal[0]);
        		endIndex=parseInt(tmpIndexVal[1]);
		}
		else
		{
			strtIndex=0;
        		endIndex=0;
		}
        
        //alert("Index : "+strtIndex+" : "+endIndex);


    //**********************************************************************************/
    	var maxCharecterLength=0;
		myFilteredArray=new Array();
	for(var i=strtIndex; i<=endIndex; i++)
	{
	 var newstr=trim(results[i]);
	
	  var  newstr1=newstr.toLowerCase();
		myFilteredArray[count]=newstr1;
	//alert(newstr1);
         if  (newstr1.substring(0,str.length)==str.toLowerCase() &&  count<=parseInt(total)) 
         {
            if (ChildName=="tbxHint"+tbxID)
	        {
				var mouseaction = "onmouseover='reloadInfoAll(); ";
			}
	          mouseaction =mouseaction + "fnSelectedElement(this,\""+tbxID+"\");document.getElementById(\"hdn"+tbxID+"\").value="+ k +";' onmouseout='reloadInfo(this); ' onclick='javascript:refillTextBox(this,\""+tbxID+"\");clearDropDownList(\""+tbxID+"\");LatLng(\""+tbxID+"\");gotonewPage(\""+tbxID+"\");'";
	          div.innerHTML += "<div style='cursor:pointer;width:auto; overflow:auto;font-family:Arial ;font-size:12px;' id='" + SubChild + k + "'" + mouseaction + ">" + "<b><nobr>"   + newstr.substring(0,str.length) + "</nobr></b>" + newstr.substring(str.length, newstr.length) + "</div>";
	        k++;
		var currentCharLength=newstr.length;
		if(currentCharLength>=maxCharecterLength)
		{
			maxCharecterLength=currentCharLength
		}
	        show=true;
		//div.style.width="450px";
		//alert(maxCharecterLength);
		if(maxCharecterLength >=35)
		{
			div.style.width="auto";		
			//div.style.width="120px";		
		}
		else
		{	
			div.style.width="175px";
			//div.style.width= maxCharecterLength * 2 + "px";
			//div.style.width="120px";
		}
		count=parseInt(count)+1;
         }
	}

	if(count==0)
		clearDropDownList(tbxID);
		
	NUMBER_OF_RESULTS=count;
	//code commented by vyom on 20/10/2008----------

	

	//new code-------
	if(NUMBER_OF_RESULTS == 0)
	{
		div.style.display = "none";  //parseInt(15*count) + "px";
		if(document.getElementById("tbxHint"+tbxID)!=null)
			document.getElementById("tbxHint"+tbxID).style.display='none';
	}
	else if(NUMBER_OF_RESULTS <= 10)
	{
		var resultHeight=parseInt(NUMBER_OF_RESULTS * 15);
		//alert(resultHeight);
		div.style.height=resultHeight + "px";
		//div.style.width="auto";
		//div.style.width="120px";
	}
	else if(NUMBER_OF_RESULTS >10)
	{
		var resultHeight=parseInt(NUMBER_OF_RESULTS * 16);
		//alert(resultHeight);
		div.style.height=resultHeight + "px";
//	div.style.height = 120+"px";
	//div.style.width="auto";
	//div.style.width= 120+"px";
	}
	else
	{
		document.getElementById("tbxHint"+tbxID).style.display='none';	
	}
	//----------------
	

    	if(results.length == 0)
	{
		div.style.display = "none";
	}
	else
	{
		div.style.display = "block";
	}
 }
else
	{
		NUMBER_OF_RESULTS=0;
		div.style.display = "none";
	}
//alert(NUMBER_OF_RESULTS);	
//**********************************************************************************/
	}

	
       var total="";
function reloadInfoAll(){
	var total = NUMBER_OF_RESULTS ;
	 //alert(total);
	for(var i=0; i<total; i++){
		try{
			//alert(objCurrentText);
			reloadInfo(document.getElementById(CurrentEventId + i));
		}catch(e){}
	}
	
	
}

 function trim(str)
 {
    return str.replace(/^\s*|\s*$/g,"");
 }


function LatLng(tbxID)
{
    FlagAddTravel=true; 
    //document.getElementById("tbxLatitute").focus();
	//document.getElementById("btnSearch").focus();
	document.getElementById(tbxID).focus();
   
}




// code by vyom----------------on 20/10/2008 Monday

	
	function fnGoToSearch(tbxID)
	{
		var locationValue=document.getElementById(tbxID).value;
		
//		document.body.style.cursor = "wait";
		//document.getElementById('btnSearch').style.className="clsFindSearch";
		//alert(locationValue);

		var divText=matchResult;
		if(divText.toString().indexOf("#")>0)
		{
		  locationArray=divText.toString().split("#");
		}
		else
		{
		  locationArray=divText;
		}		
		if(locationValue=="")
		{
			alert("Please select any country from the list.");
			//document.body.style.cursor = "default";
			document.getElementById("imgLoading").innerHTML = "";
			return false;
		}
		else if(divText!="")
		{
			var iCount=0;
			var locationCount=locationArray.length;
			
			var isValueExist=false;
			//this variable contains 0 index city name 
			var zeroIndexCity="";
			
			if(locationCount>1)
			{
				for(iCount=0;iCount<locationCount;iCount++)
				{
					
					var arrayValue=	locationArray[iCount].toString().toUpperCase();	
					var locVal=locationValue.toString().toUpperCase();	
					//alert(arrayValue + "_" + locVal);
					if(arrayValue==locVal) 
					{
						isValueExist=true;
						//alert("came in isValueExist=true vd");
						break;
					}
					else
					{
						//alert("came in else case");
						isValueExist=false;	
					}
				}
			}
			else if(locationArray==locationValue)
			{
				//alert("came in locationvalue=locationArray");
				isValueExist=true;
			}
			else
			{
				//alert("came in else new case");
			}
			for(var jCount=0;jCount<NUMBER_OF_RESULTS;jCount++)
			{
				var initText=locationValue.toString().toUpperCase();
				//alert(myFilteredArray[jCount].toString().toUpperCase().indexOf(initText));
				if(myFilteredArray[jCount].toString().toUpperCase().indexOf(initText)>-1)
				{
					zeroIndexCity=myFilteredArray[0].toString();
					break;
				}
				else
				{
					zeroIndexCity="Not Found";
				}
			}
			
			if(isValueExist==false)
			{
				var obj=document.getElementById("imgLoading");
				if(obj)
					obj.innerHTML = "<img src='http://www.mosttraveledpeople.com/images/loading.gif' />";
				if(zeroIndexCity!="")
				{
					if(zeroIndexCity!="Not Found")
					{
						//alert("came in if case of isValueExistFalse");
						var tempLocation;
						locationValue=zeroIndexCity;
						for(var iCount=1;iCount<LocationNameArray.length;iCount++)
						{
							tempLocation=LocationNameArray[iCount].toString();
							if(tempLocation.toUpperCase()==locationValue.toString().toUpperCase())
							{
								document.getElementById("hdnlocid").value = iCount;
								break;
							}
						}
						isReturn = true;
						openNewWindow(locationValue,tbxID);	
						//alert(locationValue);
					}
					else
					{
						
						//alert("came in else case of isValueExistFalse");
						showAddress(locationValue, "",tbxID);
					//	alert("No match found.");					
					//	isReturn = false;
					//	return false;
					}
				}
				else
				{
					//alert("came in isValueExistTrue"+locationValue+"~"+tbxID);
					//new code to redirect the page to different location like PIP.
					showAddress(locationValue, "",tbxID);
					//alert("No match found.");
					
				}
			}
			else
			{
				var tempLocation;
				for(var iCount=1;iCount<LocationNameArray.length;iCount++)
				{
					tempLocation=LocationNameArray[iCount].toString();
					if(tempLocation.toUpperCase()==locationValue.toString().toUpperCase())
					{
						document.getElementById("hdnlocid").value = iCount;
						break;
					}

				}

				isReturn = true;
				document.getElementById("frm"+tbxID).submit();
				return true;
			}
		}
	}
	
	function fnEnterSearch(ev,tbxID)
	{
		var key = (window.event) ? window.event.keyCode : ev.keyCode;
		var ENTER = 13;
		if(key==ENTER)
		{
			fnGoToSearch(tbxID);
		}
	}
	
	
function openNewWindow(locationTEXT,tbxID)
{
	document.getElementById(tbxID).value=locationTEXT;
//	alert(document.getElementById("frm"+tbxID).action+"?Location="+locationTEXT);
//	return false;
//	document.getElementById("frm"+tbxID).submit();
}


// code by vyom----------------
//this function search the location name by pip if location doesn't exist in filled list.
	var map;
	var pointLat="";
	var pointLng="";
    var geocoder = null;
    var addressMarker;

    function load() {
      if (GBrowserIsCompatible()) {
        map = new GMap2(document.getElementById("map"));
        geocoder = new GClientGeocoder();
      }
    }

    function showAddress(address, countryCode,tbxID) 
	{
      if(geocoder) 
	  {
      	geocoder.setBaseCountryCode(countryCode);
        geocoder.getLatLng(address,function(point){
			if (!point) 
			{
				document.getElementById("imgLoading").innerHTML = "";
			  	alert(address + " not found");
            } 
			else 
			{
              	addressMarker = new GMarker(point);
			  	var points=point.toString();
			 	points=points.split(",");
			 	pointLat=point.lat();
			 	pointLng=point.lng()
				
				var dt=new Date();
				if(pointLat !="" && pointLng!="")
				{

					 //-------------------
  					$.get('../../SearchPolygon/FullSearch.php?dt='+ dt.getTime()+'&lng='+pointLat+'&lat='+ pointLng,
						function(data)
						{
//							alert(data);
							//alert("came in function");
							var formActionURL="";
							if(data!="Not Found ")
							{
					
								var locid=data.split("###");

								document.getElementById("hdnlocid").value = locid[0];
								
								var formaction=document.getElementById("frm"+tbxID).action;
								if(formaction.indexOf("?")>0)
								{
									var formact=formaction.split("?");
									formActionURL=formact[0];
								}
								else
								{
									formActionURL=formaction;
								}
								formaction=formActionURL + "?locid="+locid[0];

								document.getElementById("frm"+tbxID).action.value=formaction;
								isReturn=true;
								document.getElementById("frm"+tbxID).submit();
								return true;
								//-----------------------------
								//return true;	
							}
							else
							{
								//document.body.style.cursor = "default";
								document.getElementById("imgLoading").innerHTML ="";
								alert("No Match Found.");
								isReturn = false;
								return false;							
							}
							
						}
						);
					 //-------------------
				}
				else
				{
					isReturn = true;
					openNewWindow(locationValue,tbxID);
				}
			//------------------------
            }
          }
        );
      }
    }

	
	
    

	



