	/*
	*********************************************************
		Description		: City List
		Author			: Chandana Gamage
		Version			: 1.0
		Created on		: 25th April 2008
		Last Modified	: 25th April 2008
	*********************************************************	
	*/
	
	var intRow = 0; 
	var intCol = 0; 
	var intCeilValue = 0;
	var strFocus= "i" + intRow + "j" + intCol;
	var strPostURL		= "../../../qribe-web";
	var strCityColor 	= "cityColor";	
	
	function callCityList(hdnMode , hdnFrom , hdnFromText,hdnTo,hdnTab){
		remoteSubmit(hdnMode , hdnFrom , hdnFromText,hdnTo,hdnTab)
	}

	/*
	 * Ajax Remote Submit
	 */
	function remoteSubmit(hdnMode , hdnFrom , hdnFromText,hdnTo,hdnTab){
		makePOST(strPostURL + "/public/showCityList.do","hdnMode=" + hdnMode + "&hdnFrom="+ escape(hdnFrom)+ "&hdnFromText="+ escape(hdnFromText)+ "&hdnTo="+ escape(hdnTo)+ "&hdnTab="+ escape(hdnTab));
	}

	/*
	 * Ajax Return Call
	 */
	function processStateChange() {
		if (httpReq.readyState == 4){
			if (httpReq.status == 200){
				strSYSError = "";
				eval(httpReq.responseText);
				if (strSYSError == ""){
					ajaxReturnCall(true);									
				}					
			}
		}
	}

	/*
	 * after Ajax Reuturn 
	 */
	function ajaxReturnCall(blnSuccess){
		//alert(intCeilValue);

		//var strFocus= "i" + 0 + "j" + 0;
		if (strhdnMode == "GETFSFROMFULLSEARCH"){
			buildHeader(arrFromCity,"F");
			buildFullsearch(arrFromCity,"F");
			buildButton(arrFromCity,"F");
			
			if (arrFromCity.length>0){
				if (strhdnCity == ""){
					strFocus = "i"+ 0 + "j"+ 0; 
					setFocus(strFocus);
					intRow = 0;
					intCol = 0;
					setStyleClass(strFocus ,strCityColor)
				}else {
					setDefaultFocus(arrFromCity);
					
				}
			}
		}else if (strhdnMode == "GETFSTOFULLSEARCH"){
			buildHeader(arrToCity,"T");
			buildFullsearch(arrToCity,"T"); 
			buildButton(arrToCity,"T"); 
			if (arrToCity.length>0){
				if (strhdnCity == ""){
					
					strFocus = "i"+ 0 + "j"+ 0; 
					setFocus(strFocus);

					intRow = 0;
					intCol = 0;
					setStyleClass(strFocus ,strCityColor)
				}else {
					setDefaultFocus(arrToCity);
					
				}
			}
		} else if (strhdnMode == "GETTTFROMFULLSEARCH"){
			buildHeader(arrFromCity,"F");
			buildFullsearch(arrFromCity,"F");
			buildButton(arrFromCity,"F");
			
			if (arrFromCity.length>0){
				if (strhdnCity == ""){
					strFocus = "i"+ 0 + "j"+ 0; 
					setFocus(strFocus);
					intRow = 0;
					intCol = 0;
					setStyleClass(strFocus ,strCityColor)
				}else {
					setDefaultFocus(arrFromCity);
					
				}
			}
		}else if (strhdnMode == "GETTTTOFULLSEARCH"){
			buildHeader(arrToCity,"T");
			buildFullsearch(arrToCity,"T"); 
			buildButton(arrToCity,"T"); 
			if (arrToCity.length>0){
				if (strhdnCity == ""){
					
					strFocus = "i"+ 0 + "j"+ 0; 
					setFocus(strFocus);

					intRow = 0;
					intCol = 0;
					setStyleClass(strFocus ,strCityColor)
				}else {
					setDefaultFocus(arrToCity);
					
				}
			}
		} else if (strhdnMode == "GETSFROMFULLSEARCH"){
			buildHeader(arrFromCity,"F");
			buildFullsearch(arrFromCity,"F");
			buildButton(arrFromCity,"F");
			
			if (arrFromCity.length>0){
				if (strhdnCity == ""){
					strFocus = "i"+ 0 + "j"+ 0; 
					setFocus(strFocus);
					intRow = 0;
					intCol = 0;
					setStyleClass(strFocus ,strCityColor)
				}else {
					setDefaultFocus(arrFromCity);
					
				}
			}
		}else if (strhdnMode == "GETSTOFULLSEARCH"){
			buildHeader(arrToCity,"T");
			buildFullsearch(arrToCity,"T"); 
			buildButton(arrToCity,"T"); 
			if (arrToCity.length>0){
				if (strhdnCity == ""){
					
					strFocus = "i"+ 0 + "j"+ 0; 
					setFocus(strFocus);

					intRow = 0;
					intCol = 0;
					setStyleClass(strFocus ,strCityColor)
				}else {
					setDefaultFocus(arrToCity);
					
				}
			}
		}else if (strhdnMode == "GETMPFROMFULLSEARCH"){
			buildHeader(arrFromCity,"F");
			buildFullsearch(arrFromCity,"F");
			buildButton(arrFromCity,"F");
			
			if (arrFromCity.length>0){
				if (strhdnCity == ""){
					strFocus = "i"+ 0 + "j"+ 0; 
					setFocus(strFocus);
					intRow = 0;
					intCol = 0;
					setStyleClass(strFocus ,strCityColor)
				}else {
					setDefaultFocus(arrFromCity);
					
				}
			}
		}else if (strhdnMode == "GETMPTOFULLSEARCH"){
			buildHeader(arrToCity,"T");
			buildFullsearch(arrToCity,"T"); 
			buildButton(arrToCity,"T"); 
			if (arrToCity.length>0){
				if (strhdnCity == ""){
					
					strFocus = "i"+ 0 + "j"+ 0; 
					setFocus(strFocus);

					intRow = 0;
					intCol = 0;
					setStyleClass(strFocus ,strCityColor)
				}else {
					setDefaultFocus(arrToCity);
					
				}
			}
		}
		
	}

	function buildHeader(arrCity,strType){
		var strHTMLText = ""; 
		var strHeader = "";
		
		if (strType == "F"){
			strHeader = strDepartureCity ;
		}else {
			strHeader = strArrivalCity +  " " + strhdnFrom ;
		}
		
		strHTMLText += "<table width='100%' border='0' cellpadding='1' cellspacing='0' align='" + strAlignRight + "'>";
		strHTMLText += "<tr>";
		strHTMLText += "<td class='bgDark' dir='ltr'>";
		strHTMLText += "	<table width='100%' border='0' cellpadding='3' cellspacing='0' align='" + strAlignRight + "'>";

		strHTMLText += "<tr>";
		strHTMLText += "<td colspan='4'><font class='fntHLite fntBold'>" + strHeader + "<\/font>";
		strHTMLText += "<td align='right'><a href='javascript:void(0)' onclick='pageClose();return false;'><img src='" + strImageURL + "Close.jpg' alt='' border='0' title='Close'><\/a>";
		strHTMLText += "<\/td>";
		strHTMLText += "<\/tr>";

		strHTMLText += "<\/table>";
		strHTMLText += "<\/td>";
		strHTMLText += "<\/tr>";
		strHTMLText += "<\/table>";

		parent.DivWrite("spnHeader", strHTMLText);
	}

	function buildFullsearch(arrCity,strType){
		var strHTMLText = ""; 
		var strClsItems = "GridItemsAlternate";	
		var strClsDisable = "";
		var strHeader = "";
		
		if (strType == "F"){
			strHeader = strDepartureCity ;
		}else {
			strHeader = strArrivalCity +  " " + strhdnFrom ;
		}
		
		
		strHTMLText += "<table width='100%' border='0' cellpadding='1' cellspacing='0' align='" + strAlignRight + "'>";
		strHTMLText += "<tr>";
		//strHTMLText += "<td class='bgDark'>";
		strHTMLText += "<td>";
		strHTMLText += "	<table width='100%' border='0' cellpadding='3' cellspacing='0' align='" + strAlignRight + "'>";
		/*
		strHTMLText += "<tr>";
		strHTMLText += "<td colspan='4'><font class='fntHLite fntBold'>" + strHeader + "<\/font>";
		strHTMLText += "<td align='right'><a href='javascript:void(0)' onclick='pageClose();return false;'><img src='" + strImageURL + "Close.jpg' alt='' title='Close'><\/a>";
		strHTMLText += "<\/td>";
		strHTMLText += "<\/tr>";
		*/		
		
		if (arrCity.length>0){
			intCeilValue = Math.ceil(arrCity.length / 5)
			
			
				for (var i = 0 ; i < intCeilValue ; i++){
					strHTMLText += "<tr>";
					for (var j = 0 ; j < 5 ; j++){
						var count = 0;
						
						switch (j){
							case 0 : 
								count = i;		
								break;
							case 1 : 
								count = intCeilValue*j + i;			
								break;
							case 2 : 
								count = intCeilValue*j + i;			
								break;
							case 3 : 
								count = intCeilValue*j + i;			
								break;
							case 4 : 
								count = intCeilValue*j + i;			
								break;
						}	
						
						var linkID =  "i"+i +"j" +j;	
						//class='" + strClsItems +"'
						if (count <arrCity.length){
							strHTMLText += "<td width='20%'  align='left' valign='top'><a href='#' id='" + linkID + "' onclick='setFlightFullSearch(" +  '"' + arrCity[count][0] + '"' + "," +  '"' + strType + '"' + ");' onmouseover='showMouseOver(" + i + " , " + j + ");' ><font class='" + strClsDisable + " fntLink'>" + arrCity[count][1] + "<\/font><\/td>"
						}else {
							strHTMLText += "<td width='20%' ><\/td>";
						}						
					}					
					strHTMLText += "<\/tr>";					
				}
			
			
		} else {
			strHTMLText += "<tr>";
			strHTMLText += "	<td colspan='5'>&nbsp;";
			strHTMLText += "		<font class='fntHLite fntBold'>" + strNoRecord + "<\/font>";
			strHTMLText += "	<\/td>";
			strHTMLText += "<\/tr>";
		}
		/*
		if (arrCity.length>0){
			strHTMLText += "<tr>";
		}else {
			strHTMLText += "<tr height='213px'>";
		}
			
			strHTMLText += "	<td colspan='5' class='" + strClsItems +"'>&nbsp;";
			strHTMLText += "	<\/td>";
			strHTMLText += "<\/tr>";
			strHTMLText += "<tr>";
			strHTMLText += "	<td colspan='5' align='center' class='" + strClsItems +"'>";
			strHTMLText += "		<input type='button' id='btnClose' name='btnClose' class='button buttonLL' value='Close' onclick='pageClose()' >";
			strHTMLText += "	<\/td>";
			strHTMLText += "<\/tr>";
		
		*/
		
		strHTMLText += "<\/table>";
		strHTMLText += "<\/td>";
		strHTMLText += "<\/tr>";
		strHTMLText += "<\/table>";
			
		DivWrite("spnFullSearch", strHTMLText);
		/*
		if (arrCity.length>0){
			setDisplay("divFullSearch", true);
		}else{
			setDisplay("divFullSearch", false);
			strErrMsg += buildError(arrErr["007"]) + "<br>";	
		}
		*/
		
	}	

	function buildButton(arrCity,strType){
		var strHTMLText = ""; 
		var strClsItems = "GridItemsAlternate";	

		strHTMLText += "<table width='100%' border='0' cellpadding='1' cellspacing='0' align='" + strAlignRight + "'>";
		strHTMLText += "<tr>";
		strHTMLText += "<td class='bgDark' dir='ltr'>";
		strHTMLText += "	<table width='100%' border='0' cellpadding='0' cellspacing='0' align='" + strAlignRight + "'>";

		strHTMLText += "<tr>";
		strHTMLText += "	<td colspan='5' align='center'>";
		strHTMLText += "		<input type='button' id='btnClose' name='btnClose' class='button buttonLL' value='Close' onclick='pageClose()' >";
		strHTMLText += "	<\/td>";
		strHTMLText += "<\/tr>";

		strHTMLText += "<\/table>";
		strHTMLText += "<\/td>";
		strHTMLText += "<\/tr>";
		strHTMLText += "<\/table>";

		parent.DivWrite("spnButton", strHTMLText);
	}
	
	function setFlightFullSearch(strCity,strType){
		
		if (strhdnTab == "FLIGHTSTATUS"){
			parent.setFlightFullSearch(strCity,strType);
		}else if (strhdnTab == "TIMETABLE"){
			parent.setFlightFullSearchTT(strCity,strType);
		}else if (strhdnTab == "FLIGHTSEARCH"){
			parent.setFlightFullSearchFSearch(strCity,strType);
		}else if (strhdnTab == "MULTIPOINT"){
			parent.setFlightFullSearchMP(strCity,strType);
		}
		//pageClose();
	}

	function pageClose(){
		try{
			/*
			if (opener != null){
				window.close();
			}else{
				parent.helpClose();
			}
			*/
			parent.setDisplay("spnAjaxSearch", false);
		}catch(e){}
	}

	function onLoad(){			
	}

	function setLinkFocus(objEvent){
		//alert(objEvent.keyCode)

		if (objEvent.keyCode != 34 && objEvent.keyCode != 33){
			for (var i = 0 ; i < intCeilValue ; i++){
				for (var j = 0 ; j < 5 ; j++){
					var strCon = "i"+i+"j"+j;
					try{
						setStyleClass(strCon ,"GridItemsDisable")
					}catch(e){}
				}
			}
		}
		
		
		if (objEvent.keyCode == 9){
			/*
			if ((intCol < 4) && (intRow < intCeilValue)) {
				intCol++;
				try{
					strFocus = "i" + intRow + "j" + intCol;
					setStyleClass(strFocus ,strCityColor)
					setFocus(strFocus);					
				}catch(e){
					intCol--;
					strFocus = "i" + intRow + "j" + intCol;
					setStyleClass(strFocus ,strCityColor)
				}
			}else{
				intCol = 0;
				intRow++;
				try{
					strFocus = "i" + intRow + "j" + intCol;
					setStyleClass(strFocus ,strCityColor)
					setFocus(strFocus);					
				}catch(e){
					intCol--;
					strFocus = "i" + intRow + "j" + intCol;
					setStyleClass(strFocus ,strCityColor)
				}
			}
			*/
			//alert(objEvent)

			
		}	
		

		if (objEvent.keyCode == 37){
			if ((intCol < 5) && (intRow < intCeilValue) && (intCol > 0)) {
				intCol--;
				try{
					strFocus = "i" + intRow + "j" + intCol;
					setStyleClass(strFocus ,strCityColor)
					setFocus(strFocus);
				}catch(e){
					intCol++;
					strFocus = "i" + intRow + "j" + intCol;
					setStyleClass(strFocus ,strCityColor)
				}
			}else{
				setStyleClass(strFocus ,strCityColor)
			}
		} 
		if (objEvent.keyCode == 38){
			if ((intRow > 0) && (intRow < intCeilValue)) {
				intRow--;
				try{
					strFocus = "i" + intRow + "j" + intCol;
					setStyleClass(strFocus ,strCityColor)
					setFocus(strFocus);
				}catch(e){
					intRow++;
					strFocus = "i" + intRow + "j" + intCol;
					setStyleClass(strFocus ,strCityColor)
				}
			}else{
				setStyleClass(strFocus ,strCityColor)
			}
		}
		
		if (objEvent.keyCode == 39){
			if ((intCol < 4) && (intRow < intCeilValue)) {
				intCol++;
				try{
					strFocus = "i" + intRow + "j" + intCol;
					setStyleClass(strFocus ,strCityColor)
					setFocus(strFocus);					
				}catch(e){
					intCol--;
					strFocus = "i" + intRow + "j" + intCol;
					setStyleClass(strFocus ,strCityColor)
				}
			}else{
				setStyleClass(strFocus ,strCityColor)
			}
		} 
		if (objEvent.keyCode == 40){
			if ((intRow >= 0) && (intRow < intCeilValue-1)) {
				intRow++;
				try{
					strFocus = "i" + intRow + "j" + intCol;
					setStyleClass(strFocus ,strCityColor) 
					setFocus(strFocus);					
				}catch(e){
					intRow--;
					strFocus = "i" + intRow + "j" + intCol;
					setStyleClass(strFocus ,strCityColor)
				}
			}else{
				setStyleClass(strFocus ,strCityColor)
			}

		}
		
		
	}

	function setDefaultFocus(arrCity){
		var blnFind = false;
		if (arrCity.length>0){
			intCeilValue = Math.ceil(arrCity.length / 5)
					
			for (var i = 0 ; i < intCeilValue ; i++){
				for (var j = 0 ; j < 5 ; j++){
					var count = 0;
					
					switch (j){
						case 0 : 
							count = i;		
							break;
						case 1 : 
							count = intCeilValue*j + i;			
							break;
						case 2 : 
							count = intCeilValue*j + i;			
							break;
						case 3 : 
							count = intCeilValue*j + i;			
							break;
						case 4 : 
							count = intCeilValue*j + i;			
							break;
					}	
					
					
					if (count <arrCity.length){
						if (arrCity[count][0] == strhdnCity){
							intRow = i;
							intCol = j;
							blnFind = true;	
							
						}
					}
				}										
			}					
		}
		if (blnFind){
			strFocus =  "i"+intRow +"j" +intCol;
			setFocus(strFocus);
			setStyleClass(strFocus ,strCityColor);
			
		}
	}

	function showMouseOver(inti , intj){
		for (var i = 0 ; i < intCeilValue ; i++){
			for (var j = 0 ; j < 5 ; j++){
				var strCon = "i"+i+"j"+j;
				try{
					setStyleClass(strCon ,"GridItemsDisable")
				}catch(e){}
			}
		}

		strFocus =  "i"+inti +"j" +intj;
		intRow = inti;
		intCol = intj;
		setFocus(strFocus);
		setStyleClass(strFocus ,strCityColor);
	}


	onLoad();