
//var 
sc_svr = "http://sc.info.gov.hk/gb/";
test_svr = "www0.eac.gov.hk";
prod_svr = "www.eac.gov.hk";
test_url = "http://www0.eac.gov.hk";
prod_url = "http://www.eac.gov.hk";
testsite= "www0.reo.gov.hk";
prodsite= "www.reo.gov.hk";
english = "/en/";
chinese = "/sc/";
_url = top.location.href;

function eac_URL(){
	if (istest(_url))
		return test_svr;
	else
		return prod_svr;
}

function reo_URL(){
	if (istest(_url))
		return testsite;
	else
		return prodsite;
}

function sc_reo_URL(new_url){
	var popwin = window.open (new_url,'reo','toolbar=yes,menubar=yes,scrollbars=yes,status=yes,location=yes,titlebar=yes,resizable=yes');
	popwin.focus();
}

function is_sc(){
	if (_url.indexOf(sc_svr) != -1){
		return true;	
	}	
	return false;
}


function istest(str_url){
	if (str_url.indexOf(testsite) != -1){
		return true;
	}
	return false;
}

function reo_page(str_url){
	
	if (_url.indexOf(sc_svr) != -1){
		if (istest(_url)){
			link7 = test_url + str_url;	
		}else{
			link7 = prod_url + str_url;
		}
		link7 = link7.replace("sc.info.gov.hk/gb/","");
		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(english) != -1){
		link = link.replace(english,chinese); 	
	}
	link = link.replace("http://",sc_svr);	
	//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);	

	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(english) != -1){
		link2 = link2.replace(english,chinese); 	
	}
	
	top.location.href=link2;

}

function stn_english(){
	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(chinese) != -1){
		link2 = link2.replace(chinese,english); 	
	}
	if (link2.indexOf('#top') != -1){
		link2 = link2.replace ('#top','');
		}
	top.location.href=link2;
}


function reo_ch(int_id){
	//int_id--;
	ar_url = 
Array("/reo/ch/about/org_1.htm","/reo/ch/voter/application.htm","/reo/ch/form/form.htm","#","#","#","#","/reo/en/electoral/facilities.htm","/reo/ch/ecenter/index.htm","#","/reo/ch/estimates/index.htm");
	link = top.location.href;
	//
	if (int_id == 4){
		to_eac('/eac/ch/chief/2005ce_election_fact.htm');
		/*var pop1 = window.open('/eac/popup_ch.htm','NewsUpdate','width=262,height=158,left=0,top=0,screenX=0,screenY=0,resizable=0,status=0,menubar=0,scrollbars=0');
		pop1.focus();*/
	}else if (int_id == 5){
		to_eac('/eac/ch/ecse/function.htm');
		/*var pop1 = window.open('/eac/popup_ch.htm','NewsUpdate','width=262,height=158,left=0,top=0,screenX=0,screenY=0,resizable=0,status=0,menubar=0,scrollbars=0');
		pop1.focus();*/
	}else if (int_id == 6){
		to_eac('/eac/ch/legco/2004.htm');
		/*var pop1 = window.open('/eac/popup_ch.htm','NewsUpdate','width=262,height=158,left=0,top=0,screenX=0,screenY=0,resizable=0,status=0,menubar=0,scrollbars=0');
		pop1.focus();*/
	}else if (int_id == 7){
		to_eac('/eac/ch/distco/2003dc_elect.htm');
		/*var pop1 = window.open('/eac/popup_ch.htm','NewsUpdate','width=262,height=158,left=0,top=0,screenX=0,screenY=0,resizable=0,status=0,menubar=0,scrollbars=0');
		pop1.focus();*/
	}else if (int_id == 8){
		to_eac('/eac/');
		/*var pop1 = window.open('/eac/popup_ch.htm','NewsUpdate','width=262,height=158,left=0,top=0,screenX=0,screenY=0,resizable=0,status=0,menubar=0,scrollbars=0');
		pop1.focus();*/
	}else if (int_id == 10){ //village
		to_eac('/eac/ch/village/2003v_elect.htm');
		/*var pop1 = window.open('/eac/popup_ch.htm','NewsUpdate','width=262,height=158,left=0,top=0,screenX=0,screenY=0,resizable=0,status=0,menubar=0,scrollbars=0');
		pop1.focus();*/
	}else{
	
		if (_url.indexOf(sc_svr) != -1){
			if (istest(_url)){
				link = sc_svr + test_svr + ar_url[int_id-1];	
			}else{
				link = sc_svr + prod_svr + ar_url[int_id-1];
			}
			//alert (link);
			top.location.href= link;
		}else{
			top.location.href = ar_url[int_id-1];
		}
	}
}

