﻿<!--
/*
 File		: common.js

 Purpose    : This javascript file contains all the common functions

 Functions  : addBookmark()
	      - bookmark the current page
	      rollOut(imgName)
	      - mouse out image function
	      rollOver(imgName)
	      - mouse over image function
	      goTo(urlStr)
	      - redirect the page to the target url
	      flashLink(param)
	      - generate the links for the flash files
	      genImageTagthisName, thisSection, clickable, imgWidth, imgHeight, altTag, imgType
	      - generate the image tag for the top navigation bar
	      genAtoZImage(thisImg, thisLink, clickable, imgWidth, imgHeight, altTag)
	      - generate the A to Z image for guides and resources
	      addOption(object,text,value)
	      - add options to pull down menus
	      genMenu(valArr, linkArr, objectName)
	      - generate pull down menu
	      popscreen(wtgweb)
	      - open new window 
	      openPopUp(name, urls, winWidth, winHeight, menubar)
	      - open new window of the specified height and width for the url specified 
	      getConMsg(type)
	      - get the warning message for different language according to the type specified
	      chgLang(thisLang, targetLang)
	      - switch page language
	      genNavImageTag(thisName, thisSection, clickable, imgWidth, imgHeight, foldername, altTag) {
	      - generate the images for the top primary navigation bar
	      resetForm(frm)
	      - reset all the values in the form 
	      sRollOut(imgName)
	      -roll out function
	      sRollOver(imgName)
	      -roll over function
	      SendpagePopUp(name, urls, winWidth, winHeight, menubar)
	      - open pop up window for the "send this page" function
	      goSSL(fileLocation, target)
	      - go from non-SSL webpage to SSL webpage
	      leaveSSL(fileLocation, target)
	      - go from SSL webpage to non-SSL page
	      goSSLPopUp(name, urls, winWidth, winHeight, menubar)
	      - go from non-SSL webpage to SSL webpage via pop-up window
	      leaveSSLPopUp(name, urls, winWidth, winHeight, menubar)
	      - go from SSL webpage to non-SSL webpage via pop-up window
	      goSSLSendpagePopUp(name, urls, winWidth, winHeight, menubar)
	      - go from non-SSL webpage to SSL webpage and Pop up for send this page us only
	      leaveSSLSendpagePopUp(name, urls, winWidth, winHeight, menubar)
	      - go from SSL webpage to non-SSL webpage and Pop up for send this page us only
	      leaveSSLgo_search()
	      - search function is located in non-SSL environment
	      - go from SSL webpage to non-SSL webpage and submit search function

	      

 Modification History :
 Version    Date	    By		    Description
 -----------------------------------------------------------------------
 1st	    2002-05-13	   Vivian Au	    First Version
 2nd	    2002-08-08	   Gordon Tsang     add goSSL, leaveSSL, goSSLPopUp, leaveSSLPopUp
                                            goSSLSendpagePopUp, leaveSSLSendpagePopUp, 
                                            leaveSSLgo_search

 -----------------------------------------------------------------------
*/

//check the browser version and the platform of the client machine
var pc=(navigator.appVersion.indexOf('Win') != -1);
var iexp=(navigator.appName.indexOf('Microsoft') != -1);
var ns=(navigator.appName.indexOf('Netscape') != -1);
//define the variable for checking the section
var thisSection = '';
var clickAble = false;
var home = '';
self.name = 'parent';

function addBookmark()
{
    if (window.sidebar&&window.sidebar.addPanel) {
	//configure two parameters below to your own (title, url of content to store)
	 window.sidebar.addPanel(document.title,window.location.href,"");
    }else if (ns) {
    //getConMsg is declared in common.js
	alert(getConMsg('addBookmark'));
    }else {
	window.external.AddFavorite(window.location.href, document.title);
    }
}

function rollOut(imgName)
{
    if (document.images)
	{
	document.images[imgName].src = eval(imgName + "_off.src");
    }
}

function rollOver(imgName)
{
    if (document.images)
	{
	document.images[imgName].src = eval(imgName + "_on.src");
    }
}

function goTo(urlStr){
    tmpUrlStr = urlStr.toLowerCase();
    javaScriptStr = 'javascript:';
    if (urlStr != "" && urlStr != null) {
	if (tmpUrlStr.indexOf(javaScriptStr) >= 0 ){
	    setTimeout(urlStr, 0);
	} else {
	    location.href = urlStr;
	}
    }

}

