﻿var isIE = true;
if (navigator.appName.indexOf("Microsoft") > -1) {
	isIE = true;
} else {
	isIE = false;
}

function checkIEVersion(num)
{
	var ver = window.navigator.appVersion.toLowerCase();
	if (ver.indexOf('msie ' + num + '.0') >= 0)	return true;
	return false;
}

function GetParam(name)
{
	var start=location.search.indexOf("?"+name+"=");
	if (start<0) start=location.search.indexOf("&"+name+"=");
 	if (start<0) return '';
 	start += name.length+2;
 	var end=location.search.indexOf("&",start)-1;
 	if (end<0) end=location.search.length;
 	var result=location.search.substring(start,end);
 	var result='';
 	for(var i=start;i<=end;i++)
 	{
 		var c=location.search.charAt(i);
 		result=result+(c=='+'?' ':c);
 	}
 	//alert(unescape(result));
 	return unescape(result);
}

function getSharpParam()
{
	var str = location.toString();
	var result = str.split('#')[1];
	
	if (str.indexOf('?')!=-1)
		{
			result = str.split('?')[1];
		}
	//alert(result);
 	return unescape(result);
}

function checkURL(array)
{
	var url = window.top.location.href;
	var id = "";
	var va = [["/", "/"], ["=", ""], ["/", "."], ["_", "."]];
	
	for (var item=0; item<va.length && id == ""; item++)
	{
		for (var i=0; i<array.length && id == ""; i++)
		{
			if (url.indexOf((va[item][0] + array[i] + va[item][1])) >= 0)
			{
				id = array[i];
				break;
			}
		}
	}
	
	return id;
}

function changeLanguage(target)
{
	var array = new Array("chi", "eng", "gb");
	var nowL = checkURL(array);
	var va = [["/", "/"], ["=", ""]];
	var url = window.top.location.href;
	for (var item=0; item<va.length; item++)
	{
		if (url.indexOf((va[item][0] + nowL + va[item][1])) >= 0)
		{
			url = url.replace((va[item][0] + nowL + va[item][1]), (va[item][0] + target + va[item][1]));
			break;
		}
	}
	if (url.substring((url.length-1), url.length) == '#')	url = url.substring(0, (url.length-1))
	
	trackPage('topNav', "changeLanguage("+target+")");
	
	window.top.location.href = url;
}

function changeTerminal(target)
{
	if ((window[(target+'Ready')] == false && target != 'all'))	return;
	var array = new Array("all", "t1", "t2","sp");
	var nowL = checkURL(array);
	var url = window.top.location.href.replace((nowL+'/'), (target+'/'));
	window.top.location.href = url;
}

function faqGo()
{
	var array = new Array("t1", "t2");
	var sect = checkURL(array);
	window.top.location.href = path + "shopping/faq_" + sect + ".html";
}

