//sc_svr = "http://sc.info.gov.hk/gb/";
test_svr = "test.ird.gov.hk";
prod_svr = "www.gov.hk";
test_url = "http://test.ird.gov.hk";
prod_url = "http://www.gov.hk";
english = "/eng/";
chinese = "/chi/";
sim_chinese = "/chs/";

_url = top.location.href;

//url function
function istest(str_url){
	if (str_url.indexOf(test_svr) != -1){
		return true;
	}
	return false;
}

function is_sc(){
	if (_url.indexOf(sim_chinese) != -1){
		return true;	
	}	
	return false;
}

function eac_page(str_url){
	
	if (_url.indexOf(sim_chinese) != -1){
		if (istest(_url)){
			link7 = test_url + str_url;	
		}else{
			link7 = prod_url + str_url;
		}
		link7 = link7.replace(sim_chinese,chinese); 	
		top.location.href= link7;
	}else{
		top.location.href= str_url;
	}
}

function gb_page(str_url){
	if (istest(_url)){
		link = sc_svr + test_svr + str_url;	
	}else{
		link = sc_svr + prod_svr + str_url;
	}
	top.location.href = link;
}

function simp_chinese(){
	link = top.location.href;
	if (link.indexOf(sim_chinese) != -1) 
	{
		trad_chinese();
	}
	else
	{
		simp_chinese2();		
	}
}

function simp_chinese2(){
	link = top.location.href;
	if (link.indexOf(english) != -1){
		link = link.replace(english,chinese); 	
	}
	link = link.replace(chinese,sim_chinese);	
	//alert(link);
	top.location.href = link;

}

function gra_simp_chinese(){
	link4 = top.location.href;
	if (link4.indexOf(english) != -1){
		link4 = link4.replace(english,chinese); 	
	}
	
//	link4 = link4.replace("http://",sc_svr);	
	link4 = link4.replace(chinese,sim_chinese);	
	top.location.href = link4;
	
}

function trad_chinese(){
	
	link2 = top.location.href;
	
/*	if (link2.indexOf("http://sc.info.gov.hk/gb/") != -1){
		link2 = link2.replace("sc.info.gov.hk/gb/","");	
	}*/
	if (link2.indexOf(sim_chinese) != -1) {
		link2 = link2.replace(sim_chinese,chinese);	
	}
	if (link2.indexOf(english) != -1){
		link2 = link2.replace(english,chinese); 	
	}
	top.location.href=link2;
}

function stn_english(){
	
	link2 = top.location.href;
	if (link2.indexOf(sim_chinese) != -1){
		link2 = link2.replace(sim_chinese,english);	
	}
	if (link2.indexOf(chinese) != -1){
		link2 = link2.replace(chinese,english); 	
	}
	if (link2.indexOf('#top') != -1){
		link2 = link2.replace ('#top','');
	}
	if (link2.indexOf("tax/guide/cbir") != -1){
		link2 = link2.replace("cbir", "ebir");
	}
	if (link2.indexOf("tax/guide/mbir") != -1){
		link2 = link2.replace("mbir", "ebir");
	}
	
	top.location.href=link2;
}
/*
function GIC_search(){
	var currentUrl = location.href.toString();
	var url = "http://search2.info.gov.hk/cgi-bin/se.cgi";
	var SearchWin;
	var mode = document.search.mode.value;
	var qu = document.search.qu.value;

	SearchWin=window.open(eval('url +"?mode=" + mode + "&la=1&gr_1=ird&ma=100&ft_1=alltype&so=0&nu=10&ca=0&ta=all&fu=&fd=&qu=" + qu'));
	document.location.href = currentUrl;
	SearchWin.focus();
}



	SearchWin=window.open(eval('url +"?mode=119&la=1&gr_1=ird&ma=100&ft_1=alltype&so=0&nu=10&ca=0&ta=all&fu=&fd=&qu=" + qu'));
	document.location.href = currentUrl;
	SearchWin.focus();
}
*/
// Yahoo search
function GIC_search(){
	var currentUrl = location.href.toString();
	var SearchWin, pg_lg, ui_lg ;
//	var mode = document.search.mode.value;
	var qu = document.search.qu.value;

	if (_url.indexOf(sim_chinese) != -1) {
		ui_lg = "zh-cn";
		pg_lg = "chs";	
  }	else if (_url.indexOf(chinese) != -1) {
  	ui_lg = "zh-cnhk";
		pg_lg = "chi";	
  }	else {
  	ui_lg = "en";
		pg_lg = "eng";
  }	

	if (qu.length==0) {
		var url = "http://www.ird.gov.hk/"+pg_lg+"/adv_search.htm?gp0=ird_home&gp1=ird_home";
		SearchWin=window.open(eval('url +"&ui_lang=" + ui_lg'));
	} else {
		var url = "http://search.gov.hk/search.html?tpl_id=ird&web=this&gp0=ird_home&gp1=ird_home";
		SearchWin=window.open(eval('url +"&ui_lang=" + ui_lg + "&query=" + qu'));
	}
	document.location.href = currentUrl;
	SearchWin.focus();
}

function GIC_searchgb(){
	var currentUrl = location.href.toString();
	var SearchWin;
	var qu = document.search.qu.value;
	var ui_lg = "zh-cn";

	if (qu.length==0) {
		var url = "www.ird.gov.hk/chs/adv_search.htm?gp0=ird_home&gp1=ird_home";
		SearchWin=window.open(eval('url +"&ui_lang=" + ui_lg'));
	} else {
		var url = "http://search.gov.hk/search.html?tpl_id=ird&web=this&gp0=ird_home&gp1=ird_home";
		SearchWin=window.open(eval('url +"&ui_lang=" + ui_lg + "&query=" + qu'));
	}

	document.location.href = currentUrl;
	SearchWin.focus();
}

