 function FunctionLogin(CenMode)
  {
   document.FormLogin.CenMode.value = CenMode;
   document.FormLogin.submit();
  }

 function ForgottenInformation(CenMode)
  {
   document.FormLogin.CenMode.value = CenMode;
   document.FormLogin.submit();
  }

function ForgottenPasswordSubmit(SubmitMethod,CenMode)
  {
   var validateform = true;
   if (document.PasswordForm.email.value == "")
     {
      alert("Please specify a valid User Id");
      validateform = false;
      document.PasswordForm.email.focus();
     }
   if (validateform == true)
     {
      document.PasswordForm.SubmitFormMethod.value = SubmitMethod;
      document.PasswordForm.submit();
     }
  }

function LoginAccount(submitmethod)
  {
   var validateform = true;
   if (document.FormLogin.email.value == "")
     {
      alert("Please specify a valid User Id");
      validateform = false;
      document.FormLogin.email.focus();
     }
   if (validateform == true)
     {
      document.FormLogin.CenMode.value = submitmethod;
      document.FormLogin.submit();
     }
  }

function ResetLoginFields()
  {
   document.FormLogin.email.value = "";
   document.FormLogin.password.value = "";
   document.FormLogin.email.focus();
  }

function GenerateNewAccount(CenMode)
  {
   document.AccountGenerate.CenMode.value = CenMode;
   document.AccountGenerate.submit();
  }

function LeftButtonSubmit(CenMode)
  {
   document.ButtonLeftForm.CenMode.value = CenMode;
   document.ButtonLeftForm.submit();
  }

function LeftButtonAction(FormAction)
  {
   document.ButtonLeftForm.action = FormAction;
   document.ButtonLeftForm.submit();
  }

function LeftButtonScreenCall(FormAction,CenMode,CompanySiteKey,CompanyMeterSiteKey,QuoteKey,QuoteHeaderKey)
  {
   document.ButtonLeftForm.CompanySiteKey.value = CompanySiteKey;
   document.ButtonLeftForm.CompanyMeterSiteKey.value = CompanyMeterSiteKey;
   document.ButtonLeftForm.QuoteKey.value = QuoteKey;
   document.ButtonLeftForm.QuoteHeaderKey.value = QuoteHeaderKey;
   document.ButtonLeftForm.CenMode.value = CenMode;
   document.ButtonLeftForm.action = FormAction;
   document.ButtonLeftForm.submit();
  }

function ButtonAction(CenMode)
  {
   document.FormButton.CenMode.value = CenMode;
   document.FormButton.submit();
  }

function ButtonActionStq(CenMode,Stq)
  {
   document.FormButton.CenMode.value = CenMode;
   document.FormButton.Stq.value = Stq;
   document.FormButton.submit();
  }

function ButtonActionValue(CenMode,FormAction)
  {
   document.FormButton.CenMode.value = CenMode;
   document.FormButton.action = FormAction;
   document.FormButton.submit();
  }

function QuoteReview(CenMode,QuoteHeaderKey)
  {
   document.FormButton.CenMode.value = CenMode;
   document.FormButton.QuoteHeaderKey.value = QuoteHeaderKey;
   document.FormButton.submit();
  }

function QuoteReviewHeader(CenMode,CompanyMeterSiteKey)
  {
   document.FormButton.CenMode.value = CenMode;
   document.FormButton.CompanyMeterSiteKey.value = CompanyMeterSiteKey;
   document.FormButton.submit();
  }

function ChangePasswordSubmit(CenMode)
  {
   document.FormButton.CenMode.value = CenMode;
   document.FormButton.submit();
  }

function KeyPress(what,e,max,action)
  {
   if (document.layers)
     {
      if (e.target.value.length >= max)
        eval(action);
     }
   else if (document.all)
     {
      if (what.value.length > (max-1))
        eval(action);
     }
  }

function ReplaceChars(entry)
  {
   out = ","; // replace this
   add = ""; // with this
   temp = "" + entry; // temporary holder

   while (temp.indexOf(out)>-1) {
     pos= temp.indexOf(out);
   temp = "" + (temp.substring(0, pos) + add + 
   temp.substring((pos + out.length), temp.length));
  }
  return temp;
  }

function NumberFormat(what,e) {
  var arr=new Array('0'), i=0;
  var numbertoformat;
  if (document.layers)
     {
      numbertoformat=ReplaceChars(e.target.value);
     }
   else if (document.all)
     {
      numbertoformat=ReplaceChars(what.value);
     }
  while (numbertoformat>0) 
    {arr[i]=''+numbertoformat%1000; numbertoformat=Math.floor(numbertoformat/1000); i++;}
  arr=arr.reverse();
  for (var i in arr) if (i>0)
    while (arr[i].length<3) arr[i]='0'+arr[i];
  
  if (document.layers)
   {
    e.target.value=arr.join();
   }
 else if (document.all)
   {
    what.value=arr.join();
   }
}

function NumberFormatVariable(FieldValue) {
  var arr=new Array('0'), i=0;
  var numbertoformat;
  numbertoformat=ReplaceChars(FieldValue);
  while (numbertoformat>0) 
    {arr[i]=''+numbertoformat%1000; numbertoformat=Math.floor(numbertoformat/1000); i++;}
  arr=arr.reverse();
  for (var i in arr) if (i>0)
    while (arr[i].length<3) arr[i]='0'+arr[i];
  
  return arr.join();

}

function QuoteDetail(CenMode,QuoteKey)
  {
   document.FormButton.CenMode.value = CenMode;
   document.FormButton.QuoteKey.value = QuoteKey;
   document.FormButton.submit();
  }