function NewWindow(mypage, myname, w, h, scroll,resizable) {
	if (isIE)
	{
		w = w - 4;
		h = h - 4;
	}
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable='+resizable+','
	win = window.open(mypage, myname, winprops)
	win.self.focus()
	if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function genFlash(file, width, height, id, vars) {
	var tempHtml = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="'+width+'" height="'+height+'" id="'+id+'" name="'+id+'">';
	tempHtml += '<param name="movie" value="'+file+'">';
	tempHtml += '<param name="quality" value="high">';
	tempHtml += '<param name="menu" value="false">';
	tempHtml += '<param name="wmode" value="opaque">';
	//tempHtml += '<param name="scale" value="noscale">';
	tempHtml += '<param name="salign" value="TL">';
	
	//alert(vars);
	if (vars != null) {
		tempHtml += '<param name="flashVars" value="'+vars+'">';
		tempHtml += '<embed src="'+file+'" flashVars="'+vars+'" salign="TL" quality="high" wmode="opaque" menu="false" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="'+width+'" height="'+height+'" id="'+id+'" name="'+id+'"></embed>';
	} else {
		tempHtml += '<embed src="'+file+'" salign="TL" quality="high" wmode="opaque" menu="false" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="'+width+'" height="'+height+'" id="'+id+'" name="'+id+'"></embed>';
	}
	
	tempHtml += '</object>';
	
	document.write(tempHtml);
}

function innerFlash(file, width, height, id, vars) {
	tempHtml += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="'+width+'" height="'+height+'" id="'+id+'" name="'+id+'">';
	tempHtml += '<param name="movie" value="'+file+'">';
	tempHtml += '<param name="quality" value="high">';
	tempHtml += '<param name="menu" value="false">';
	tempHtml += '<param name="wmode" value="noscale">';
	tempHtml += '<param name="scale" value="noscale">';
	tempHtml += '<param name="salign" value="TL">';
	
	if (vars != null) {
		tempHtml += '<param name="flashVars" value="'+vars+'">';
		tempHtml += '<embed src="'+file+'" flashVars="'+vars+'" salign="TL" quality="high" scale="noscale" wmode="noscale" menu="false" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="'+width+'" height="'+height+'" id="'+id+'" name="'+id+'"></embed>';
	} else {
		tempHtml += '<embed src="'+file+'" salign="TL" quality="high" scale="noscale" wmode="noscale" menu="false" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="'+width+'" height="'+height+'" id="'+id+'" name="'+id+'"></embed>';
	}
	
	tempHtml += '</object>';
	
//	document.write(tempHtml);
}


function checkIsFrame()
{
	if (!level1)	return;
	if (level1 == "flight" && level2 == "real")
	{
		if (level3 == "passarrival" | level3 == "passdeparture")
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	else
	{
		return false;
	}
}


function resizeDiv()
{
	var siteW = 988;
	var w = 0;
	var innerW;
	
	if( typeof( window.innerWidth ) == 'number' )
	{
		//Non-IE
		innerW = window.innerWidth;
	}
	else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) )
	{
		//IE 6+ in 'standards compliant mode'
		innerW = document.documentElement.clientWidth;
	}
	
	if (innerW < siteW)
	{
		w = siteW + "px";
	}
	else
	{
		w = '100%'
	}
	
	if (document.getElementById("topNavContainer"))	document.getElementById("topNavContainer").style.width = w;
	if (document.getElementById("homeFlash"))	document.getElementById("homeFlash").style.width = w;
	if (document.getElementById("secondLevelHeaderBreadcrumbs"))	document.getElementById("secondLevelHeaderBreadcrumbs").style.width = w;
	if (document.getElementById("contentContainer"))	document.getElementById("contentContainer").style.width = w;
}


var isFrame = checkIsFrame();

if (!isFrame)
{
	window.onload = resizeDiv;
	window.onresize = resizeDiv;
}


//Specify affected tags. Add or remove from list:
var tgs = new Array('p', 'h1', 'h2');
//var tgs = new Array('span', 'td', 'strong', 'a', 'li', 'div', 'p', 'h1', 'h2');
//Specify spectrum of different font sizes:
var szs = new Array('70%', '78%', '90%');
//var szs = new Array('x-small', 'small', 'medium');
//var szs = new Array('1em', '1.05em', '1.10em', '1.15em');
var startSz = sz = 0;

function getFontSize()
{
	if (getCookie('fontSize') == null)
	{
		startSz = 0;
	}
	else
	{
		startSz = getCookie('fontSize');
		if (startSz == "NaN")	startSz = 0;
	}
	
	changeFontSize(startSz, true);
}

function changeFontSize(inc, start)
{
	if (!document.getElementById) return;
	var d = document,cEl = null,sz = eval(startSz),i,j,cTags;
	
	if (!start)
	{
		sz += inc;
		
		if ( sz < 0 ) sz = 0;
		if ( sz > (szs.length-1) ) sz = (szs.length-1);
		startSz = sz;
	}
	else
	{
		sz = inc;
	}
	
	if (isFrame)
	{
		var cEl = window.parent.frames['infoFrame'].d.getElementsByTagName('body')[ 0 ];
	}
	else
	{
		//if ( !( cEl = d.getElementById( trgt ) ) ) cEl = d.getElementsByTagName('body')[0];
		cEl = d.getElementsByTagName('body')[0];
	}
	
	cEl.style.fontSize = szs[ sz ];
	
	setCookie("fontSize", sz, nd, cpath, cdomain);
	
	/*for ( i = 0 ; i < tgs.length ; i++ )
	{
		cTags = cEl.getElementsByTagName( tgs[ i ] );
		for ( j = 0 ; j < cTags.length ; j++ )
		{
			cTags[ j ].style.fontSize = szs[ sz ];
		}
	}*/
	
	/*var temp = window.parent.frames['infoFrame'];
	var txt = '';
	for (var i in temp)
	{
		txt += i + "  :  " + temp[i] + '\n';
	}
	alert(txt)*/
	if (isFrame)	window.parent.frames['infoFrame'].frameElement.style.display = 'block';
//	window.status = sz;
}

