this.name='eac';
sc_svr = "http://sc.info.gov.hk/gb/";
test_svr = "www0.reo.gov.hk";
prod_svr = "www.reo.gov.hk";
test_url = "http://www0.reo.gov.hk";
prod_url = "http://www.reo.gov.hk";
testsite= "www0.eac.gov.hk";
prodsite= "www.eac.gov.hk";
english = "/en/";
chinese = "/ch/";
_url = top.location.href;

function eac_URL(){
	if (istest(_url))
		return testsite;
	else
		return prodsite;
}
function reo_URL(){
	if (istest(_url))
		return test_svr;
	else
		return prod_svr;
}

function sc_eac_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 teamclean(){
	if (is_sc()){
		window.open ('http://sc.info.gov.hk/gb/www.had.gov.hk/tc/public_services/team_clean_corner/team_index.htm','just','');
	}else{
		window.open ('http://www.had.gov.hk/tc/public_services/team_clean_corner/team_index.htm','just','');
	}
}

//url function
function justice_link(idf){
	urla_sc = 'http://210.3.20.212/han3/2/1/1/0/0/1/0/www.justice.gov.hk/blis.nsf/6033a8cc1f220686482564840019d2f2/1b443695c8d5a516482568cf000b4990?OpenDocument';
	urla_tc = '';
	urlb_sc = 'http://210.3.20.212/han3/2/1/1/0/0/1/0/www.justice.gov.hk/blis.nsf/6033a8cc1f220686482564840019d2f2/fba2e1b7a6bef163482568cf001172e2?OpenDocument';
	urlb_tc = '';
	
	if (is_sc()){
		window.open (eval(idf + '_sc'),'just','');
	}else{
		window.open (eval(idf + '_tc'),'just','');
	}
	

}

function istest(str_url){
	if (str_url.indexOf(testsite) != -1){
		return true;
	}
	return false;
}

function is_sc(){
	if (_url.indexOf(sc_svr) != -1){
		return true;	
	}	
	return false;
}

function eac_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/","");
		//link2 = "http://" + link2;
		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 eac_ch(int_id){
	link = top.location.href;
	int_id--;
	ar_url = Array("/eac/ch/about/chairman.htm","http://www.justice.gov.hk/blis_export.nsf/CurAllChinDocAgent?OpenAgent&Chapter=541","#","/eac/ch/chief/2005ce_election_fact.htm","/eac/ch/ecse/function.htm","/eac/ch/legco/2004.htm","/eac/ch/distco/2003dc_elect.htm","#","/eac/ch/village/2003v_elect.htm");

	if (int_id == 1){
		if (!is_sc()){
			window.open (ar_url[int_id]);	
		}else{
			window.open ('http://218.188.27.99/han3/2/1/1/0/0/1/0/www.justice.gov.hk/blis_export.nsf/CurAllChinDocAgent?OpenAgent&Chapter=541','just','');	
		}
		
	}else if (int_id == 2){
		to_reo('/reo/ch/voter/application.htm');
		/*
		var pop1 = window.open('/reo/popup_ch.htm','ReoNews','width=244,height=102,left=0,top=0,screenX=0,screenY=0,resizable=0,status=0,menubar=0,scrollbars=0');
		pop1.focus();
		var pop3 = window.open('/reo/popup2_ch.htm','ReoNews1','width=244,height=102,left=410,top=0,screenX=0,screenY=0,resizable=0,status=0,menubar=0,scrollbars=0');
		pop3.focus();*/
	}else if (int_id == 7){
		to_reo('/reo/');
		/*
		var pop1 = window.open('/reo/popup_ch.htm','ReoNews','width=244,height=102,left=0,top=0,screenX=0,screenY=0,resizable=0,status=0,menubar=0,scrollbars=0');
		pop1.focus();
		var pop3 = window.open('/reo/popup2_ch.htm','ReoNews','width=400,height=300,left=410,top=0,screenX=0,screenY=0,resizable=0,status=0,menubar=0,scrollbars=0');
		pop3.focus();*/
	}else{
		if (link.indexOf(sc_svr) != -1){
			if (istest(link)){
				link = sc_svr + test_svr + ar_url[int_id];	
			}else{
				link = sc_svr + prod_svr + ar_url[int_id];
			}
			top.location.href= link;
		}else{
			top.location.href = ar_url[int_id];
		}
	}
}

