﻿
var expDays = 1; // number of days the cookie should last

var path = "/";

var domain ;
var locapath = document.location.href

if (locapath.toString().search('/preview/')!= -1){
	var page  = "/preview";
}else{
	var page  = "";
}

if (locapath.toString().search('/textonly/')!= -1){
	 page += "/textonly/sc_chi/disclaimer/statment.html";
}else{
	 page += "/sc_chi/disclaimer/statment.html";
}


org_path_start = locapath.indexOf("://") + 3;
org_path_end = locapath.length;
domain = locapath.substring(org_path_start, org_path_end);
if (domain.toString().search('/')!= -1){
org_path_start = 0;
org_path_end = domain.indexOf("/");
domain = domain.substring(org_path_start, org_path_end);
}

//find how many sub-directory
org_path_start = locapath.indexOf("://") + 3;
org_path_end = locapath.length;
temppath = locapath.substring(org_path_start, org_path_end);

subdirno = 0;
//alert(temppath);
pos = temppath.indexOf("/");
while ( pos != -1 ) {   
   subdirno++;
   pos = temppath.indexOf("/",pos+1);
}

subdirno = subdirno -1

if (locapath.toString().search('/preview/')!= -1){
	subdirno = subdirno -1
}


subdirpath = "";

for (i=0;i<subdirno;i++){
	subdirpath = subdirpath + "../";
}

//alert(subdirpath);

//end how many sub-directory



function GetCookie (name) {  
var arg = name + "=";  
var alen = arg.length;  
var clen = document.cookie.length;  
var i = 0;  
while (i < clen) {    
var j = i + alen;    
if (document.cookie.substring(i, j) == arg)      
return getCookieVal (j);    
i = document.cookie.indexOf(" ", i) + 1;    
if (i == 0) break;   
}  
return null;
}
function SetCookie (name, value) {  
var argv = SetCookie.arguments;  
var argc = SetCookie.arguments.length;  
var expires = (argc > 2) ? argv[2] : null;  
//var path = (argc > 3) ? argv[3] : null;  
//var domain = (argc > 4) ? argv[4] : null;  

var secure = (argc > 5) ? argv[5] : false;  
document.cookie = name + "=" + escape (value) + 
//((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + 
//((expires == null) ? "" : ("; expires=")) + 
((path == null) ? "" : ("; path=" + path)) +  
((domain == null) ? "" : ("; domain=" + domain)) +    
((secure == true) ? "; secure" : "");
}
function DeleteCookie (name) {  
var exp = new Date();  
exp.setTime (exp.getTime() - 1);  
var cval = GetCookie (name);  
document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}
var exp = new Date(); 
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));
function amt(){
var count = GetCookie('sccount')
if(count == null) {
SetCookie('count','1')
return 1
}
else {
var newcount = parseInt(count) + 1;
DeleteCookie('sccount')
SetCookie('sccount',newcount,exp)
return count
   }
}
function getCookieVal(offset) {
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1)
endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}

function checkCount() {
var sccount = GetCookie('sccount');
if (sccount == null) {

SetCookie('orgiurl',document.location.href, exp);

window.location.href=page;
}
else {
//count++;
//SetCookie('count', count, exp);
   }
}

//if ((locapath.toString().search('/sc_chi/')!= -1)||(locapath.toString().search('scindex.html')!= -1))   {
//	checkCount();
//}



//Finish Check SC statment




var dept = "/";
var domain = "";
var scserver = "http"+"://sc.info.gov.hk/gb/";
var locapath = document.location.href
//var locapath = "http://www.sar-expertcom.gov.hk/textonly/eindex.html";




var atlang,domname,sitepath,atgb,atindex,org_part;
	sc_path = "sc_chi/";
	sctxt_path = "textonly/sc_chi/";
	tc_path = "tc_chi/";
	tctxt_path = "textonly/tc_chi/";
	en_path = "english/";
	entxt_path = "textonly/english/";
	atgb = false;
	atindex = false;

if (locapath.toString().search('/gb/')!= -1){
	atgb = true;
	org_path_start = locapath.indexOf("/gb/") +4;
	org_path_end = locapath.length;
	sitepath = locapath.substring(org_path_start, org_path_end);
}else{
	atgb = false;
	sitepath = locapath.substring(7,locapath.length);
}

