// READ COOKIE AND REDIRECT IF NESCESSARY

function Get(CkName) {
  var dc = document.cookie;
  var prefix = CkName + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null; 
  } else {
    begin += 2;
  }
  var end = document.cookie.indexOf(";", begin);
  if (end == -1) {
    end = dc.length;
  }
  return unescape(dc.substring (begin + prefix.length, end));
}

function Check() {
  var CkVal = Get("clgnlng");
  alert(CkVal);
  if ( CkVal == "ZHS" ) location.replace("/zhs/index.html");
  if ( CkVal == "ZHT" ) location.replace("/zht/index.html");
  if ( CkVal == "KO" ) location.replace("/ko/index.html");
  if ( CkVal == "ES" ) location.replace("/es/index.html");
}

// SET COOKIE AND REDIRECT

var Exp = new Date();
Exp.setFullYear(Exp.getFullYear() + 5);
function Set(Lingo){
  document.cookie = "clgnlng=" + Lingo + "; expires=" + Exp.toGMTString() + "; path=/;"; 
  if ( Lingo == "EN" ) location.replace("/index.html");
  if ( Lingo == "ZHS" ) location.replace("/zhs/index.html");
  if ( Lingo == "ZHT" ) location.replace("/zht/index.html");
  if ( Lingo == "KO" ) location.replace("/ko/index.html");
  if ( Lingo == "ES" ) location.replace("/es/index.html");
}


// WRITE FORM

var NS4 = (document.layers) ? 1 : 0;
var IE = (document.all) ? 1 : 0;
var DOM = (parseInt(navigator.appVersion) >=5) ? 1 : 0;
var MAC = ((navigator.appVersion.indexOf("PPC") >0) || (navigator.appVersion.indexOf("Mac") >0)) ? 1 : 0;
var OPERA = (navigator.userAgent.indexOf("Opera") != -1);

document.write('<select name=\"Lingo\" id=\"lingo\" size=\"1\" onchange=\"Set(this.options[this.selectedIndex].value)\">');
document.write('<option value=\"\">Select Language</option>');
document.write('<option value=\"EN\">English</option>');
document.write('<option value=\"ZHT\">Chinese (Traditional)</option>');
document.write('<option value=\"ZHS\">Chinese (Simplified)</option>');
document.write('<option value=\"KO\">Korean</option>');
document.write('<option value=\"ES\">Spanish</option>');
document.write('</select>');