function flashLink(param){
    if (param != "" && param != null) {
	if (flashUrls[param] == 'pop')
	    openPopUp(popUrls[param][0], popUrls[param][1], popUrls[param][2], popUrls[param][3], popUrls[param][4], popUrls[param][5]);
	else if (flashUrls[param] == 'js')
	    setTimeout(jsStr[param], 0);
	else
	    location.href = flashUrls[param];
	    
    }
}

function genImageTag(thisName, thisSection, clickable, imgWidth, imgHeight, altTag, imgType) {
    var str;
    if (thisSection && imgType=='hactlNav') {
	str = "";
    } else {
	var str;
	var src;
	var strHead = "";
	var strTail = "";
	var imgName = "";
    //object "urls" is declared in [Lang]css.js
	if (thisSection && clickable) {
	    imgName = eval(thisName + "_on.src");
	    strHead = "<A HREF=\"" + urls[thisName] + "\">";
	    strTail = "</A>";
	} else if (thisSection) {
	    imgName = eval(thisName + "_on.src");
	} else {
	    imgName = eval(thisName + "_off.src");
	    strHead = "<A HREF=\"" + urls[thisName] + "\" ONMOUSEOVER=\"rollOver('" + thisName + "')\" ONMOUSEOUT=\"rollOut('" + thisName + "')\">";
	    strTail = "</A>";
	}
    
	str = strHead;
	str += "<IMG SRC=\"" + imgName +"\" WIDTH=\"" + imgWidth + "\" HEIGHT=\"" + imgHeight + "\" BORDER=\"0\" ALT=\"" + altTag + "\" NAME=\"" + thisName + "\">";
	str += strTail;
    }
    return str;
}

function genAtoZImage(thisImg, thisLink, clickable, imgWidth, imgHeight, altTag) {
    var str;
    var src;
    var strHead = "";
    var strTail = "";
    var imgName = "";
    if (!clickable) {
	strHead = "<A HREF=\" " + thisLink + " \">";
	strTail = "</A>";
    }

    str = strHead;
    str += "<IMG SRC=\"" + thisImg +"\" WIDTH=\"" + imgWidth + "\" HEIGHT=\"" + imgHeight + "\" BORDER=\"0\" ALT=\"" + altTag + "\">";
    str += strTail;
    
    return str;
}

function addOption(object,text,value) {
    var optionName = new Option(text, value, false, false);
    object.options[object.length] = optionName;
}

function genMenu(valArr, linkArr, objectName) {
    var objLen = objectName.length;
    for (i = 0; i < objLen; i++) {
	objectName.options[0] = null;
    }
    for (i = 0; i < valArr.length; i++) {
	addOption(objectName,valArr[i],linkArr[i]);
    }
    objectName.options[0].selected = true;
}

function popscreen(wtgweb){
 eval("wtghtm=\""+wtgweb+"\"");
window.open(wtghtm,"PublicHoliday","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=660,height=500,left=130,screenX=130,top=0,screenY=0");
}

function openPopUp(name, urls, winWidth, winHeight, menubar, scrollbar){
    if (urls != "" && urls != null) {
	var tmpMenu = '';
	if (menubar) {
	    tmpMenu = 'yes';
	} else {
	    tmpMenu = 'no';
	}

	var tmpScrollbar = '';
	if (scrollbar) {
	    tmpScrollbar = 'yes';
	} else {
	    tmpScrollbar = 'no';
	}


	var nw;
	nw =  window.open(urls, name,"toolbar=" + tmpMenu + ",location=no,directories=no,status=no,menubar=no,scrollbars=" + tmpScrollbar + ",resizable=no,width=" + winWidth + ",height=" + winHeight + ",left=130,screenX=130,top=0,screenY=0");
	nw.focus();
   }
}

function getConMsg(type) {
// object "popMsg" is declared in [Lang]css.js
    return popMsg[type];
}

function chgLang(thisLang, targetLang) {

    var thisLangChg = "/" + thisLang + "/";
    var targetLangChg = "/" + targetLang + "/";

    var urlStr = location.pathname;
    var queryStr = location.search;
    if (queryStr.length > 0)
	urlStr += queryStr;
    var newurlStr = urlStr.replace(thisLangChg, targetLangChg);
    return newurlStr;
}

