document.write("<iframe id='iframe1' scrolling='no' frameborder='0' style='position:absolute;top:0px;left:0px;z-index:5;display:none;'></iframe>");
document.write("<div id='showCityList' style='display:none;position:absolute;background:white;z-index:4;height:' onmouseout='showCount=0;' onmouseover='showCount=1;'></div>");

var departureCityHotList="";
var destinationCityHotList="";
var destinationHotelCityHotList="";
var departureCityList=departureCityListTmp;
var destinationCityList=destinationCityListTmp;
var textObject="",currentRow="",showCount="",isOnclick,size=1000,cityListType="",textValue="",_KEY_CODE_9="",_ENABLED_KEY=false;

function Get_Cookie( check_name ) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f

	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );


		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			switch (cookie_value){
				case "flightDom":
					cookie_value="CN";
					break;
				case "flightInt":
					cookie_value="HK";
					break;		
				case "flightTwi":
					cookie_value="TW";
					break;
				case "flightAus":
					cookie_value="AU";
					break;
				case "flightSin":
					cookie_value="SG";
					break;
				case "hotelDom":
					cookie_value="CN";
					break;
				case "hotelInt":
					cookie_value="HK";
					break;
				case "hotelGta":
					cookie_value="GTA";
					break;
				case "hotelTwi":
					cookie_value="TW";
					break;
				default:
					cookie_value="CN";
					break;		
			}
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found )
	{
		return "CN";
	}
}

var currentCountryCode=Get_Cookie("indexType");


 //charis 新加入的方法!;
function ischinese(s){ 
	var ret=true; 
	for(var i=0;i<s.length;i++) 
	ret=ret && (s.charCodeAt(i)>=10000); 
	return ret; 
} 

function isChinese2(temp){ 
	var re = /[^\u4e00-\u9fa5]/; 
	if(re.test(temp)) 
		return false; 
	return true; 
} 

