sc_svr = "http://sc.info.gov.hk/gb/";
test_svr = "www0.info.gov.hk";
prod_svr = "www.info.gov.hk";
test_url = "http://www0.cso.gov.hk";
prod_url = "http://www.cso.gov.hk";
english = "/eng/";
chinese = "/sc/";
_url = top.location.href;

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


function cso_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 getLang(){
	var langs = ["chi", "eng", "sc"];
	var fromLang = '';
	for(counter = 0; counter < langs.length; counter++){
		if(location.href.search('/'+langs[counter]+'/')!= -1){
			fromLang = langs[counter];
		}
	}
	return fromLang;
}
function simp_chinese(){
	top.location.href = top.location.href.replace("/"+getLang()+"/", "/chi/");
}

function trad_chinese(){
	top.location.href = top.location.href.replace("/"+getLang()+"/", "/chi/");
}

function stn_english(){
	top.location.href = top.location.href.replace("/"+getLang()+"/", "/eng/");
}


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