function AcceptQuote(CenMode,CompanyKey,CompanySiteKey,CompanyMeterSiteKey,QuoteKey,CenAction)
  {
   document.FormButton.action = CenAction;
   document.FormButton.CenMode.value = CenMode;
   document.FormButton.CompanyKey.value = CompanyKey;
   document.FormButton.CompanySiteKey.value = CompanySiteKey;
   document.FormButton.CompanyMeterSiteKey.value = CompanyMeterSiteKey;
   document.FormButton.QuoteKey.value = QuoteKey;
   document.FormButton.submit();
  }

function CalculateSaving(CenMode,CompanyKey,CompanySiteKey,CompanyMeterSiteKey,QuoteKey,CenAction)
  {
   document.CalculateSaving.action = CenAction;
   document.CalculateSaving.CenMode.value = CenMode;
   document.CalculateSaving.CompanyKey.value = CompanyKey;
   document.CalculateSaving.CompanySiteKey.value = CompanySiteKey;
   document.CalculateSaving.CompanyMeterSiteKey.value = CompanyMeterSiteKey;
   document.CalculateSaving.QuoteKey.value = QuoteKey;
   document.CalculateSaving.target = "_blank";
   document.CalculateSaving.submit();
  }

function ValidateValue(whatvalue,action)
  {
    if (!Validate(whatvalue))
       {
        alert(~'Please only enter numeric values~');
        eval(action);
       }
  }

function Validate(string) 
  {
   if (!string) return false;
   var Chars = ".0123456789";
   for (var i = 0; i < string.length; i++)
     {
      if (Chars.indexOf(string.charAt(i)) == -1)
        return false;
     }
  return true;
  }

function SetInvoiceExample(InvoiceExample)
  {
  document.FormButton.InvoiceImage.value = InvoiceExample;
  }

function ControlWindowOpen(url,windowName,width,height,directories,location,menubar,scrollbars,status,toolbar,resizable)
  {
   var features =
               "width="        + width +
               ",height="      + height +
               ",directories=" + directories +
               ",location="    + location +
               ",menubar="     + menubar +
               ",scrollbars="  + scrollbars +
               ",status="      + status +
               ",toolbar="     + toolbar +
               ",resizable="   + resizable;
   
    msgWindow=window.open(url, windowName, features);
    if (msgWindow.opener == null) msgWindow.opener= self;
   }

function PrintForm()
  {
   document.FormButton.printdd.style.visibility="hidden";
   self.print();
   document.FormButton.printdd.style.visibility="visible";
  }

function PleaseWaitScreenVisible()
  {
   document.all.PleaseWaitScreen.style.pixelTop = (document.body.scrollTop + 50);
   document.all.PleaseWaitScreen.style.visibility="visible";
   window.setTimeout('PleaseWaitScreenHidden',1);
  }

function PleaseWaitScreenHidden()
  {
   document.all.PleaseWaitScreen.style.visibility="hidden";
  }

var isNN = (navigator.appName.indexOf("Netscape")!=-1);

function autoTab(input,len, e) {
var keyCode = (isNN) ? e.which : e.keyCode; 
var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
if(input.value.length >= len && !containsElement(filter,keyCode)) {
input.value = input.value.slice(0, len);
input.form[(getIndex(input)+1) % input.form.length].focus();
}

function containsElement(arr, ele) {
var found = false, index = 0;
while(!found && index < arr.length)
if(arr[index] == ele)
found = true;
else
index++;
return found;
}
function getIndex(input) {
var index = -1, i = 0, found = false;
while (i < input.form.length && index == -1)
if (input.form[i] == input)index = i;
else i++;
return index;
}
return true;
}

function swapcardimage(cardvalue, cardarray) {
if (cardvalue == "")
  {
   cardvalue = "space"
  }
if (cardvalue == " ")
  {
   cardvalue = "space"
  }

cardimage = "/images/" + cardvalue + ".gif";

if (cardarray == '1')
  {
   document.KeyOnline.FacCardImage1.src = cardimage;
  }
else if (cardarray == '2')
  {
   document.KeyOnline.FacCardImage2.src = cardimage;
  }
else if (cardarray == '3')
  {
   document.KeyOnline.FacCardImage3.src = cardimage;
  }
else if (cardarray == '4')
  {
   document.KeyOnline.FacCardImage4.src = cardimage;
  }
else if (cardarray == '5')
  {
   document.KeyOnline.FacCardImage5.src = cardimage;
  }
else if (cardarray == '6')
  {
   document.KeyOnline.FacCardImage6.src = cardimage;
  }
else if (cardarray == '7')
  {
   document.KeyOnline.FacCardImage7.src = cardimage;
  }
else if (cardarray == '8')
  {
   document.KeyOnline.FacCardImage8.src = cardimage;
  }
else if (cardarray == '9')
  {
   document.KeyOnline.FacCardImage9.src = cardimage;
  }
else if (cardarray == '10')
  {
   document.KeyOnline.FacCardImage10.src = cardimage;
  }
else if (cardarray == '11')
  {
   document.KeyOnline.FacCardImage11.src = cardimage;
  }
else if (cardarray == '12')
  {
   document.KeyOnline.FacCardImage12.src = cardimage;
  }
else if (cardarray == '13')
  {
   document.KeyOnline.FacCardImage13.src = cardimage;
  }
else if (cardarray == '14')
  {
   document.KeyOnline.FacCardImage14.src = cardimage;
  }
else if (cardarray == '15')
  {
   document.KeyOnline.FacCardImage15.src = cardimage;
  }
else if (cardarray == '16')
  {
   document.KeyOnline.FacCardImage16.src = cardimage;
  }
else if (cardarray == '17')
  {
   document.KeyOnline.FacCardImage17.src = cardimage;
  }
else if (cardarray == '18')
  {
   document.KeyOnline.FacCardImage18.src = cardimage;
  }
}