function getDepartureCity(query,cityList){
	var arr=new Array();
	var length=cityList.length;
	var chlength=query.length;
	var j=0;	
	if(ischinese(query)) {		
		for(var i=0;i<length;i++) {
			var ch=cityList[i]['SCName'];
			var tw=cityList[i]['TCName'];
			var en=cityList[i]['ENName'];
			var cy=cityList[i]['Country'];
			var ic=cityList[i]['IATACode'];	
			var pa=cityList[i]['IATACode2'];
			if (currentCountryCode =='TW') {
				if (cy == 'TW') {
					if(chlength == 0 || ch.substr(0,chlength)==query || tw.substr(0,chlength)==query) {
						arr[j]=new Array();
						arr[j][0]=ch;
						arr[j][1]=en;
						arr[j][2]=cy;
						arr[j][3]=ic;
						j++;
					}
				}
			} else if (currentCountryCode =='AU'){
				if (cy == 'AU') {
					if(chlength == 0 || ch.substr(0,chlength)==query || tw.substr(0,chlength)==query) {
						arr[j]=new Array();
						arr[j][0]=tw;
						arr[j][1]=en;
						arr[j][2]=cy;
						arr[j][3]=ic;
						j++;
					}
				}
			} else if (currentCountryCode =='SG'){
				if (cy == 'SG') {
					if(chlength == 0 || ch.substr(0,chlength)==query || tw.substr(0,chlength)==query) {
						arr[j]=new Array();
						arr[j][0]=tw;
						arr[j][1]=en;
						arr[j][2]=cy;
						arr[j][3]=ic;
						j++;
					}
				}
			} else if (currentCountryCode == 'HK' && chlength == 0) {
				// show HK and MO only if HK tab page is selected and blank input
				if (cy == 'HK' || cy == 'MO') {					
					//alert("cy = " + cy);
						arr[j]=new Array();
						arr[j][0]=ch;
						arr[j][1]=en;
						arr[j][2]=cy;
						arr[j][3]=ic;
						j++;
				}
			} else {
				// default CN and others
				//if (cy == 'HK' || cy == 'MO' || cy == 'TW') {
					// ignore
				//} else {
					//alert("cy = " + cy);
					if(ch.substr(0,chlength)==query || tw.substr(0,chlength)==query) {
						arr[j]=new Array();
						arr[j][0]=ch;
						arr[j][1]=en;
						arr[j][2]=cy;
						arr[j][3]=ic;
						j++;
					}
				//}
			}			
		}
	} else {
		for(var i=0;i<length;i++) {
			var ch=cityList[i]['SCName'];
			var en=cityList[i]['ENName'];
			var py=cityList[i]['Pinyin'];
			var cy=cityList[i]['Country'];
			var ic=cityList[i]['IATACode'];
			var pa=cityList[i]['IATACode2'];
			if (currentCountryCode == 'TW') {
				if (cy == 'TW') {
					if(2!=cityListType){
						if(en.substr(0,chlength).toUpperCase()==query.toUpperCase() || py.substr(0,chlength).toUpperCase()==query.toUpperCase() || ic.substr(0,chlength).toUpperCase()==query.toUpperCase()|| pa.substr(0,chlength).toUpperCase()==query.toUpperCase()) {
							arr[j]=new Array();
							arr[j][0]=ch;
							arr[j][1]=en;
							arr[j][2]=cy;
							arr[j][3]=ic;
							j++;
						}
					}else{
						if(en.substr(0,chlength).toUpperCase()==query.toUpperCase() || py.substr(0,chlength).toUpperCase()==query.toUpperCase() || ic.substr(2,chlength).toUpperCase()==query.toUpperCase()|| pa.substr(0,chlength).toUpperCase()==query.toUpperCase()) {
							arr[j]=new Array();
							arr[j][0]=ch;
							arr[j][1]=en;
							arr[j][2]=cy;
							arr[j][3]=ic;
							j++;
						}
					}
				}					
			} else if (currentCountryCode == 'AU') {
				if (cy == 'AU') {
					if(2!=cityListType){
						if(en.substr(0,chlength).toUpperCase()==query.toUpperCase() || py.substr(0,chlength).toUpperCase()==query.toUpperCase() || ic.substr(0,chlength).toUpperCase()==query.toUpperCase()|| pa.substr(0,chlength).toUpperCase()==query.toUpperCase()) {
							arr[j]=new Array();
							arr[j][0]=ch;
							arr[j][1]=en;
							arr[j][2]=cy;
							arr[j][3]=ic;
							j++;
						}
					}else{
						if(en.substr(0,chlength).toUpperCase()==query.toUpperCase() || py.substr(0,chlength).toUpperCase()==query.toUpperCase() || ic.substr(2,chlength).toUpperCase()==query.toUpperCase()|| pa.substr(0,chlength).toUpperCase()==query.toUpperCase()) {
							arr[j]=new Array();
							arr[j][0]=ch;
							arr[j][1]=en;
							arr[j][2]=cy;
							arr[j][3]=ic;
							j++;
						}
					}
				}					
			} else if (currentCountryCode == 'SG') {
				if (cy == 'SG') {
					if(2!=cityListType){
						if(en.substr(0,chlength).toUpperCase()==query.toUpperCase() || py.substr(0,chlength).toUpperCase()==query.toUpperCase() || ic.substr(0,chlength).toUpperCase()==query.toUpperCase()|| pa.substr(0,chlength).toUpperCase()==query.toUpperCase()) {
							arr[j]=new Array();
							arr[j][0]=ch;
							arr[j][1]=en;
							arr[j][2]=cy;
							arr[j][3]=ic;
							j++;
						}
					}else{
						if(en.substr(0,chlength).toUpperCase()==query.toUpperCase() || py.substr(0,chlength).toUpperCase()==query.toUpperCase() || ic.substr(2,chlength).toUpperCase()==query.toUpperCase()|| pa.substr(0,chlength).toUpperCase()==query.toUpperCase()) {
							arr[j]=new Array();
							arr[j][0]=ch;
							arr[j][1]=en;
							arr[j][2]=cy;
							arr[j][3]=ic;
							j++;
						}
					}
				}					
			} else {
				// default CN and other
				//if (cy == 'HK' || cy == 'MO' || cy == 'TW') {
					// ignore
				//} else {
					if(cityListType == 4 || cityListType == 2){
						if(en.substr(0,chlength).toUpperCase()==query.toUpperCase() || py.substr(0,chlength).toUpperCase()==query.toUpperCase() || ic.substr(2,chlength).toUpperCase()==query.toUpperCase()|| pa.substr(0,chlength).toUpperCase()==query.toUpperCase()) {
							arr[j]=new Array();
							arr[j][0]=ch;
							arr[j][1]=en;
							arr[j][2]=cy;
							arr[j][3]=ic;
							j++;
						}
					}else{
						if(en.substr(0,chlength).toUpperCase()==query.toUpperCase() || py.substr(0,chlength).toUpperCase()==query.toUpperCase() || ic.substr(0,chlength).toUpperCase()==query.toUpperCase()|| pa.substr(0,chlength).toUpperCase()==query.toUpperCase()) {
							arr[j]=new Array();
							arr[j][0]=ch;
							arr[j][1]=en;
							arr[j][2]=cy;
							arr[j][3]=ic;
							j++;
						}
					}
				//}
			}			
		}
	}
	return arr;
}

