﻿//var gburl = "hanweb.kanhan.com/gb/"
 
var gburl = "sc.chp.gov.hk/TuniS/"

// For Quick Find
function LogicNgo(theForm, ans, golvl, ansid){
	if (theForm.question.value==ans){
		theForm.level.value = golvl;
		theForm.ans.value = ansid;
	}
	theForm.submit();
}


// Function by Macromedia Dreamwaver
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.0
  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 && document.getElementById) x=document.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_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();
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function ChangeLang(curlang, tolang){
	var cururl = document.location.href;
	cururl = cururl.replace("?lang="+curlang, "?lang="+tolang);
	cururl = cururl.replace("lang="+curlang, "lang="+tolang);
	cururl = cururl.replace(gburl, "");
	
	//Cut the '#'(which is last character) at the url - mady in 2005-07-29 16:39
	if ( cururl.substr(cururl.length-1)=="#") {
		cururl = cururl.substr(0, cururl.length-1) ;
	}
	document.location = cururl;		
}

function ChangeVer(curver, tover) {
	var cururl = document.location.href;
	cururl = cururl.replace(curver, tover);
	
	//Cut the '#'(which is last character) at the url - mady in 2005-07-29 16:39
	if ( cururl.substr(cururl.length-1)=='#') {
		cururl = cururl.substr(0, cururl.length-1) ;
	}
	
	if (tover=="/tc/")
	    cururl = cururl.replace('index','cindex');
	else
	    cururl = cururl.replace('cindex','index');
	
	if (cururl.indexOf('TuniS') > 0 && (tover=='/en/' || tover=='/en_text/'))
	    cururl = cururl.replace(gburl,"");
	
	document.location = cururl;		
}

function ChiToogle(){
	var cururl = document.location.href;
	var where_is = cururl.indexOf('TuniS');
	
	//cururl = cururl.replace("/en/", "/tc/");

	if (cururl.indexOf("/en") > 0)
		cururl = cururl.replace("index.html","cindex.html");

	cururl = cururl.replace("/en/", "/tc/");
	cururl = cururl.replace("/en_text/", "/tc_text/");

	//Cut the '#'(which is last character) at the url - mady in 2005-08-03 19:22
	if ( cururl.substr(cururl.length-1)=="#") {
		cururl = cururl.substr(0, cururl.length-1) ;
	}
	
	var newurl = "";
	if (where_is<0){
		cururl = cururl.replace("http://", "");
		newurl = "http://" + gburl + cururl;
	}else{
		cururl = cururl.replace(gburl, "");
		newurl = cururl;
	}
	
	document.location = newurl;
}


function printmenuheader(){        
	link = top.location.href;	
	if (link.indexOf(gburl) != -1){
		document.write("<IMG alt=\"衞生防護中心\" src=\"/gb/images/logo.gif\">");
	}else{
		document.write("<IMG alt=\"衞生防護中心\" src=\"/tc/images/logo.gif\">");
	}
}


function printmenuicon(){        
	link = top.location.href;	
	if (link.indexOf(gburl) != -1){
		document.write("<a href=\"javascript:ChangeVer('/tc/', '/tc_text/');\" onMouseOut=\"MM_swapImgRestore()\"  onMouseOver=\"MM_swapImage('mainbar2','','/gb/images/mainbar2_f2.gif',1)\" ><img name=\"mainbar2\" src=\"/gb/images/mainbar2.gif\" width=\"77\" height=\"19\" border=\"0\" alt=\"繁體純文字\"></a>");
	}else{
		document.write("<a href=\"javascript:ChangeVer('/tc/', '/tc_text/');\" onMouseOut=\"MM_swapImgRestore()\"  onMouseOver=\"MM_swapImage('mainbar2','','/tc/images/mainbar2_f2.gif',1)\" ><img name=\"mainbar2\" src=\"/tc/images/mainbar2.gif\" width=\"77\" height=\"19\" border=\"0\" alt=\"繁體純文字\"></a>");
	}
}