if (locapath.toString().search('/textonly/english/')!= -1){
	atlang = "entxt";
	org_part = entxt_path;
}else
if (locapath.toString().search('/textonly/tc_chi/')!= -1){
	atlang = "tctxt";
	org_part = tctxt_path;
}else
if (locapath.toString().search('/textonly/sc_chi/')!= -1){
	atlang = "sctxt";
	org_part = sctxt_path;
}else
if (locapath.toString().search('/english/')!= -1){
	atlang = "en";
	org_part = en_path;
}else
if (locapath.toString().search('/tc_chi/')!= -1){
	atlang = "tc";
	org_part = tc_path;
}else
if (locapath.toString().search('/sc_chi/')!= -1){
	atlang = "sc";
	org_part = sc_path;
}else
if (locapath.toString().search('/textonly/eindex.html')!= -1){
	atlang = "txteindex";
	org_part = "textonly/eindex.html";
	atindex = true;
}else
if (locapath.toString().search('eindex.html')!= -1){
	atlang = "eindex";
	org_part = "eindex.html";
	atindex = true;
}else
if (locapath.toString().search('/textonly/cindex.html')!= -1){
	atlang = "txtcindex";
	org_part = "textonly/cindex.html";
	atindex = true;
}else
if (locapath.toString().search('cindex.html')!= -1){
	atlang = "cindex";
	org_part = "cindex.html";
	atindex = true;
}else
if (locapath.toString().search('/textonly/scindex.html')!= -1){
	atlang = "txtsindex";
	org_part = "textonly/scindex.html";
	atindex = true;
}else
if (locapath.toString().search('scindex.html')!= -1){
	atlang = "sindex";
	org_part = "scindex.html";
	atindex = true;
}

//domain = sitepath.substring(0, sitepath.indexOf("/"));
domain = "202.57.255.178";
subdir = "/preview";

function chglang(lang){

	switch(lang){
		case 'entxt': 
			des_part = entxt_path;
			des_ind_part = "textonly/eindex.html";
			base_path = "http://";
			break;
		case 'tctxt':
			des_part = tctxt_path;
			des_ind_part = "textonly/cindex.html";
			base_path = "http://";
			break;
		case 'sctxt':
			des_part = tctxt_path;
			des_ind_part = "textonly/cindex.html";
			base_path = scserver;
			//base_path = "http://";
			break;
		case 'en':
			des_part = en_path;
			des_ind_part = "eindex.html";
			base_path = "http://";
			break;
		case 'tc':
			des_part = tc_path;
			des_ind_part = "cindex.html";
			base_path = "http://";
			break;
		case 'sc':
			des_part = tc_path;
			des_ind_part = "cindex.html";
			base_path = scserver;
			//base_path = "http://";
			break;
	}

	if (atindex == true){
		tail = sitepath.replace(org_part, des_ind_part);
	}else{
		tail = sitepath.replace(org_part, des_part);
	}

//alert(base_path+tail)
	window.location =  base_path+tail;

}

function tellafriend( lang )
{
  if (lang == 'eng')
  {
     window.location = subdir + '/english/tell/tell.html?base=http%3A//'+ domain + subdir + '/english/tell/&url=' + escape(window.location);
  }else if (lang == 'chi')
  {
     window.location = subdir + '/tc_chi/tell/tell.html?base=http%3A//'+ domain + subdir + '/tc_chi/tell/&url=' + escape(window.location);
  }else if (lang == 'schi')
  {
     window.location = subdir + '/sc_chi/tell/tell.html?base=http%3A//'+ domain + subdir + '/sc_chi/tell/&url=' + escape(window.location);
  }else if (lang == 'eng_txt')  
  {
     window.location = subdir + '/textonly/english/tell/tell.html?base=http%3A//'+ domain + subdir + '/textonly/english/tell/&url=' + escape(window.location);
  }else if (lang == 'chi_txt')
  {
     window.location = subdir + '/textonly/tc_chi/tell/tell.html?base=http%3A//'+ domain + subdir + '/textonly/tc_chi/tell/&url=' + escape(window.location);
  }else if (lang == 'schi_txt')
  {
     window.location = subdir + '/textonly/sc_chi/tell/tell.html?base=http%3A//'+ domain + subdir + '/textonly/sc_chi/tell/&url=' + escape(window.location);
  }
  //window.location = '../tell/tell.html?url=' + escape(window.location);
}