function getCity(query,cityList){
	var arr=new Array();
	var length=cityList.length;
	var chlength=query.length;
	var j=0;	
	if(ischinese(query)) {
		for(var i=0;i<length;i++) {
			var ch=cityList[i]['SCName'];
			var tw=cityList[i]['TCName'];
			var en=cityList[i]['ENName'];
			var cy=cityList[i]['Country'];
			var ic=cityList[i]['IATACode'];	
			var pa=cityList[i]['IATACode2'];
			if(ch.substr(0,chlength)==query || tw.substr(0,chlength)==query) {
				arr[j]=new Array();
				arr[j][0]=ch;
				arr[j][1]=en;
				arr[j][2]=cy;
				arr[j][3]=ic;
				j++;
			}
		}
	} else {
		for(var i=0;i<length;i++) {
			var ch=cityList[i]['SCName'];
			var en=cityList[i]['ENName'];
			var py=cityList[i]['Pinyin'];
			var cy=cityList[i]['Country'];
			var ic=cityList[i]['IATACode'];
			var pa=cityList[i]['IATACode2'];
			if(2!=cityListType){
				if(en.substr(0,chlength).toUpperCase()==query.toUpperCase() || py.substr(0,chlength).toUpperCase()==query.toUpperCase() || ic.substr(0,chlength).toUpperCase()==query.toUpperCase()|| pa.substr(0,chlength).toUpperCase()==query.toUpperCase()) {
					arr[j]=new Array();
					arr[j][0]=ch;
					arr[j][1]=en;
					arr[j][2]=cy;
					arr[j][3]=ic;
					j++;
				}
			}else{
				if(en.substr(0,chlength).toUpperCase()==query.toUpperCase() || py.substr(0,chlength).toUpperCase()==query.toUpperCase() || ic.substr(2,chlength).toUpperCase()==query.toUpperCase()|| pa.substr(0,chlength).toUpperCase()==query.toUpperCase()) {
					arr[j]=new Array();
					arr[j][0]=ch;
					arr[j][1]=en;
					arr[j][2]=cy;
					arr[j][3]=ic;
					j++;
				}
			}
		}
	}
	return arr;
}

function onDocumentLoad(cityHotList){
	_ENABLED_KEY=true;
	var table=document.getElementById("showCityList");
	//var str="<iframe id='iframe1' scrolling='no' frameborder='0' style='position:absolute; top:0px; left:0px;z-index:600;' onload='textObject.focus();'></iframe>";
	var str = "";
	if (cityHotList.length==0)	{
		str="<div style='position:absolute;height:27px;border:1px solid;width:232px;overflow:auto;z-index:700;background:white;'><table class='table1'>";
	} else {
		if (cityHotList.length>=20)
		{
			str="<div style='position:absolute;height:300px;border:1px solid;width:250px;overflow:auto;z-index:700;background:white;'><table class='table1'>";
		} else {
			str="<div style='position:absolute;height:300px;border:1px solid;width:232px;overflow:auto;z-index:700;background:white;'><table class='table1'>";
		}
	}	
	str+="<tr><td class='td0' colspan='2' height='20px'>Please enter City Name or Pinyin</td></tr>";
	for(var i=0;i<cityHotList.length;i++) {
		if(i==0)
			str+="<tr class='tr2' onmouseover='changeClass(this,\""+cityHotList[i]['SCName']+"\")' onmouseout='this.className=\"\"' onclick=\"changeValue('"+cityHotList[i]['ENName']+"','"+cityHotList[i]['IATACode']+"','"+cityHotList[i]['Country']+"')\"><td class='td2'>"+cityHotList[i]['ENName']+"</td><td class='td3'>"+cityHotList[i]['SCName']+"</td></tr>";
		else
			str+="<tr onmouseover='changeClass(this,\""+cityHotList[i]['SCName']+"\")' onmouseout='this.className=\"\"' onclick=\"changeValue('"+cityHotList[i]['ENName']+"','"+cityHotList[i]['IATACode']+"','"+cityHotList[i]['Country']+"')\"><td class='td2'>"+cityHotList[i]['ENName']+"</td><td class='td3'>"+cityHotList[i]['SCName']+"</td></tr>";
	}
	str+="</table></div>";
	table.innerHTML=str;
	var tableElement = table.childNodes[0].firstChild;
	var tBodyElement = tableElement.firstChild;
	currentRow=tBodyElement.childNodes[1];
	if(!currentRow){
		currentRow="";
		_ENABLED_KEY=false;
	}
	showDiv(textObject);
}

function funpage(arr,page,size){
	var str="";
	var start=(page-1)*size;
	var end2=page*size;
	var arrlength=arr.length;
	end=end2>arrlength?arrlength:end2;
	for(var i=start;i<end;i++) {
		if(i==start) {
			str+="<tr onmouseover='this.className=\"tr2\"' onmouseout='this.className=\"\"' onclick=\"changeValue('"+arr[i][1]+"','"+arr[i][3]+"','"+arr[i][2]+"')\"><td class='td2'>"+arr[i][1]+"</td><td class='td3'>"+arr[i][0]+"</td></tr>";
		} else {
			str+="<tr onmouseover='this.className=\"tr2\"' onmouseout='this.className=\"\"' onclick=\"changeValue('"+arr[i][1]+"','"+arr[i][3]+"','"+arr[i][2]+"')\"><td class='td2'>"+arr[i][1]+"</td><td class='td3'>"+arr[i][0]+"</td></tr>";
		}
	}
	return str;
}

