//webserver_path = "202.64.76.168";
//webserver_path = "118.142.26.68";
webserver_path = "cs-crda.nd.gov.hk";
//webserver_path = "www.cweb.com.hk";
kanserver_path = "sc.info.gov.hk/gb";

//webserver_path = "192.168.0.88";
//kanserver_path = "192.168.0.88:1982/gb";

div_path = "/";
cv_sc_base_path = "http:" + "//" + kanserver_path + "/" + webserver_path;
cv_nonsc_base_path = "http:" + "//" + webserver_path;

sc_path = cv_sc_base_path + div_path;
tc_path = cv_nonsc_base_path + div_path;

if (location.href.toString().search('/gb/') != -1) {
	atgb = 1;
} else {
	atgb = 0;
}

function switchLang(lang)
{
var tempPath="";
 if (parent.frames.length > 0)
  {

	for (i=0; i<parent.frames.length; i++)
	{
		org_path=parent.frames[i].location.pathname;
		//org_path_start=org_path.indexOf(div_path);
		org_path_start=org_path.indexOf(webserver_path);
		if (org_path_start>-1)
		{
			org_path_end=webserver_path.length;
			//add=org_path.substring(org_path_start, org_path_end);
			add = org_path.substring(org_path_start+org_path_end, org_path.length);
		}
		else
		{
			org_path_end=org_path.length;
			add=org_path.substring(org_path_start, org_path_end);
		}
		
		if (lang == "tc")
		{
			tempPath = add.replace("/en/", "/tc/");
			tempPath = tempPath.replace("/tc_txt/", "/tc/");
		}
		else if (lang == "sc")
		{
			tempPath = add.replace("/en/", "/tc/");
			tempPath = tempPath.replace("/tc_txt/", "/tc/");
		}
		else if (lang == "en")
		{
			tempPath = add.replace("/tc/", "/en/");
			tempPath = tempPath.replace("/en_txt/", "/en/");
		}
		else if (lang == "tc_txt")
		{
			tempPath = add.replace("/tc/", "/tc_txt/");
			tempPath = tempPath.replace("/en_txt/", "/tc_txt/");
		}
		else if (lang == "sc_txt")
		{
			tempPath = add.replace("/tc/", "/tc_txt/");
			tempPath = tempPath.replace("/en_txt/", "/tc_txt/");
		}
		else if (lang == "en_txt")
		{
			tempPath = add.replace("/en/", "/en_txt/");
			tempPath = tempPath.replace("/tc_txt/", "/en_txt/");
		}
		path = tempPath;

		if((lang == 'sc')||(lang == 'sc_txt')) {
			base_path = cv_sc_base_path;
		} else {
			base_path = cv_nonsc_base_path;
		}	
	
		parent.frames[i].location.href = base_path + path;

	}
  }
  else
  {

	  	org_path=parent.location.pathname;
		org_path_start=org_path.indexOf(webserver_path);
		if (org_path_start>-1)
		{
			org_path_end=webserver_path.length;
			//add=org_path.substring(org_path_start, org_path_end);
			add = org_path.substring(org_path_start+org_path_end, org_path.length);
		}
		else
		{
			org_path_start=org_path.indexOf(div_path);
			org_path_end=org_path.length;
			add=org_path.substring(org_path_start, org_path_end);
		}

		if (lang == "b5")
		{
			if (add.indexOf("/gb/") >= 0 )
			{
				tempPath = add.replace("/gb/", "/b5/");
				tempPath = tempPath.replace("/tc_txt/", "/tc/");
			}
			else if (add.indexOf("/en/") >= 0)
			{
				tempPath = add.replace("/en/", "/b5/");
				tempPath = tempPath.replace("/tc_txt/", "/tc/");
			}
			
		}
		else if (lang == "gb")
		{

			if (add.indexOf("/en/") >= 0)
			{

				tempPath = add.replace("/en/", "/gb/");
				tempPath = tempPath.replace("/tc_txt/", "/tc/");

			}
			else if (add.indexOf("/b5/") >= 0 )
			{

				tempPath = add.replace("/b5/", "/gb/");
				tempPath = tempPath.replace("/tc_txt/", "/tc/");
			}
			
		}
		else if (lang == "en")
		{
			if (add.indexOf("/b5/") >= 0)
			{
			tempPath = add.replace("/b5/", "/en/");
			tempPath = tempPath.replace("/en_txt/", "/en/");
			}
			else if (add.indexOf("/gb/") >= 0 )
			{
				tempPath = add.replace("/gb/", "/en/");
				tempPath = tempPath.replace("/en_txt/", "/en/");
			}
		}
		else if (lang == "tc_txt")
		{
			tempPath = add.replace("/tc/", "/tc_txt/");
			tempPath = tempPath.replace("/en_txt/", "/tc_txt/");
		}
		else if (lang == "sc_txt")
		{
			tempPath = add.replace("/tc/", "/tc_txt/");
			tempPath = tempPath.replace("/en_txt/", "/tc_txt/");
		}
		else if (lang == "en_txt")
		{
			tempPath = add.replace("/en/", "/en_txt/");
			tempPath = tempPath.replace("/tc_txt/", "/en_txt/");
		}


		if (tempPath.indexOf("enquiry_result.asp") >= 0 )
		{
			tempPath = tempPath.replace("enquiry_result.asp", "enquiry.asp");
		}

		path = tempPath;

		if((lang == 'sc')||(lang == 'sc_txt')) {
			base_path = cv_sc_base_path;
		} else {
			base_path = cv_nonsc_base_path;
		}	
		parent.location.href = base_path + path;
  		//parent.location.href = base_path + path + "?num=" + getVar('num');
  }

}

function show_link() {

	if (atgb) 
	{
		document.write("<A onmouseover=\"MM_swapImage('mainbar3','','../clf/gb/mainbar3b_f2.gif',1)\"  onmouseout=MM_swapImgRestore() href=\"javascript:changelang('tc')\"    target=_top><IMG src=\"../clf/gb/mainbar3b.gif\" alt=\"ÁcÅéª©\" name=mainbar3 width=49 height=19       border=0 id=\"mainbar3\"></A>");

	} else 
	{
	document.write ("<A  onmouseover=\"MM_swapImage('mainbar3','','../clf/b5/mainbar3b_f2.gif',1)\"    onmouseout=MM_swapImgRestore()     href=\"javascript:changelang('sc')\"       target=_top><IMG src=\"../clf/b5/mainbar3b.gif\" alt=\"Â²Ê^ª©\" name=mainbar3 width=49 height=19       border=0 id=\"mainbar3\"></A>");
	}
}

function getVar(name)
         {
         get_string = document.location.search;         
         return_value = '';
         
         do { //This loop is made to catch all instances of any get variable.
            name_index = get_string.indexOf(name + '=');
            
            if(name_index != -1)
              {
              get_string = get_string.substr(name_index + name.length + 1, get_string.length - name_index);
              
              end_of_value = get_string.indexOf('&');
              if(end_of_value != -1)                
                value = get_string.substr(0, end_of_value);                
              else                
                value = get_string;                
                
              if(return_value == '' || value == '')
                 return_value += value;
              else
                 return_value += ', ' + value;
              }
            } while(name_index != -1)
            
         //Restores all the blank spaces.
         space = return_value.indexOf('+');
         while(space != -1)
              { 
              return_value = return_value.substr(0, space) + ' ' + 
              return_value.substr(space + 1, return_value.length);
							 
              space = return_value.indexOf('+');
              }
          
         return(return_value);        
}