function GIC_searchchs(){
	var currentUrl = location.href.toString();
	var SearchWin;
	var qu = document.search.qu.value;
	var ui_lg = "zh-cn";

	if (qu.length==0) {
		var url = "http://www.ird.gov.hk/chs/adv_search.htm?gp0=ird_home&gp1=ird_home";
		SearchWin=window.open(eval('url +"&ui_lang=" + ui_lg'));
	} else {
		var url = "http://search.gov.hk/search.html?tpl_id=ird&web=this&gp0=ird_home&gp1=ird_home";
		SearchWin=window.open(eval('url +"&ui_lang=" + ui_lg + "&query=" + qu'));
	}

	document.location.href = currentUrl;
	SearchWin.focus();
}

function lang(version,version2){
	link = location.href;
	english = "/eng/";
	chinese = "/chi/";
  sim_chinese = "/chs/";
	
	if (version == "eng")
	{		
		if (version2 == "chi")
		{
			if (link.indexOf("tax/guide/ebir") != -1){
				link = link.replace("ebir", "cbir");
			}
			
			link = link.replace (english, chinese);
			parent.location.href = link;
		}else if ((version2 == "gb") || (version2 == "chs"))
		{
			if (link.indexOf("tax/guide/ebir") != -1){
				link = link.replace("ebir", "cbir");
			}
/*			link = link.replace (english, chinese);
			link = link.replace("http://",sc_svr);
*/			
			link = link.replace (english, sim_chinese);
			parent.location.href = link;
		}		
	}

}

// general functions
function win_popup(str_url,str_winname,int_width,int_height,str_feature){
	if (!str_feature){
		str_feature = 'toolbars='	+ 'no'
		+ ',top='			+ '100'
		+ ',left='			+ '100'
		+ ',width=' 			+ int_width
		+ ',height=' 			+ int_height
		+ ',scrollbars='		+ 'no'
		+ ',resizable='			+ 'no'
		+ ',screenX='			+ '0'
		+ ',screenY='			+ '0'
		+ ',status='			+ 'no' 
	}
	
	var win = window.open(str_url, str_winname , str_feature);		
	win.focus();
	//return win;
}

// url functions

function getfoldername(){
	 
	 private_str_path = location.href;
	 private_int_len_path = private_str_path.length;
	 private_str_subpath = private_str_path.substring (7,private_int_len_path);
	 private_int_subpathid = private_str_subpath.lastIndexOf("/");
	 private_str_subpath = private_str_subpath.substring(0,private_int_subpathid);
	 private_int_subpathid = private_str_subpath.lastIndexOf("/");
	 private_int_len_path = private_str_subpath.length;
	 private_str_subpath = private_str_subpath.substring (private_str_subpath+1,private_int_len_path);
	 return private_str_subpath;
	 
}

function getfilename(){
	
	private_str_path = location.href;
	private_int_fileid = private_str_path.lastIndexOf("/");
	private_int_filesubid = private_str_path.lastIndexOf(".");
	private_str_filename = private_str_path.substring(private_int_fileid+1,private_int_filesubid);
	return private_str_filename;
}


//swap image functions
function si_over(str_image_name , str_path){
	document[str_image_name].src = str_path;
}

function si_out(str_image_name , str_path){
	document[str_image_name].src = str_path;
}

// String functions
function is_valid_length(str_param, int_length){
	if ((str_param.length > int_length ) || (str_param.length == 0 )){
		return false;
	}
	return true;
}

function printmenuicon(intLv){        
        var strPathLv = "";
        
        for (intI = 0; intI < intLv; intI++)
         strPathLv += "../";

	
	link = top.location.href;	
//	if (link.indexOf(sc_svr) != -1)
	if (link.indexOf(sim_chinese) != -1)
	{
		document.write("<kanhanbypass>");
		document.write("<a href=\"javascript:simp_chinese();\" onMouseOut=\"MM_swapImgRestore()\"  onMouseOver=\"MM_swapImage('mainbar3','','" + strPathLv + "images/g_menu/gb/mainbar3_f2.gif',1)\" ><img name=\"mainbar3\" src=\"" + strPathLv + "images/g_menu/gb/mainbar3.gif\" width=\"49\" height=\"20\" border=\"0\" alt=\"繁體版\"></a>");
		document.write("</kanhanbypass>");
	}
	else
	{
		document.write("<kanhanbypass>");
		document.write("<a href=\"javascript:simp_chinese();\" onMouseOut=\"MM_swapImgRestore()\"  onMouseOver=\"MM_swapImage('mainbar3','','" + strPathLv + "images/g_menu/ch/mainbar3_f2.gif',1)\" ><img name=\"mainbar3\" src=\"" + strPathLv + "images/g_menu/ch/mainbar3.gif\" width=\"49\" height=\"20\" border=\"0\" alt=\"簡體版\"></a>");
		document.write("</kanhanbypass>");
	}
}

// for application, eg eTAX
function openwindow800x530(url,windowName) {
 if (windowName == undefined) {
 windowName = "_blank";
 }
 var translatedUrl = url;
 var newwin = window.open(translatedUrl, windowName, 'width=800px,height=530px,top=0,left=0,directories=no,location=no,menubar=no,scrollbars=yes,status=yes,toolbar=no,resizable=yes');
 newwin.focus();  // set focus to new window
 return false;
}
