var gburl = "/sc/"
var wwwurl = "http://webstaging2.swd.hksarg/"
var urli = document.location.href.indexOf(gburl);

// 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;
	
	if (cururl.indexOf(gburl) != -1){
		curlang = "sc";
	}

	cururl = cururl.replace("/"+curlang+"/", "/"+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) ;
	}
	document.location = cururl;		
}

function ChiToogle(){
	var cururl = document.location.href;
	var where_is = cururl.indexOf(gburl);
	
	cururl = cururl.replace("/en/", "/tc/");
	cururl = cururl.replace("swdwww", "swdstaging");	// Remove this line for production

	//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){
		newurl = cururl.replace("/tc/", "/sc/");
	}else{
		newurl = cururl.replace("/sc/", "/tc/");
	}
	
	document.location = newurl;
}

function printmenuicon(){        
	link = top.location.href;	
	if (link.indexOf(gburl) != -1){
		document.write("<a href=\"javascript:ChangeVer(\'index\', \'textonly\');\" onMouseOut=\"MM_swapImgRestore()\"  onMouseOver=\"MM_swapImage(\'mainbar2\',\'\',\'/sc/img/clf/sc_mainbar2_f2.gif\',1)\" ><img name=\"mainbar2\" src=\"/sc/img/clf/sc_mainbar2.gif\" border=\"0\" alt=\"简体纯文字\"></a>");
	}else{
		document.write("<a href=\"javascript:ChangeVer(\'index\', \'textonly\');\" onMouseOut=\"MM_swapImgRestore()\"  onMouseOver=\"MM_swapImage(\'mainbar2\',\'\',\'/sc/img/clf/sc_mainbar2_f2.gif\',1)\" ><img name=\"mainbar2\" src=\"/sc/img/clf/sc_mainbar2.gif\" border=\"0\" alt=\"繁体纯文字\"></a>");
	}
}


function printmenuicon2(){        
	link = top.location.href;	
	if (link.indexOf(gburl) != -1){
		document.write("<a href=\"javascript:ChangeLang(\'sc\', \'tc\');\" onMouseOut=\"MM_swapImgRestore()\"  onMouseOver=\"MM_swapImage(\'mainbar3\',\'\',\'/sc/img/clf/sc_mainbar3_f2.gif\',1)\" ><img name=\"mainbar3\" src=\"/sc/img/clf/sc_mainbar3.gif\" border=\"0\" alt=\"繁体版\"></a>");
	}else{
		document.write("<a href=\"javascript:ChangeLang(\'tc\', \'sc\');\" onMouseOut=\"MM_swapImgRestore()\"  onMouseOver=\"MM_swapImage(\'mainbar3\',\'\',\'/sc/img/clf/sc_mainbar3_f2.gif\',1)\" ><img name=\"mainbar3\" src=\"/sc/img/clf/sc_mainbar3.gif\" border=\"0\" alt=\"简体版\"></a>")
	}
}

var link = "/cgi-bin/swd/popup_qf.pl?_xml=";
var linktext = "/cgi-bin/swd/popuptext_qf.pl?_xml=";
var clink = "/cgi-bin/swd/cpopup_qf.pl?_xml=";
var clinktext = "/cgi-bin/swd/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;
		}
		window.location = path;
	}
	else 
	{
		if (urli2<0){
			
			path = clink + filename;
		}else{
			path = link + filename;
		}
		window.open(path,'QuickFind','width=400,height=400,scrollbars=yes,toolbar=no,location=no,status=no,menubar=no,resizable=no');	
	}
}

function printgovhkbar(){
	link = top.location.href;	
	if (link.indexOf(gburl) != -1){
		document.write("<a href=\"http://www.gov.hk/sc/residents/\" onMouseOut=\"MM_swapImgRestore()\"  onMouseOver=\"MM_swapImage(\'mainbar1\',\'\',\'/sc/img/clf/sc_mainbar1_f2.gif\',1)\" target=\"_blank\" >");
	}else{
		document.write("<a href=\"http://www.gov.hk/sc/residents/\" onMouseOut=\"MM_swapImgRestore()\"  onMouseOver=\"MM_swapImage(\'mainbar1\',\'\',\'/sc/img/clf/sc_mainbar1_f2.gif\',1)\" target=\"_blank\" >");
	}
}

function printgovhktxt(){
	link = top.location.href;	
	if (link.indexOf(gburl) != -1){
		document.write("<a href=\"http://www.gov.hk/sc/residents/\" target=\"_blank\" class=\"footerlink\">香港政府一站通</a>");
	}else{
		document.write("<a href=\"http://www.gov.hk/sc/residents/\" target=\"_blank\" class=\"footerlink\">香港政府一站通</a>");
	}

}


function popupSCCSNewsEN(){
	window.open('/en/mindex/site_sccsnews/','SCCSNews','width=340,height=500,scrollbars=yes,toolbar=no,location=no,status=no,menubar=no,resizable=no');
}

function popupSCCSNewsTC(){
	var cururl = document.location.href;
	
	if (cururl.indexOf(gburl) != -1){
		curlang = "sc";
	}else{
		curlang = "tc";
	}

	
	window.open('/'+ curlang +'/mindex/site_sccsnews/','SCCSNews','width=340,height=500,scrollbars=yes,toolbar=no,location=no,status=no,menubar=no,resizable=no');
}