function reo_en(int_id){
	link = top.location.href;
	ar_url = Array("/reo/en/about/org_1.htm","/reo/en/voter/application.htm","/reo/en/form/form.htm","#","#","#","#","/reo/en/electoral/facilities.htm","/reo/en/ecenter/index.htm","#","/reo/en/estimates/index.htm");
	//
	//
	if (int_id == 4){
		to_eac('/eac/en/chief/2005ce_election_fact.htm');
		/*var pop1 = window.open('/eac/popup_en.htm','NewsUpdate','width=262,height=158,left=0,top=0,screenX=0,screenY=0,resizable=0,status=0,menubar=0,scrollbars=0');
		pop1.focus();*/
	}else if (int_id == 5){
		to_eac('/eac/en/ecse/function.htm');
		/*var pop1 = window.open('/eac/popup_en.htm','NewsUpdate','width=262,height=158,left=0,top=0,screenX=0,screenY=0,resizable=0,status=0,menubar=0,scrollbars=0');
		pop1.focus();*/
	}else if (int_id == 6){
		to_eac('/eac/en/legco/2004.htm');
		/*var pop1 = window.open('/eac/popup_en.htm','NewsUpdate','width=262,height=158,left=0,top=0,screenX=0,screenY=0,resizable=0,status=0,menubar=0,scrollbars=0');
		pop1.focus();*/
	}else if (int_id == 7){
		to_eac('/eac/en/distco/2003dc_elect.htm');
		/*var pop1 = window.open('/eac/popup_en.htm','NewsUpdate','width=262,height=158,left=0,top=0,screenX=0,screenY=0,resizable=0,status=0,menubar=0,scrollbars=0');
		pop1.focus();*/
	}else if (int_id == 8){
		to_eac('/eac/index_en.htm');
		/*var pop1 = window.open('/eac/popup_en.htm','NewsUpdate','width=262,height=158,left=0,top=0,screenX=0,screenY=0,resizable=0,status=0,menubar=0,scrollbars=0');
		pop1.focus();*/
	}else if (int_id == 10){ //village 
		to_eac('/eac/en/village/2003v_elect.htm');
		/*var pop1 = window.open('/eac/popup_en.htm','NewsUpdate','width=262,height=158,left=0,top=0,screenX=0,screenY=0,resizable=0,status=0,menubar=0,scrollbars=0');
		pop1.focus();*/
	}else{
		if (link.indexOf(sc_svr) != -1){
			if (istest(link)){
				link = sc_svr + test_svr + ar_url[int_id-1];	
			}else{
				link = sc_svr + prod_svr + ar_url[int_id-1];
			}
			top.location.href= link;
		}
		
		top.location.href = ar_url[int_id-1];
	}
}

function to_eac(str_url){
	
	if (_url.indexOf(sc_svr) != -1){
		if (istest(_url)){
			new_url = sc_svr + test_svr + str_url;
		}else{
			new_url = sc_svr + prod_svr + str_url;
		}
	}else{
		if (istest(_url)){
			new_url = test_url + str_url;
		}else{
			new_url =  prod_url + str_url;
		}
	}
	var popwin =window.open(new_url,'eac','toolbar=yes,menubar=yes,scrollbars=yes,status=yes,location=yes,titlebar=yes,resizable=yes');
	popwin.focus();

}

function search(str_param){
	//location.href="/reo/" + str_param + '/search.htm';
	//top.location.href= "http://search2.info.gov.hk";
	if (str_param == "ch") {
		window.open('http://search2.info.gov.hk','','toolbar=yes,menubar=yes,scrollbars=yes,status=yes,location=yes,titlebar=yes,resizable=yes');
	}else if (str_param == "en") {
		window.open('http://search.info.gov.hk','','toolbar=yes,menubar=yes,scrollbars=yes,status=yes,location=yes,titlebar=yes,resizable=yes');
	}
}

function contact(str_param){
	top.location.href="/reo/" + str_param + '/contact.htm';
}

function lang(version){
	link = location.href;
	english = "/en/";
	chinese = "/sc/";

	if (version == "en"){
		link = link.replace (chinese, english);
		if (link.indexOf('#top') != -1){
		link = link.replace ('#top','');
		}
		parent.location.href = link;
	}else if (version == "ch"){
		link = link.replace (english, chinese);
		if (link.indexOf('#top') != -1){
		link = link.replace ('#top','');
		}
		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'
		+ ',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;
}


function reo_get_url_param(name) {
	var strParam = window.location.search
	
	id1 = strParam.indexOf(name + "=")
	if (id1 == -1)	return ""

	id1 = id1 + name.length + 1
	id2 = strParam.indexOf("&", id1)

	if (id2 != -1)
		len = id2 - id1
	else
		len = strParam.length

	return unescape(strParam.substr(id1, len))
}	

function geturlparam(name) {
	var strParam = window.location.search
	
	idx1 = strParam.indexOf(name + "=")
	if (idx1 == -1)	return ""

	idx1 = idx1 + name.length + 1
	idx2 = strParam.indexOf("&", idx1)

	if (idx2 != -1)
		len = idx2 - idx1
	else
		len = strParam.length

	return unescape(strParam.substr(idx1, len))
}	


//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;
}

