	
	var PanelOne = null;
	var PanelTwo = null;
	function chSearchType(sType)
	{
		if(PanelOne==null)PanelOne = document.getElementById("PanelOneTBL");
		if(PanelTwo==null)PanelTwo = document.getElementById("PanelTwoTBL");
		switch(sType){
			case "RoundTrip" : {
				PanelOne.style.display = "block";
				PanelTwo.style.display = "none";
				document.getElementById("ReturnFlightTR").style.display = document.all? "block" : "table-row";
				break;
			}
			case "OneWay" : {
				PanelOne.style.display = "block";
				PanelTwo.style.display = "none";
				document.getElementById("ReturnFlightTR").style.display = "none";
				break;
			}
			case "MultiDestination" : {
				PanelOne.style.display = "none";
				PanelTwo.style.display = "block";
				document.getElementById("ReturnFlightTR").style.display = "none";
				buildPanelTwo();
				break;
			}
		}
	}
	function buildPanelTwo()
	{
		segTotal = document.forms["AirSearchForm"].segCount.value;
		segToAdd = segTotal - (PanelTwo.rows.length-1);
		for(s=0;s<segToAdd;s++)addSegment();
	}
	function addSegment(){
		rowToAdd = PanelTwo.rows[PanelTwo.rows.length-2];
		rowIndex = PanelTwo.rows.length-1;
		//alert(rowIndex);
		newRow = PanelTwo.insertRow(rowIndex);
		for(i=0;i<rowToAdd.cells.length;i++){
			newCell = newRow.insertCell(i);
			innerHTML = rowToAdd.cells[i].innerHTML;
			switch(i){
				case 1 : {innerHTML = innerHTML.replace("fromCity_" + rowIndex,"fromCity_" + (rowIndex+1));break;}
				case 3 : {innerHTML = innerHTML.replace("toCity_" + rowIndex,"toCity_" + (rowIndex+1));break;}
				case 5 : {innerHTML = innerHTML.replace("flyDate_" + rowIndex,"flyDate_" + (rowIndex+1));break;}
				case 7 : {innerHTML = innerHTML.replace("flyTime_" + rowIndex,"flyTime_" + (rowIndex+1));break;}
			}
			//alert(innerHTML);
			newCell.innerHTML = innerHTML;
		}
		eButtons();
	}
	function removeSegment(){
		PanelTwo.deleteRow(PanelTwo.rows.length-2);
		eButtons();
	}
	function eButtons()
	{
		segCount = PanelTwo.rows.length-1;
		document.forms["AirSearchForm"].segCount.value = segCount;
		document.getElementById("AddSegmentBTN").disabled = segCount<8 ? false : true;
		document.getElementById("DelSegmentBTN").disabled = segCount>1 ? false : true;
	}
	function focusObj(obj){
		if(obj.value==obj.getAttribute("defValue"))obj.value="";
	}
	function blurObj(obj){
		if(obj.value=="")obj.value = obj.getAttribute("defValue");
		window.setTimeout(hideList2,100);
	}
	function OpenWin(url,name,features){
		window.open(url,name,features);
	}
	function ValidateSearch(){
		alert_message = "";
		formObj = document.forms["AirSearchForm"];

		if(formObj.searchType[0].checked) {
			if(formObj.fromCity.value == "" || formObj.fromCity.value == formObj.fromCity.getAttribute("defValue"))alert_message += " - departure city\n";
			if(formObj.flyDate_from.value == "" || formObj.flyDate_from.value == formObj.flyDate_from.getAttribute("defValue"))alert_message += " - departure date\n";
			if(formObj.toCity.value == "" || formObj.toCity.value == formObj.toCity.getAttribute("defValue"))alert_message += " - arrival city\n";
			if(formObj.flyDate_return.value == "" || formObj.flyDate_return.value == formObj.flyDate_return.getAttribute("defValue"))alert_message += " - return date\n";

		}
		else if(formObj.searchType[1].checked) {
			if(formObj.fromCity.value == "" || formObj.fromCity.value == formObj.fromCity.getAttribute("defValue"))alert_message += " - departure city\n";
			if(formObj.toCity.value == "" || formObj.toCity.value == formObj.toCity.getAttribute("defValue"))alert_message += " - arrival city\n";
			if(formObj.flyDate_from.value == "" || formObj.flyDate_from.value == formObj.flyDate_from.getAttribute("defValue"))alert_message += " - departure date\n";
		}
		else if(formObj.searchType[2].checked) {
			for(i=1;i<=document.forms["AirSearchForm"].segCount.value;i++){
				if(formObj["fromCity_" + i].value == "" || formObj["fromCity_" + i].value == formObj["fromCity_" + i].getAttribute("defValue"))alert_message += " - flight #"+ i +" departure city\n";
				if(formObj["toCity_" + i].value == "" || formObj["toCity_" + i].value == formObj["toCity_" + i].getAttribute("defValue"))alert_message += " - flight #"+ i +" arrival city\n";
				if(formObj["flyDate_" + i].value == "" || formObj["flyDate_" + i].value == formObj["flyDate_" + i].getAttribute("defValue"))alert_message += " - flight #"+ i +" departure date\n";
			}
		}
		
		passNum = parseInt(formObj.aCount.value) + parseInt(formObj.sCount.value) + parseInt(formObj.cCount.value) + parseInt(formObj.yCount.value);
		if(passNum == 0){
			alert_message += " - the number of passengers travelling \n";
		}
		
		if(alert_message!=""){
			alert("The following information was not provided : \n" + alert_message);
			return false;
		}
		return true;
	}
	
	
	
	
	var cObj;
	var hCalInt = null;
	function showCalendar(obj){
		window.clearInterval(hCalInt)
		cObj = obj;
		cBody = document.getElementById("calBody");
		cBody.style.left=obj.offsetLeft;
		cBody.style.top=obj.offsetTop + obj.offsetHeight + 1;
		window.frames["calBody"].selectDate(obj.value,obj.attributes["minDate"].value,obj.attributes["maxDate"].value);
		cBody.style.display='block';
		cObj.select();
	}
	function hideCalendar(obj){
		if(!document.all || document.activeElement.id=='calBody') return;
		window.frames["calBody"].selectDate(obj.value,obj.attributes["minDate"].value,obj.attributes["maxDate"].value);
		doHideCal(obj);
	}
	function doHideCal(obj){
		window.clearInterval(hCalInt)
		cBody = document.getElementById("calBody");
		cBody.style.display='none';
		cObj.value = window.frames["calBody"].selDate;
		if(cObj.attributes["raiseChangeEvent"].value=='true')calChange(cObj);
	}
	function calChange(calObj){
		formObj = document.forms["AirSearchForm"];
		switch(calObj.name)
		{
			case "flyDate_from" : formObj["flyDate_return"].attributes["minDate"].value = calObj.value;break;
			case "flyDate_1" : if(formObj["flyDate_2"]){formObj["flyDate_2"].attributes["minDate"].value = calObj.value;}break;
			case "flyDate_2" : if(formObj["flyDate_3"]){formObj["flyDate_3"].attributes["minDate"].value = calObj.value;}break;
			case "flyDate_3" : if(formObj["flyDate_4"]){formObj["flyDate_4"].attributes["minDate"].value = calObj.value;}break;
			case "flyDate_4" : if(formObj["flyDate_5"]){formObj["flyDate_5"].attributes["minDate"].value = calObj.value;}break;
			case "flyDate_5" : if(formObj["flyDate_6"]){formObj["flyDate_6"].attributes["minDate"].value = calObj.value;}break;
			case "flyDate_6" : if(formObj["flyDate_7"]){formObj["flyDate_7"].attributes["minDate"].value = calObj.value;}break;
			case "flyDate_7" : if(formObj["flyDate_8"]){formObj["flyDate_8"].attributes["minDate"].value = calObj.value;}break;
		}
	}
	
	
	var lObj;
	var hListInt = null;
	function showAirportsList(obj){
		
		window.clearInterval(hListInt)
		lObj = document.forms["AirSearchForm"][obj];
		lBody = document.getElementById("listBody");
		lObj.select();
		
		/*lObj1 = obj;	
		
		lBody.style.left=Left(lObj1)+'px';
		lBody.style.top=Top(lObj1)+lObj1.offsetHeight+'px';
		lBody.style.display='';
		lBody.style.zIndex=10;
		*/
		
		
		lBody.style.left=lObj.offsetLeft;
		lBody.style.top=lObj.offsetTop + lObj.offsetHeight + 1;
		window.frames["listBody"].selectAirport(lObj.value);
		lBody.style.display='block';
		
	}
	function hideList(obj){
		if(!document.all || document.activeElement.id=='listBody') return;
		doHideList();
	}
	function doHideList(){
		window.clearInterval(hListInt)
		lBody = document.getElementById("listBody");
		lBody.style.display='none';
	}
	
	function buildList(obj)
	{
		
		
		strVal = lObj.value.toLowerCase();
		lBody = document.getElementById("listBody2");
		lBodyDoc = window.frames["listBody2"].document;
		if(strVal.length > 2)
		{
			lBody.style.left=lObj.offsetLeft;
			lBody.style.top=lObj.offsetTop + obj.offsetHeight + 1;
			
			
			//search
			foundValues = new Array()
			for(a in a_values)
			{
				for(i=0;i<a_values[a].length;i++){
					str = a_values[a][i].split(":");
					if(str[0].toLowerCase().indexOf(strVal)==0)
					{ 
						//foundValues[foundValues.length] = a_values[a][i] +", "+ getCountryAndState(a);
						foundValues.unshift(a_values[a][i] +", "+ getCountryAndState(a));
					}
					else if (str[1].toLowerCase().indexOf(strVal)==0)
					{
						foundValues[foundValues.length] = a_values[a][i] +", "+ getCountryAndState(a);
					}
				}
			}
			
			if(foundValues.length>0)
			{
				lBody.style.display='block';
				lBody.style.height = foundValues.length > 10 ? 170 : foundValues.length * 17;
				lBodyDoc.clear();
				lBodyDoc.write("<body bgColor='beige' style='font:11px Verdana;margin:0;padding:0'>");
				for(i=0;i<foundValues.length; i++)
				{						
					str = foundValues[i].split(":");
					lBodyDoc.write("<div style=\"padding:2;cursor:pointer\" onMouseOver=\"this.style.backgroundColor='wheat'\" onMouseOut=\"this.style.backgroundColor='transparent'\" onClick=\"parent.closeList('"+ str[0] +"')\">["+ str[0] +"] "+ str[1] +"</div>");
				}
				lBodyDoc.write("</body>");
				lBodyDoc.close();
			}
			else lBody.style.display='none';
		}
		else lBody.style.display='none';
	}
	function getCountryAndState(sCode)
	{
		contry_state = sCode.split(":");
		country = "";
		state = contry_state[1];
		for(s in c_values)
		{
			if(c_values[s].indexOf(contry_state[0])==0){
				country = c_values[s].split(":")[1];
			}
		}
		if(state!="All") return state + ", " + country;
		else return country;
	}
	/*close the click*/
	function cllst()
	{
			if(document.getElementById("listBody2").style.display=='block')
			{
				document.getElementById("listBody2").style.display='none';
			}
	}
	function closeList(str){  lObj.value = str; hideList2();   }
	function hideList2(){document.getElementById("listBody2").style.display='none';}
