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_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_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];}
}

var tabdropdown={
	disappeardelay: 200, 
	disablemenuclick: false, 

	dropmenuobj: null, ie: document.all, firefox: document.getElementById&&!document.all, previousmenuitem:null,
	currentpageurl: window.location.href.replace("http://"+window.location.hostname, "").replace(/^\//, ""), 

	getposOffset:function(what, offsettype){
		var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
		var parentEl=what.offsetParent;
			while (parentEl!=null){
				totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
				parentEl=parentEl.offsetParent;
			}
		return totaloffset;
	},

	showhide:function(obj, e, obj2){ 
		if (this.ie || this.firefox)
			this.dropmenuobj.style.left=this.dropmenuobj.style.top="-500px"
		if (e.type=="click" && obj.visibility==hidden || e.type=="mouseover"){
			obj2.parentNode.className="selected"
			obj.visibility="visible"
			}
		else if (e.type=="click")
			obj.visibility="hidden"
	},

	iecompattest:function(){
		return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
	},

	clearbrowseredge:function(obj, whichedge){
		var edgeoffset=0
		if (whichedge=="rightedge"){
			var windowedge=this.ie && !window.opera? this.standardbody.scrollLeft+this.standardbody.clientWidth-15 : window.pageXOffset+window.innerWidth-15
			this.dropmenuobj.contentmeasure=this.dropmenuobj.offsetWidth
		if (windowedge-this.dropmenuobj.x < this.dropmenuobj.contentmeasure)
			edgeoffset=this.dropmenuobj.contentmeasure-obj.offsetWidth
		}
		else{
			var topedge=this.ie && !window.opera? this.standardbody.scrollTop : window.pageYOffset
			var windowedge=this.ie && !window.opera? this.standardbody.scrollTop+this.standardbody.clientHeight-15 : window.pageYOffset+window.innerHeight-18
			this.dropmenuobj.contentmeasure=this.dropmenuobj.offsetHeight
			if (windowedge-this.dropmenuobj.y < this.dropmenuobj.contentmeasure){ 
				edgeoffset=this.dropmenuobj.contentmeasure+obj.offsetHeight
				if ((this.dropmenuobj.y-topedge)<this.dropmenuobj.contentmeasure)
					edgeoffset=this.dropmenuobj.y+obj.offsetHeight-topedge
			}
			this.dropmenuobj.firstlink.style.borderTopWidth=(edgeoffset==0)? 0 : "1px" 
		}
		return edgeoffset
	},

	dropit:function(obj, e, dropmenuID){
		if (this.dropmenuobj!=null){
			this.dropmenuobj.style.visibility="hidden"
			if (this.previousmenuitem!=null && this.previousmenuitem!=obj)
				this.previousmenuitem.parentNode.className=""
		}
		if (tabdropdowns.dropmenuobjs!=null){ 
			tabdropdowns.dropmenuobjs.style.visibility="hidden"
		}
		this.clearhidemenu()
		if (this.ie||this.firefox){
			obj.onmouseout=function(){tabdropdown.delayhidemenu(obj)}
			this.dropmenuobj=document.getElementById(dropmenuID)
			this.dropmenuobj.onmouseover=function(){tabdropdown.clearhidemenu()}
			this.dropmenuobj.onmouseout=function(e){tabdropdown.dynamichide(e, obj)}
			this.dropmenuobj.onclick=function(){tabdropdown.delayhidemenu(obj)}
			this.showhide(this.dropmenuobj.style, e, obj)
			this.dropmenuobj.x=this.getposOffset(obj, "left")
			this.dropmenuobj.y=this.getposOffset(obj, "top")
			this.dropmenuobj.style.left=this.dropmenuobj.x-this.clearbrowseredge(obj, "rightedge")+"px"
			this.dropmenuobj.style.top=this.dropmenuobj.y-this.clearbrowseredge(obj, "bottomedge")+obj.offsetHeight+1+"px"
			this.previousmenuitem=obj
		}
	},

	contains_firefox:function(a, b) {
		while (b.parentNode)
		if ((b = b.parentNode) == a)
			return true;
		return false;
	},

	dynamichide:function(e, obj2){ 
		var evtobj=window.event? window.event : e
		if (this.ie&&!this.dropmenuobj.contains(evtobj.toElement))
			this.delayhidemenu(obj2)
		else if (this.firefox&&e.currentTarget!= evtobj.relatedTarget&& !this.contains_firefox(evtobj.currentTarget, evtobj.relatedTarget))
			this.delayhidemenu(obj2)
	},

	delayhidemenu:function(obj2){
		this.delayhide=setTimeout(function(){tabdropdown.dropmenuobj.style.visibility='hidden'; if (obj2.parentNode.className.indexOf('default')==-1) obj2.parentNode.className=''},this.disappeardelay) 
	},

	clearhidemenu:function(){
		if (this.delayhide!="undefined")
			clearTimeout(this.delayhide)
	},

	isSelected:function(menuurl){
		var menuurl=menuurl.replace("http://"+menuurl.hostname, "").replace(/^\//, "")
		return (tabdropdown.currentpageurl==menuurl)
	},

	init:function(menuid, dselected){
		this.standardbody=(document.compatMode=="CSS1Compat")? document.documentElement : document.body
		var menuitems=document.getElementById(menuid).getElementsByTagName("a")
		for (var i=0; i<menuitems.length; i++){
			if (menuitems[i].getAttribute("rel")){
				var relvalue=menuitems[i].getAttribute("rel")
				document.getElementById(relvalue).firstlink=document.getElementById(relvalue).getElementsByTagName("a")[0]
				menuitems[i].onmouseover=function(e){
					var event=typeof e!="undefined"? e : window.event
					tabdropdown.dropit(this, event, this.getAttribute("rel"))
				}
			}
		}
	}

}

var tabdropdowns={
	disappeardelay: 200, 
	disablemenuclick: true, 
  horizontaloffset:2, 

	dropmenuobjs: null, ie: document.all, firefox: document.getElementById&&!document.all, previousmenuitem:null,
	currentpageurl: window.location.href.replace("http://"+window.location.hostname, "").replace(/^\//, ""), 
	
	getposOffset:function(what, offsettype){
		var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
		var parentEl=what.offsetParent;
			while (parentEl!=null){
				totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
				parentEl=parentEl.offsetParent;
			}
		return totaloffset;
	},

	showhide:function(obj, e, obj2){ 
		if (this.ie || this.firefox)
			this.dropmenuobjs.style.left=this.dropmenuobjs.style.top="-500px"
		if (e.type=="click" && obj.visibility==hidden || e.type=="mouseover"){
			obj.visibility="visible"
			}
		else if (e.type=="click")
			obj.visibility="hidden"
	},

	iecompattest:function(){
		return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
	},

	clearbrowseredge:function(obj, whichedge){
		var edgeoffset=0
		if (whichedge=="rightedge"){
			var windowedge=this.ie && !window.opera? this.standardbody.scrollLeft+this.standardbody.clientWidth-15 : window.pageXOffset+window.innerWidth-15
			this.dropmenuobjs.contentmeasure=this.dropmenuobjs.offsetWidth
		if (windowedge-this.dropmenuobjs.x < this.dropmenuobjs.contentmeasure)  
			edgeoffset=this.dropmenuobjs.contentmeasure-obj.offsetWidth
		}
		else{
			var topedge=this.ie && !window.opera? this.standardbody.scrollTop : window.pageYOffset
			var windowedge=this.ie && !window.opera? this.standardbody.scrollTop+this.standardbody.clientHeight-15 : window.pageYOffset+window.innerHeight-18
			this.dropmenuobjs.contentmeasure=this.dropmenuobjs.offsetHeight
			if (windowedge-this.dropmenuobjs.y < this.dropmenuobjs.contentmeasure){ 
				edgeoffset=this.dropmenuobjs.contentmeasure+obj.offsetHeight
				if ((this.dropmenuobjs.y-topedge)<this.dropmenuobjs.contentmeasure)
					edgeoffset=this.dropmenuobjs.y+obj.offsetHeight-topedge
			}
			this.dropmenuobjs.firstlink.style.borderTopWidth=(edgeoffset==0)? 0 : "1px" 
		}
		return edgeoffset
	},

	dropit:function(obj, e, dropmenuID){
		if (this.dropmenuobjs!=null){ 
			this.dropmenuobjs.style.visibility="hidden" 
			if (this.previousmenuitem!=null && this.previousmenuitem!=obj)
					this.previousmenuitem.parentNode.className=""
		}
		this.clearhidemenu()
		if (this.ie||this.firefox){
			obj.onmouseout=function(){tabdropdowns.delayhidemenu(obj)}
			this.dropmenuobjs=document.getElementById(dropmenuID)
			this.dropmenuobjs.onmouseover=function(){
				tabdropdown.clearhidemenu()
				tabdropdowns.clearhidemenu()
				}
			this.dropmenuobjs.onmouseout=function(e){
				tabdropdowns.dynamichide(e, obj)
				tabdropdown.dynamichide(e, tabdropdown.previousmenuitem)
				}
			this.dropmenuobjs.onclick=function(){tabdropdowns.delayhidemenu(obj)}
			this.showhide(this.dropmenuobjs.style, e, obj)
			this.dropmenuobjs.x=this.getposOffset(obj, "left")
			this.dropmenuobjs.y=this.getposOffset(obj, "top")
			this.dropmenuobjs.style.left=this.dropmenuobjs.x-this.clearbrowseredge(obj, "rightedge")+obj.offsetWidth+this.horizontaloffset+"px"
			this.dropmenuobjs.style.top=this.dropmenuobjs.y-this.clearbrowseredge(obj, "bottomedge")+"px"
			this.previousmenuitem=obj 
		}
	},

	contains_firefox:function(a, b) {
		while (b.parentNode)
		if ((b = b.parentNode) == a)
			return true;
		return false;
	},

	dynamichide:function(e, obj2){ 
		var evtobj=window.event? window.event : e
		if (this.ie&&!this.dropmenuobjs.contains(evtobj.toElement))
			this.delayhidemenu(obj2)
		else if (this.firefox&&e.currentTarget!= evtobj.relatedTarget&& !this.contains_firefox(evtobj.currentTarget, evtobj.relatedTarget))
			this.delayhidemenu(obj2)
	},

	delayhidemenu:function(obj2){
		this.delayhide=setTimeout(function(){tabdropdowns.dropmenuobjs.style.visibility='hidden'; if (obj2.parentNode.className.indexOf('default')==-1) obj2.parentNode.className=''},this.disappeardelay) 
	},

	clearhidemenu:function(){
		if (this.delayhide!="undefined")
			clearTimeout(this.delayhide)
	},

	isSelected:function(menuurl){
		var menuurl=menuurl.replace("http://"+menuurl.hostname, "").replace(/^\//, "")
		return (tabdropdowns.currentpageurl==menuurl)
	},

	init:function(menuid, dselected){
		this.standardbody=(document.compatMode=="CSS1Compat")? document.documentElement : document.body 
		var menuitems=document.getElementById(menuid).getElementsByTagName("a")
		for (var i=0; i<menuitems.length; i++){
			if (menuitems[i].getAttribute("rels")){
				var relvalue=menuitems[i].getAttribute("rels")
				document.getElementById(relvalue).firstlink=document.getElementById(relvalue).getElementsByTagName("a")[0]
				menuitems[i].onmouseover=function(e){
					var event=typeof e!="undefined"? e : window.event
					tabdropdowns.dropit(this, event, this.getAttribute("rels"))
				}
			}
		}
	}
}

function SelectLanguage(fromlang, tolang) {
	currentURL = new String(document.location.href);
	//currentURL = currentURL.replace(/#/,"");
	newURL = currentURL.replace(fromlang,tolang);
	
	if (newURL.indexOf("#") > -1)
	{
		newURL = newURL.substring(0,newURL.indexOf("#"));
	}
	location.href=newURL;
}

function AddBookMark() {
	var url = document.location.href;
	var title = document.title;
	if (window.sidebar) // firefox
		window.sidebar.addPanel(title, url, "");
	else if(window.opera && window.print){ // opera
		var elem = document.createElement('a');
		elem.setAttribute('href',url);
		elem.setAttribute('title',title);
		elem.setAttribute('rel','sidebar');
		elem.click();
	} 
	else if(document.all) // ie
		window.external.AddFavorite(url, title);
}

function PrintPage() {
	window.print();
}

intNewsMarqueeMarginTop = "a";
intNewsMarqueeScrollAmount = 1;
function move_marquee() {
  if (intNewsMarqueeMarginTop == "a") {
    intNewsMarqueeMarginTop = Number((document.getElementById("news_marquee_container").style.height).replace("px", ""))/2;
    document.getElementById("news_marquee").style.marginTop = intNewsMarqueeMarginTop+'px';
  } else {
    if (Number(document.getElementById("news_marquee").offsetHeight)/2 < Math.abs(intNewsMarqueeMarginTop)) {
      intNewsMarqueeMarginTop = 0;
    }
    intNewsMarqueeMarginTop -= intNewsMarqueeScrollAmount;
    document.getElementById("news_marquee").style.marginTop = intNewsMarqueeMarginTop+'px';
  }
}

function getCookie(c_name) {
  if (document.cookie.length>0) {
    c_start=document.cookie.indexOf(c_name + "=");
    if (c_start!=-1) { 
      c_start=c_start + c_name.length+1; 
      c_end=document.cookie.indexOf(";",c_start);
      if (c_end==-1) {
        c_end=document.cookie.length;
      }
      return unescape(document.cookie.substring(c_start,c_end));
    } 
  }
  return "";
}

function setCookie(c_name,value,expiredays) {
  var exdate=new Date();
  exdate.setDate(exdate.getDate()+expiredays);
  document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

function openLogin() {
	//window.open(bcomURL('/MPF/GenLogin.do?lang=0'),'','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=800,height=600');
	window.open("https://trust.bocomtrust.com.hk/impf/welcome.action?lang=en_US","Welcome","toolbar=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,revisable=yes,width=1100,height=768,left=0, top=0");
}

function openDemo() {
	//window.open(bcomURL('/MPF/demo/login_EN.html'),'','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=800,height=600');
	window.open("/MPF/demo/Demomain_EN.htm","Demo","toolbar=no,status=yes,menubar=no,scrollbars=yes,revisable=yes,width=1024,height=768,left=0, top=0");
}

