//cv_sc_base_path = "http:" + "//" + "sc.info.gov.hk/gb/www.sb.gov.hk";
cv_sc_base_path = "http:" + "//" + "www.sb.gov.hk";
cv_nonsc_base_path = "http:" + "//" + "www.sb.gov.hk";

var section = '';
var content = '';
idx = 3;
cgistr = '/cgi-bin/sb/';	
basestr = '/sb/';	

org_path=window.location.pathname;
tmpstr=org_path.substring(0, cgistr.length);
if (tmpstr == cgistr) {
	section = 'cgi-bin';
	content = org_path.substring(cgistr.length, org_path.length)
} else {
	path_end=org_path.length;
	path_start=org_path.indexOf(basestr);
	org_path=org_path.substring(path_start ,path_end);

	path_end=org_path.length;	
	content = org_path.substring(basestr.length + 0 ,path_end);
	for (var j=1; j<=idx; j++) {
		path_end=org_path.length;
		path_start=org_path.indexOf("/");
		org_path=org_path.substring(path_start + 1 ,path_end);
	}
	
	path_start=org_path.indexOf("/");
	section=org_path.substring(0, path_start);	
}

function changeVer(lang) {

	if (lang == 'simp') {
		base_path = cv_sc_base_path;
	} else {
		base_path = cv_nonsc_base_path;
	}	
	
	if (section=='cgi-bin') {
	
		for (var j=1; j<=idx; j++) {
			path_end=content.length;
			path_start=content.indexOf("/");
			content=content.substring(path_start + 1 ,path_end);
		}
		
		if (lang == 'eng') {
			org_path=content.substring(2 ,content.length);
		}
		
		// alert(base_path + '/cgi-bin/edlb/' + content);
		window.location.href = base_path + '/cgi-bin/sb/' + content;
				
	} else {
		
		if (content.indexOf("ue_") >= 0) {
			path_end=content.lastIndexOf("/");
			content = content.substring(0 ,path_end+1);
		}
		
		if (lang == 'eng') {
			sec = '/eng/';
		} else {
			sec = '/chi/';
		}	
	
//	alert(content);			
	window.location.href = sec + content;

	}
}

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) { //v3.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); 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];}
}

cookiename = 'sb';  
cookieval= '123';  

function GetCookie(cookieName) {
thisCookie = document.cookie.split("; ")
for (i = 0; i < thisCookie.length; i++) {
	if (cookieName == thisCookie[i].split("=")[0]) {
		return thisCookie[i].split("=")[1];
	}
}
return "";
}

function changePage(obj) {
    i = obj.redirect.selectedIndex;
        self.location = obj.redirect.options[i].value;
}

