function showdets() {
   ret = showdetsfrom();
   ret = showdetsto();
}

function getinfofrom() { 
  var frominfo = "";
  var fromfldval = document.AirRqst.FromInfo.value;
  //alert ("in getinfofrom() fromfldval=" + fromfldval);   
  if ( fromfldval != "" ) {
     var infoar = fromfldval.split("|");
     var cntry = infoar[1];
     var city = infoar[2];
     var st = infoar[3];
     var port = infoar[4];
	 port = removeport(port);
     if ( st == cntry ) { frominfo = city + ", " + cntry; }
     else { frominfo = city + ", " + st + ", " + cntry; }
     if (( city != rtrim(port, " ")) && ( port != "")) { frominfo += ", " + port; }
     if ( frominfo.length > 40 ) { frominfo = frominfo.substr(0,40); }
  } 
  return frominfo;
}


function getinfoto() { 
  var toinfo = "";
  var tofldval = document.AirRqst.ToInfo.value;
  if ( tofldval != "" ) {
     var infoar = tofldval.split("|");
     var cntry = infoar[1];
     var city = infoar[2];
     var st = infoar[3];
     var port = infoar[4];
	 port = removeport(port);
     if ( st == cntry ) { toinfo = city + ", " + cntry; }
     else { toinfo = city + ", " + st + ", " + cntry; }
     if (( city != rtrim(port, " ")) && ( port != "")) { toinfo += ", " + port; }
     if ( toinfo.length > 40 ) { toinfo = toinfo.substr(0,40); }
  } 
  return toinfo;
}



function showdetsfrom() {
   var showval = getinfofrom();
//   alert ("in showdetsfrom() val =" + showval);
//   alert ("in showdetsfrom() length =" + showval.length );
   if (showval.length > 36 ) { showval = showval.substring(0,36); }
   var fromdiv = document.getElementById('portinfofrom');
   fromdiv.innerHTML = showval;
   if ( showval == "" ) { animatedcollapse.hide('portinfofrom'); }
   else { animatedcollapse.show('portinfofrom'); }
}

function showdetsto() {
   var showval = getinfoto();
   if (showval.length > 36 ) { showval = showval.substring(0,36); }
   var todiv = document.getElementById('portinfoto');
   todiv.innerHTML = showval;
   if ( showval == "" ) { animatedcollapse.hide('portinfoto'); }
   else { animatedcollapse.show('portinfoto'); }
}

function fillairportfrom(inportcode, inportinfo) {
//fill airport information after city selected from the list
   document.AirRqst.FromInfo.value = inportinfo;
   document.AirRqst.From.value = inportcode;
   animatedcollapse.hide('codeselectfrom');
   showdetsfrom();
}

function fillairportto(inportcode, inportinfo) {
//fill airport information after city selected from the list
   document.AirRqst.ToInfo.value = inportinfo;
   document.AirRqst.To.value = inportcode;
   animatedcollapse.hide('codeselectto');
   showdetsto();
}

function closeselectfrom() {
   animatedcollapse.hide('codeselectfrom');
}

function closeselectto() {
   animatedcollapse.hide('codeselectto');
}

function setdeparttime(intype){
   var timeval;
   if (intype=="dep") {
      timeval = document.AirRqst.LastDepTm.value;
      for(var i = 0; i < document.AirRqst.DepartTm.options.length; i++){
         if (document.AirRqst.DepartTm.options[i].value == timeval){
            document.AirRqst.DepartTm.options[i].selected = true;
            return;
         }
      }
   }
   else {
      timeval = document.AirRqst.LastRetTm.value;
      for(var i = 0; i < document.AirRqst.ReturnTm.options.length; i++){
         if (document.AirRqst.ReturnTm.options[i].value == timeval){
            document.AirRqst.ReturnTm.options[i].selected = true;
            return;
         }
      }
   }   
}