function eac_en(int_id){
	int_id--;
	ar_url = Array("/eac/en/about/chairman.htm","http://www.justice.gov.hk/blis_export.nsf/CurAllEngDocAgent?OpenAgent&Chapter=541","#","/eac/en/chief/2005ce_election_fact.htm","/eac/en/ecse/function.htm","/eac/en/legco/2004.htm","/eac/en/distco/2003dc_elect.htm","#","/eac/en/village/2003v_elect.htm");

	if (int_id == 1){
		window.open (ar_url[int_id]);
	}else if (int_id == 2){
		to_reo('/reo/en/voter/application.htm');
		/*
		var pop1 = window.open('/reo/popup_en.htm','ReoNews','width=244,height=102,left=0,top=0,screenX=0,screenY=0,resizable=0,status=0,menubar=0,scrollbars=0');
		pop1.focus();
		var pop3 = window.open('/reo/popup2_en.htm','ReoNews1','width=244,height=102,left=410,top=0,screenX=0,screenY=0,resizable=0,status=0,menubar=0,scrollbars=0');
		pop3.focus();*/
	}else if (int_id == 7){
		to_reo('/reo/index_en.htm');
		/*
		var pop1 = window.open('/reo/popup_en.htm','ReoNews','width=244,height=102,left=0,top=0,screenX=0,screenY=0,resizable=0,status=0,menubar=0,scrollbars=0');
		pop1.focus();
		var pop3 = window.open('/reo/popup2_en.htm','ReoNews','width=400,height=300,left=410,top=0,screenX=0,screenY=0,resizable=0,status=0,menubar=0,scrollbars=0');
		pop3.focus();*/
	}else{
		if (_url.indexOf(sc_svr) != -1){
			if (istest(_url)){
				link = sc_svr + test_svr + ar_url[int_id];	
			}else{
				link = sc_svr + prod_svr + ar_url[int_id];
			}
			top.location.href= link;
		}else{
			top.location.href = ar_url[int_id];
		}
	}
}

function to_reo(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,'reo','toolbar=yes,menubar=yes,scrollbars=yes,status=yes,location=yes,titlebar=yes,resizable=yes');
	popwin.focus();
}

function search(str_param){
	//location.href="/eac/" + str_param + '/search.htm';;	
	//top.location.href= "http://search2.info.gov.hk";
	if (str_param == "en") {
		popwin =window.open('http://search.info.gov.hk','','toolbar=yes,menubar=yes,scrollbars=yes,status=yes,location=yes,titlebar=yes,resizable=yes');
	}else if (str_param == "ch") {
		if (is_sc()){
			popwin =window.open('http://sc.info.gov.hk/gb/search2.info.gov.hk','','toolbar=yes,menubar=yes,scrollbars=yes,status=yes,location=yes,titlebar=yes,resizable=yes');
		}else{
			popwin =window.open('http://search2.info.gov.hk','','toolbar=yes,menubar=yes,scrollbars=yes,status=yes,location=yes,titlebar=yes,resizable=yes');
		}
		
	}
}

function contact(str_param){
	top.location.href="/eac/" + str_param + '/contact.htm';;
}

function lang(version){
	link = location.href;
	english = "/en/";
	chinese = "/ch/";

	if (version == "en"){
		link = link.replace (chinese, english);
		parent.location.href = link;
	}else if (version == "ch"){
		link = link.replace (english, 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;
}


function eac_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;
}