function changeValue(scname,citycode,countycode){
	textObject.value=scname;	
	if(cityListType=="from" || cityListType==0) {	
		if(document.regformfl){
			document.regformfl.fromCity.value=citycode;
		}else if(!document.regformfl){
		   document.getElementById('fromCity').value=citycode;
		}
		bindCityList(1,citycode);
		var destinationCityIATACode=document.getElementById('toCity').value;
		var beingDestinationCityIATACode=false;
		if(destinationCityIATACode!=""){
			for(var index in destinationCityList){
				if(destinationCityList[index]["IATACode"]==destinationCityIATACode){
					beingDestinationCityIATACode=true;
					break;
				}
			}
		}
		if(!beingDestinationCityIATACode){
			document.getElementById('toCity').value="";
			document.getElementById('citytoDomestic').value="";			
		}
	}else if(cityListType=="hotel" || cityListType=="hotelGta" || cityListType==2 || cityListType==4){
		if(document.getElementById('city'))
			document.getElementById('city').value=citycode;
	}else{		 
		if(document.regformfl){
			document.regformfl.toCity.value=citycode;
		}else if(!document.regformfl){
		   document.getElementById('toCity').value=citycode;
		}
	}
	isOnclick=1;
	hiddenDiv();
	if(_KEY_CODE_9!=1) {
		nextControl(textObject);
	}	
}

function changeClass(obj,value){
	obj.className='tr2';
}
function hiddenDiv(){
	document.getElementById('showCityList').style.display='none';
	document.getElementById('iframe1').style.display='none';
}

function showDiv(obj){
	var divObj=document.getElementById('showCityList');	
	var iframe=document.getElementById('iframe1');		
	var t=obj.offsetTop;
	var l=obj.offsetLeft;
	var height=obj.offsetHeight;	
	while(obj=obj.offsetParent){
		t+=obj.offsetTop;
		l+=obj.offsetLeft;
	}
	if(window.ActiveXObject) {
			divObj.style.left=l;
			divObj.style.top=t+height+3;
			iframe.style.left=l;
			iframe.style.top=t+height+3;
	}else {
		divObj.style.left=l+'px';
		divObj.style.top=t+height+3+'px';
		iframe.style.left=l+'px';
		iframe.style.top=t+height+3+'px';
	}
	iframe.style.width=divObj.firstChild.offsetWidth;
	iframe.style.height=divObj.firstChild.offsetHeight;
	iframe.style.zIndex=divObj.style.zIndex-1;	
	iframe.style.display='';
	divObj.style.display='';	
}

//键盘按上下左右选择城市列表
function addTable2(obj,value,currentPage,type,evt) {
	isOnclick=0;
	if(value.trim()=="" && type==0 ){		
		destinationCityList=destinationCityListTmp;
	}
	if(value.trim()=="" && type==1){
		departureCityList=departureCityListTmp;
	}
	if(!textObject || textObject!=obj){
		textObject=obj;
		cityListType=type;
		textValue=obj.value;
		currentRow="";
	}
	var table=document.getElementById("showCityList");
	if(table.style.display!='none'){
		var tableElement = table.childNodes[0].firstChild;
		var tBodyElement = tableElement.firstChild;
	}
	var e=(evt)?evt:(window.event?window.event:"");
	var keyCode= e.keyCode ? e.keyCode : e.which;
	switch (keyCode){
		case 39:			
		case 40: //down key
			if(table.style.display=='none'){
				addTable(obj,value,currentPage);
				return ;
			}
			if(!_ENABLED_KEY){
				return ;
			}
			if(currentRow){
				currentRow.onmouseout();
			}
			if(currentRow && currentRow.nextSibling && currentRow.nextSibling.firstChild.firstChild){
				currentRow=currentRow.nextSibling;
				currentRow.onmouseover();
			} else {
				currentRow=tBodyElement.firstChild.nextSibling;
				currentRow.onmouseover();
			}
			break;
		case 37:
		case 38://up key
			if(table.style.display=='none'){
				addTable(obj,value,currentPage);
				return ;
			}
			if(!_ENABLED_KEY){
				return ;
			}
			if(currentRow){
				currentRow.onmouseout();
			}
			if(currentRow && currentRow.previousSibling.previousSibling){					
				currentRow=currentRow.previousSibling;
				currentRow.onmouseover();
			} else{				
				currentRow=tBodyElement.childNodes[tBodyElement.childNodes.length-1];
				while(!currentRow.firstChild.firstChild)
					currentRow=currentRow.previousSibling;
				currentRow.onmouseover();
			}
			break;
		case 13:
			if(table.style.display=='none'){
				addTable(obj,value,currentPage);
				return ;
			}
			if(currentRow){
				currentRow.onclick();
			}
			break;
		default:
			addTable(obj,value,currentPage);
	}
}

