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_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_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];}
}

//swap language
function WO_swapLanguage(lang) {
	var loc = document.location + "";
	
	//start -- added for ESCAB project by Johnny Lam
	var targetPath = "/hkana/gs1/escab/";
	var loginPath = "/hkana/gs1/escab/login.html";
	var forgetPasswordPath = "/hkana/gs1/escab/forget_password.html";
	if((loc.search(targetPath) != -1) && ((loc.search(loginPath) == -1) && (loc.search(forgetPasswordPath) == -1)))
	{
		alert("English Version only!");
		return;
	}
	// end -- addded for ESCAB project
	
	var startpos = loc.indexOf("/", 8);
	//alert(loc);
	loc = "/" + lang + "/" + loc.substring(startpos + 4);
	///alert(loc);
	window.open(loc, "_self");
}

//Popup
function WO_openWindow(URL, width, height, name) 
{
	//alert (window.screen.width);
	 
	if (width == null || width == 0) {
		//width = window.screen.width / 2;
		width = 500;
	}
		
	if (height == null || height == 0) {
		//height = window.screen.height / 2;
		height = 400;
	}
		
	if (name == null || name == '') {
		name = 'PopupWindow';
	}
	win=open('', name, 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width='+width+',height='+height);

	if (win != null) 
	{
		if (win.opener == null) 
		{
			win.opener = self;
		}
		win.location.href=URL;
 		if (win.focus) win.focus();
   }
}

function WO_openWindow2(URL, name, para){
	window.open(URL, name, para);
}
// navigation

function WO_onClickImage(URL, title) {
	Window2=open("", "Image", 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes');
	if (Window2 != null) {
		if (Window2.opener == null) {
			Window2.opener = self;
		}
		Window2.document.open();
		Window2.document.write("<HTML><HEAD><title>" + title + "</title></HEAD><BODY TOPMARGIN=0 LEFTMARGIN=0><IMG SRC='" + URL + "'/></BODY></HTML>");
		Window2.document.close();
		//Window2.location.href=url;
		var x = new Image();		
		x.onload = resizepopup;
		x.src = URL;
		
		if (Window2.focus) Window2.focus();
	}	
}

function resizepopup()
{
	Window2.resizeTo(this.width + 10, this.height + 60);
}

function trimAll(sString) 
{
	while (sString.substring(0,1) == ' ')
	{
		sString = sString.substring(1, sString.length);
	}
	while (sString.substring(sString.length-1, sString.length) == ' ')
	{
		sString = sString.substring(0,sString.length-1);
	}
	return sString;
}

function keyPressLogin(e){
   var charCode = (e.which) ? e.which : window.event.keyCode;
   if(charCode == "13") escabLogin();
}

function escabLogin()
{
	if(document.getElementById("loginID").value == "" || document.getElementById("password").value == "")
	{
		alert("Please enter your loginID and password first!");
		return;
	}
	else
	{
		var pw = document.getElementById("password").value;
		if(pw.length != 8)
		{
			alert("Passsword must be an 8-digit string!");
			return;
		}
		else
		{
			var loginFrm = document.getElementById("escabLoginFrm");
			document.getElementById("hiddenAction").value = "login";
			
			if(document.getElementById("hiddenRedirect").value != "" && document.getElementById("hiddenRedirect").value != null)
				loginFrm.action = loginFrm.action + "?p=" + document.getElementById("hiddenRedirect").value;
			/*else
				document.getElementById("hiddenAction").value = "login";*/
			loginFrm.submit();
		}
	}
}

function escabLogout()
{
	document.getElementById("hiddenAction").value = "logout";
	var memberFrm = document.getElementById("escabMemberFrm");
	
	memberFrm.action = "/en/hkana/gs1/escab/logout.html";
	memberFrm.submit();
}

function escabRedirectLogin(page)
{
	var urlPath = location.search;
    var escapedUrlPath = urlPath.replace("&amp;","%26");
	//window.location = "/en/hkana/gs1/escab/login.html?p="+page+".html";
	window.location = "/en/hkana/gs1/escab/login.html?p="+page+".html"+escapedUrlPath;
}

function changebtn(id)
{
	var tempSrc = document.all[id].src;
	document.all[id].src = tempSrc.replace("off.jpg", "on.jpg");
}

function changebtnback(id)
{
	var tempSrc = document.all[id].src;
	document.all[id].src = tempSrc.replace("on.jpg", "off.jpg");
}

function showDocument(date, group, level)
{
	window.location = "/en/hkana/gs1/escab/doc_download.html?date="+date+"&group="+group+"&level="+level;
}

function changeArchiveMode(url)
{
	window.location = url + ".html?mode=archive";
}

function changeArchivePage(page){
	window.location = location.pathname + "?mode=archive&page=" + page;
}

function changeArchiveModeTaskForce(url,section)
{
	window.location = url + ".html?mode=archive&section=" + section;
}

function changeArchivePageTaskForce(page,section){
	window.location = location.pathname + "?mode=archive&section=" + section + "&page=" + page;
}

function selectSection(url,section){
	window.location = url + ".html?mode=normal&section=" + section;
}

function escabForgetPassword(){
	window.location = "/en/hkana/gs1/escab/forget_password.html";
}

function changeTagBtn(obj){
   obj.className = "maintext_year_on";
}

function changeTagBtnBack(obj){
	obj.className = "maintext_year_off";
}

function changeTagBtnBackSelected(obj){
	obj.className = "maintext_year_selected";
}

function changeClass(obj, className, status){
   if(status = "on") obj.className = className;
   else obj.className = "";
}

function escapeRedirectUrl(){
   var urlPath = location.search.substring(3,location.search.length);
   document.getElementById("hiddenRedirect").value = urlPath.replace("&amp;","%26");
}