function printmenuicon_clf(){        
	link = top.location.href;	
	if (link.indexOf(gburl) != -1){
		document.write("<a href=\"javascript:ChangeVer('chp.gov.hk/', 'chp.gov.hk/text/');\" onMouseOut=\"MM_swapImgRestore()\"  onMouseOver=\"MM_swapImage('mainbar2','','/gb/images/mainbar2_f2.gif',1)\" ><img name=\"mainbar2\" src=\"/gb/images/mainbar2.gif\" border=\"0\" alt=\"繁體純文字\"></a>");
	}else{
		document.write("<a href=\"javascript:ChangeVer('chp.gov.hk/', 'chp.gov.hk/text/');\" onMouseOut=\"MM_swapImgRestore()\"  onMouseOver=\"MM_swapImage('mainbar2','','/tc/images/mainbar2_f2.gif',1)\" ><img name=\"mainbar2\" src=\"/tc/images/mainbar2.gif\" border=\"0\" alt=\"繁體純文字\"></a>");
	}
}


function printmenuicon2(){        
	link = top.location.href;
	if (link.indexOf(gburl) != -1){
		document.write("<a href=\"javascript:ChiToogle();\" onMouseOut=\"MM_swapImgRestore()\"  onMouseOver=\"MM_swapImage('mainbar3','','/gb/images/mainbar3_f2.gif',1)\" ><img name=\"mainbar3\" src=\"/gb/images/mainbar3.gif\" width=\"49\" height=\"19\" border=\"0\" alt=\"簡體版\"></a>");
	}else{
		document.write("<a href=\"javascript:ChiToogle();\" onMouseOut=\"MM_swapImgRestore()\"  onMouseOver=\"MM_swapImage('mainbar3','','/tc/images/mainbar3_f2.gif',1)\" ><img name=\"mainbar3\" src=\"/tc/images/mainbar3.gif\" width=\"49\" height=\"19\" border=\"0\" alt=\"簡體版\"></a>");
	}
}

function printmenuicon2_clf(){        
	link = top.location.href;
	if (link.indexOf(gburl) != -1){
		document.write("<a href=\"javascript:ChiToogle();\" onMouseOut=\"MM_swapImgRestore()\"  onMouseOver=\"MM_swapImage('mainbar3','','/gb/images/mainbar3_f2.gif',1)\" ><img name=\"mainbar3\" src=\"/gb/images/mainbar3.gif\" border=\"0\" alt=\"簡體版\"></a>");
	}else{
		document.write("<a href=\"javascript:ChiToogle();\" onMouseOut=\"MM_swapImgRestore()\"  onMouseOver=\"MM_swapImage('mainbar3','','/tc/images/mainbar3_f2.gif',1)\" ><img name=\"mainbar3\" src=\"/tc/images/mainbar3.gif\" border=\"0\" alt=\"簡體版\"></a>");
	}
}


function printtextmenuicon(){        
	link = top.location.href;
	if (link.indexOf(gburl) != -1){
		document.write("<a href=\"javascript:ChiToogle();\" class=\"txttitlelink\">純文字簡體中文版</a>");
	}else{
		document.write("<a href=\"javascript:ChiToogle();\" class=\"txttitlelink\">純文字簡體中文版</a>");
	}
}


var link = "/cgi-bin/popup_qf.pl?_xml=";
var linktext = "/cgi-bin/popuptext_qf.pl?_xml=";
var clink = "/cgi-bin/cpopup_qf.pl?_xml=";
var clinktext = "/cgi-bin/cpopuptext_qf.pl?_xml=";
function isTextOnly() {
	var url = document.location.href;	
	var urli = url.indexOf('textonly');
	
	if (urli<0){
		// in graphic version
		return false;
	}else{
		// in textonly
		return true;
	}	
}
function popupQF(filename){
	var path ="";
	var url = document.location.href;
	var urli2 = url.indexOf('en');	
	if (isTextOnly()) 
	{
		if (urli2<0){
			path = clinktext + filename;
			
		}else{
			path = linktext + filename;
		}
	}
	else 
	{
		if (urli2<0){
			
			path = clink + filename;
		}else{
			path = link + filename;
		}
		
	}
	window.location = path;
}
