var CurrentForm = 0;

function redirect()
{
  if ((! parent) || (parent.document.title != "Corporate Practical Solutions Limited"))
    document.location.href = "../index.htm";
}

function WriteCookie(CookieName, CookieValue)
{
  if (window.navigator.cookieEnabled)
  {
    expireDate = new Date;
    expireDate.setMinutes(expireDate.getMinutes()+60);
    document.cookie = CookieName+"="+CookieValue+"; expires="+expireDate.toGMTString();
//    alert("WriteCookie : " + CookieName + " = " + CookieValue);
  }
}

function ReadCookie(CookieName, CookieDefault)
{
  var CookieValue = 0;

  if ((window.navigator.cookieEnabled) && (document.cookie != ""))
  {
    CookieValue = eval(CookieVal(CookieName));
//    alert("ReadCookie : " + CookieName + " = " + CookieValue);
    if (CookieValue == 0)
      CookieValue = CookieDefault;
//    alert("ReadCookie : " + CookieName + " = " + CookieValue);
  }
  if (! IsNumeric(CookieValue))
    return(0);
  else
    return(CookieValue);
}

function CookieVal(cookieName)
{
  if (document.cookie != "")
  {
    thisCookie = document.cookie.split("; ");
    for (i=0; i<thisCookie.length; i++)
    {
      if (cookieName == thisCookie[i].split("=")[0])
      {
        return(thisCookie[i].split("=")[1]);
      }
    }
  }
  return(0);
}

function PopupDocument(DocumentLocation, Title, x, y)
{
//  alert("PopupDocument : " + DocumentLocation);
  if ((document.all) || (DocumentLocation.lastIndexOf(".htm") != -1))
  {
    if ((x == 0) && (y == 0))
      WinString = 'resize="yes", title="' + Title + '"';
    else
      WinString = 'width=' + x + ',height=' + y + ',title="' + Title + '",resizable=yes,scrollbars=yes,status=yes,toolbar=no,menubar=no,location=no';
    NewWindow = window.open(DocumentLocation, 'NewWin', WinString);
  }
  else
  {
    WriteCookie("PopupDocument", DocumentLocation);
    NewWindow = window.open("docs/launch.htm", "NewWin", "width=10,height=10,resizeable=no,scrollbars=no,status=no,toolbar=no,menubar=no");
  }
}

function IsNumeric(Value)
{
  var loop;

  if (Value == "")
    return(false);
  for (loop=0; loop<Value.length; loop++)
  {
    if ((Value.charAt(loop) < "0") || (Value.charAt(loop) > "9"))
      return(false);
  }
  return(true);
}

function IsTelephoneNumber(Value)
{
  var loop;

  if (Value == "")
    return(false);
  for (loop=0; loop<Value.length; loop++)
  {
    if (((Value.charAt(loop) < "0") || (Value.charAt(loop) > "9")) && (Value.charAt(loop) != " ") && (Value.charAt(loop) != "-"))
      return(false);
  }
  return(true);
}

function IsEmail(email)
{
  invalidchars = " /:,;";
  if (email == "")
    return(false);
  for (i=0; i<invalidchars.length; i++)
  {
    badchar = invalidchars.charAt(i);
    if (email.indexOf(badchar, 0) > -1)
      return(false);
  }
  atPos = email.indexOf("@", 1);
  if (atPos == -1)
    return(false);
  periodpos = email.indexOf(".", atPos);
  if (periodpos == -1)
    return(false);
  if (periodpos+3 > email.length)
    return(false);
  return(true);
}


function Highlight(string, text)
{
    var strLength = string.length;
    txtLength = text.length;

    if ((strLength == 0) || (txtLength == 0))
      return string;
    
    LowerString = string.toLowerCase();
    var i = LowerString.indexOf(text);
    
    if ((! i) && (text != LowerString.substring(0,txtLength)))
      return string;

    if (i == -1)
      return string;

    var newstr = string.substring(0, i) + "<u>" + string.substring(i, i + txtLength) + "</u>";

    if ((i + txtLength) < strLength)
        newstr += Highlight(string.substring(i + txtLength, strLength), text);

    return newstr;
}

function UpdateDiv(DivID, innerHTML)
{
  if (document.all)
	  document.all[DivID].innerHTML = innerHTML;
  else if (document.getElementById)
	  document.getElementById(DivID).innerHTML = innerHTML;
  else if (document.layers)
  {
		with(document.layers[DivID].document)
    {
			open();
			write(txt);
			close();
		}
	}
}

function HideDiv(DivID)
{
  if (document.all)
	  document.all[DivID].style.display = "none";
  else if (document.getElementById)
	  document.getElementById(DivID).style.display = "none";
  else if (document.layers)
		document.layers[DivID].document.style.display = "none";
}

function ShowDiv(DivID)
{
  if (document.all)
	  document.all[DivID].style.display = "";
  else if (document.getElementById)
	  document.getElementById(DivID).style.display = "";
}

function GetObject(ObjectName)
{
  if (document.all)
  {
    if (document.all[ObjectName])
      return(document.all[ObjectName]);
    else
      return(Null);
  }
  else if (document.getElementById)
  {
  	if (document.getElementById(ObjectName))
  	  return(document.getElementById(ObjectName));
    else
      return(Null);
  }
}

function SetFocus(ObjectName)
{
  if (document.all)
  {
    if (document.all[ObjectName])
      document.all[ObjectName].focus();
  }
  else if (document.getElementById)
  {
  	if (document.getElementById(ObjectName))
  	  document.getElementById(ObjectName).focus();
  }
  return(true);
}