//addTable
function addTable(obj,value,currentPage,type){
	var arr;
	if(value=="" && (cityListType=="to" || cityListType==1 || currentCountryCode=="CN")){
		if(cityListType=="from" || cityListType==0) 
			onDocumentLoad(departureCityHotList);
		else if(cityListType=="hotel" || cityListType==2)
			onDocumentLoad(destinationHotelCityHotList);
		else if(cityListType=="hotelGta" || cityListType==4)
			onDocumentLoad(destinationHotelGTACityList);
		else 
			onDocumentLoad(destinationCityHotList);
	} else {
		var table=document.getElementById("showCityList");	
		if (cityListType=="to" || cityListType==1) {
			arr=getCity(value,destinationCityList);
		} else {
			if(cityListType=="from" || cityListType==0) 
				arr=getDepartureCity(value,departureCityList);
			else if(cityListType=="hotel" || cityListType==2)
				arr=getDepartureCity(value,destinationHotelCityList);
			else if(cityListType=="hotelGta" || cityListType==4)
				arr=getDepartureCity(value,destinationHotelGTACityList);
			else 
				arr=getCity(value,destinationCityList);
		}	
		var arrlength=arr.length;
		var page=parseInt(arrlength/size);
		page= arrlength%size>0 ? page+1 : page;
		//var str="<iframe id='iframe1' scrolling='no' frameborder='0' style='position:absolute; top:0px; left:0px;z-index:400;' onload='textObject.focus();'></iframe>";
		if(arrlength!=0) {
			_ENABLED_KEY=true;
			var str="<div style='position:absolute;height:300px;border:1px solid;width:250px;overflow:auto;z-index:500;background:white;'><table class='table1'>";
			str+="<tr><td class='td1' colspan='2' height='20px'>Please enter City Name or Pinyin</td></tr>";
			str+=funpage(arr,currentPage,size);
			if(page>1) {
				str+="</table></div><div style='border-left:1px solid;border-right:1px solid;border-bottom:1px solid;height:20px;width:230px;'>";
				for(var k=1;k<=page;k++) {
					if(currentPage==k)
						str+="<span style='padding-left:15px'>"+k+"</span>";
					else
						str+="<span style='padding-left:15px'><a href='javascript:addTable(\""+obj+"\",\""+value+"\","+k+");textObject.focus()'>"+k+"</a></span>";
				}
				str+="</div>";
			} else {
				str+="</table></div>";
			}
			table.innerHTML=str;
			var tableElement = table.childNodes[0].firstChild;
			var tBodyElement = tableElement.firstChild;
			if(tBodyElement.childNodes[1]){
				currentRow=tBodyElement.childNodes[1];
				currentRow.onmouseover();
			}
		} else {
			_ENABLED_KEY=false;
			var str="<div style='position:absolute;height:27px;border:1px solid;width:232px;overflow:auto;z-index:700;background:white;'><table class='table1'>";
			str+="<tr><td class='td0' colspan='2' height='20px'>"+textObject.value+",Invalid city</td></tr>";
			str+=funpage(arr,currentPage,size);
			if(page>1) {
				str+="</table></div><div style='border-left:1px solid;border-right:1px solid;border-bottom:1px solid;height:20px;width:230px;'>";
				for(var k=1;k<=page;k++) {
					if(currentPage==k)
						str+="<span style='padding-left:15px'>"+k+"</span>";
					else
						str+="<span style='padding-left:15px'><a href='javascript:addTable(\""+obj+"\",\""+value+"\","+k+");textObject.focus()'>"+k+"</a></span>";
				}
				str+="</div>";
			} else {
				str+="</table></div>";
			}
			table.innerHTML=str;
			currentRow="";
		}	
	}
	showDiv(obj);
}

function textOnclick(obj,type){
	currentRow="";
	obj.focus();
	textObject=obj;
	textValue=textObject.value;
	cityListType=type;	
	if(obj.value=="" && (cityListType==="to" || cityListType == 1 || currentCountryCode == "CN") ) {
		isOnclick=0;
		if(cityListType=="from" || cityListType==0){
			onDocumentLoad(departureCityHotList);
		}else if(cityListType=="hotel" || cityListType==2){
			onDocumentLoad(destinationHotelCityHotList);
		}else if(cityListType=="hotelGta" || cityListType==4){
			onDocumentLoad(destinationHotelGTACityList);
		}else {
			onDocumentLoad(destinationCityHotList);
		}	
	}else{
		isOnclick=1;
		addTable(obj,obj.value,1);
	}
	showDiv(obj);
}