function setticksadult(){
   var ticksno = document.AirRqst.Lastadults.value;
   for(var i = 0; i < document.AirRqst.adults.options.length; i++){
      if (document.AirRqst.adults.options[i].value == ticksno){
         document.AirRqst.adults.options[i].selected = true;
         return;
      }
   }
}
function settickskids(){
   var ticksno = document.AirRqst.Lastkids.value;
   for(var i = 0; i < document.AirRqst.kids.options.length; i++){
      if (document.AirRqst.kids.options[i].value == ticksno){
         document.AirRqst.kids.options[i].selected = true;
         return;
      }
   }
}
function settickssenr(){
   var ticksno = document.AirRqst.Lastsenr.value;
   for(var i = 0; i < document.AirRqst.seniors.options.length; i++){
      if (document.AirRqst.seniors.options[i].value == ticksno){
         document.AirRqst.seniors.options[i].selected = true;
         return;
      }
   }
}

function setdatetype(intype){
   if (intype=="dep") {
      if (document.AirRqst.LastDeptype.value=='2') 
	     document.AirRqst.deptdttype[1].checked=true;
	  else	 
	     document.AirRqst.deptdttype[0].checked=true;
   }   
   else {
      if (document.AirRqst.LastRettype.value=='2') 
	     document.AirRqst.retdttype[1].checked=true;
	  else	 
	     document.AirRqst.retdttype[0].checked=true;
   }
}

function setclass(){
   var cclass = document.AirRqst.Lastclass.value;
   for(var i = 0; i < document.AirRqst.tickclass.options.length; i++){
      if (document.AirRqst.tickclass.options[i].value == cclass){
         document.AirRqst.tickclass.options[i].selected = true;
         return;
      }
   }
}

function setaddons(){
   if (document.AirRqst.Lastneedhotel.value == "yes")
      document.AirRqst.needhotel.checked=true;
   if (document.AirRqst.Lastneedcar.value == "yes")
      document.AirRqst.needcar.checked=true;
   if (document.AirRqst.Lastneedtrans.value == "yes")
      document.AirRqst.needtrans.checked=true;
   if (document.AirRqst.Lastneedfun.value == "yes")
      document.AirRqst.needfun.checked=true;
}

function settriptype(){
   var ctype = document.AirRqst.Lasttriptype.value - 1;
   if (ctype == null) { ctype = 1; }
   document.AirRqst.triptype[ctype].checked=true;
}

function openportswin(intype) {
	nwin = window.open( "airportsus.html?fromto=" + intype,'windport',
			"toolbar=no,location=yes,directories=no,status=yes," +
   			"menubar=no,scrollbars=yes,resizable=yes," +
   			"width=370,height=400");
}

function submitform(inval) {
  document.AirRqst.Curaction.value = inval;
  if (inval == 'reset') {
     document.AirRqst.FromInfo.value = "";
	 document.AirRqst.ToInfo.value = "";
  }
  document.AirRqst.submit();
}


function removeport(inval) {
   var outval = "";
   var cval = "";
   var pval = inval.toLowerCase();
   if ( pval.indexOf("airport") > -1 ) { 
       var valparts = inval.split(" ");
       for (var i = 0; i < valparts.length -1 ; i++) {
	       cval = valparts[i].toLowerCase();
		   if (cval != "airport") { outval += valparts[i] + " "; }
	   }
   }
   else { outval = inval; }
   return outval;
}

function rtrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}


function checkcode(intype, inval) {
  var done = false; 
  if ( inval.length == 3 ) {
     done = getportinfobycode(intype, inval);
  }	 
  else {
     if ( intype == 1 ) { done = infobycityfrom(inval); } 
	 else { done = infobycityto(inval); } 
  }
  return done;
}

