//webserver_path = "http://www.yearbook.gov.hk";
//kanserver_path = "sc.info.gov.hk/gb";

webserver_path = "www.yearbook.gov.hk";
kanserver_path = "sc.info.gov.hk/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;
}

/*** Start - Added for Offline SC ***/

// Language directory
var chi_path= "/tc/"
var sim_path= "/sc/"
var eng_path= "/en/"

function switchLang(lang) {

	if (isSim()) {
		location.href = location.href.replace(sim_path, "/" + lang + "/");
	}

	if (isChi()) {
		location.href = location.href.replace(chi_path, "/" + lang + "/");
	}

	if (isEng()) {
		location.href = location.href.replace(eng_path, "/" + lang + "/");
	}

}

function isEng() {
	return (location.href.toString().indexOf(eng_path) != -1) ? true : false;
}

function isChi() {
	if (isSim()) return false;
	return (location.href.toString().indexOf(chi_path) != -1) ? true : false;
}

function isSim() {
	return (location.href.toString().indexOf(sim_path) != -1) ? true : false;
}

/*** End - Added for Offline SC ***/


/*function switchLang(lang)
{

 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 == "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.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=\"繁體版\" 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);        
}
