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];}
}

function MM_showHideLayers() { //v3.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_displayStatusMsg(msgStr) { //v1.0
  status=msgStr;
  document.MM_returnValue = true;
}

function open_popup() {  
//  open_popup_removal_notice();
}
 
function open_popup_removal_notice() {
  urllink = document.location.href;
  if(urllink.lastIndexOf("/welcome/") != -1) {
    popup = window.open("removal_notice.htm", "removal_notice", "toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=yes, width=400, height=320");
    popup.moveTo(610,0);    
  }  
}

function open_popup_emstf10() {
  urllink = document.location.href;
  if(urllink.lastIndexOf("/welcome/") != -1) {
    popup = window.open("emstf10.htm", "emstf10", "toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=yes, copyhistory=yes, width=560, height=340");
    popup.moveTo(0,0);
  }    
}

function open_popup_gold_award() {
  urllink = document.location.href;
  if(urllink.lastIndexOf("/welcome/") != -1) {
    popup = window.open("gold_award_notice.htm", "gold_award_notice", "toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=yes, copyhistory=yes, width=600, height=370");
    popup.moveTo(0,0);
  }
}

function open_popup_by_wnew() {
  urllink = document.location.href;
    popup = window.open("gold_award_notice.htm", "gold_award_notice", "toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=yes, copyhistory=yes, width=600, height=370");
    popup.moveTo(0,0);
}

function open_5days(name) {
	//fivedays = window.open("../welcome/5-days.htm","fivedays","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=yes, width=280, height=190");
	//fivedays = window.open("../welcome/five-day_week.htm","fivedays","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, copyhistory=yes, width=600, height=480");
	if (name != null) {
		switch (name) {
			case 'Eng' : 	fivedays = window.open("http://www.emsd.gov.hk/emsd/eng/welcome/five-day_week.htm","fivedays","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, copyhistory=yes, width=600, height=600");
					     	break;
			case 'Chi' : 	fivedays = window.open("http://www.emsd.gov.hk/emsd/chi/welcome/five-day_week.htm","fivedays","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, copyhistory=yes, width=600, height=600");
					     	break;
			case 'SChi': 	fivedays = window.open("http://www.emsd.gov.hk/emsd/schs/welcome/five-day_week.htm","fivedays","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, copyhistory=yes, width=600, height=600");
					     	break;
		}		
	}	
	fivedays.moveTo(0,0);
}

function HK_govt(name) {	
	if (name != null) {
		switch (name) {
			case 'Eng' : 	popup = window.open("http://www.gov.hk/en/residents/","GovHK","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, copyhistory=yes, width=800, height=600");
					     	break;
			case 'Chi' : 	popup = window.open("http://www.gov.hk/tc/residents/","GovHK","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, copyhistory=yes, width=800, height=600");
					     	break;
			case 'SChi': 	popup = window.open("http://www.gov.hk/sc/residents/","GovHK","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, copyhistory=yes, width=800, height=600");
					     	break;
		}		
	}	
	popup.moveTo(0,0);
}

function Get_Cookie(name) {
    var start = document.cookie.indexOf(name+"=");
    var len = start+name.length+1;
    if ((!start) && (name != document.cookie.substring(0,name.length))) return null;
    if (start == -1) return null;
    var end = document.cookie.indexOf(";",len);
    if (end == -1) end = document.cookie.length;
    return unescape(document.cookie.substring(len,end));
}

function Set_Cookie(name,value,expires,path,domain,secure) {
	document.cookie = name + "=" + escape (value) +     // save cookie value
        "; expires=" + expires.toGMTString() +  "; path=/";     
}

function Delete_Cookie(name,path,domain) {
    if (Get_Cookie(name)) document.cookie = name + "=" +
        ( (path) ? ";path=" + path : "") +
        ( (domain) ? ";domain=" + domain : "") +
        ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}


function checkcookie(){
	
	var emsd_version = Get_Cookie("emsd_version");
	return emsd_version;
}

