
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);
}


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 = "/hkedc/";
var domain = document.location.host;
var scserver = "sc.icac.org.hk/gb/";
var locapath = document.location.href;
var http = "http"+"://";
var https = "https"+"://";
var protocol = "";
var menu_path = "";
var menu_path_https = "";
var https_path = "/https";

//var locapath = "http://www.sar-expertcom.gov.hk/textonly/eindex.html";




var atlang,domname,sitepath,atgb,atindex,org_part, athttps, sc_base_path, img_part
	sc_path = "chi/";
	sctxt_path = "txt_chi/";
	scimg_path = "gb/";
	tc_path = "chi/";
	tctxt_path = "txt_chi/";
	tcimg_path = "chi/";
	en_path = "eng/";
	entxt_path = "txt_eng/";
	enimg_path = "eng/";
	atgb = false;
	atindex = false;
	athttps=false;

if (locapath.toString().search('https'+'://')!= -1){
	athttps=true
	protocol = https
	sc_base_path = https + scserver;
}else{
	athttps=false
	protocol = http
	sc_base_path = http + scserver;
}
	
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;
	if (athttps){
		sitepath = locapath.substring(8,locapath.length);
	}else{
		sitepath = locapath.substring(7,locapath.length);
	}
}

if (locapath.toString().search('/txt_eng/')!= -1){
	atlang = "entxt";
	org_part = entxt_path;
	img_part = enimg_path;
}else
if (locapath.toString().search('/txt_chi/')!= -1){
	atlang = "tctxt";
	org_part = tctxt_path;
	img_part = tcimg_path;
}else
if (locapath.toString().search('/txt_chi/')!= -1){
	atlang = "sctxt";
	org_part = sctxt_path;
	img_part = scimg_path;
}else
if (locapath.toString().search('/eng/')!= -1){
	atlang = "en";
	org_part = en_path;
	img_part = enimg_path;
}else
if (locapath.toString().search('/chi/')!= -1){
	atlang = "tc";
	org_part = tc_path;
	img_part = tcimg_path;
}

if (atgb){
	atlang = "sc";
	org_part = sc_path;
	img_part = scimg_path;
}/*else
if (locapath.toString().search('/txtonly/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 = "www.icac.org.hk";
subdir = "/preview";
if(atgb){
	menu_path = scserver+domain+dept+org_part
}else{
	menu_path = domain+dept+org_part
}
if(atgb){
	menu_path_https = scserver+domain+https_path+dept+org_part
}else{

	menu_path_https = domain+https_path+dept+org_part;
}
image_path = domain+dept+img_part

function chglang(lang){

	switch(lang){
		case 'entxt': 
			des_part = entxt_path;
			des_ind_part = "textonly/eindex.html";
			base_path = protocol;
			break;
		case 'tctxt':
			des_part = tctxt_path;
			des_ind_part = "textonly/cindex.html";
			base_path = protocol;
			break;
		case 'sctxt':
			des_part = sctxt_path;
			des_ind_part = "textonly/scindex.html";
			base_path = sc_base_path;
			//base_path = "http://";
			break;
		case 'en':
			des_part = en_path;
			des_ind_part = "eindex.html";
			base_path = protocol;
			break;
		case 'tc':
			des_part = tc_path;
			des_ind_part = "cindex.html";
			base_path = protocol;
			break;
		case 'sc':
			des_part = sc_path;
			des_ind_part = "scindex.html";
			base_path = sc_base_path;
			//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.asp?base=http%3A//'+ domain + subdir + '/english/tell/&url=' + escape(window.location);
  }else if (lang == 'chi')
  {
     window.location = subdir + '/tc_chi/tell/tell.asp?base=http%3A//'+ domain + subdir + '/tc_chi/tell/&url=' + escape(window.location);
  }else if (lang == 'schi')
  {
     window.location = subdir + '/sc_chi/tell/tell.asp?base=http%3A//'+ domain + subdir + '/sc_chi/tell/&url=' + escape(window.location);
  }else if (lang == 'eng_txt')  
  {
     window.location = subdir + '/textonly/english/tell/tell.asp?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.asp?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.asp?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];
}

var win;
function OpenWindow(mypage, myname, w, h, scroll) {
if (w < 500) w=500;
var winw = (screen.width - w) / 2;
var winh = (screen.height - h) / 2;
winprops = 'scrollbars='+scroll+',resizable,height='+h+',width='+w+',top='+winh+',left='+winw
		if (win!=null && !win.closed)
		  win.close();
//alert(winprops)
// top.location.href=mypage;
win = window.open("", myname, winprops)
win.document.write("<title>ICAC</title>");
win.document.write("<frameset rows='*,40' border='0'>");
win.document.write("<frame src='"+mypage+"' name='top' noresize border='0'>");
win.document.write("<frame src='http://www.icac.org.hk/eng/comm/popfooter.html' name='bottom' noresize border='0'>");
win.document.write("</frameset>");
win.window.focus();
}


function gotosubenews(){
	document.location=https+menu_path_https+'subenews.asp';
}

function OpenWin(mypage) {
if (win!=null && !win.closed)
	win.close();
//alert(winprops)
// top.location.href=mypage;
win = window.open(mypage)
win.window.focus();
}