var pjName = "/AtlasjetWeb";
var show=0;
var hide=0;
function setBrowser() {
	if(show==0 || hide==0) {
		if (navigator.appName=="Microsoft Internet Explorer"){	
			show='inline';
			hide='none';
		}
		else {
			show='table-row';
			hide='none';
		}
	}
}
setBrowser();


function cityPairProcess(from,to,lang) {
	ajaxpack.getAjaxRequest(pjName+'/include/cityPair.jsp', 'from='+from+'&to='+to+'&lang='+lang, processCityPair, 'xml');
}

function processCityPair(){  
	arrayList = null;
	var myajax=ajaxpack.ajaxobj
	var myfiletype=ajaxpack.filetype
	if (myajax.readyState == 4){
		if (myajax.status==200 || window.location.href.indexOf("http")==-1){
			if (myfiletype=="txt") {
				alert(myajax.responseText)
			}
			else{

				var airopen = myajax.responseXML.getElementsByTagName("CityPair")[0];
				if (airopen!=null){
					arrayList = new Array(airopen.childNodes.length);
					for(var iP=0;iP<airopen.childNodes.length;iP++) {
					  var param = myajax.responseXML.getElementsByTagName("Param")[iP];
					  if (param != null){
					  		parpro = param.childNodes[0].nodeValue.split(","); 
							arrayList[i] = new Array(3);
							pFrom = parpro[0];
							pTo = parpro[1];
							pLang = parpro[2];
							
					  }
					
					}
				}
				
				if (pLang=='EN'){
					lblChoose = "Select"
				}else{
					lblChoose = "Seçiniz";
				}

				var toId = 1;
				var ecnfound = 0;
				var theSelect = document.forms["criters"].to;
				theSelect.options.length = 0;
				
				var option = new Option(lblChoose, "CHOOSE");
				theSelect.options[0] = option;

			
				if (airopen!=null){
					arrayList = new Array(airopen.childNodes.length);
					for(var i=0;i<airopen.childNodes.length;i++) {
					  var city = myajax.responseXML.getElementsByTagName("City")[i];
					   if (city != null){
							emrpro = city.childNodes[0].nodeValue.split(","); 
							arrayList[i] = new Array(2);
							to = emrpro[0];
							todesc = emrpro[1];

							var option = new Option(todesc, to);
							theSelect.options[i+1] = option;
							
							if (to!='IST' && to==pTo){
								toId = i+1;
							}else if (to=='IST'){
								toId = i+1;
							}	
							
							if (pFrom=='ECN' || to=='ECN'){
								ecnfound = 1;
							}
						
							//alert(to);
							//alert(todesc);
					   }

					}					
					
				}

				if (ecnfound==0){
					noScClosediv('tblogr');
					noScClosediv('tbltsk');
				}
				
				
				document.criters.to.options[toId].selected=true;
				ftControl();
				
			}
		}

	}
}				

function cityPairProcessTimeTable(from,to,lang) {
	ajaxpack.getAjaxRequest(pjName+'/include/cityPair.jsp', 'from='+from+'&to='+to+'&lang='+lang, processCityPairTimeTable, 'xml');
}

function processCityPairTimeTable(){  
	arrayList = null;
	var myajax=ajaxpack.ajaxobj
	var myfiletype=ajaxpack.filetype
	if (myajax.readyState == 4){
		if (myajax.status==200 || window.location.href.indexOf("http")==-1){
			if (myfiletype=="txt") {
				alert(myajax.responseText)
			}
			else{

				var airopen = myajax.responseXML.getElementsByTagName("CityPair")[0];
				if (airopen!=null){
					arrayList = new Array(airopen.childNodes.length);
					for(var iP=0;iP<airopen.childNodes.length;iP++) {
					  var param = myajax.responseXML.getElementsByTagName("Param")[iP];
					  if (param != null){
					  		parpro = param.childNodes[0].nodeValue.split(","); 
							arrayList[i] = new Array(3);
							pFrom = parpro[0];
							pTo = parpro[1];
							pLang = parpro[2];
							
					  }
					
					}
				}
				
				if (pLang=='EN'){
					lblChoose = "Select"
				}else{
					lblChoose = "Seçiniz";
				}

				var toId = 1;
				var ecnfound = 0;
				var theSelect = document.forms["criters"].to;
				theSelect.options.length = 0;
				
				var option = new Option(lblChoose, "CHOOSE");
				theSelect.options[0] = option;

			
				if (airopen!=null){
					arrayList = new Array(airopen.childNodes.length);
					for(var i=0;i<airopen.childNodes.length;i++) {
					  var city = myajax.responseXML.getElementsByTagName("City")[i];
					   if (city != null){
							emrpro = city.childNodes[0].nodeValue.split(","); 
							arrayList[i] = new Array(2);
							to = emrpro[0];
							todesc = emrpro[1];

							var option = new Option(todesc, to);
							theSelect.options[i+1] = option;
							
							
							/*
							if (to!='IST' && to==pTo){
								toId = i+1;
							}else if (to=='IST'){
								toId = i+1;
							}
							*/
							if(to==pTo){
								toId=i+1;
							}	
							
							if (pFrom=='ECN' || to=='ECN'){
								ecnfound = 1;
							}
						
							//alert(to);
							//alert(todesc);
					   }

					}					
					
				}

				if (ecnfound==0){
					noScClosediv('tblogr');
					noScClosediv('tbltsk');
				}
				
				
				document.criters.to.options[toId].selected=true;
				ttSend();
				
			}
		}

	}
}				




function createAjaxObj(){
var httprequest=false
if (window.XMLHttpRequest){ // if Mozilla, Safari etc
httprequest=new XMLHttpRequest()
if (httprequest.overrideMimeType)
httprequest.overrideMimeType('text/xml')
}
else if (window.ActiveXObject){ // if IE
try {
httprequest=new ActiveXObject("Msxml2.XMLHTTP");
} 
catch (e){
try{
httprequest=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e){}
}
}
return httprequest
}

var ajaxpack=new Object()
ajaxpack.basedomain="http://"+window.location.hostname
ajaxpack.ajaxobj=createAjaxObj()
ajaxpack.filetype="txt"
ajaxpack.addrandomnumber=0 //Set to 1 or 0. See documentation.

ajaxpack.getAjaxRequest=function(url, parameters, callbackfunc, filetype){
ajaxpack.ajaxobj=createAjaxObj() //recreate ajax object to defeat cache problem in IE
if (ajaxpack.addrandomnumber==1) //Further defeat caching problem in IE?
var parameters=parameters+"&ajaxcachebust="+new Date().getTime()
if (this.ajaxobj){
this.filetype=filetype
this.ajaxobj.onreadystatechange=callbackfunc
this.ajaxobj.open('GET', url+"?"+parameters, true)
this.ajaxobj.send(null)
}
}

ajaxpack.postAjaxRequest=function(url, parameters, callbackfunc, filetype){
ajaxpack.ajaxobj=createAjaxObj() //recreate ajax object to defeat cache problem in IE
if (this.ajaxobj){
this.filetype=filetype
this.ajaxobj.onreadystatechange = callbackfunc;
this.ajaxobj.open('POST', url, true);
this.ajaxobj.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
this.ajaxobj.setRequestHeader("Content-length", parameters.length);
this.ajaxobj.setRequestHeader("Connection", "close");
this.ajaxobj.send(parameters);
}
}



