//url function
function search(str_param){
	//location.href="/reo/" + str_param + '/search.htm';;	
	location.href= "http://search2.info.gov.hk";
}

function sitemap(ver){
	location.href=  '/' + ver + '/text/sitemap.asp';
}

function contactus(ver){
	location.href= '/' + ver + '/text/contact.asp';
}

function faq(ver){
	location.href= '/' + ver + '/text/faq.asp';
}

function related(ver){
	location.href= '/' + ver + '/text/related.asp';
}

function graphical(){
	link = location.href;
	link = link.replace('/text/','/');
	top.location.href= link;
}

function lang(fr_ver , to_ver){
	
	link = location.href;
	fr_ver1 = fr_ver;
	fr_ver = '/' + fr_ver + '/';
	
	english = "/en/";
	chinese = "/ch/";
	gb = "/gb/";
	
	if (to_ver == "en"){
		if (is_contain_ver(fr_ver1)){
			link = link.replace('ver='+ fr_ver1, 'ver='+ to_ver);
		}
		link = link.replace (fr_ver, english);
		parent.location.href = link;
	}else if (to_ver == "ch"){
		if (is_contain_ver(fr_ver1)){
			link = link.replace('ver='+ fr_ver1, 'ver='+ to_ver);
		}
		link = link.replace (fr_ver, chinese);
		parent.location.href = link;
	}else if (to_ver == "gb"){
		if (is_contain_ver(fr_ver1)){
			link = link.replace('ver='+ fr_ver1, 'ver='+ to_ver);
		}
		link = link.replace (fr_ver, gb);
		parent.location.href = link;
	}
}

function is_contain_ver(ver){
	str_url = location.href;
	str_query = "&ver=" + ver;
	if (str_url.indexOf(str_query) == -1){
		return false;
	}else{
		return true;
	}
}



function textonly(ver){
	link = location.href;
	english = "/en/";
	chinese = "/ch/";
	gb = "/gb/";

	if (ver == "en"){
		link = link.replace (english, "/en/text/");
		parent.location.href = link;
	}else if (ver == "ch"){
		link = link.replace (chinese, "/ch/text/");
		parent.location.href = link;
	
	}else if (ver == "gb"){
		link = link.replace (gb, "/gb/text/");
		parent.location.href = link;
	}
}

function totextonly(ver){
	link = location.href;
	english = "/en/";
	chinese = "/ch/";
	gb = "/gb/";

	if (ver == "en"){
		link = link.replace (english, "/en/text/");
		parent.location.href = link;
	}else if (ver == "ch"){
		link = link.replace (chinese, "/ch/text/");
		parent.location.href = link;
	
	}else if (ver == "gb"){
		link = link.replace (gb, "/gb_txt/");
		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 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;
}

