<!--

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);
}


var motion;
var goSpeed = 20;
var tempNum;
var frameBody;
var tempX;
var tempY;
var isIFrame = false;

function scrollStart(name, goNum, iFrame) {
	tempNum = goNum;
	if (navigator.appName.indexOf("Microsoft") > -1) {
		if (iFrame != null) {
    		frameBody  = document.frames(name).document.body;
    		isIFrame = true;
    	} else {
    		frameBody  = document.getElementById(name);
    	}
	} else {
		if (iFrame != null) {
    		frameBody  = document.all(name);
    	//	frameBody.contentWindow.scrollTo(0, 0);
    		isIFrame = true;
    	} else {
    		frameBody  = document.getElementById(name);
    	}
	}
	scrollMotion();
}


function scrollMotion(){
//	window.status = document.getElementById("contentIFrame").document.body.scrollHeight +"  :  "+ frameBody.offsetHeight;
	if (navigator.appName.indexOf("Microsoft") > -1) {
		frameBody.scrollTop += tempNum;
	} else {
		if (isIFrame) {
			tempX = frameBody.contentWindow.pageXOffset;
			tempY = frameBody.contentWindow.pageYOffset;
			tempY += tempNum;
			frameBody.contentWindow.scrollTo(tempX, tempY);
		} else {
			frameBody.scrollTop += tempNum;
		}
	}
	
	motion = setTimeout("scrollMotion()", goSpeed);
}

function scrollStop() {
	clearTimeout(motion);
}