var nd= new Date();
nd.setTime(nd.getTime()+(365*24*60*60*1000));
//cdomain = (location.domain) ? location.domain : null;
var cdomain = (location.domain) ? location.domain : null;
var cpath = "/";

function setCookie(name, value, expires, path, domain, secure)
{
  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
	  
//	alert(curCookie)
  document.cookie = curCookie;
}


function getCookie(name)
{
	if (document.cookie.indexOf(name) < 0)
	{
		return null;
	}
	else
	{
		var startStr = document.cookie.indexOf(name) + name.length + 1;
		var endStr = document.cookie.indexOf(";", startStr);
		if (endStr == -1)	endStr = document.cookie.length;
		return unescape(document.cookie.substring(startStr, endStr));
	}
}


var mvqTimeout = 125;
var mvqPDiv, mvqPStyle;

function hideComponent(f)
{
	mvqPHideEleByX(f);
}

function mvqPHideEleByX(boolHide)
{
    window.setTimeout("mvqPHideEleByX1('OBJECT'," +  boolHide + ")", mvqTimeout);
    window.setTimeout("mvqPHideEleByX1('SELECT'," +  boolHide + ")", mvqTimeout+1);
}

function mvqPVerifyOverlapByX(x, overlapElm)
{
    var p1 = new mvqPDimension(overlapElm);
		return (p1.left>x);
}

function mvqPHideEleByX1(el, boolShowHide)
{
    var objects = document.getElementsByTagName(el);
    if(objects.length == 0) return;
    for(var i=0; i < objects.length; i++)
    {
        var obj = objects.item(i);
            if(boolShowHide && mvqPVerifyOverlapByX(655, obj))
            {
                obj.style.visibility = "hidden";
            }
            else
            {
                if(obj.style.visibility == "hidden") obj.style.visibility = "visible";
			}
    }
}


function menuHideSelect(name, boolHide)
{
	var selectHide = true;
	if (navigator.appName.indexOf("Microsoft") > -1) {
		var tempV1 = Number(navigator.appVersion.indexOf('MSIE ')) + 5;
		var tempV2 = Number(navigator.appVersion.substring(tempV1, (tempV1+1)));
		if (tempV2 >= 7)	selectHide = false;
	//	alert(selectHide);
	} else {
		selectHide = false;
	}
	if (selectHide) {
		mvqPDiv = name;
		mvqPStyle = mvqPDiv.style;
	    mvqPHideEle(boolHide);
	}
}

function mvqPHideEle(boolHide)
{
    window.setTimeout("mvqPHideEle1('OBJECT'," +  boolHide + ")", mvqTimeout);
    window.setTimeout("mvqPHideEle1('SELECT'," +  boolHide + ")", mvqTimeout+1);
}

function mvqPHideEle1(el, boolShowHide)
{
    var objects = document.getElementsByTagName(el);
    if(objects.length == 0) return;
    for(var i=0; i < objects.length; i++)
    {
        var obj = objects.item(i);
        elm = mvqPDiv.firstChild;
		//alert(elm);
        if(elm)
        {
            if(boolShowHide && mvqPVerifyOverlap(elm, obj))
            {
                obj.style.visibility = "hidden";
            }
            else
            {
                if(obj.style.visibility == "hidden") obj.style.visibility = "visible";
            }
        }
    }
}

