// common.js

/***************************************************************************************************************
* Function		: arn_MouseOut()
* Description		: Restore original image when mouse out
* Parameter Usage	: N/A
* Location		:
* Author		: Arnold CHAN
* Creation Date		: 16 Jan 2004
* Side effect		: N/A
* Amendment History	:
* Date		By		Description
* ---------	------------	--------------------------------------------------------------------------------
***************************************************************************************************************/
function arn_MouseOut()
{
  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		: arn_findObj(n, d)
* Description		: Called by arn_MouseOver() only. It should be used to find object n in document d
* Parameter Usage	: d : current document (optional)
*                   n : object
* Location		:
* Author		: Arnold CHAN
* Creation Date		: 16 Jan 2004
* Side effect		: N/A
* Amendment History	:
* Date		By		Description
* ---------	------------	--------------------------------------------------------------------------------
*
*
****************************************************************************************************************
* Remarks - This has the same functionality as function MM_findObj() in /hk/personal/card/common/js/cs01g.js
*           This function should be generated by Macromedia's application
***************************************************************************************************************/
function arn_findObj(n, d) {
  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=arn_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

/***************************************************************************************************************
* Function		: arn_preloadImages(imgarraystr)
* Description		: Preload the images in imgarray
* Parameter Usage	: imgarray - array of image files
* Location		:
* Author		: Arnold CHAN
* Creation Date		: 12 Feb 2004
* Side effect		: N/A
* Amendment History	:
* Date		By		Description
* ---------	------------	--------------------------------------------------------------------------------
*
***************************************************************************************************************/
function arn_preloadImages(imgarraystr) {
	var d=document;
	var imgarray = imgarraystr.split(",");

	if(d.images) {
		if(!d.p) d.p=new Array();
		var i=0,j=d.p.length,a=imgarray;

		for(i=0; i<a.length; i++)
			if (a[i].indexOf("#")!=0) {
				d.p[j]=new Image; d.p[j++].src=a[i];
			}
	}
}

/***************************************************************************************************************
* Function		: arn_SwapImage(imgArrayStr)
* Description		: Change the src property of specified images
* Parameter Usage	: imgArrayStr - in the format of "imgName1,imgPath1,imgName2,imgPath2..."
*                   where imgName1, imgName2 ... = name of image to be changed
*                         imgFullpath1, imgFullpath2 ... = path of the image
* Location		:
* Author		: Arnold CHAN
* Creation Date		: 13 Feb 2004
* Side effect		: N/A
* Amendment History	:
* Date      By             Description
* ---------	------------   --------------------------------------------------------------------------------
*
***************************************************************************************************************/
function arn_SwapImage(imgArrayStr)
{
	var a = imgArrayStr.split(",");

	if((a.length / 2) != Math.ceil(a.length/2)) {
		alert("Invalid parameters for arn_SwapImage!\nIt must be in format of imgName1,imgPath1,imgName2,imgPath2...");
	} else {
		var i,imgObj;
		for(i=0;i<a.length;i+=2) {
			if ((imgObj=arn_findObj(a[i]))!=null){
				imgObj.src=a[i+1];
			}
		}
	}
	a = null;
}



/***************************************************************************************************************
* Function		: arn_MouseOver(imgName, imgOther, imgPath, imgControl)
* Description		: Display another image when mouse over
*						  When user only wants to change one image when mouseover (most mouse over effect is this case), set imgControl to 1
*						  When uesr needs to change two images to the same image when mouseover, set imgControl to 2
*						  If user wants to change the image only when it's currently displaying a specific image, use imgControl = "e"
*						  If user wants to change the image only when it's currently not displaying a specific image, use imgControl = "ne"
*						    (eg see www.hsbc.com.hk/hk/personal/bank/waystobank.htm. There are 3 states for the buttons,
*						     on, off and over. Normally it will show the off state. When user moves mouse over it, it will
*						     change to over state. It will return to off when mouse out. When the user clicks the button,
*						     it will change to on state. When the button is at on state, there will be no image change whether
*						     the user mouseover or mouseout the button)
* Parameter Usage	: imgName		: The name of image
*                   imgPath		: Path of the image for display when mouse over
*                   imgOther		: This usage depends on the value of imgControl
*                   imgControl	: If this is 1, then only change the src of the image with name = imgName to imgPath
*													imgOther will have no use in this case.
*											  If this is 2, imgOther should another image name.
*													Both the imgName and imgOther will change to imgPath
*											  If this is "e", imgOther should be an image src.
*													If imgName's src = imgOther, then change imgName's src to imgPath. Otherwise no change.
*											  If this is "ne", imgOther should be an image src.
*													If imgName's src != imgOther, then change imgName's src to imgPath. Otherwise no change.
*											  Other values will be treated as case 1
* Supported browsers : IE 6, Netscape 7
* Location		:
* Author		: Arnold CHAN
* Creation Date		: 6 Feb 2004
* Side effect		: N/A
* Amendment History	:
* Date      By             Description
* ---------	------------   --------------------------------------------------------------------------------
****************************************************************************************************************
*
***************************************************************************************************************/
function arn_MouseOver(imgName, imgPath, imgOther, imgControl)
{

	switch(imgControl)
	{
		case "1":
			var i,j=0,x;
			document.MM_sr=new Array;
			if ((x=arn_findObj(imgName))!=null){
				document.MM_sr[j++]=x;
				if(!x.oSrc) x.oSrc=x.src;
				x.src=imgPath;
			}
			break;

		case "2":
			var i,j=0,x;
			document.MM_sr=new Array;
			if ((x=arn_findObj(imgName))!=null){
				document.MM_sr[j++]=x;
				if(!x.oSrc) x.oSrc=x.src;
				x.src=imgPath;
			}

			if ((x=arn_findObj(imgOther))!=null){
				document.MM_sr[j++]=x;
				if(!x.oSrc) x.oSrc=x.src;
				x.src=imgPath;
			}
			break;

		case "e":
			var imgSrc = location.protocol + "//" + location.hostname;

			if (!(!location.port || location.port==80)) {
				imgSrc+=":"+location.port;
			}

			if (imgOther.indexOf('/') == 0) {
				imgSrc += imgOther
			} else {
				imgSrc += location.pathname.substr(0,location.pathname.lastIndexOf('/')+1) + imgOther;
			}

			imgObj = arn_findObj(imgName);
			if (imgObj != null ) {
				if (imgObj.src == imgSrc) {
					imgObj.src = imgPath;
				}
			}
			break;

		case "ne":
			var imgSrc = location.protocol + "//" + location.hostname;

			if (!(!location.port || location.port==80)) {
				imgSrc+=":"+location.port;
			}

			if (imgOther.indexOf('/') == 0) {
				imgSrc += imgOther
			} else {
				imgSrc += location.pathname.substr(0,location.pathname.lastIndexOf('/')+1) + imgOther;
			}

			imgObj = arn_findObj(imgName);
			if (imgObj != null ) {
				if (imgObj.src != imgSrc) {
					imgObj.src = imgPath;
				}
			}
			break;

		default:
			var i,j=0,x;
			document.MM_sr=new Array;
			if ((x=arn_findObj(imgName))!=null){
				document.MM_sr[j++]=x;
				if(!x.oSrc) x.oSrc=x.src;
				x.src=imgPath;
			}
			break;
	}
}


/***************************************************************************************************************
* Function		: arn_writeFlash(swfsrc,swfwidth,swfheight,swfclassid,swfcodebase,swfpluginspage,imgurl,imgwidth,imgheight,imghref,imgtarget,imgalt,imgborder,otherparam)
* Description		: Generate codes for displaying Flash if appropriate plugin is installed.
*			  Otherwise it will display a graphic file with an option of hyperlink.
* Parameter Usage	: swfsrc - Specifies the location (URL) of the movie to be loaded.
*						  swfwidth - Specifies the width of the movie in either pixels or percentage of browser window.
*						  swfheight - Specifies the height of the movie in either pixels or percentage of browser window.
*						  swfclassid - Identifies the ActiveX control for the browser. OBJECT only.
*						  swfcodebase - Identifies the location of the Flash Player ActiveX control so that the browser
*						                can automatically download it if it is not already installed. OBJECT only.
*						  swfpluginspage - Identifies the location of the Flash Player plug-in so that the user can
*						                   download it if it is not already installed. EMBED only.
*						  imgurl - url of the image file to be called
*						  imgwidth - width of the image file (blank if same width as Flash)
*						  imgheight - height of the image file (blank if same height as Flash)
*						  imghref - hyperlink of the image file (no link if blank)
*						  imgtarget - target window of the hyperlink (ignore if hyperlink is blank)
*						  imgalt - alt text of image (default blank)
*						  imgborder - border of image  (default 0)
*						  otherparam - Other optional attributes and possible values. The format of the string is a
*						               set of name,value combinations separated by '|'.
*						               Please read http://www.macromedia.com/support/flash/ts/documents/tag_attributes.htm
* Location		:
* Author		: Arnold CHAN
* Creation Date		: 24 Feb 2004
* Side effect		: N/A
* Amendment History	:
* Date		By					Description
* ---------	------------	--------------------------------------------------------------------------------
*
***************************************************************************************************************/
function arn_writeFlash(swfsrc,swfwidth,swfheight,swfclassid,swfcodebase,swfpluginspage,imgurl,imgwidth,imgheight,imghref,imgtarget,imgalt,imgborder,otherparam) {
	var i=0;
	var isOK=false;
	document.returnValue = false;
	plgIn='Shockwave Flash';

	!swfclassid? swfclassid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000":i=i;
	!swfcodebase? swfcodebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0":i=i;
	!swfpluginspage? swfpluginspage="http://www.macromedia.com/go/getflashplayer":i=i;

	!imgwidth? imgwidth=swfwidth:i=i;
	!imgheight? imgheight=swfheight:i=i;
	!imgalt? imgalt="":i=i;
	!imgborder? imgborder=0:i=i;

	with (navigator) if (appName.indexOf('Microsoft')!=-1 && appVersion.indexOf('Mac')==-1)
		document.write(''+'<scr'+'ipt language="VBScript">\nOn error resume next\n'+'dir = IsObject(CreateObject("SWCtl.SWCtl.1"))\n'+'flash = NOT IsNull(CreateObject("ShockwaveFlash.ShockwaveFlash"))\n</scr'+'ipt>');

	with (navigator) if (appName.indexOf('Microsoft')==-1 || (plugins && plugins.length)) {
		isOK=(plugins && plugins[plgIn]);
	} else if (appVersion.indexOf('3.1')==-1) { //not Netscape or Win3.1
		if (plgIn.indexOf("Flash")!=-1 && window.flash!=null)
			isOK=window.flash;
		else if (plgIn.indexOf("Director")!=-1 && window.dir!=null)
			isOK=window.dir;
		else isOK=false;
	}


	if (isOK) {
		document.write('<OBJECT classid="' + swfclassid + '" codebase="' + swfcodebase + '" WIDTH='+swfwidth+' HEIGHT='+swfheight+'>');
		document.write('<PARAM NAME=movie VALUE="'+swfsrc+'">');

		var op = otherparam.split("|");
		var op1;
		var embedStr="";

		for(i=0;i<op.length;i++) {
			op1 = op[i].split(",");
			document.write('<PARAM NAME=' + op1[0] + ' VALUE="' + op1[1] + '">');
			embedStr = embedStr + op1[0] + '="' + op1[1] + '" ';
		}

		document.write('<EMBED src="'+swfsrc+'" WIDTH='+swfwidth+' HEIGHT='+swfheight+' TYPE="application/x-shockwave-flash" PLUGINSPAGE="' + swfpluginspage + '" wmode="transparent" ');
		document.write(embedStr);
		document.write('></');
		document.write('EMBED>');
		document.write('</');
		document.write('OBJECT>');
	}
	else
	{
		if (imghref) {
			document.write('<a href="'+imghref+'"');
			if (imgtarget) {
				document.write(' target="'+imgtarget+'"');
			}
			document.write('>');
		}

		document.write('<img alt="' + imgalt + '" src="'+imgurl+'" width="'+imgwidth+'" height="'+imgheight+'" border="' + imgborder + '">');
		if (imghref) {
			document.write('</a>');
		}
	}

	op=null;
	op1=null;
}

function arn_newWin(url, status, location, scroll, mbar, toolbar, resize, width, height, winname, pleft, ptop)
{
	!winname? winname="nb":winname=winname;
	nb=window.open(url, winname, "status=" + status + ",location=" + location + ",scrollbars=" + scroll + ",menubar=" + mbar + ",toolbar=" + toolbar + ",resizable=" + resize + ",height=" + height + ",width=" + width + ",left=" + pleft + ",top=" + ptop);
	nb.focus();
}

/***************************************************************************************************************
* Function		   : arn_ShowHideLayer(layerarraystr)
* Description		: Show or Hide a layer by setting the visibility property.
* Parameter Usage	: layerarraystr is in format of "layer1,property1,layer2,property2 ..."
*                   where layer1, layer2 ... = id of the layer
*                         property1, property2 ... = show or hide
* Location		:
* Author		: Arnold CHAN
* Creation Date		: 17 Feb 2004
* Side effect		: N/A
* Amendment History	:
* Date		By		Description
* ---------	------------	--------------------------------------------------------------------------------
*
***************************************************************************************************************/
function arn_ShowHideLayer(layerarraystr) {
	var a = layerarraystr.split(",");
	if((a.length / 2) != Math.ceil(a.length/2)) {
		alert("Invalid parameters for ShowHideLayer!\nIt must be in format layer1,property1,layer2,property2 ...");
	} else {
		var i,v,obj;
		for (i=0; i<a.length; i+=2) {
			if ((obj=arn_findObj(a[i]))!=null) {
				v=a[i+1];
				if (obj.style) {
					obj=obj.style;
					v=(v=='show')?'visible':(v='hide')?'hidden':v;
				}
				obj.visibility=v;
			}
		}
	}
	a = null;
}

/***************************************************************************************************************
* Function		   : arn_toggleLayerDisplay(layerarraystr)
* Description		: Show or Hide a layer by setting the display property.
* Parameter Usage	: pLayer - name of layer
* Location		:
* Author		: Arnold CHAN
* Creation Date		: 17 Feb 2004
* Side effect		: N/A
* Amendment History	:
* Date		By		Description
* ---------	------------	--------------------------------------------------------------------------------
*
***************************************************************************************************************/
function arn_toggleLayerDisplay(pLayer) {
	var i,v,obj;
	if ((obj=arn_findObj(pLayer))!=null) {
		if (obj.style) {
			obj=obj.style;
		}
		if(obj.display=="none") {
			obj.display="block";
		} else {
			obj.display="none";
		}
	}
}

function arn_setLayerDisplay(pLayer, disp) {
	var i,v,obj;
	if ((obj=arn_findObj(pLayer))!=null) {
		if (obj.style) {
			obj=obj.style;
		}
		if (disp==1) {
			obj.display = 'block';
		} else {
			obj.display = 'none';
		}
	}
}


/***************************************************************************************************************
 * Page Number
***************************************************************************************************************/

function pagenum( ) {
	var x;
	var y = location.href ;

	lastUnderscore = y.lastIndexOf( '_' ) ;
	lastDot = y.lastIndexOf( '.' ) ;

	x = y.substr( lastUnderscore + 1, lastDot - lastUnderscore-1 );
	return x;
}


/***************************************************************************************************************
* Function		: arn_getParamVal(name, defaultValue)
* Description		: Get parameters from querystring of URL
* Parameter Usage	: name - variable name
*						  defualtValue - defualt value when variable name is not set
* Supported browsers	: IE6
* Location		:
* Author		: Arnold
* Creation Date		: 19 Apr 2004
* Side effect		: N/A
* Amendment History	:
* Date		By		         Description
* ---------	------------	--------------------------------------------------------------------------------
***************************************************************************************************************
*
***************************************************************************************************************/

function arn_getParamVal(name, defaultValue)
{
	s=location.search;
	reg=new RegExp('.*'+name+'=([^&]*).*');
	s=s.replace(reg,'$1');
	if (s==location.search) s=defaultValue;
	return s;
}

/***************************************************************************************************************
 * disable right click
***************************************************************************************************************/
/*		//Disable select-text script (IE4+, NS6+)
		//visit http://www.rainbow.arch.scriptmania.com/scripts/
		///////////////////////////////////
		function disableselect(e){
		return false
		}
		function reEnable(){
		return true
		}
		//if IE4+
		document.onselectstart=new Function ("return false")
		//if NS6
		if (window.sidebar){
		document.onmousedown=disableselect
		document.onclick=reEnable
		}

		//Disable right click script
		//visit http://www.rainbow.arch.scriptmania.com/scripts/
		var message="Sorry, right-click has been disabled";
		///////////////////////////////////
		function clickIE() {if (document.all) {(message);return false;}}
		function clickNS(e) {if
		(document.layers||(document.getElementById&&!document.all)) {
		if (e.which==2||e.which==3) {(message);return false;}}}
		if (document.layers)
		{document.captureEvents(Event.MOUSEDOWN);document.onmousedown=clickNS;}
		else{document.onmouseup=clickNS;document.oncontextmenu=clickIE;}
		document.oncontextmenu=new Function("return false")


*/

/***************************************************************************************************************
* Function		: arn_SetHomepage(obj, homepage)
* Description		: Set homepage of browser
* Parameter Usage	: obj - this
*						  homepage - homepage URL
* Supported browsers	: IE6
* Location		:
* Author		: Arnold
* Creation Date		: 4 Jul 2006
* Side effect		: N/A
* Amendment History	:
* Date		By		         Description
* ---------	------------	--------------------------------------------------------------------------------
***************************************************************************************************************
*
***************************************************************************************************************/

function arn_setHomepage( obj, homepage ) {
	obj.style.behavior='url(#default#homepage)';
	obj.setHomePage(homepage);
}

/***************************************************************************************************************
* Function		: arn_setHomepage(obj, homepage)
* Description		: Set homepage of browser
* Parameter Usage	: obj - this
*						  homepage - homepage URL
* Supported browsers	: IE6
* Location		:
* Author		: Arnold
* Creation Date		: 4 Jul 2006
* Side effect		: N/A
* Amendment History	:
* Date		By		         Description
* ---------	------------	--------------------------------------------------------------------------------
***************************************************************************************************************
*
***************************************************************************************************************/

function arn_switchLang( lang ) {
	cur_path = location.href;
	alert( cur_path );
}


/***************************************************************************************************************
* Function		:  arn_spacer()
* Description		: gen spacer
* Parameter Usage	: w - width
*					  h - height
* Location		:
* Author		: Arnold CHAN
* Creation Date		: 27 Jan 2006
* Side effect		: N/A
* Amendment History	:
* Date		By		Description
* ---------	------------	--------------------------------------------------------------------------------
***************************************************************************************************************/
function arn_spacer(w, h) {
	document.write("<img src='../common/images/spacer.gif' width='" + w + "' height='" + h + "' alt='' border='0'>");
}


/***************************************************************************************************************
* Function		:  arn_submitform(f)
* Description		: submit form
* Parameter Usage	: f - form
* Location		:
* Author		: Arnold CHAN
* Creation Date		: 10 Aug 2006
* Side effect		: N/A
* Amendment History	:
* Date		By		Description
* ---------	------------	--------------------------------------------------------------------------------
***************************************************************************************************************/
function arn_submitform(f) {
	f.submit();
}

/***************************************************************************************************************
* Function		:  arn_resetform(f)
* Description		: reset form
* Parameter Usage	: f - form
* Location		:
* Author		: Arnold CHAN
* Creation Date		: 12 Oct 2006
* Side effect		: N/A
* Amendment History	:
* Date		By		Description
* ---------	------------	--------------------------------------------------------------------------------
***************************************************************************************************************/
function arn_resetform(f) {
	f.reset();
}