var NN = false;
var IE = false;
var deletecode = 127;
var backspacecode = 8;
var space = 32;
var quote = 39;
var doublequote = 34;

if (navigator.appName == 'Netscape')
  NN = true;
else
  IE = true;
var version = parseInt(navigator.appVersion);

function getLink(link) {
  if (link.substr(0,7) == "http://")
    location.href = link;
  else
    location.href = "/index/content/" + link;
}
function hidethis(obj) {
  obj.style.visibility = "hidden";
}
function showthis(obj) {
  obj.style.visibility = "visible";
}

function getObject(obj) {
  if (IE)
    return eval("document.all.sub" + obj.id);
  else
    return document.getElementById("sub" + obj.id);
}
function showsubdiv(obj) {
  master = getObject(obj);
  master.style.visibility = "visible";
  obj.style.clip = "rect(auto auto auto auto)";
}

function hidesubdiv(obj, objwidth) {
  master = getObject(obj);
  master.style.visibility = "hidden";
  obj.style.clip = "rect(0px " + objwidth + "px 15px 0px)";
}

function isEmpty(data) {
  var nonempty = new RegExp('.+');
  if (window.RegExp)
    return !nonempty.test(data);
}
function isEmail(data) {
  var isemail = new RegExp('^[\\w-_\.]*[\\w-_\.]\@[\\w]\.+[\\w]+[\\w]$');
  if (window.RegExp)
    return isemail.test(data);
}
function getKeyCode(evt) {
  if (NN)
    return evt.which;
  else
    return window.event.keyCode;
}
function checkcode(evt, type) {
  var code = getKeyCode(evt);
  if (!isValidCode(code, type)) {
    if (NN)
      return false;
    else {
      window.event.returnValue=false;
      return false;
    }
  }
  return true;
}

function isValidCode(code, type) {
  if (type == 'c' || type == 'm' || type == 'e')
    return true;
  if (code == deletecode || code == backspacecode || code == 0)
    return true;
  if (type == 'n' && code <= 57 && code >= 48)
    return true;
  if (type == 'a' && (code <= 90 && code >= 48 || code == space || code <= 122 && code >= 97 || code == doublequote || code == quote))     return true;
  if (type == 't' && (code >= 40 && code <= 41 || code == space || isValidCode(code, 'n')))
    return true;
  if (type == 'i' && (isValidCode(code, 'a') || isValidCode(code, 't')))
    return true;
  if (type == 'p' && (isValidCode(code, 'n') || code == 46))
    return true;
  if (type == 'd' && (isValidCode(code, 'n') || code == 45))
    return true;
  return false;
}

function getPageContent(obj) {
  targetobj = eval("document.forms[0]." + obj);
  document.getElementById("mastercontent").innerHTML = targetobj.value;
}
function getDivObject(target) {
  if (IE)
    return eval("document.all." + target);
  else
    return document.getElementById(target);
}

function divover(obj) {
  obj.style.color = "#076935";
}

function divout(obj) {
  if (obj.id != target)
    obj.style.color = "blue";
}

function getTarget(obj) {
  objname = obj.id.substr(3);
  targetobj = eval("document.forms[0]." + objname);
  div = getDivObject("mastercontent");
  div.innerHTML = "<table style=\"border:1px solid #C0BCBC;\"><tr><td height=10></td></tr><tr><td width=10></td><td height=200 valign=top align=left><table width=584 border=0 cellpadding=0 cellspacing=0>" + targetobj.value + "</table></td><td width=10></td></tr><tr><td height=10></td></tr></table>";
  for (i = 0; i < divs.length; i++) {
    if (divs[i] == objname) {
      obj.style.backgroundImage = "url(http://www.coresearch.hk/images/" + images[i] + "over.gif)";
      obj.style.color = "#076935";
    }
    else {
      div = getDivObject("div" + divs[i]);
      div.style.backgroundImage = "url(http://www.coresearch.hk/images/" + images[i] + ".gif)";
      div.style.color = "blue";
    }
  }
  target = obj.id;
}

function changelang(lang) {
  form = document.forms["content"];
  form.language.value = lang;
  form.submit();
}
function setImage(obj, fromimage, toimage) {
  image = obj.getAttribute('src');
  image = image.substr(0, image.indexOf(fromimage)) + toimage;
  obj.setAttribute('src', image);
}
function setOverImage(obj) {
  setImage(obj, '.gif', 'over.gif');
}
function setOutImage(obj) {
  setImage(obj, 'over.gif', '.gif');
}
function getNewChildWindow(url, name, width, height) {
  newWindow = window.open(url, name, 'dependent,width=' + width + ',height=' + height + ',scrollbars=yes,toolbar=no,location=no,menubar=no, statusbar=no,left=50,screenX=50,top=50,screenY=50');
}
function getWindow(url) {
  newWindow = window.open("http://" + url);
}