function getCookieVal (offset) {
  var endstr = document.cookie.indexOf (";", offset);
  if (endstr == -1)
    endstr = document.cookie.length;
  return unescape(document.cookie.substring(offset, endstr));
}
function GetCookie (name) {
  var arg = name + "=";
  var alen = arg.length;
  var clen = document.cookie.length;
  var i = 0;
  while (i < clen) {
    var j = i + alen;
    if (document.cookie.substring(i, j) == arg)
      return getCookieVal (j);
    i = document.cookie.indexOf(" ", i) + 1;
    if (i == 0) break; 
  }
  return null;
}
function clearnsp()
{
document.cookie="NSPNUM=;expires=Thu, 01-Jan-70 00:00:01 GMT;path=/;domain=.oectools.org"
document.cookie="LAST_NAME=;expires=Thu, 01-Jan-70 00:00:01 GMT;path=/;domain=.oectools.org"
}
function return_URI(fn)
{
// This function is used when transferring to secure mode for registration cgi's
// This function always builds an online URI for the requested page
// Builds URI from directory and file name.(fn) 
// If online, uses current domain (zz), if offline uses "www.oectools.org"
// If current domain has only two words (eg. oectools.org) "www." is prefixed to the domain
// If Cookie SECURE (yy) is null or https, the URI begins "https" else it begins "http"
// Cookie SECURE is set to "http" when the user asks to use the non-secure server
yy = "http"
zz = location.hostname
if (zz == ""){zz = "www.oectools.org"}
if (zz.indexOf(".") == zz.lastIndexOf(".")  ){zz = "www."+zz}
xx = yy + "://" + zz + fn
return xx
}
function return_secure_URI(fn)
{
// This function is used when transferring to secure mode for registration cgi's
// This function always builds an online URI for the requested page
// Builds URI from directory and file name.(fn) 
// If online, uses current domain (zz), if offline uses "www.oectools.org"
// If current domain has only two words (eg. oectools.org) "www." is prefixed to the domain
// If Cookie SECURE (yy) is null or https, the URI begins "https" else it begins "http"
// Cookie SECURE is set to "http" when the user asks to use the non-secure server
yy = GetCookie("SECURE")
if (yy != "http"){yy = "https"}
zz = location.hostname
if (zz == ""){zz = "www.oectools.org"}
if (zz.indexOf(".") == zz.lastIndexOf(".")  ){zz = "www."+zz}
xx = yy + "://" + zz + fn
return xx
}
function dispatch_http(fn)
{
// This function always goes online for the requested page
// Builds URI from directory and file name.(fn) & transfers to it
// If online, uses current domain (zz), if offline uses "www.oectools.org"
// If current domain has only two words (eg. oectools.org) "www." is prefixed to the domain
zz = location.hostname
if (zz == ""){zz = "www.oectools.org"}
if (zz.indexOf(".") == zz.lastIndexOf(".")  ){zz = "www."+zz}
xx = "http://" + zz + fn
window.location = xx
}
function dispatch_https(fn)
{
window.location = return_secure_URI(fn)
}

