﻿
var airlines=new Array(0);
var win=null;
var prefix=null;
var suffix=null;
var cnrowner=null;


/* airline list
 * the order should be the same as in the input screen !!
 */  
 /*Castle 29Jun07 : change the order of the airline to make them(full airline names) in alphabetic order
   CI CV CX CZ  ---> CV CX CI CZ       
 */
	  var airlineIndex=0;
	  airlines[airlineIndex++]=new airline("LD","288","AHK Air Hong Kong");
	  /* Castle 26Jun07: temporary remark
	  airlines[airlineIndex++]=new airline("AC","014","Air Canada");
	  */

	  /* Modified by Arthur 06Dec2007,add compose_RUpage(prefix,suffix)*/
	  airlines[airlineIndex++]=new airline("RU","580","AirBridge Cargo");

	  airlines[airlineIndex++]=new airline("CA","999","Air China");

	  airlines[airlineIndex++]=new airline("BA","125","British Airways");

	  airlines[airlineIndex++]=new airline("CV","172","Cargolux Airlines");
	  airlines[airlineIndex++]=new airline("CX","160","Cathay Pacific Airways");
	  airlines[airlineIndex++]=new airline("CI","297","China Airlines");
	  airlines[airlineIndex++]=new airline("CZ","784","China Southern Airlines");
      /* Castle 26Jun07: temporary remark 
	  airlines[airlineIndex++]=new airline("LY","114","El-Al Israel Airlines");
	  airlines[airlineIndex++]=new airline("EK","176","Emirates");
	  */
	  airlines[airlineIndex++]=new airline("BR","695","Eva Airways");

	  airlines[airlineIndex++]=new airline("AY","105","Finnair Cargo");

	  airlines[airlineIndex++]=new airline("KA","043","Hong Kong Dragon Airlines Ltd");
	  
	  //Added by Boo 25APR 2008 for APP001255, start--
      airlines[airlineIndex++]=new airline("JL","131","Japan Airlines International Co., Ltd.");
      //Added by Boo 25APR 2008 for APP001255, end--
      
	  airlines[airlineIndex++]=new airline("MH","232","Malaysia Airlines");
      // Castle 25Jun: switch position of 'VS' and '5X'
      
      /* Modified by Castle 16May 2007 ,add an element in airlines*/
      airlines[airlineIndex++]=new airline("5X","406","UPS");
      
      airlines[airlineIndex++]=new airline("VS","932","Virgin Atlantic Airway");

/* hactl provide Airine Cargo Tracking services for other airlines
 */
var hactlProvide=new Array(0);
	  airlineIndex=0
	  hactlProvide[airlineIndex++] = "LD";
	  //Castle 25Jun07  new link for'MH'
	  //hactlProvide[airlineIndex++] = "MH";



if (typeOfBrowser == "IE4" || typeOfBrowser == "NN4")
{
	var btnSubmit = new Image();
	var btnClear = new Image();
	var btnClose = new Image();
	var btnSubmit_b = new Image();
	var btnClear_b = new Image();
	var btnClose_b = new Image();

	btnSubmit.src = "images/btn_submit.jpg";
	btnClear.src = "images/btn_clear.jpg";
	btnClose.src = "images/btn_close.jpg";;
	btnSubmit_b.src = "images/btn_submit_b.jpg";;
	btnClear_b.src = "images/btn_clear_b.jpg";;
	btnClose_b.src = "images/btn_close_b.jpg";;
}

function submitawb()
{

  if(document.frmMain.tracktype[0].checked)
  {
    document.frmMain.submit();
  }
  else if(document.frmMain.tracktype[1].checked)
  {
    airlineTrack();
  }
}

function airlineTrack() {

    prefix=document.frmMain.Prefix.value;
    suffix=document.frmMain.Suffix.value;
    if (document.frmMain.Owner.selectedIndex == 0)
    {
       // submit to server to get the error message
       if (document.frmMain.Owner.selectedIndex==0) {
	  document.ACTForm.Prefix.value = prefix;
	  document.ACTForm.Suffix.value = suffix;
	  document.ACTForm.Owner.value = cnrowner;
	  document.ACTForm.submit();
       }
    } else {
	// find the airline name (short form) of the cnr owner
	cnrowner = airlines[document.frmMain.Owner.selectedIndex-1].airname;

	if (isHactlProvide(cnrowner) == 0) {
	   // invoke Airline cargo tracking provided by Hactl.com
	   document.ACTForm.Prefix.value = prefix;
	   document.ACTForm.Suffix.value = suffix;
	   document.ACTForm.Owner.value = cnrowner;
	   document.ACTForm.submit();

	} else {
	   // redirect to airline's cargo tracking page
	   win=window.open("","airline_result","HEIGHT=500,WIDTH=660,status=yes,toolbar=no,directories=no,menubar=no,location=no,scrollbars=yes,resizable=yes,left=130,screenX=130,top=0,screenY=0");
	   win.focus();
	   logfile="http://www.hactl.com/LOGCT_"+cnrowner+".htm";
	   win.location.href=logfile;
	   setTimeout("trackpage()",1000);
	}
    }
}

