 var Content_Amended = false;

 function Clock_Interrupt()
  {
   var currentTime = new Date();
   var currentHours = currentTime.getHours();
   var currentMinutes = currentTime.getMinutes();
   var currentSeconds = currentTime.getSeconds();
   
   currentHours = currentHours < 10 ? "0" + currentHours : currentHours;
   currentMinutes = currentMinutes < 10 ? "0" + currentMinutes : currentMinutes;
   currentSeconds = currentSeconds < 10 ? "0" + currentSeconds : currentSeconds;
   
   var divID = document.getElementById("menuclock");
   divID.innerHTML = currentHours + ":" + currentMinutes + ":" + currentSeconds;
   
   setTimeout("Clock_Interrupt()", 1000);
  }

 function Clock_Start()
 {
  setTimeout("Clock_Interrupt()", 1000);
 }

 function Image_Swap(Img_ID, Filename)
 // Small function to swap icons 
  {
  }

 function Get_Value(From, To)
  {
    FromValue = document.getElementById(From).value;

    LastSlash = FromValue.lastIndexOf("/");
    if (LastSlash == -1)
     LastSlash = FromValue.lastIndexOf("\\");

    document.getElementById(To).value = FromValue.substring(++LastSlash);
  }

 function Clear_Text(ID, From)
  {
    document.getElementById(ID).value = document.getElementById(From).value;
  }

 function Clear_Select(ID)
  {
     if (document.getElementById(ID).length > 0)
      document.getElementById(ID).options[0].selected = true; // Select first element of select, always null in this software
  }

 function Check_Changes(Location)
  {
    try
     {
       if (Content_Amended)
        {
          if (Query_User("Warning: You have made changes, if you continue all changes will be LOST\nOkay to continue?", true))
           Relocate(false, Location);
          else
           return(false);
        }
       else
        Relocate(false, Location);
     }
    catch(Error)
     {
       Relocate(false, Location);
     }
  }

 function Relocate(Query, Location, Message, NoPrefix)
 // Redirect the user to an alternative url (mostly used to recurse the current page)
  {
    if (Query)
     {
       if (Query_User(Message, NoPrefix))
        document.location.href = Location;
     }
    else
     document.location.href = Location;
  }

 function Query_User(Message, noPrefix)
 // Ask a simple Okay Cancel question
  {
    if (Message == "" || Message == null)
     Message = "continue?";

    if (!noPrefix)
     Message = "Okay to " + Message;

    return(confirm(Message));
  }

 function Submit_Form(Query, Message)
 // Query the user about submitting the form when they click submit
  {
    if (Message == "" || Message == null)
     Message = " save changes?";

    if (Query)
     {
       if (Query_User(Message))
        return(true);
       else
        return(false)
     }
    else
     return(true);
  }

function Disable_Elements(Name, Check, Self)
 {
   // Check that element is a select and if is has more than 1 items in it, if not disable it and return from function
   if (document.getElementById(Name).type == "select" && document.getElementById(Name).length < 2)
    {
      document.getElementById(Name).disabled = true;
      return(false);
    }

   if (Check)
    {
      if (document.getElementById(Self).value == "")
       {
         document.getElementById(Name).disabled = false;
         document.getElementById('save').disabled = true;
       }
      else
       document.getElementById('save').disabled = false;
    }
   else
    {
      if (!document.getElementById(Name).disabled) // If the element to check is not already disabled, disable it
       document.getElementById(Name).disabled = true;
    }
 }

function IsNumeric(sField)
 {
   var Valid_Characters = "0123456789.-";
   var IsNumber = true;

   for (CharCount = 0; CharCount < sField.length && IsNumber == true; CharCount++) 
    { 
      if (Valid_Characters.indexOf(sField.charAt(CharCount)) == -1) 
       IsNumber = false;
    }

   return IsNumber;

 }

function IsDate(sField)
 {
   var Valid_Characters = "01234567890/-: ";
   var IsDate = true;

   for (CharCount=0; CharCount < sField.length && IsDate == true; CharCount++)
    {
      if (Valid_Characters.indexOf(sField.charAt(CharCount)) == -1)
       isDate = false;
    }

   return(isDate);
 }

function IsTeleFax(sField, Valid)
 {
   var Valid_Characters = "0123456789.-+() ";
   var IsTeleFax = true;

   if (sField.length > 0)
    {
      if (sField.length < 6)
       IsTeleFax = false;
      else
       {
        for (CharCount = 0; CharCount < sField.length && IsTeleFax == true; CharCount++) 
         { 
           if (Valid_Characters.indexOf(sField.charAt(CharCount)) == -1)
            IsTeleFax = false;
         }
       }
      return IsTeleFax;
    }
   else
    return Valid;
 }

function IsEmail(sField, Valid) 
 {
   if (sField.length > 0)
    {
      if (sField.length <9) // e.g. a.b@c.de
       return(false)
      else
       return (sField.indexOf(".") >= 2) && (sField.indexOf("@") > 0);
    }
   else
    return Valid;
 }

function input_filterAmt (str, dec, bNeg) 
{ // auto-correct input - force numeric data based on params. 
 var cDec = '.'; // decimal point symbol 
 var bDec = false; var val = ""; 
 var strf = ""; var neg = ""; var i = 0; 

 if (str == "") return; 
 parseFloat ("0").toFixed (dec); 
 if (bNeg && str.charAt (i) == '-') { neg = '-'; i++; } 

 for (i; i < str.length; i++) 
 { 
  val = str.charAt (i); 
  if (val == cDec) 
  { 
   if (!bDec) { strf += val; bDec = true; } 
  } 
  else if (val >= '0' && val <= '9') 
   strf += val; 
 } 
 strf = (strf == "" ? 0 : neg + strf); 
 return parseFloat (strf).toFixed (dec); 
}