document.onmouseup=function(){
	var activeEle=(document.activeElement)?document.activeElement:event.srcElement;
	if(activeEle!=textObject){
	  if(showCount==0 || !showCount) {
		hiddenDiv();
		if( typeof(isOnclick)!='undefined' && isOnclick !=1 && ((textValue!=textObject.value) || textObject.value=="") ) {			
			textObject.value="";
			if(cityListType=="from" || cityListType==0) {
				destinationCityList=destinationCityListTmp;
			}else if(cityListType=="to" || cityListType==1) {
				departureCityList=departureCityListTmp;
			}
		}
	  }
	}
}

function onkeydownfun(evt) {
	var e=evt?evt:(window.event?window.event:"");
	var keyCode= e.keyCode ? e.keyCode : e.which;
	if(keyCode==9) {	
		hiddenDiv();
		_KEY_CODE_9=1;
		if(currentRow!=""){
			currentRow.onclick();
		}else{
			if( typeof(isOnclick)!='undefined' && isOnclick !=1 && ((textValue!=textObject.value) || textObject.value=="") ) {			
				textObject.value="";
				//textObject.focus();		
				//textObject.onclick();	
				if(cityListType=="from" || cityListType==0) {
					destinationCityList=destinationCityListTmp;
				}else if(cityListType=="to" || cityListType==1) {
					departureCityList=departureCityListTmp;
				}
				return ;	
			}
		}		
	}else{
		_KEY_CODE_9=0;
	}
}


///////////////////////////////////////////////////////////////////////////////////////////////
var maxStrLength=0;

function changeDiv(divId,selId,boxId){
	var obj=document.getElementById(divId);
	var selDivObj=document.getElementById(selId);
	var selObj=document.getElementById(boxId); //selDivObj.firstChild;
	if(obj.style.display!='none'){
		obj.style.display='none';
		selDivObj.style.display='';
		selObj.focus();
		if(divId=="hotelCityfromDomesticDiv"){
			for(var i=0;i<destinationHotelCityHotList.length;i++){
				var currentStrLength=(destinationHotelCityHotList[i]['ENName'].length*2);
				selText=destinationHotelCityHotList[i]['ENName'];
				for(var j=0;j<maxStrLength-currentStrLength;j++)		
					selText+=" ";
				selValue=destinationHotelCityHotList[i]['ENName']+","+destinationHotelCityHotList[i]['Country']+","+destinationHotelCityHotList[i]['IATACode'];
				var option=new Option(selText,selValue);
				selObj.options.add(option);
			}
			var option=new Option("-----------","");
			selObj.options.add(option);

			for(var i=0;i<destinationHotelCityList.length;i++){
				var currentStrLength=(destinationHotelCityList[i]['ENName'].length*2);
				selText=destinationHotelCityList[i]['ENName'];
				for(var j=0;j<maxStrLength-currentStrLength;j++)		
					selText+=" ";
				selValue=destinationHotelCityList[i]['ENName']+","+destinationHotelCityList[i]['Country']+","+destinationHotelCityList[i]['IATACode'];
				var option=new Option(selText,selValue);
				selObj.options.add(option);
			}
			getCityAndCountyCode(selObj.options[0],'cityfromDomestic');
		}
		if(divId=="cityfromDomesticDiv"){
			for(var i=0;i<departureCityHotList.length;i++){
				var currentStrLength=(departureCityHotList[i]['ENName'].length*2);
				selText=departureCityHotList[i]['ENName'];
				for(var j=0;j<maxStrLength-currentStrLength;j++)		
					selText+=" ";
				selValue=departureCityHotList[i]['ENName']+","+departureCityHotList[i]['Country']+","+departureCityHotList[i]['IATACode'];
				var option=new Option(selText,selValue);
				selObj.options.add(option);
			}
			var option=new Option("-----------","");
			selObj.options.add(option);

			for(var i=0;i<departureCityList.length;i++){
				var currentStrLength=(departureCityList[i]['ENName'].length*2);
				selText=departureCityList[i]['ENName'];
				for(var j=0;j<maxStrLength-currentStrLength;j++)		
					selText+=" ";
				selValue=departureCityList[i]['ENName']+","+departureCityList[i]['Country']+","+departureCityList[i]['IATACode'];
				var option=new Option(selText,selValue);
				selObj.options.add(option);
			}
			getCityAndCountyCode(selObj.options[0],'cityfromDomestic');
		}
		if(divId=="citytoDomesticDiv"){
			for(var i=0;i<destinationCityHotList.length;i++){
				var currentStrLength=(destinationCityHotList[i]['ENName'].length*2);
				selText=destinationCityHotList[i]['ENName'];
				for(var j=0;j<maxStrLength-currentStrLength;j++)		
					selText+=" ";
				selValue=destinationCityHotList[i]['ENName']+","+destinationCityHotList[i]['Country']+","+destinationCityHotList[i]['IATACode'];
				var option=new Option(selText,selValue);
				selObj.options.add(option);
			}
			var option=new Option("-----------","");
			selObj.options.add(option);

			for(var i=0;i<destinationCityList.length;i++){
				var currentStrLength=(destinationCityList[i]['ENName'].length*2);
				selText=destinationCityList[i]['ENName'];
				for(var j=0;j<maxStrLength-currentStrLength;j++)		
					selText+=" ";
				selValue=destinationCityList[i]['ENName']+","+destinationCityList[i]['Country']+","+destinationCityList[i]['IATACode'];
				var option=new Option(selText,selValue);
				selObj.options.add(option);
			}
			getCityAndCountyCode(selObj.options[0],'citytoDomestic');
		}		
	}else{
		obj.style.display='';
		selDivObj.style.display='none';
		while(selObj.firstChild) {
			selObj.removeChild(selObj.firstChild);
		}
	}
}

