function items(code, which, sep)
{
  var thestring = code;
  var cnt = which;
  while (cnt > 0)
  {
    pos = thestring.indexOf(sep);
    if (pos != -1)
    {
      resultstring = thestring.substring(0,pos);
      thestring = thestring.substring(pos+1,thestring.length);
    } else
    {
      resultstring = thestring;
      thestring = "";
    }
    cnt = cnt - 1;
  }
  return resultstring;
}

function language(which)
{
  var fulllocation = document.location.href+"";

  var filename = ""
  var extn = "";
  var cnt = fulllocation.length;
  do
  {
    if (cnt == 0) break;
    cnt--;
    if (fulllocation.substring(cnt,cnt+1) == ".") extn = fulllocation.substring(cnt,fulllocation.length);
    if (fulllocation.substring(cnt,cnt+1) == "/") filename = fulllocation.substring(cnt+1,fulllocation.length);
    if (filename != "") break;
  } while (1==1);
  filename = items(filename, 1, extn);
  if (filename == "index") filename = filename+"_english";
  // extract the old language
  fulllocation = filename;
  filename = "";
  var cnt = fulllocation.length;
  do
  {
    if (cnt == 0) break;
    cnt--;
    if (fulllocation.substring(cnt,cnt+1) == "_") filename = fulllocation.substring(0, cnt);
    if (filename != "") break;
  } while (1==1);
  filename = filename+"_"+which+extn;
  if (filename == "index_english.html") filename = "index.html";
  document.location.href=filename;  

}