function genNavImageTag(thisName, thisSection, clickable, imgWidth, imgHeight, foldername, altTag) {
//image tag for tools nav (table structure is included)
    var str;
    var src;
    var strHead = "";
    var strTail = "";
    var imgName = "";
    var outputStr = "";
//object "urls" is declared in [Lang]css.js

    outputStr +="<TR VALIGN=\"TOP\"><TD HEIGHT=\"15\"><IMG SRC=\"" + thisPath + "images/common/blank.gif\" WIDTH=\"5\" HEIGHT=\"9\" BORDER=\"0\" NAME=\"" + thisName + "\"></TD>\n<TD>";
	
    if (thisSection && clickable) {
	imgName = thisName + "_on.gif";
	strHead = "<A HREF=\"" + urls[thisName] + "\">";
	strTail = "</A>";
    } else if (thisSection) {
	imgName = thisName + "_on.gif";
    } else {
	imgName = thisName + "_off.gif";
	strHead = "<A HREF=\"" + urls[thisName] + "\" ONMOUSEOVER=\"rollOver('" + thisName + "')\" ONMOUSEOUT=\"rollOut('" + thisName + "')\">";
	strTail = "</A>";
    }

    str = strHead;
    str += "<IMG SRC=\"" + thisPath + "images/" + foldername + "/" + imgName +"\" WIDTH=\"" + imgWidth + "\" HEIGHT=\"" + imgHeight + "\" BORDER=\"0\" ALT=\"" + altTag + "\">";
    str += strTail;

    outputStr += str;
    outputStr += "</TD></TR>\n";
    
    return outputStr;
}
/*
function resetForm(frm)
{
    var f = frm;
    var fname = "";
    var optsel = false;
    for (var i = 0; i < frm.length; i++)
    {
	e = f.elements[i];
	ftype = e.type;
	if (ftype == "text")
	    e.value = e.defaultValue";
	else if (ftype == "radio")
	{
	    if (e.defaultChecked)
		e.checked = true;
	    else 
		e.checked = false;
	}
	else if (ftype == "select-one")
	{
	    optsel = false;
	    for (var j = 0; j < e.options.length; j++)
	    {
	       if(e.options[j].defaultSelected)
	       {
		    e.options[j].selected = true;
		    optsel = true;
	       }
	       else
		    e.options[j].selected = false;
	    }
	    j = 0;
	    if (!optsel)
		e.options[j].selected = true;
	}
	else if (ftype == "checkbox")
	{
	    e.checked = false;
	}
    }
}
*/

function resetForm(frm)
{
    var f = frm;
    var fname = "";
    var optsel = false;
    for (var i = 0; i < frm.length; i++)
    {
	e = f.elements[i];
	ftype = e.type;
	if (ftype == "text")
	    e.value = "";
	else if (ftype == "radio")
	{
	    if (e.defaultChecked)
		e.checked = true;
	    else
		e.checked = false;
	}
	else if (ftype == "select-one")
	{
	    for (var j = 0; j < e.options.length; j++)
	    {
		e.options[j].selected = false;
	    }
	    e.options[0].selected = true;
	}
	else if (ftype == "checkbox")
	{
	    e.checked = false;
	}
    }
}

function sRollOut(imgName)
{
    if (document.images)
	{
	document.images['display'].src = eval(imgName + "_off.src");
    }
}

function sRollOver(imgName)
{
    if (document.images)
	{
	document.images['display'].src = eval(imgName + "_on.src");
    }
}

// Pop up functions for send this page us only
function SendpagePopUp(name, urls, winWidth, winHeight, menubar){
    if (urls != "" && urls != null) {
	var tmpMenu = '';
	if (menubar) {
	    tmpMenu = 'yes';
	} else {
	    tmpMenu = 'no';
	}

	var nw;

    // GT200209, enable hyperlink with ?language=en&country=US for jsp to get correct parameter value ..
    tmpLoc=window.location.href;
    while (tmpLoc.indexOf("&")>-1) {
        tmpPos=tmpLoc.indexOf("&");
        tmpLoc=tmpLoc.substring(0,tmpPos) + "___" + tmpLoc.substring(tmpPos+1,tmpLoc.length);
    }
    // .. GT200209

	nw =  window.open(urls + "?URL=" + tmpLoc, name ,"toolbar=" + tmpMenu + ",location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=" + winWidth + ",height=" + winHeight + ",left=130,screenX=130,top=0,screenY=0");
	nw.focus();

   }
}