function mvqPDimension(elm)
{
    var top = 0;
    var height = 0;
    var width = 0;
    var left = 0;
    if(elm)
    {
        this.height = elm.offsetHeight;
        this.width = elm.offsetWidth;
        while(elm)
        {
            left += elm.offsetLeft;
            top += elm.offsetTop;
            elm = elm.offsetParent;
        }
        this.left = left;
        this.top = top;
    }
}

function mvqPVerifyOverlap(tbl, overlapElm)
{
    var p1 = new mvqPDimension(overlapElm);
    var p = new mvqPDimension(tbl);
    return ( ((p.left + p.width) > p1.left) && (p.left < (p1.left + p1.width)) && (p.top < (p1.top - overlapElm.offsetTop + p1.height)) && ((p.top + p.height) > (p1.top - overlapElm.offsetTop)) );
}


function genAnnounce(x, y, w)
{
	//alert(getCookie('announceShow'));
	var obj = announcementArray;
	
	//if (getCookie('hkia_announce') == obj.cookieName)	return;
	
	var box = d.getElementById('announceWrapper');
	var txt = d.getElementById('announceText');
	var link = d.getElementById('announceLink');
	var btn = d.getElementById('announceClose');
	var content = d.getElementById('announceContent');
	
	if (!obj.isShow)	return;
	
	txt.innerHTML = obj.txt;
	link.getElementsByTagName('a')[0].href = obj.link;
	link.getElementsByTagName('a')[0].target = obj.target;
	box.style.top = y + 'px';
	box.style.left = x + 'px';
	box.style.width = w + 'px';
	btn.style.left = (w-30) + 'px';
	content.style.width = (w-141) + 'px';
	box.style.display = 'block';
}


function announceClose()
{
	var box = d.getElementById('announceWrapper');
	var obj = announcementArray;
	
	box.style.display = 'none';

	setCookie("hkia_announce", obj.cookieName, nd, cpath, cdomain);
}


function genAnnounceLink()
{
	if (announcementArray == undefined || announcementArray == null || !announcementArray.isShow)	return;
	if (d.getElementById('iconSpecial') == undefined || d.getElementById('iconSpecial') == null)	return;

	var icon = d.getElementById('iconSpecial');
	var obj = announcementArray;
	
	if (obj.target == '_top')
	{
		icon.onclick = function() {window.top.location.href = obj.link;};
	}
	else if (obj.target == '_blank')
	{
		icon.onclick = function() {window.open(obj.link);};
	}
	else
	{
		icon.onclick = function() {window.location.href = obj.link;};
	}
	
	icon.style.visibility = 'visible';
}


function emailAFriend()
{
	var emailMsg = new Array();
	emailMsg[0] = "请按这里以连接送上的超连结：%0AClick the following to access the sent link:%0A%0A";
	emailMsg[1] = "你收到以下连接香港国际机场网站的超连结 You have received the following link to the HKIA website";
	//emailMsg[0] = "Click the following to access the sent link:%0A%0A";
	//emailMsg[1] = "You have received the following link to the HKIA website";
	var winEF = window.open("mailto:?body="+ emailMsg[0] + escape((window.top.location.href).replace("?","!")) + "&subject=" + emailMsg[1]);
}


function popupGallery (file, w, h) {
 var popUpPage2 = window.open('', ''+file+'', 'width='+w+',height='+h+',left=0,top=0,screenX=0,screenY=0,scrollbars=0,resizable=0');
 popUpPage2.document.open();
 popUpPage2.document.write('<html>');
 popUpPage2.document.write('<head><title>Hong Kong International Airport</title></head>');
 popUpPage2.document.write('<body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">');
 popUpPage2.document.write(' <img src="'+path+'img/media/photo/lrg/'+file+'.jpg" width="'+w+'" height="'+h+'">');
 popUpPage2.document.write('</body>');
 popUpPage2.document.write('</html>');
 popUpPage2.document.close();
 popUpPage2.focus();
}