if (cookieval == GetCookie(cookiename)) {
document.write ("Secutiry Bureau<br><br><font size=\"-1\"><a href=\"/sc/text.htm\">Back to menu</a></font>"); 
} else {
document.write("<table width=\"760\" border=\"0\" height=\"87\" cellpadding=\"0\" cellspacing=\"0\" background=\"/sc/images/bkgdtexture.gif\"><form name=\"form1\" method=\"get\" action=\"http://search.gov.hk/search.html\" target=_blank><input name=\"tpl_id\" type=\"hidden\" value=\"stdsearch\"><input name=\"gp0\" type=\"hidden\" value=\"sb_home\"><input name=\"gp1\" type=\"hidden\" value=\"sb_home\"><input name=\"web\" type=\"hidden\" value=\"this\"><input name=\"ui_charset\" type=\"hidden\" value=\"utf-8\"><input name=\"ui_lang\" type=\"hidden\" value=\"zh-cn\">");

document.write("<TBODY><TR><TD height=66 colspan=\"2\">"
+ "<table width=\"760\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">"
+ "<tr><td width=\"600\"><kanhanbypass><a href=\"/index.htm\"><img alt=\"保安局\" title=\"保安局\" height=66 src=\"/sc/images/branding.gif\" width=500 border=0></a></kanhanbypass></td>"
+ "<td width=\"170\" align=\"right\" valign=\"bottom\"><a href=\"http://www.brandhk.gov.hk/brandhk/index.htm\" target=_new><img src=\"/sc/images/BrandHK.gif\" alt=\"香港品牌形象 - 亚洲国际都会\" name=\"brandhk\" width=\"190\" height=\"60\" border=\"0\" align=\"right\"></a></td></tr>"
+ "</table>"
+ "</TD></TR>"
+ "<TR vAlign=bottom><TD width=470 > "
+ "<table width=\"100\"  border=\"0\" cellpadding=\"0\" cellspacing=\"0\">"
+ "<tr><td ><A href=\"http://www.gov.hk/sc/residents/\" target=_blank><img src=\"/sc/images/mainbar1.gif\" height=19 alt=\"GovHK 香港政府一站通\" name=\"mainbar1\"  border=\"0\" onMouseOver=\"MM_swapImage('mainbar1','','/sc/images/mainbar1_f2.gif',1)\" onMouseOut=\"MM_swapImgRestore()\"></A></td>");

document.write('<td height=\"19\"><a href=\"javascript:changeVer(\'chi\');\" onMouseOut=\"MM_swapImgRestore()\"  onMouseOver=\"MM_swapImage(\'mainbar3\',\'\',\'/sc/images/mainbar3_f2.gif\',1)\" ><img name=\"mainbar3\" src=\"/sc/images/mainbar3.gif\" width=\"49\" height=\"19\" border=\"0\" alt=\"繁体版\\"></a></td>');
document.write('<td height=\"19\"><a href=\"javascript:changeVer(\'eng\');\" onMouseOut=\"MM_swapImgRestore()\"  onMouseOver=\"MM_swapImage(\'mainbar4\',\'\',\'/sc/images/mainbar4_f2.gif\',1)\" ><img name=\"mainbar4\" src=\"/sc/images/mainbar4.gif\" width=\"56\" height=\"19\" border=\"0\" alt=\"English\"></a></td>'
  + '            <td height="19" ><img name="mainbar5" src="/sc/images/mainbar5.gif" border="0" height="19"></td></tr></table>'
+ "</TD><TD  height=\"19\" align=\"right\"> "
+ "<table width=\"100\" height=\"19\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">"
+ "<tr><td><A onmouseover=\"MM_swapImage('mainbar6','','/sc/images/mainbar6b_f2.gif',1)\" onmouseout=MM_swapImgRestore() href=\"/sc/search/index.htm\" target=_top><IMG src=\"/sc/images/mainbar6b.gif\" alt=搜寻 name=mainbar6 width=36 height=19 border=0 id=\"mainbar6\" valign=bottom></A></td><td><input type=\"text\" name=\"query\" size=\"12\" value=\"\" class=\"search\"></td>"
+ "<td><input type=\"image\" width=\"22\" height=\"19\" alt=\"搜寻\" src=\"/sc/images/mainbar8b.gif\" border=\"0\" name=\"mainbar8\" onmouseover=\"MM_swapImage('mainbar8','','/sc/images/mainbar8b_f2.gif',1)\" onmouseout=\"MM_swapImgRestore()\" valign=bottom></td>"
+ "<td><A onmouseover=\"MM_swapImage('mainbar9','','/sc/images/mainbar9b_f2.gif',1)\" onmouseout=MM_swapImgRestore() href=\"/sc/sitemap/index.htm\" target=_top><IMG src=\"/sc/images/mainbar9b.gif\" alt=\"网页指南\" name=mainbar9 width=67 height=19 border=0 id=\"mainbar9\" valign=bottom></A></td>"
+ "<td><A onmouseover=\"MM_swapImage('mainbar10','','/sc/images/mainbar10_f2.gif',1)\" onmouseout=MM_swapImgRestore() href=\"/sc/contact/index.htm\"><IMG src=\"/sc/images/mainbar10.gif\" alt=\"联络我们\" name=mainbar10 width=29 height=19 border=0 id=\"mainbar10\" valign=bottom></A></td></tr>"
+ "</table>"
+ "</TD></TR></TBODY></FORM></TABLE>"
+ "<table width=\"760\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr><td><img src=\"/sc/images/mainbar9.gif\" width=\"760\" height=\"2\"></td></tr></table>");
 
}