function getCityAndCountyCode(selObj,selId)
{
	var selectValue=selObj.value;
	var selValue=selectValue.split(",");
	if(selId=='cityfromDomestic' || selId=='destinationCity'){
		if(document.getElementById('fromCity'))
			document.getElementById('fromCity').value=selValue[2];
		selectboxLoadCity('citytoDomestic',document.getElementById('toCity').value);
		var destinationCityIATACode=document.getElementById('toCity').value;
		var beingDestinationCityIATACode=false;
		if(destinationCityIATACode!=""){
			for(var index in destinationCityList){
				if(destinationCityList[index]["IATACode"]==destinationCityIATACode){
					beingDestinationCityIATACode=true;
					break;
				}
			}
		}
		if(!beingDestinationCityIATACode){
			document.getElementById('toCity').value="";
			document.getElementById('citytoDomestic').value="";		
		}
	}
	if(selId=='citytoDomestic'){
		if(document.getElementById('toCity'))
			document.getElementById('toCity').value=selValue[2];
		selectboxLoadCity('cityfromDomestic',document.getElementById('fromCity').value);
		
	}
}

function selectboxLoadCity(boxId,selectedCity) {
	var selObj=document.getElementById(boxId);
	while(selObj.firstChild){
		selObj.removeChild(selObj.firstChild);
	}
	var option=new Option("Please choose a city","");
	selObj.options.add(option);	
	var cityList;
	var cityHotList;
	if (boxId=='cityfromDomestic'){
	/*
		if(document.getElementById('destinationCityIATACode').value!=""){
			if(document.getElementById("citytoDomestic") && document.getElementById("citytoDomestic").value!=""){
				bindCityList(2,document.getElementById('destinationCityIATACode').value);
			}else{
				departureCityList=departureCityListTmp;
			}
		}else{
			departureCityList=departureCityListTmp;
		}
	*/
		cityList=departureCityList;
		cityHotList=departureCityHotList;
	} else if (boxId=='citytoDomestic') {
		if(document.getElementById('fromCity').value!="" && document.getElementById('cityfromDomestic').value!=""){
			bindCityList(1,document.getElementById('fromCity').value);
		}else{
			destinationCityList=destinationCityListTmp;
		}
		cityList=destinationCityList;
		cityHotList=destinationCityHotList;
	} else {
		cityList=destinationHotelCityList;
		cityHotList=destinationHotelCityHotList;
	}
	var optgroup = document.createElement("optgroup");
	optgroup.label = 'Popular Cities';

	for(var i=0;i<cityHotList.length;i++){
		selText=cityHotList[i]['ENName'];
		selValue=cityHotList[i]['ENName']+","+cityHotList[i]['Country']+","+cityHotList[i]['IATACode'];
		var opt = document.createElement("option");
        opt.innerHTML = selText;
        opt.value = selValue;
		if (selectedCity==cityHotList[i]['IATACode']){
			opt.selected = true;
		}
		optgroup.appendChild( opt );
	}
	selObj.appendChild(optgroup);

	optgroup = document.createElement("optgroup");
	optgroup.label = '- - - - - - - - - - - -';
	selObj.appendChild(optgroup);

	var country = "";
	for(var i=0;i<cityList.length;i++){
		if (cityList[i]['CountryENName'] != country) {
			country = cityList[i]['CountryENName'];
			optgroup = document.createElement("optgroup");
			optgroup.label = cityList[i]['CountryENName'];
		}
		selText=cityList[i]['ENName'];
		selValue=cityList[i]['ENName']+","+cityList[i]['Country']+","+cityList[i]['IATACode'];
		var opt = document.createElement("option");
        opt.innerHTML = selText;
        opt.value = selValue;
		if (selectedCity==cityList[i]['IATACode']){
			opt.selected = true;
		}
		optgroup.appendChild( opt );
		selObj.appendChild(optgroup);
	}
}