function popupSkylimo (file, w, h) {
 var popUpPage2 = window.open('', 'win', 'width='+w+',height='+h+',left=0,top=0,screenX=0,screenY=0,scrollbars=0,resizable=0');
 popUpPage2.document.open();
 popUpPage2.document.write('<html>');
 popUpPage2.document.write('<head><title>Hong Kong International Airport</title></head>');
 popUpPage2.document.write('<body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">');
 popUpPage2.document.write(' <img src="'+path+'img/transport/transport-connection-with-mainland-china/'+file+'.jpg" width="'+w+'" height="'+h+'">');
 popUpPage2.document.write('</body>');
 popUpPage2.document.write('</html>');
 popUpPage2.document.close();
 popUpPage2.focus();
}
function popup_dynamic(pop, wsize, hsize) {

 	    

 	    setting = 'toolbar=0,status=0,menubar=0,resizable=0,width='+wsize+',height='+hsize+',scrollbars=1';

 	    theName = 'newWindow';

 	    

 	    windowPointer=window.open(pop,theName, setting);

 	}



var path_name = window.location.pathname;
if (path_name != null && path_name != undefined && path_name.length > 0 && path_name.indexOf("/flightinfo/") != 0) {
	document.write ("<scr" + "ipt type='text/javascript' src='" + path + "js/sp.js'></script>");
}



var motion;
var motion2;
var goSpeed = 20;
var tempNum;
var tempNum2;
var frameBody;
var frameBody2;
var temp1 = 0;
var temp2 = 0;
var tempL;
var tempW;
var isIFrame = false;

function autoScrollStart(name) {
	setTimeout("autoScrollGo()", 0);
//	scrollStop();
	frameBody  = document.getElementById(name);
	
	//window.status = frameBody.scrollWidth;
}

function autoScrollGo() {
	autoScrollMotion();
}

function autoScrollMotion(){
	if (frameBody.scrollTop < (frameBody.scrollHeight - 78)) {
		frameBody.scrollTop += 1;
	} else {
		if (temp1 - (frameBody.scrollHeight - 50) > 0) {
			frameBody.scrollTop = 0
			temp1 = 0;
			clearTimeout(motion);
			//setTimeout("autoScrollMotion()", 4000);
			autoScrollMotion();
			return false;
		}
	}
	temp1 += 1;
	
	//window.status = frameBody.scrollTop + "  :  " + frameBody.scrollHeight;
	//window.status = temp1;
	
	
	motion = setTimeout("autoScrollMotion()", (goSpeed*3));
}

function scrollStop() {
	temp1 = frameBody.scrollTop;
	clearTimeout(motion);
}



function autoScrollStart2(name, goNum) {	
	scrollStop2();
	tempNum2 = goNum;
	if (navigator.appName.indexOf("Microsoft") > -1) {
    	frameBody2  = document.getElementById(name);
    } else {
    	frameBody2  = document.getElementById(name);
    }
	//window.status = frameBody.scrollWidth;
	autoScrollMotion2();
}

function autoScrollMotion2(){
	
	tempL = frameBody2.scrollLeft;
	tempW = frameBody2.scrollWidth;
	
	//window.status = tempW + "  :  " + tempL;
	
	
	if (tempL < (tempW - 100)) {
		tempL += 1;
	} else {
	//	if (temp2 - tempW > 24) {
			tempL = 0
			temp2 = 0;
		//}
	}
	
	frameBody2.scrollLeft = tempL;
	
	motion2 = setTimeout("autoScrollMotion2()", goSpeed);
	//alert(tempL + "  :  " + tempW);
}

function scrollStart2(name, goNum) {
	
	scrollStop2();
	tempNum2 = goNum;
	if (navigator.appName.indexOf("Microsoft") > -1) {
    	frameBody2  = document.getElementById(name);
    } else {
    	frameBody2  = document.getElementById(name);
    }
	scrollMotion2();
}

function scrollMotion2(){
	frameBody2.scrollLeft += tempNum2;
	motion2 = setTimeout("scrollMotion2()",goSpeed);
}

function scrollStop2() {
	clearTimeout(motion2);
	temp = 0;
}

function popUpWin(url,name,tool,scroll,loc,stat,menu,resize,w,h) {
	var top = ((screen.width - w) / 2);
	var left = ((screen.height - h) / 2);
	window.open(url,name,"'toolbar="+tool+", scrollbars="+scroll+", location="+loc+", status="+stat+", menubar="+menu+", resizable="+resize+", width="+w+", height="+h+", left="+left+",top="+top+"'");
}