//function provided by hactl
function goSSL(fileLocation, target) {
    if (target != "" && target != null) {
      window.open("https://" + location.host + fileLocation, target);
    } else {
      window.location.href = "https://" + location.host + fileLocation;
    }
}

// leave from SSL webpage to non-SSL webpage
function leaveSSL(fileLocation, target) {
    if (target != "" && target != null) {
      window.open("http://" + location.host + fileLocation, target);
    } else {
      window.location.href = "http://" + location.host + fileLocation;
    }
}

// go from non-SSL webpage to SSL webpage via pop-up window
function openSSLPopUp(name, urls, winWidth, winHeight, menubar, scrollbar){
    if (urls != "" && urls != null) {
	var tmpMenu = '';
	if (menubar) {
	    tmpMenu = 'yes';
	} else {
	    tmpMenu = 'no';
	}

	var tmpScrollbar = '';
	if (scrollbar) {
	    tmpScrollbar = 'yes';
	} else {
	    tmpScrollbar = 'no';
	}

	var nw;
	nw =  window.open("https://"+location.host+urls, name,"toolbar=" + tmpMenu + ",location=no,directories=no,status=no,menubar=no,scrollbars=" + tmpScrollbar + ",resizable=no,width=" + winWidth + ",height=" + winHeight + ",left=130,screenX=130,top=0,screenY=0");
	nw.focus();
   }
}

// go from SSL webpage to non-SSL webpage via pop-up window
function leaveSSLPopUp(name, urls, winWidth, winHeight, menubar, scrollbar){
    if (urls != "" && urls != null) {
	var tmpMenu = '';
	if (menubar) {
	    tmpMenu = 'yes';
	} else {
	    tmpMenu = 'no';
	}

	var tmpScrollbar = '';
	if (scrollbar) {
	    tmpScrollbar = 'yes';
	} else {
	    tmpScrollbar = 'no';
	}

	var nw;
	nw =  window.open("http://"+location.host+urls, name,"toolbar=" + tmpMenu + ",location=no,directories=no,status=no,menubar=no,scrollbars=" + tmpScrollbar + ",resizable=no,width=" + winWidth + ",height=" + winHeight + ",left=130,screenX=130,top=0,screenY=0");
	nw.focus();
   }
}

// go from non-SSL webpage to SSL webpage and Pop up for send this page us only
function goSSLSendpagePopUp(name, urls, winWidth, winHeight, menubar){
    if (urls != "" && urls != null) {
	var tmpMenu = '';
	if (menubar) {
	    tmpMenu = 'yes';
	} else {
	    tmpMenu = 'no';
	}

	var nw;
	nw =  window.open("https://"+location.host+urls + "?URL=" + location.href, name ,"toolbar=" + tmpMenu + ",location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=" + winWidth + ",height=" + winHeight + ",left=130,screenX=130,top=0,screenY=0");
	nw.focus();

   }
}


// go from SSL webpage to non-SSL webpage and Pop up for send this page us only
function leaveSSLSendpagePopUp(name, urls, winWidth, winHeight, menubar){
    if (urls != "" && urls != null) {
	var tmpMenu = '';
	if (menubar) {
	    tmpMenu = 'yes';
	} else {
	    tmpMenu = 'no';
	}

	var nw;
	nw =  window.open("http://"+location.host+urls + "?URL=" + location.href, name ,"toolbar=" + tmpMenu + ",location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=" + winWidth + ",height=" + winHeight + ",left=130,screenX=130,top=0,screenY=0");
	nw.focus();

   }
}


function go_search()
{

    var txt = document.searchFrm.search.value;
    var language = document.searchFrm.language.value;
    var country = document.searchFrm.country.value;


    if (txt.length > 0)
    {
      querytext=escape(txt); // convert text to URL encoded form
      querytext+="&language=" + language + "&country=" + country;
//	if (searchwin && searchwin.open && !searchwin.closed) searchwin.close();

// searchwin=window.open("/cgi-bin/search.pl?KEYWORDS=" + querytext, "search_query","HEIGHT=500,WIDTH=660,status=yes,toolbar=yes,directories=no,menubar=no,location=no,scrollbars=yes,resizable=yes,left=130,screenX=130,top=0,screenY=0"); 
//	searchwin.focus();

	document.location.href = "/cgi-bin/search2.pl?KEYWORDS=" + querytext;
    }
}