function getportinfobycode(intype, inval) {
  var result = false;
  var oldcode = "";
  var newcode = "";
  var retcity = "";
  newcode = inval.toUpperCase();
  //alert("checking code " + newcode);   
  
  if ( intype == 1 ) {
     curcode = document.AirRqst.FromInfo.value;
     curcode = curcode.substr(0,3)
	 curcode = curcode.toUpperCase();
     if ( newcode != curcode ) {
        curcode = getinfobyaircode(newcode)
		if ( curcode != "" ) {
		   document.AirRqst.From.value = newcode;
		   document.AirRqst.FromInfo.value = curcode;
		   showdetsfrom();
		   result = true;
		}   
    	else { result = infobycityfrom(newcode); } //if not found airpot code try to find a 3 letter city
     }
  }
  else {
     curcode = document.AirRqst.ToInfo.value;
	 curcode = curcode.substr(0,3)
	 curcode = curcode.toUpperCase();
     if ( newcode != curcode ) {
        curcode = getinfobyaircode(newcode)
		if ( curcode != "" ) {
  	       document.AirRqst.To.value = newcode;
		   document.AirRqst.ToInfo.value = curcode;
		   showdetsto();
		   result = true;
		}   
    	else { result = infobycityto(newcode); }  //if not found airpot code try to find a 3 letter city
	 }
  }
  return result;
}

function infobycityfrom(incity) {
   var result = false;
   var ccity = incity.toUpperCase();
   var portsctr = 0;
   var ports = "";
   var port = "";
   var portcode = "";
   var portparts;
   var retcity = geportinfobycity(ccity);
   if (retcity != "") {
      var ports = retcity.split("~");
	  //if only one port get port code, 
	  //updare frominfo field 
	  //and replace current city in fromcode to port code 
	  if ( ports.length == 1 ) { 
	     port = ports[0];
	     portparts = port.split("|");
		 portcode = portparts[0];
		 document.AirRqst.From.value = portcode;
		 document.AirRqst.FromInfo.value = port;
		 result = true;
      }
	  else { //if multiple ports found build a select table
	     showselectportfrom(retcity);
		 result = false; 
	  } 
   }	   
   else { document.AirRqst.FromInfo.value = ""; }
   showdetsfrom(); 
   return result;
}

function infobycityto(incity) {
   var result = false;
   var ccity = incity.toUpperCase();
   var portsctr = 0;
   var ports = "";
   var port = "";
   var portcode = "";
   var portparts;
   var retcity = geportinfobycity(ccity);
   if (retcity != "") {
      var ports = retcity.split("~");
	  //if only one port get port code, 
	  //updare frominfo field 
	  //and replace current city in fromcode to port code 
	  if ( ports.length == 1 ) { 
	     port = ports[0];
	     portparts = port.split("|");
		 portcode = portparts[0];
		 document.AirRqst.To.value = portcode;
		 document.AirRqst.ToInfo.value = port;
		 result = true;
	  }
	  else { //if multiple ports found build a select table
	     showselectportto(retcity);
		 result = false; 
	  } 
   }	   
   else { document.AirRqst.ToInfo.value = ""; }
   showdetsto(); 
   return result;
}

function showselectportfrom(inportinfo) {
//process multiselection of airports for the same city name 
//show the list of ports to select
   var selectinfo = "";
   var frametop = '<table cellpadding="2" cellspacing="2" bgcolor="#64B1FF">' +
                  '<tr><td class="r8" align="center" bgcolor="#C4E1FF">Please select destination airport!</td></tr><tr><td>' +
                  '<table cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" class="t8">';
   var framebot = '<tr><td bgcolor="#C4E1FF" align="right" colspan="2"><a href="javascript:closeselectfrom();">x close</a></td></tr></table></td></tr></table>'
   var cclr1 = "#FFFFFF";
   var cclr2 = "#D5D5FF";
   var cclr = "#D5D5FF";
   if ( inportinfo != "" ) { 
      var ports = inportinfo.split("~");  
      for (var i = 0; i < ports.length -1 ; i++) {
	       var curport = ports[i];
           if ( curport != "" ) {
              var portinfo = "";
			  var infoar = curport.split("|");
			  var acode = infoar[0];
              var cntry = infoar[1];
              var city = infoar[2];
              var st = infoar[3];
              var port = infoar[4];
			  city = city.replace("'","`")
			  port = port.replace("'","`")
               
			  if ( st == cntry ) { portinfo = city + ", " + cntry; }
              else { portinfo = city + ", " + st + ", " + cntry; }
              
			  if ( cclr == cclr1 ) { cclr = cclr2; }
              else { cclr = cclr1; }
			  
			  var row = "<tr><td bgcolor=\"" + cclr + "\"><a href=\"javascript:fillairportfrom('" + acode + "','" + curport + "')\" class=\"t8\">" + acode + "</a>-</td>" +
			            "<td bgcolor=\"" + cclr + "\"><a href=\"javascript:fillairportfrom('" + acode + "','" + curport + "')\" class=\"t8\">" + portinfo + ", " + port + "</a></td></tr>";
			   
			  selectinfo = selectinfo + row;

		   } 
       }
       var fromdiv = document.getElementById('codeselectfrom');
       fromdiv.innerHTML = frametop + selectinfo + framebot;
	   animatedcollapse.show('codeselectfrom');
	}
}