function splitString (stringToSplit,separator) {
 var arrayOfStrings = stringToSplit.split(separator);
 return arrayOfStrings[1];
}


function showlangtop(){
	


document.write("                                <table width=\"538\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"> \n");
document.write("                                  <tr valign=\"top\"> \n");
document.write("                                    <td><a href=\"http://www.info.gov.hk/eindex.htm\" onMouseOut=\"MM_swapImgRestore()\"  onMouseOver=\"MM_swapImage('mainbar1','','"+subdirpath+"english/images/clf/mainbar1_f2.gif',1)\" target=\"_blank\" ><img name=\"mainbar1\" src=\""+subdirpath+"english/images/clf/mainbar1.gif\" border=\"0\" alt=\"Government Information Centre\"></a></td> \n");
document.write("                                    <td><a href=\"javascript:chglang('entxt')\" onMouseOut=\"MM_swapImgRestore()\"  onMouseOver=\"MM_swapImage('mainbar2','','"+subdirpath+"english/images/clf/mainbar2_f2.gif',1)\" ><img name=\"mainbar2\" src=\""+subdirpath+"english/images/clf/mainbar2.gif\" border=\"0\" alt=\"TEXT ONLY\"></a></td> \n");
document.write("                                    <td><a href=\"javascript:chglang('tc')\" onMouseOut=\"MM_swapImgRestore()\"  onMouseOver=\"MM_swapImage('mainbar3','','"+subdirpath+"english/images/clf/mainbar3_f2.gif',1)\" ><img name=\"mainbar3\" src=\""+subdirpath+"english/images/clf/mainbar3.gif\" border=\"0\" alt=\"TRADITIONAL CHINESE\"></a></td> \n");
document.write("                                    <td><a href=\"javascript:chglang('sc')\" onMouseOut=\"MM_swapImgRestore()\"  onMouseOver=\"MM_swapImage('mainbar4','','"+subdirpath+"english/images/clf/mainbar4_f2.gif',1)\" ><img name=\"mainbar4\" src=\""+subdirpath+"english/images/clf/mainbar4.gif\" border=\"0\" alt=\"SIMPLIFIED CHINESE\"></a></td> \n");
document.write("                                    <td><img name=\"mainbar5\" src=\""+subdirpath+"english/images/clf/mainbar5.gif\" border=\"0\" alt=\"image\"></td> \n");
document.write("                                    <td><a href=\"javascript:document.searchform.submit();\" onMouseOut=\"MM_swapImgRestore()\"  onMouseOver=\"MM_swapImage('mainbar6','','"+subdirpath+"english/images/clf/mainbar6_f2.gif',1)\" ><img name=\"mainbar6\" src=\""+subdirpath+"english/images/clf/mainbar6.gif\" border=\"0\" alt=\"SEARCH\"></a></td> \n");
document.write("                                  </tr> \n");
document.write("                                </table>	\n");
	
	
}

function showlangtoptxt(){

document.write("  <font size=\"2\" face=\"Arial, Helvetica, sans-serif\">  \n");
document.write("  [<a href=\"javascript:chglang('entxt')\">English Version</a>]  \n");
document.write("  [<a href=\"javascript:chglang('tctxt')\">Traditional Chinese Version</a>]  \n");
document.write("  [<a href=\"javascript:chglang('sctxt')\">Simplified Chinese Version</a>]  \n");
document.write("  [<a href=\"javascript:chglang('en')\">Graphical Version</a>]  \n");
document.write("  </font>   \n");

	
}



function showmainmenu(){
	

      
document.write("      <div id=\"rightmainmenu\" style=\"position:absolute; width:153; height:294; z-index:1; left: 577px; top: 110px; visibility: hidden\">  \n");
document.write("        <table width=\"153\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"> \n");
document.write("          <tr>  \n");
document.write("            <td><a href=\"#\" onClick=\"MM_showHideLayers('rightmainmenu','','hide')\"><img src=\""+subdirpath+"english/images/general/epd_menuclose_01.gif\" width=\"153\" height=\"21\" alt=\"Close Menu\" name=\"closemenu\" border=\"0\"></a></td> \n");
document.write("          </tr> \n");
document.write("          <tr>  \n");
document.write("            <td><a href=\"/epd/epic/english/epichome.html\" onMouseOut=\"MM_swapImgRestore()\" onMouseOver=\"MM_swapImage('menubtn_1','','"+subdirpath+"english/images/general/epd2_mainmenu_over_02.gif',1)\"><img name=\"menubtn_1\" border=\"0\" src=\""+subdirpath+"english/images/general/epd2_mainmenu_02.gif\" alt=\"Environmental Protection Interactive Centre\"></a></td> \n");
document.write("          </tr> \n");
document.write("          <tr>  \n");
document.write("            <td><a href=\""+subdirpath+"english/news_events/what_new/what_new.html\" onMouseOut=\"MM_swapImgRestore()\" onMouseOver=\"MM_swapImage('menubtn_2','','"+subdirpath+"english/images/general/epd2_mainmenu_over_03.gif',1)\"><img name=\"menubtn_2\" border=\"0\" src=\""+subdirpath+"english/images/general/epd2_mainmenu_03.gif\" alt=\"What's New\"></a></td> \n");
document.write("          </tr> \n");
document.write("          <tr>  \n");
document.write("            <td><a href=\""+subdirpath+"english/news_events/news_maincontent.html\" onMouseOut=\"MM_swapImgRestore()\" onMouseOver=\"MM_swapImage('menubtn_3','','"+subdirpath+"english/images/general/epd2_mainmenu_over_04.gif',1)\"><img name=\"menubtn_3\" border=\"0\" src=\""+subdirpath+"english/images/general/epd2_mainmenu_04.gif\" alt=\"News &amp; Events\"></a></td> \n");
document.write("          </tr> \n");
document.write("          <tr>  \n");
document.write("            <td><a href=\""+subdirpath+"english/about_epd/aboutepd_maincontent.html\" onMouseOut=\"MM_swapImgRestore()\" onMouseOver=\"MM_swapImage('menubtn_4','','"+subdirpath+"english/images/general/epd2_mainmenu_over_05.gif',1)\"><img name=\"menubtn_4\" border=\"0\" src=\""+subdirpath+"english/images/general/epd2_mainmenu_05.gif\" alt=\"About Us\"></a></td> \n");
document.write("          </tr> \n");
document.write("          <tr>  \n");
document.write("            <td><a href=\""+subdirpath+"english/laws_regulations/laws_maincontent.html\" onMouseOut=\"MM_swapImgRestore()\" onMouseOver=\"MM_swapImage('menubtn_5','','"+subdirpath+"english/images/general/epd2_mainmenu_over_06.gif',1)\"><img name=\"menubtn_5\" border=\"0\" src=\""+subdirpath+"english/images/general/epd2_mainmenu_06.gif\" alt=\"Laws &amp; Regulations\"></a></td> \n");
document.write("          </tr> \n");
document.write("          <tr>  \n");
document.write("            <td><a href=\""+subdirpath+"english/application_for_licences/application_maincontent.html\" onMouseOut=\"MM_swapImgRestore()\" onMouseOver=\"MM_swapImage('menubtn_6','','"+subdirpath+"english/images/general/epd2_mainmenu_over_07.gif',1)\"><img name=\"menubtn_6\" border=\"0\" src=\""+subdirpath+"english/images/general/epd2_mainmenu_07.gif\" alt=\"Application for Licences\"></a></td> \n");
document.write("          </tr> \n");
document.write("          <tr>  \n");
document.write("            <td><a href=\""+subdirpath+"english/how_help/howhelp_maincontent.html\" onMouseOut=\"MM_swapImgRestore()\" onMouseOver=\"MM_swapImage('menubtn_7','','"+subdirpath+"english/images/general/epd2_mainmenu_over_08.gif',1)\"><img name=\"menubtn_7\" border=\"0\" src=\""+subdirpath+"english/images/general/epd2_mainmenu_08.gif\" alt=\"How You Can Help\"></a></td> \n");
document.write("          </tr> \n");
document.write("          <tr>  \n");
document.write("            <td><a href=\""+subdirpath+"english/envir_education/edu_maincontent.html\" onMouseOut=\"MM_swapImgRestore()\" onMouseOver=\"MM_swapImage('menubtn_8','','"+subdirpath+"english/images/general/epd2_mainmenu_over_09.gif',1)\"><img name=\"menubtn_8\" border=\"0\" src=\""+subdirpath+"english/images/general/epd2_mainmenu_09.gif\" alt=\"Environmental Education\"></a></td> \n");
document.write("          </tr> \n");
document.write("          <tr>  \n");
document.write("            <td><a href=\""+subdirpath+"english/resources_pub/resourcespub_maincontent.html\" onMouseOut=\"MM_swapImgRestore()\" onMouseOver=\"MM_swapImage('menubtn_9','','"+subdirpath+"english/images/general/epd2_mainmenu_over_10.gif',1)\"><img name=\"menubtn_9\" border=\"0\" src=\""+subdirpath+"english/images/general/epd2_mainmenu_10.gif\" alt=\"Resources &amp; Publications\"></a></td> \n");
document.write("          </tr> \n");
document.write("          <tr>  \n");
document.write("            <td><a href=\""+subdirpath+"english/access_info/access_info.html\" onMouseOut=\"MM_swapImgRestore()\" onMouseOver=\"MM_swapImage('menubtn_10','','"+subdirpath+"english/images/general/epd2_mainmenu_over_11.gif',1)\"><img name=\"menubtn_10\" border=\"0\" src=\""+subdirpath+"english/images/general/epd2_mainmenu_11.gif\" alt=\"Access to Information\"></a></td> \n");
document.write("          </tr> \n");
document.write("          <tr>  \n");
document.write("            <td><a href=\""+subdirpath+"english/business_job/businessjob_maincontent.html\" onMouseOut=\"MM_swapImgRestore()\" onMouseOver=\"MM_swapImage('menubtn_11','','"+subdirpath+"english/images/general/epd2_mainmenu_over_12.gif',1)\"><img name=\"menubtn_11\" border=\"0\" src=\""+subdirpath+"english/images/general/epd2_mainmenu_12.gif\" alt=\"Business &amp; Job Opportunities\"></a></td> \n");
document.write("          </tr> \n");
document.write("          <tr>  \n");
document.write("            <td><a href=\""+subdirpath+"english/links/env_links.html\" onMouseOut=\"MM_swapImgRestore()\" onMouseOver=\"MM_swapImage('menubtn_12','','"+subdirpath+"english/images/general/epd2_mainmenu_over_13.gif',1)\"><img name=\"menubtn_12\" border=\"0\" src=\""+subdirpath+"english/images/general/epd2_mainmenu_13.gif\" alt=\"Links\"></a></td> \n");
document.write("          </tr> \n");
document.write("          <tr>  \n");
document.write("            <td><img src=\""+subdirpath+"english/images/general/epd_menu_13.gif\" alt=\"Close Menu\"></td> \n");
document.write("          </tr> \n");
document.write("        </table> \n");
document.write("      </div>	 \n");
	
}



var sc_prefix="http"+"://sc.info.gov.hk/TuniS/";
var sc_path = "sc.info.gov.hk/TuniS/";

function swapLang(langOpt){

		var thisURL = String(window.location);
		var currentLang = "";
		if (thisURL.indexOf("/tc/")!=-1){
			currentLang = "tc";
		}
		if (thisURL.indexOf("/en/")!=-1){
			currentLang = "en";
		}
		if (thisURL.indexOf("/sc/")!=-1){
			currentLang = "sc";
		}

		if (langOpt=="en"){
			if (currentLang == "tc"){
				thisURL = thisURL.replace("/tc/","/en/");
			}else if (currentLang == "sc") {
				thisURL = thisURL.replace("/sc/","/en/");
			}
		}else if (langOpt=="tc"){
			if (currentLang == "en"){
				thisURL = thisURL.replace("/en/","/tc/");
			}else if (currentLang == "sc") { 
				thisURL = thisURL.replace("/sc/","/tc/");
			}
		}else if (langOpt=="sc"){
			if (currentLang == "en"){
				thisURL = thisURL.replace("/en/","/sc/");
			}else if (currentLang == "tc"){ 
				thisURL = thisURL.replace("/tc/","/sc/");
			}else if (currentLang == "sc"){  // In fact, want to switch to tc actually!
				thisURL = thisURL.replace("/sc/","/tc/");
			}
		}
		window.location = thisURL;
}


function searchContent(){
	var thisURL = String(window.location);
	var currentLang = "";
	if (thisURL.indexOf("/tc/")!=-1){
		currentLang = "zh-hk";
	}
	if (thisURL.indexOf("/en/")!=-1){
		currentLang = "en";
	}
	if (thisURL.indexOf("/TuniS/")!=-1){
		currentLang = "zh-cn";
	}

	var searchString = document.getElementById("searchString").value;
	searchString = encodeURIComponent(searchString);
	//searchString = searchString.replace(" ", "");
	//searchString = searchString.replace(",", "+");
	window.open("http://search.gov.hk/search.html?query=" + searchString + "&gp0=tpb_home&gp1=tpb_home&web=this&ui_lang=" + currentLang + "&ui_charset=utf-8&tpl_id=stdsearch");
}

function printThisPage(){
	var disp_setting = "toolbar=yes, location=no, directories=yes, menubar=yes,";
            disp_setting+= "scrollbars=yes, width=700, height=500, left=100, top=25"; 
	var content_value = document.getElementById("print_content").innerHTML;
	content_value = content_value.replace("Print This Page", "&nbsp;");
	content_value = content_value.replace("列印此頁", "&nbsp;");

	var docprint = window.open("", "", disp_setting);
	docprint.document.open();
	docprint.document.write('<html><head><LINK href="../../resources/common/tpb.css" type=text/css rel=stylesheet><title></title>');
	docprint.document.write('</head><body onLoad="self.print()"><center>');
	docprint.document.write(content_value);
	docprint.document.write('</center></body></html>');
	docprint.document.close();
	docprint.focus();
}

function ToDetail(parm){
	window.opener.location = parm + ".html";
	window.close();
}


//20110826 bryan
function displaymobile(){
	if (locapath.indexOf("/tc/")!=-1){_lang = 'tc';}
	if (locapath.indexOf("/sc/")!=-1){_lang = 'sc';}
	if (locapath.indexOf("/en/")!=-1){_lang = 'en';}
	
		switch(_lang){
		case'tc':
	document.write("<td>");
	document.write("<a href=\"/tpb/mobile/tc/whats_new/index.html\" onMouseOut=\"MM_swapImgRestore()\" onMouseOver=\"MM_swapImage('mainbar_m','','/tpb/resources/images/mainbar_m_tc_f.gif',1)\">");
	document.write("<img name=\"mainbar_m\" src=\"/tpb/resources/images/mainbar_m_tc.gif\" border=\"0\" alt=\"手機版\" width=\"54px\" height=\"20px\"></a>");

			break;
		case'sc':
	document.write("<td>");
	document.write("<a href=\"/tpb/mobile/sc/whats_new/index.html\" onMouseOut=\"MM_swapImgRestore()\" onMouseOver=\"MM_swapImage('mainbar_m','','/tpb/resources/images/mainbar_m_sc_f.gif',1)\">");
	document.write("<img name=\"mainbar_m\" src=\"/tpb/resources/images/mainbar_m_sc.gif\" border=\"0\" alt=\"手机版\" width=\"54px\" height=\"20px\"></a>");

			break;
		case'en':
	document.write("<td align=\"left\" valign=''><a href=\"/tpb/mobile/en/whats_new/index.html\" onMouseOut=\"MM_swapImgRestore()\" onMouseOver=\"MM_swapImage('mainbar_m','','/tpb/resources/images/mainbar_m_en_f.gif',1)\">");
	document.write("<img name=\"mainbar_m\" src=\"/tpb/resources/images/mainbar_m_en.gif\" border=\"0\" alt=\"Mobile\" width=\"56px\" height=\"20px\"></a></td>");

			break;
	}	
	
}