function go_search2()
{
    var txt = document.searchFrm2.search.value;
    var language = document.searchFrm2.language.value;
    var country = document.searchFrm2.country.value;

    if (txt.length > 0)
    {
      querytext=escape(txt); // convert text to URL encoded form
      querytext+="&language=" + language + "&country=" + country;
//	if (searchwin && searchwin.open && !searchwin.closed) searchwin.close();

//searchwin=window.open("/cgi-bin/search.pl?KEYWORDS=" + querytext, "search_query","HEIGHT=500,WIDTH=660,status=yes,toolbar=yes,directories=no,menubar=no,location=no,scrollbars=yes,resizable=yes,left=130,screenX=130,top=0,screenY=0");
//	searchwin.focus();

document.location.href = "/cgi-bin/search2.pl?KEYWORDS=" + querytext;
    }
}

function go_search3()
{
    var txt = document.searchFrm3.search.value;
    var language = document.searchFrm3.language.value;
    var country = document.searchFrm3.country.value;
    if (txt.length > 0)
    {
      querytext=escape(txt); // convert text to URL encoded form
      querytext+="&language=" + language + "&country=" + country;
//	if (searchwin && searchwin.open && !searchwin.closed) searchwin.close();

//searchwin=window.open("/cgi-bin/search.pl?KEYWORDS=" + querytext, "search_query","HEIGHT=500,WIDTH=660,status=yes,toolbar=yes,directories=no,menubar=no,location=no,scrollbars=yes,resizable=yes,left=130,screenX=130,top=0,screenY=0");
//	searchwin.focus();

document.location.href = "/cgi-bin/search2.pl?KEYWORDS=" + querytext;
    }
}

//coin2 hactl.com common.js functions

function settopframe(topic)
{

	if (topic == "HOME") {
	   if ( parent.frames[0].location.href.indexOf("top_home.htm") == -1 )
		parent.frames[0].location.href="top_home.htm"
	}
	if (topic == "COMPANY") {
	   if ( parent.frames[0].location.href.indexOf("top_company.htm") == -1 )
		parent.frames[0].location.href="top_company.htm"
	}
	if (topic == "NEWS") {
	   if ( parent.frames[0].location.href.indexOf("top_news.htm") == -1 ) 
		parent.frames[0].location.href="top_news.htm"
	}
	if (topic == "E-BUSINESS") {
	   if ( parent.frames[0].location.href.indexOf("top_eb.htm") == -1 ) 
		parent.frames[0].location.href="top_eb.htm"
	}
	if (topic == "COMMUNITY") {
	   if ( parent.frames[0].location.href.indexOf("top_community.htm") == -1 ) 
		parent.frames[0].location.href="top_community.htm"
	}
	if (topic == "PRODUCT") {
	   if ( parent.frames[0].location.href.indexOf("top_product.htm") == -1 ) 
		parent.frames[0].location.href="top_product.htm"
	}
	if (topic == "SUPER") {
	   if ( parent.frames[0].location.href.indexOf("top_st1.htm") == -1 )
		parent.frames[0].location.href="top_st1.htm"
	}
}

function popwin(pageid)
{
   var mypage
   eval("mypage=\""+pageid+".htm\"")
   mypage="/" + mypage;
   popwindow=window.open(mypage,"abc","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=660,height=500,left=130,screenX=130,top=0,screenY=0");
   popwindow.focus();
}

function setbottom()
{
	document.write('<table width="100%" border="0" cellspacing="0" cellpadding="0"><TR><TD ALIGN="CENTER"><font color="#804040" face="Arial, Helvetica, sans-serif" size="1">Copyright &copy; Hong Kong Air Cargo Terminals Limited [2000]. All Rights Reserved.</font></TD><TD></TR><TR><TD ALIGN="CENTER"><font face="Arial, Helvetica, sans-serif" size="1"><a href="javascript:popwin(\'pps\');">Privacy Policy</a></font>&nbsp;|&nbsp;<font face="Arial, Helvetica, sans-serif" size="1"><a href="javascript:popwin(\'terms\');">Terms and Conditions</a></font></TD></TR></TABLE></CENTER>')
}

function setdisclaimer(disclaimertype)
{
	outdisclaimer='<div align="center">&nbsp</div>'
    document.write(outdisclaimer);
}

//-->