/*
function selectboxLoadCity2(boxId,selectedCity) {
	var selObj=document.getElementById(boxId);
	while(selObj.firstChild){
		selObj.removeChild(selObj.firstChild);
	}
	var option=new Option("Please choose a city","");
	selObj.options.add(option);	
	var cityList;
	var cityHotList;
	if (boxId=='cityfromDomestic'){
		if(document.getElementById('destinationCityIATACode').value!=""){
			if(document.getElementById("citytoDomestic") && document.getElementById("citytoDomestic").value!=""){
				bindCityList(2,document.getElementById('destinationCityIATACode').value);
			}else{
				departureCityList=departureCityListTmp;
			}
		}else{
			departureCityList=departureCityListTmp;
		}
		cityList=departureCityList;
		cityHotList=departureCityHotList;
	} else if (boxId=='citytoDomestic') {
		if(document.getElementById('departureCityIATACode').value!="" && document.getElementById('cityfromDomestic').value!=""){
			bindCityList(1,document.getElementById('departureCityIATACode').value);
		}else{
			destinationCityList=destinationCityListTmp;
		}
		cityList=destinationCityList;
		cityHotList=destinationCityHotList;
	} else {
		cityList=destinationHotelCityList;
		cityHotList=destinationHotelCityHotList;
	}
	var optgroup = document.createElement("optgroup");
	optgroup.label = 'Popular Cities';

	for(var i=0;i<cityHotList.length;i++){
		selText=cityHotList[i]['ENName'];
		selValue=cityHotList[i]['ENName']+","+cityHotList[i]['Country']+","+cityHotList[i]['IATACode'];
		var opt = document.createElement("option");
        opt.innerHTML = selText;
        opt.value = selValue;
		if (selectedCity==cityHotList[i]['IATACode']){
			opt.selected = true;
		}
		optgroup.appendChild( opt );
	}
	selObj.appendChild(optgroup);

	optgroup = document.createElement("optgroup");
	optgroup.label = '- - - - - - - - - - - -';
	selObj.appendChild(optgroup);

	var country = "";
	for(var i=0;i<cityList.length;i++){
		if (cityList[i]['CountryENName'] != country) {
			country = cityList[i]['CountryENName'];
			optgroup = document.createElement("optgroup");
			optgroup.label = cityList[i]['CountryENName'];
		}
		selText=cityList[i]['ENName'];
		selValue=cityList[i]['ENName']+","+cityList[i]['Country']+","+cityList[i]['IATACode'];
		var opt = document.createElement("option");
        opt.innerHTML = selText;
        opt.value = selValue;
		if (selectedCity==cityList[i]['IATACode']){
			opt.selected = true;
		}
		optgroup.appendChild( opt );
		selObj.appendChild(optgroup);
	}
}
*/
/************for new index start**********/
function showinfodiv(divnum)
{
document.getElementById("hotelimg").className="hotel";
document.getElementById("flightimg").className="flight01";
document.getElementById("hotelstr").className="hh";
document.getElementById("flightstr").className="ff";
document.getElementById("hotelinfo").style.display="";
document.getElementById("tripinfo").style.display="none";
if(divnum==2)
{
document.getElementById("hotelimg").className="hotel";
document.getElementById("flightimg").className="flight01";
document.getElementById("hotelstr").className="hh";
document.getElementById("flightstr").className="ff";
document.getElementById("hotelinfo").style.display="";
document.getElementById("tripinfo").style.display="none";
}
if(divnum==1)
{
document.getElementById("hotelimg").className="hotel01";
document.getElementById("flightimg").className="flight";
document.getElementById("hotelstr").className="ff";
document.getElementById("flightstr").className="hh";
document.getElementById("hotelinfo").style.display="none";
document.getElementById("tripinfo").style.display="";
}
}

function nextControl(obj){
	if(obj.value!=""){
		if(obj.id.indexOf("from")>-1){
			document.getElementById("citytoDomestic").focus();
		}else if (obj.id.indexOf("to")>-1){			
			if(document.regformfl)
				document.regformfl.leftdate.focus();
			else if(document.getElementById("leftdate"))
				document.getElementById("leftdate").focus();
		}else if(obj.id=="destinationCity"){
			if(document.regform)
				document.regform.leftdate.focus();
			else if(document.getElementById("leftdate"))
				document.getElementById("leftdate").focus();
		}
	}
}

function bindCityList(type,cityCode){	
	var city="";
	var bindCity="";
	var matchCityList="";
	var returnCityList=new Array();
	var cityPairBindList=new Array();
	if(type==1){
		city="origin";
		bindCity="destination";
		matchCityList=destinationCityListTmp;
	}else{
		city="destination";
		bindCity="origin";
		matchCityList=departureCityListTmp;
	}	
	for(var i=0;i<cityPairList.length;i++){
		if(cityCode==cityPairList[i][city]){
			cityPairBindList.push(cityPairList[i]);
		}
	}
	for(var index in matchCityList){
		for(var i=0;i<cityPairBindList.length;i++){
			if(matchCityList[index]["IATACode"] == cityPairBindList[i][bindCity]){
				returnCityList.push(matchCityList[index]);
			}
		}
	}	
	if(type==1){
		destinationCityList=returnCityList;
	}else{
		departureCityList=returnCityList;
	}
}