function setcook(ver)
{
	var name = "emsd_version";
	var today = new Date();
	var zero_date = new Date(0,0,0);
	today.setTime (today.getTime() - zero_date.getTime());
	var todays_date = new Date(today.getYear(),today.getMonth(),today.getDate(),0,0,0);
	var expire_date = new Date(todays_date.getTime()+(8*7*86400000));
	//if ((Get_Cookie("emsd_version") == null) {
		//document.cookie = name + "=" + escape (ver) + "; expires=" + expire_date.toGMTString() +  "; path=/"; 
	//}else{	
		Set_Cookie("emsd_version",ver,expire_date);
	//}
	return true;
}

function tographical(ver){

	var link = document.location.href;		
	if (ver == "chi"){
		source1 = "/chi_txt/";
		source2 = "/eng_txt/";
		source3 = "/schi_txt/";
		source4 = "/emsd/eng/";
		source5 = "/emsd/schi/";
		destination = "/emsd/chi/";
	}else if (ver == "eng"){
		source1 = "/chi_txt/";
		source2 = "/eng_txt/";
		source3 = "/schi_txt/";
		source4 = "/emsd/chi/";
		source5 = "/emsd/schi/";
		destination = "/emsd/eng/";
	}else if (ver == "schi"){
		source1 = "/chi_txt/";
		source2 = "/eng_txt/";
		source3 = "/schi_txt/";
		source4 = "/emsd/chi/";
		source5 = "/emsd/eng/";
		destination = "/emsd/schs/";
	}else{
		return false;
	}

//	emsd_version = Get_Cookie("emsd_version");
//	alert('Current Cookie : ' + emsd_version);
//	if ( emsd_version == "flash"){

	link = link.replace (source1, destination);
	link = link.replace (source2, destination);
	link = link.replace (source3, destination);
	link = link.replace (source4, destination);
	link = link.replace (source5, destination);
	parent.location.href = link;

//	}else{
//		link = link.replace (pattern, nflash);
//		parent.location.href = link;
//	}

//	alert (link);

}

function filename(){
	path = location.href;
	file_id = path.lastIndexOf("/");
	file_id2 = path.lastIndexOf(".");
	fname = path.substring(file_id+1,file_id2);
	return fname;
}

function tographical2(ver,fname){
	testlink = document.location.href;
	len = testlink.length;
	path_no = testlink.lastIndexOf("/");
	
	testlink = testlink.substring(0,path_no+1);
	
	if (ver == "chi"){
		pattern = "/chi_txt/";
		flash = "/emsd/chi/";
		nflash = "/nf_chi/";
	}else if (ver == "eng"){
		pattern = "/eng_txt/";
		flash = "/emsd/eng/";
		nflash = "/nf_eng/";		
	}else{
		return false;
	}
	
	emsd_version = Get_Cookie("emsd_version");
	if ( emsd_version == "flash"){
		testlink = testlink.replace (pattern, flash);
	}else{
		testlink = testlink.replace (pattern, nflash);
	}	
	testlink = testlink + fname;
	//alert(testlink);
	parent.location.href = testlink;
	
}

function tographical1(ver){

	var link = document.location.href;

		if (ver=="schi") ver="schs";
		ver = '/'+ver+'/';

		flash = "/chi/";
		link = link.replace (flash, ver);

		flash = "/eng/";
		link = link.replace (flash, ver);

		flash = "/schs/";
		link = link.replace (flash, ver);
/*
		if(ver == '/schi/')
			link = link.replace ('www.emsd.gov.hk', 'sc.info.gov.hk/gb/www.emsd.gov.hk');
		else
			link = link.replace ('sc.info.gov.hk/gb/www.emsd.gov.hk', 'www.emsd.gov.hk');
*/
		dec = link.indexOf('#');
		if(dec != -1)
			link = link.substring(0,dec);
		
		parent.location.href = link;

/*
	emsd_version = Get_Cookie("emsd_version");
	if ( emsd_version == "flash"){
		link = link.replace (pattern, flash);
		parent.location.href = link;
	}else{
		link = link.replace (pattern, nflash);
		parent.location.href = link;
	}
*/

}