function trackpage()
{
     eval('compose_' + cnrowner + 'page(prefix,suffix)');
}

/**
 * Compose the Form to submit
 * Note: if the form require POST method, the form is declared in the jsp
 */ 
 
 /* Castle 26Jun07: temporary remark
function compose_ACpage(prefix,suffix)
{
     document.ACForm.action = "http://ac.hexaware.com/servlet/ACTrackandTrace";
     document.ACForm.s_acn.value = prefix;
     document.ACForm.s_sref.value = suffix;
     document.ACForm.submit();
}
*/
function compose_CApage(prefix,suffix)
{
     document.CAForm.action = "http://www.cargoserv.com/webtracking/ca/etracking.asp";
     document.CAForm.Carrier.value = "CA";
     document.CAForm.Pfx.value = prefix;
     document.CAForm.Shipment.value = suffix;
     document.CAForm.submit();
}
function compose_BApage(prefix,suffix)
{
     document.BAForm.action = "http://www.baworldcargo.com/tracking/results.jsp";
     document.BAForm.AWBprefix.value = "125";
     document.BAForm.AWBnumber.value = suffix;
     document.BAForm.submit();
}
function compose_CIpage(prefix,suffix)
{    //Castle 21June 2007{
     //document.CIForm.action = "http://calenje.china-airlines.com/prog/oiaa.cgi";
     document.CIForm.action = "http://calec.china-airlines.com/ecgo/en/login.asp";
     //document.CIForm.car_pre.value = prefix;
     //document.CIForm.car_seq.value = suffix;
     document.CIForm.txtpfx.value = prefix;
     document.CIForm.txtawbno.value = suffix;     
     document.CIForm.curr.value= "tracking";
     document.CIForm.next.value= "tracking";
     document.CIForm.submit();
     //}
}
function compose_CVpage(prefix,suffix)
{    //Castle 21June 2007{
     //document.CVForm.action = "http://www.traxon.com/traxon-bin/clx_fsr.cgi";
     cv_str = "http://www.cargolux.com/intraservlet/track?awbpre=172&awbnum="+suffix+"&image.x=0&image.y=0";
     //document.CVForm.awbpre.value = prefix;
     //document.CVForm.awbnum.value = suffix;
     //document.CVForm.submit();
     /*Castle 28Jun07 : new window to open the cargo tacking page*/
     //win.location.href = cv_str;
     cv_win = window.open(cv_str,"","");
}

function compose_CXpage(prefix,suffix)
{
      //Castle 21June 2007{
     //document.CXForm.action = "http://www.cathaypacific.com/cgo/en/eservice/track/1,,110530,00.html";
     document.CXForm.action = "http://www.cathaypacificcargo.com/usrapps/eServices/track/track.aspx?i="+prefix+"-"+suffix;
     //document.CXForm.acn1.value = prefix;
     //document.CXForm.awb1.value = suffix;
     //document.CXForm.hawb1.value = "";
     //document.CXForm.rowNum.value = "1";
     //document.CXForm.event.value = "track";
     document.CXForm.submit();
}
function compose_CZpage(prefix,suffix)
{
     cz_str="http://cargo.cs-air.com/dyun/awbbrower.asp?txtPrefix="+prefix+"&txtNo="+suffix+"&NextFlag=1";
     /*Castle 28Jun07 : new window to open the cargo tacking page*/
     //win.location.href=cz_str;
     cz_win = window.open(cz_str,"","");
}
/* Castle 26Jun07: temporary remark
function compose_LYpage(prefix,suffix)
{
     ly_str="http://www4.elal.co.il/cargo/awbSearch.jsp?awbCheckDigit="+suffix.substring(suffix.length-1,suffix.length)+"&awbDataNumber="+suffix+"&airlineIdNumber="+prefix;
     win.location.href=ly_str;
}
function compose_EKpage(prefix,suffix)
{
     ek_str="http://www.skychain.com/cgi-bin/status.pl?Esys=P&Eac=EK&Mform=Cargo_Status&Mid=WEBFSR&Mname=Tracking&Msmi=FSR&status=do&job_no=&Mdata=&awb_pre="+prefix+"&awb_no="+suffix+"&process=do";
     win.location.href=ek_str;
}
*/
function compose_BRpage(prefix,suffix)
{    //Castle 21June 2007 
     //br_str="http://service.evaair.com/online/html/global/asi0a140.asp?Language=E&PreCode="+prefix+"&AwbNo="+suffix;
     //win.location.href=br_str;
     document.BRForm.action = "http://www.brcargo.com/AWB/cargoQuery.do?locale=en_us";
     document.BRForm.preCode.value = prefix;
     document.BRForm.awbNo.value = suffix;
     document.BRForm.submit();
    
}