function showselectportto(inportinfo) {
//process multiselection of airports for the same city name 
//show the list of ports to select
   var selectinfo = "";
   var frametop = '<table cellpadding="2" cellspacing="2" bgcolor="#64B1FF">' +
                  '<tr><td class="r8" align="center" bgcolor="#C4E1FF">Please select destination airport!</td></tr><tr><td>' +
                  '<table cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" class="t8">';
   var framebot = '<tr><td bgcolor="#C4E1FF" align="right" colspan="2"><a href="javascript:closeselectto();">x close</a></td></tr></table></td></tr></table>'
   var cclr1 = "#FFFFFF";
   var cclr2 = "#D5D5FF";
   var cclr = "#D5D5FF";
   if ( inportinfo != "" ) { 
      var ports = inportinfo.split("~");  
      for (var i = 0; i < ports.length -1 ; i++) {
	       var curport = ports[i];
           if ( curport != "" ) {
              var portinfo = "";
			  var infoar = curport.split("|");
			  var acode = infoar[0];
              var cntry = infoar[1];
              var city = infoar[2];
              var st = infoar[3];
              var port = infoar[4];
 			  city = city.replace("'","`")
			  port = port.replace("'","`")
              
			  if ( st == cntry ) { portinfo = city + ", " + cntry; }
              else { portinfo = city + ", " + st + ", " + cntry; }
              
			  if ( cclr == cclr1 ) { cclr = cclr2; }
              else { cclr = cclr1; }
			  
			  var row = "<tr><td bgcolor=\"" + cclr + "\"><a href=\"javascript:fillairportto('" + acode + "','" + curport + "')\" class=\"t8\">" + acode + "</a>-</td>" +
			            "<td bgcolor=\"" + cclr + "\"><a href=\"javascript:fillairportto('" + acode + "','" + curport + "')\" class=\"t8\">" + portinfo + ", " + port + "</a></td></tr>";
			   
			  selectinfo = selectinfo + row;
		   } 
       }
       var todiv = document.getElementById('codeselectto');
       todiv.innerHTML = frametop + selectinfo + framebot;
	   animatedcollapse.show('codeselectto');
	}
}

function openmlto(ina, inn, intype) {
	nwin = window.open( "mtoagent.asp?a=" + ina + "&n=" + inn + "&t=" + intype,"mto",
			"toolbar=no, location=no, directories=no, status=no," +
   			"menubar=no,scrollbars=no,resizable=no,width=20,height=10") 
}

function openpulaski() {
	nwin = window.open( "http://www.pulaskitravel.com/mkaplenko",'pulaski',
			"toolbar=yes,location=yes,directories=no,status=yes," +
   			"menubar=yes,scrollbars=yes,resizable=yes")
}

function openwebmlto(infile) {
	nwin = window.open( "webmltoagent.asp?fl=" + infile,"wmto",
			"toolbar=no, location=no, directories=no, status=no," +
   			"menubar=no,scrollbars=yes,resizable=yes,width=400,height=400");
}