function NewWindow(mypage, myname, w, h, scroll,resizable,menubar,toolbar) {
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top=0,left=0,scrollbars='+scroll+',resizable='+resizable+',menubar='+menubar+',toolbar='+toolbar;
	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

var targ_link = selObj.options[selObj.selectedIndex].value;
	if (targ_link.indexOf("javascript:") >= 0){
		var link = "";
		var width = "";
		var height = "";
		
		link = targ_link.substring(targ_link.indexOf("https:"), targ_link.indexOf(","));
		link = link.replace(/'/, "");
		link = link.replace(/\\/, "");
		targ_link = targ_link.substring(targ_link.indexOf("width="));
		width = targ_link.substring(targ_link.indexOf("width=")+ 6, targ_link.indexOf(","));
		targ_link = targ_link.substring(targ_link.indexOf("height="));
		height = targ_link.substring(targ_link.indexOf("height=") + 7, targ_link.indexOf(","));
//		alert(link);
//		alert(width);
//		alert(height);
		window.open(link, 'rate', 'status=yes, scrollbars=yes, width=' + width + ', height=' + height + ', top=0, left=0');
	} else {
	  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
	}
  selObj.selectedIndex=0;
  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=6,0,29,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" scale="noscale" 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" scale="noscale" 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=6,0,29,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="transparent">';
	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="transparent" 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="transparent" 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 changeTab(tab) {
	if (tab.className=='unselected') {
		tab.className = 'selected';
		
		var _count;
		var _body;
		
		if (tab.id.substring(0,3) == 'sc_') {
			_count = sc_tabCount;
			_body = 'sc_innerBody';
		} else {
			_count = tabCount;
			_body = 'innerBody';
		}
		
		// Unselect all other tabs.
		
		for(var i=0;i<_count;i++) {
			var _tab = document.getElementById(tab.id.substring(0,tab.id.length-1) + i);
			
			if (_tab.id == tab.id) continue;
			_tab.className = 'unselected';
		}
		var tmp = location.href.replace(/\/(tc|en)\//i,"/lang/");
		createCookie('DahSingTabUrl',tmp.toLowerCase(),0);
		createCookie('DahSingTabSelected',tab.id,0);
		// Update main body.
		document.getElementById(_body).innerHTML = document.getElementById(tab.id + 'Body').innerHTML;
	}
}

function setTab() {
	var tmp = location.href.replace(/\/(tc|en)\//,"/lang/");
	var tab_id = "";
	var currentURL = document.URL;
	if (currentURL.indexOf("?sel_tab") != -1){
		tab_id = currentURL.substring(currentURL.indexOf("?sel_tab=")+9);
	}
	
//	if (tmp.toLowerCase() == readCookie('DahSingTabUrl') && readCookie('DahSingTabSelected') != null) {
//		var tab = document.getElementById(readCookie('DahSingTabSelected'));
	if (tab_id){
		var tab = document.getElementById(tab_id);
		if (tab) {
			changeTab(tab);
		}
	} else {
		eraseCookie('DahSingTabUrl');
		eraseCookie('DahSingTabSelected');
	}
  init_selected_tab();
}

var banner_link = "";

function changeBanner(banner,point,link,type) {
	var obj = "";

	MM_swapImage('section_banner','',banner,1);
	for(var i=0;i<4;i++) {
		if(document.getElementById('banner_div_' + i) != null){
			document.getElementById('banner_div_' + i).style.display  = "none";
		}
		if (i==point) {
			MM_swapImage('banner_point_' + i,'','/common/images/common/arrow_banner_f2.gif',1);
			document.getElementById('front_link_' + i).style.color = "#9D3C51";
			document.getElementById('front_link_' + i).style.fontWeight = "bold";
		} else {
			MM_swapImage('banner_point_' + i,'','/common/images/common/arrow_banner.gif',1);
			var front_link = document.getElementById('front_link_' + i);
			
			if(front_link != null) {
				front_link.style.color = "#000";
				front_link.style.fontWeight = "normal";
			}
		}
	}
	
	obj = document.getElementById('banner_div_' + point);
	obj.style.display = "";
}


function changeLanguage(c_lang) {
	var selected_tab = readCookie('DahSingTabSelected');
	
	if(c_lang == 'tc') {
		document.getElementById('tcTable1').style.display = "";
		document.getElementById('tcTable2').style.display = "";
		document.getElementById('scTable1').style.display = "none";
		document.getElementById('scTable2').style.display = "none";
		document.getElementById('lblTitle').innerText = tcTitle;
		if (selected_tab != null){
			selected_tab = selected_tab.replace(/sc_/, "");
			changeTab(document.getElementById(selected_tab));
			changeTab(document.getElementById("sc_" + selected_tab));
		}
	} else {
		document.getElementById('tcTable1').style.display = "none";
		document.getElementById('tcTable2').style.display = "none";
		document.getElementById('scTable1').style.display = "";
		document.getElementById('scTable2').style.display = "";
		document.getElementById('lblTitle').innerText = scTitle;
		if (selected_tab != null){
			selected_tab = selected_tab.replace(/sc_/, "");
			changeTab(document.getElementById("sc_" + selected_tab));
			changeTab(document.getElementById(selected_tab));
		}
	}
}

var groupList = new Array();
groupList.push("box_01");
groupList.push("box_02");
groupList.push("box_03");
groupList.push("box_04");
groupList.push("box_05");

function showhidecards(type){	
	
	var this_btn = document.getElementById('btn_' + type);
	if (this_btn.src.indexOf("more") > -1) {
		for(var i=0;i<card_rows.length;i++) {
			var btn = document.getElementById('btn_' + i);
			if(btn) {
				if (i==type) {
					btn.setAttribute("src","/" + lang + "/images/credit_card/close.jpg");
				} else {
					btn.setAttribute("src","/" + lang + "/images/credit_card/more.gif");
				}
			}
			if (card_rows[i]>1) {
				for (var j=1;j<card_rows[i];j++) {
					var row_card = document.getElementById('ccCard_' + i + '_' + j);
					var row_text = document.getElementById('ccText_' + i + '_' + j);				
					if (i==type) {
						row_card.style.display = "";
						row_text.style.display = "";
					} else {
						row_card.style.display = "none";
						row_text.style.display = "none";
					}
				}
			}
		}
	} else {
		for (var j=1;j<card_rows[type];j++) {
			var row_card = document.getElementById('ccCard_' + type + '_' + j);
			var row_text = document.getElementById('ccText_' + type + '_' + j);
			
			row_card.style.display = "none";
			row_text.style.display = "none";
		}
		document.getElementById('btn_' + type).setAttribute("src","/" + lang + "/images/credit_card/more.gif");
	}
}

function changelang(){
	var currentURL = document.URL;
	var newURL = "";
	var selected_tab = readCookie('DahSingTabSelected');
	if (selected_tab != "" && selected_tab != null){
		eraseCookie('DahSingTabSelected');
		if (currentURL.indexOf("?sel_tab") != -1){
			currentURL = currentURL.substring(0, currentURL.indexOf("?sel_tab"));
		}
		
		if (currentURL.match("/tc/") == null){
			newURL = currentURL.replace(/\/en\//, "/tc/");
		} else if (currentURL.match("/en/") == null){
			newURL = currentURL.replace(/\/tc\//, "/en/");		
		}
		selected_tab = selected_tab.replace(/sc_/, "");
		if (selected_tab){
			newURL = newURL + "?sel_tab=" + selected_tab;
		}
	} else {
		
		if (currentURL.match("/tc/") == null){
			newURL = currentURL.replace(/\/en\//, "/tc/");
		} else if (currentURL.match("/en/") == null){
			newURL = currentURL.replace(/\/tc\//, "/en/");		
		}
	}
	window.location = newURL;
}

function setTDClass(tr, c)
{
	var tds = tr.getElementsByTagName('td');
	for (var item in tds)
		{
			var td = tds[item];
			if (typeof(td) != 'object') continue;
			if (td.className == 'header') return false;
			td.className = c;
		}
	return true;
}

function switchBranchArea(area) {
//	alert(area);
	var areaName = '';
	var new_url = window.location.href;
	var branch = "";
	if (new_url.indexOf("?branch=") >= 0){
		branch = new_url.substring(new_url.indexOf("?branch=") + 8);
		new_url = new_url.substring(0, new_url.indexOf("?branch="));
	} else {
		branch = "";
	}
//	alert(branch);
	switch (area) {
		case 'hk' :
			document.getElementById('hkbranchesInfo').style.display = "";
			document.getElementById('kowloonbranchesInfo').style.display = "none";
			document.getElementById('ntbranchesInfo').style.display = "none";
//			createCookie('selectedbranch','hk',0);
			if (branch != area){
			window.location = new_url + "?branch=hk";
			}
			if (lang == 'tc') {
				areaName = '香港島分行';
			} else {
				areaName = 'Hong Kong Island Branches';
			}
			break;
		case 'kowloon' :
			document.getElementById('hkbranchesInfo').style.display = "none";
			document.getElementById('kowloonbranchesInfo').style.display = "";
			document.getElementById('ntbranchesInfo').style.display = "none";
//			createCookie('selectedbranch','kowloon',0);
			if (branch != area){
			window.location = new_url + "?branch=kowloon";
			}
			if (lang == 'tc') {
				areaName = '九龍區分行';
			} else {
				areaName = 'Kowloon Branches';
			}
			break;
		case 'nt' :	
			document.getElementById('hkbranchesInfo').style.display = "none";
			document.getElementById('kowloonbranchesInfo').style.display = "none";
			document.getElementById('ntbranchesInfo').style.display = "";
//			createCookie('selectedbranch','nt',0);
			if (branch != area){
			window.location = new_url + "?branch=nt";
			}
			if (lang == 'tc') {
				areaName = '新界區分行';
			} else {
				areaName = 'New Territories Branches';
			}
			break;
		default:
			document.getElementById('hkbranchesInfo').style.display = "";
			document.getElementById('kowloonbranchesInfo').style.display = "";
			document.getElementById('ntbranchesInfo').style.display = "";
			if (branch != area){
				window.location = new_url;
			}
			if (lang == 'tc') {
				areaName = '所有分行';
			} else {
				areaName = 'All Branches';
			}
			break;
	}
	document.getElementById('lblAreaType').innerHTML = areaName;
}

function setBranch() {
	var branch = gup('branch');
	switchBranchArea(branch)
}

function gup(name){
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}

function switchPressYear(index) {
	var tmp = location.href.replace(/\/(tc|en)\//,"/lang/");
	createCookie('PressReleasePath',tmp,0);
	for(var i=0;i<avail_years.length;i++) {
		var table = document.getElementById('tbl'+avail_years[i]);
		if (table) {
			if (avail_years[i]==index) {
				table.style.display="";
				document.getElementById("lblPressYear").innerHTML=index;
				createCookie('DahSingPressYear',index,0);
			} else {
				table.style.display="none";
			}
		}
	}
}

function setPressYear() {
	var pressYear = readCookie('DahSingPressYear');
	if (pressYear == null) pressYear = avail_years[0];
	switchPressYear(pressYear);
}

function switchSnapshotMonth(index) {
	var tmp = location.href.replace(/\/(tc|en)\//,"/lang/");
	createCookie('DahSingSnapshotUrl',tmp.toLowerCase(),0);
	for(var i=0;i<avail_months.length;i++) {
		var table = document.getElementById('tbl'+i);
		if (table) {
			if (i==index) {
				table.style.display="";
				document.getElementById("lblSnapshotMonth").innerHTML=avail_months[i];
				createCookie('DahSingSnapshotMonth',index,0);
			} else {
				table.style.display="none";
			}
		}
	}
}

function setSnapshotMonth() {
	var tmp = location.href.replace(/\/(tc|en)\//,"/lang/");
	var SnapshotMonth = readCookie('DahSingSnapshotMonth');
	var url = readCookie('DahSingSnapshotUrl');
	if (SnapshotMonth == null || url != tmp.toLowerCase()) {
		SnapshotMonth = 0;
	}
	switchSnapshotMonth(SnapshotMonth);
}


function createCookie(name,value,days) {

	if (days) {

		var date = new Date();

		date.setTime(date.getTime()+(days*24*60*60*1000));

		var expires = "; expires="+date.toGMTString();

	}

	else var expires = "";

	document.cookie = name+"="+value+expires+"; path=/";

}

function readCookie(name) {

	var nameEQ = name + "=";

	var ca = document.cookie.split(';');

	for(var i=0;i < ca.length;i++) {

		var c = ca[i];

		while (c.charAt(0)==' ') c = c.substring(1,c.length);

		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);

	}

	return null;

}

function eraseCookie(name) {

	createCookie(name,"",-1);

}

function stockquote() {
	var url = '';
	var path = location.href.split('?');
	if (lang == 'tc') {
		url = 'http://gateway.etnet.com.hk/DahSing/big5/public-DLSS.html';
	} else if (lang == 'en') {
		url = 'http://gateway.etnet.com.hk/DahSing/eng/public-DLSS.html';
	}	
	
	try {
		url += "?" + path[1];
	} catch (err) {
	}
	
	var temp = '<iframe src ="' + url + '" name="stock_area" id="stock_area" marginwidth="0" marginheight="0" frameBorder="0" width="575" height="300"></iframe>';
//	document.getElementById('stockquote').InnerHTML = "temp";
	document.write(temp);
	
}

function switchFront(index) {
	for (var i=0;i<=fronts;i++) {
		var front = document.getElementById("front"+i);
		var link = document.getElementById("front_link"+i);
		if (front) {
			if (i==index) {
				front.style.display="";
				link.className = "graduate2";
			} else {
				front.style.display="none";
				if (i>0) {
					link.className = "graduate";
				}
			}
		}
	}
}

function showhide(btn, box_id){
	var currentURL = document.URL;
	
	if (lang == "tc"){	
		btn.innerHTML = (btn.innerHTML=='更多')?'關閉':'更多';
	} else {
		btn.innerHTML = (btn.innerHTML=='More')?'Close':'More';
	}
	var box = document.getElementById(box_id);
	if (box.style.display=='none'){
		box.style.display='';
	}else{
		box.style.display='none'
	}

}

function changeRadio() {

	var args = changeRadio.arguments;
	var isIE = true;

	if (navigator.appName.indexOf("Microsoft") > -1) {
		isIE = true;
	} else {
		isIE = false;
	}
	
	for (var i=0; i<args.length; i+=2) {
		var mc = document.getElementById(args[i]);
		if (args[(i+1)] == "block" && !isIE)	var temp = "table";	else	var temp = args[(i+1)];
		mc.style.display = temp;
	}
}

function showDialog(id, f) {

	var dialog = document.getElementById(id);
	if (f){
		dialog.style.top = 0;
		var bodyH = ElmHeight(document.body);
		var bodyST = document.body.scrollTop;
		var bodySH = document.body.scrollHeight;
		var dY = getElementPositionY(id);
		var dH = ElmHeight(id);

		if ((dY - bodyST + dH) > bodyH) {
			dialog.style.top = -20-ElmHeight(id);
		}
		dialog.style.visibility = "visible";
	} else {
		dialog.style.visibility = "hidden";
	}
}

function ElmHeight(elmID) {
	if (typeof(elmID) == 'string')
		{
			var e = document.getElementById(elmID);
		}
	else
		{
			var e = elmID;
		}

	if(e.clientHeight) {
		return (e.clientHeight);
	}
	else {
		if(e.offsetHeight) {
			return (e.offsetHeight);
		}
	}
}

function getElementPositionY(elemID)
{
   var offsetTrail = document.getElementById(elemID);
   var offsetTop = 0;

   while(offsetTrail)
   {
      offsetTop += offsetTrail.offsetTop;
      offsetTrail = offsetTrail.offsetParent;
   }
    if (navigator.userAgent.indexOf("Mac") != -1 &&
        typeof(document.body.leftMargin) != "undefined") {
        offsetTop += document.body.topMargin;
    }

    return offsetTop;
}

function allow_numeric(obj){
 if (/[^0-9]/i.test(obj.value))
  obj.value=obj.value.replace(/[^0-9]/g,'')
  obj.value+=''
  obj.focus()
  
}

function init_selected_tab(){
  var url = document.URL;
  if (url.indexOf("init_tab=") != -1){
    var selected_tab = url.substr(url.indexOf("init_tab=") + 9, 1);
    changeTab(document.getElementById("tab" + selected_tab));
  } else {
  }
}
-->
