var ShowJS = false;
var IsCDROM = self.location.protocol == 'file:';
var l1="", l2="", l3="";

function GetObject(Id)
{
   if (document.layers)
      return eval("document." + Id);
   if (navigator.userAgent.indexOf("Opera") != -1)
      return eval("document.all." + Id);
   if (document.getElementById)
      return document.getElementById(Id);
   if (document.all)
      return eval("document.all." + Id);
   return null;
}

function DisplayAs(Id, On, how)
{
   var O = GetObject(Id);
   if (O)
      O.style.display = On ? how : "none";
}

function Display(Id, On)
{
   DisplayAs(Id, On, "block");
}


// Cookie stuff

var s = null;
var Form = null;
var OtherChoice = 10;

function ParseCookie(Field, Seperator)
{
   var aCookie = s.split(Seperator);
   for (var i=0; i < aCookie.length; i++)
   {
      var aCrumb = aCookie[i].split("=");
      if (Field == aCrumb[0]) 
         return aCrumb[1];
   }
   return "";
}

function GetCookie(Field)
{
   if (s == null)
   {
      s = document.cookie;
      s = unescape(ParseCookie("OnTimeRegistration", "; "));
   }
   return ParseCookie(Field, "\t");
}

function AddCookieValue(Field, Value)
{
   if (Value != null)
      if (Value != "")
         s = s + "\t" + Field + "=" + Value;
}

function AddCookie(Field)
{
   AddCookieValue(Field, eval("Form. " + Field + ".value"));
}

function AddCookieBool(Field)
{
   AddCookieValue(Field, eval("Form. " + Field + ".checked") ? "ON" : "");
}

function AddCookieList(Field)
{
   Value = eval("Form. " + Field + ".selectedIndex");
   if (Value != null)
      if (Value)
      {
         if ((Field == "Lead1") && (Value == OtherChoice))
            Value = -1;
         AddCookieValue(Field, Value);
      }
}

function Check(Field, Property, InvalidValue)
{
   Value = eval("Form. " + Field + "." + Property);
   if ((Value == null) || (Value == InvalidValue))
   {
      alert("Please enter a value for field " + Field);
      eval("Form." + Field + ".focus()");
      return false;
   }
   else
      return true;
}

function Validate(Field)
{
   return Check(Field, "value", "");
}

function WriteCookie(HaveLicense)
{
   if (!Validate("Name")) return false;
   if (!Validate("Company")) return false;
   if (!Validate("Address1")) return false;
   if (!Validate("City")) return false;
   if (!Validate("Zip")) return false;
   if (!Validate("Country")) return false;
   if (!Check("Lead1", "selectedIndex", 0)) return false;
   if (!Validate("Lead2")) return false;

   s = "";

   AddCookieList("Title");
   AddCookie("Name");
   AddCookie("Company");
   AddCookie("Department");
   AddCookie("Address1");
   AddCookie("Address2");
   AddCookie("City");
   AddCookie("State");
   AddCookie("Zip");
   AddCookie("Country");
   AddCookie("Phone");
   AddCookie("Fax");
   AddCookie("Email");
   AddCookieBool("RTTarget32");
   AddCookieBool("RTKernelC");
//   AddCookieBool("emailings");
   AddCookieList("Lead1");
   AddCookie("Lead2");

   if (HaveLicense)
   {
      l1 = Form.License1.value;
      l2 = Form.License2.value;
      l3 = Form.License3.value;
   }
   // else lx where read from the cookie
   AddCookieValue("License1", l1);
   AddCookieValue("License2", l2);
   AddCookieValue("License3", l3);

   expires = new Date();
   expires.setTime(expires.getTime() + (1000 * 60 * 60 * 24 * 365 * 2)); // two year
   document.cookie = "OnTimeRegistration=" + escape(s + "\t") + "; path=/; expires=" + expires.toGMTString();
   return true;
}

function InitCookie(Id, HaveLicense)
{
   var t = GetCookie("Title");

   Form = GetObject(Id);
   if (!Form)
      Form = document.RegForm;

   if (t != "")
      Form.Title.options.selectedIndex = t;
   Form.Name.value = GetCookie("Name");
   Form.Company.value = GetCookie("Company");
   Form.Department.value = GetCookie("Department");
   Form.Address1.value = GetCookie("Address1");
   Form.Address2.value = GetCookie("Address2");
   Form.City.value = GetCookie("City");
   Form.State.value = GetCookie("State");
   Form.Zip.value = GetCookie("Zip");
   Form.Country.value = GetCookie("Country");
   Form.Phone.value = GetCookie("Phone");
   Form.Fax.value = GetCookie("Fax");
   Form.Email.value = GetCookie("Email");
   Form.RTTarget32.checked = GetCookie("RTTarget32") == "ON";
   Form.RTKernelC.checked = GetCookie("RTKernelC") == "ON";

//   if (GetCookie("emailings") == null)
//      Form.emailings.checked = false;
//   else
//      Form.emailings.checked = GetCookie("emailings") == "ON";

   t = GetCookie("Lead1");
   if (t == "")
      t = 0;
   if (t == -1)
      t = OtherChoice;
   Form.Lead1.options.selectedIndex = t;
   Form.Lead2.value = GetCookie("Lead2");

   l1 = GetCookie("License1");
   l2 = GetCookie("License2");
   l3 = GetCookie("License3");
   if (HaveLicense)
   {
      Form.License1.value = l1;
      Form.License2.value = l2;
      Form.License3.value = l3;
   }
}

function HasRegistered()
{
   return (document.cookie.length > 2);
}

function RegisterAndDownload(FileName)
{
   if (IsCDROM)
   {
      location.href = "../Binaries/" + FileName;
      return;
   }
   if (!HasRegistered() && window.confirm("   You are not registered!\r\n" + "Do you want to register now?"))
   {
      location.href = "register.htm";
      return;
   }
   location.href = "ftp://ftp.on-time.com/q/" + FileName;
}

function RegisterAndFTP(FileName)
{
   if (IsCDROM)
   {
      location.href = "ftp://ftp.on-time.com/q/" + FileName;
      return;
   }
   if (!HasRegistered() && window.confirm("   You are not registered!\r\n" + "Do you want to register now?"))
   {
      location.href = "register.htm";
      return;
   }
   location.href = "ftp://ftp.on-time.com/q/" + FileName;
}