/* Modified by Castle 16May 2007, comment the old compose_AYpage(),and add a new one */
/*
function compose_AYpage(prefix,suffix)
{
     document.AYForm.action = "http://cgocool.finnair.fi/Public/default.asp";
     document.AYForm.LAN.value = "1";
     document.AYForm.prefix.value = "105";
     document.AYForm.AWBnro.value = suffix;
     document.AYForm.submit();
}
*/
function compose_AYpage(prefix,suffix)
{          
     document.AYForm.action = "http://www.champ.aero/intraservlet/fintrack";
     document.AYForm.LAN.value = "1";
     document.AYForm.awbpre.value = "105";
     document.AYForm.awbnum.value = suffix;
     document.AYForm.submit();
}

/*Castle 28Jun07 : new link http://www.virgin-atlantic.com/en/cn/cargo/traceresults.jsp*/
function compose_VSpage(prefix,suffix)
{
     //document.VSForm.action = "http://www.virgin-atlantic.com/trackTrace.do";
     document.VSForm.action = "http://www.virgin-atlantic.com/en/cn/cargo/traceresults.jsp";
     document.VSForm.awbPrefix.value = prefix;
     document.VSForm.awbNumber.value = suffix;
     document.VSForm.submit();
}
function compose_KApage(prefix,suffix)
{
    //Castle 21June 2007 { 
      /* 
     document.KAForm.action = "http://www1.traxon.net/dragonair/status/svrscript/status.asp";
     document.KAForm.airline.value = "ka";
     document.KAForm.companyid.value = "traxon";
     document.KAForm.awbpre1.value = "043";
     document.KAForm.awbnum1.value = suffix;
     document.KAForm.awbpre2.value = "043";
     document.KAForm.awbnum2.value = "";
     document.KAForm.awbpre3.value = "043";
     document.KAForm.awbnum3.value = "";
     document.KAForm.awbpre4.value = "043";
     document.KAForm.awbnum4.value = "";
     document.KAForm.awbpre5.value = "043";
     document.KAForm.awbnum5.value = "";
     document.KAForm.submit();
     */
     ka_str = "http://www.dragonaircargo.com/usrapps/eServices/track/track.aspx?i="+prefix+"-"+suffix;
      /*Castle 28Jun07 : new window to open the cargo tacking page*/
     //win.location.href = ka_str;
     ka_win = window.open(ka_str,"","");
     //}
}

/* Modified by Castle 16May 2007 ,add compose_5Xpage(prefix,suffix)*/
/* Castle 28Jun07 : 406->prefix*/
function compose_5Xpage(prefix,suffix)
{
     document.FXForm.action = "http://www.ups.com/actrack/track/submit";
     document.FXForm.loc.value = "en_US";
     //document.FXForm.awbNum.value = "406"+suffix;
     document.FXForm.awbNum.value = prefix+suffix;
     document.FXForm.submit();
}

/* Modified by Castle 26June 2007 ,add compose_MHpage(prefix,suffix)*/
function compose_MHpage(prefix,suffix)
{
    mh_str="http://mhcargotrk.ccnexchange.com/trackingv2/MHTrkReply.asp?Process=Yes&awbnum="+suffix+"&submit=GO";
    window.location.href = mh_str;
}

/* Modified by Arthur 06Dec2007,add compose_RUpage(prefix,suffix)*/
function compose_RUpage(prefix,suffix)
{
     document.RUForm.action = "http://www.airbridgecargo.com/eng/customer/tracktrace/index.php";
     document.RUForm.AIRBRIDGE.value = "YES";
     document.RUForm.awbpre.value = prefix;
     document.RUForm.awbnum.value = suffix;
     document.RUForm.submit();
}

/* Added by Boo 25Apr2008,add compose_JLpage(prefix,suffix) for APP001255*/
function compose_JLpage(prefix,suffix)
{
     document.JLForm.action = "http://www.cargo.jal.co.jp/cgi-bin/db2www/AWBINFOe.d2w/report";
     document.JLForm.AWB_NO_P.value = prefix;
     document.JLForm.AWB_NO_S.value = suffix;
     document.JLForm.submit();
}

/* define the object airline
 */
function airline(name,carriercode,airfullname)
{
	this.airname=name;
	this.code=carriercode;
	this.fullname=airfullname;
}

function searchair(airprefix)
{
    for (i=0;i<airlines.length;i++) {
	 if (airlines[i].code == airprefix) {
	       document.frmMain.Owner.selectedIndex=i+1;
	       break;
	 }
    }
}

/* input : prefix
 * outpur : full name of the airline
 */
function getAirlineName(airprefix) {
    for (i=0;i<airlines.length;i++) {
	 if (airlines[i].code == airprefix) {
	       document.write(airlines[i].fullname);
	       break;
	 }
    }
}

/* to check if hactl to provide the ariline cargo tracking service
 * true : 0
 * false : 1
 */
function isHactlProvide(airline) {
   for (i=0;i<hactlProvide.length;i++) {
       if (hactlProvide[i] == airline) {
	   return 0;
       }
   }
   return 1
}
