  //******************************************************************************
  // validation.js
  // Copyright 2000, Logic Solution, Inc.
  //******************************************************************************

  //
  // This is a collection of javascript functions to validate a date input
  // by a user into an html form.  It will accept mm/dd/yy or mm/dd/yyyy.
  //

  function LSICheckDate(field) {
    value=field.value;
    if ((value.length<6) || (value.length>10)) { return false; }
    else  {
      value=LSICheckBothFormat(field,value);
      value=LSICheckMonthFormat(field,value);
      value=LSICheckDayFormat(field,value);
      value=LSICheckCentury(field,value);
       if (value.length>10) {return false;}   
      if (LSICheckFormat(field,value)) return true;
      return false;
    }
  }

  function LSICheckCentury(field,day) {
    if (day.length==8) {
      day=day.substring(0,6) + "20" + day.substring(6,8);
      field.value=day;
    }
    return day;
  }

  function LSICheckBothFormat(field,day) {
    if ((day.charAt(1)=="/") && (day.charAt(3)=="/")) {
      day = "0" + day.substring(0,1) + "/0" + day.substring(2,9);
      field.value=day;
    }
    return day;
  }

  function LSICheckMonthFormat(field,day) {
    if (day.charAt(1)=="/") {
      day = "0" + day;
      field.value=day;
    }       
    return day;
  }

  function LSICheckDayFormat(field,day) {
    if (day.charAt(4)=="/") {
      day = day.substring(0,2) + "/0" + day.substring(3,9);
      field.value=day;
    }
    return day;
  }

  function LSICheckFormat(field,day) {
    var bError = false;
    var aChar = null;
    var holder = null;      
    var Short =0;
    var FebCheck = null;
    var NovCheck = 0;
    var MonthCheck = null;
    var Reference = day
    for (i = 0; i < 10; i++) {
      aChar = day.charAt(i)
      if (i == 0 && day.charAt(0)==0 && day.charAt(1)==0) bError = true;
      if (i == 0 && day.charAt(3)==0 && day.charAt(4)==0) bError = true;
      if (i == 0 && day.charAt(6)==0) bError = true;

      if (i == 0 && aChar < "0" || aChar > "9") bError = true;
      if (i == 0 && aChar > 1) bError = true;
      if (i == 0 && aChar ==1) {MonthCheck=1;NovCheck=1;}

      if (i == 1 && aChar < "0" || aChar > "9") bError = true;
      if (i == 1 && aChar == 2) FebCheck=1;
      if (i == 1 && MonthCheck == 1 && aChar >2) bError = true;
      if (i == 1 && aChar == 4 || aChar ==6 || aChar ==9) Short=1;
      if (i == 1 && NovCheck == 1 && aChar == 1) Short=1;

      if (i == 2 && aChar != '/')  bError = true;

      if (FebCheck == 1 && NovCheck != 1) {
        if (i==3 && aChar > 2) bError = true;
      }

      if (i == 3 && aChar < "0" || aChar > "9") bError = true;
      if (i == 3 && aChar > 3) bError = true;        
      if (i == 3 && aChar ==3) holder=1;

      if (i == 4 && aChar < "0" || aChar > "9") bError = true;
      if (i == 4 && aChar >0 && Short==1 && holder==1) bError = true;
      if (i == 4 && aChar >1 && holder==1) bError = true;

      if (i == 5 && aChar != '/')  bError = true;

      if (i == 6 && aChar < "1" || aChar > "9") bError = true;
      if (i == 7 && aChar < "0" || aChar > "9") bError = true;
      if (i == 8 && aChar < "0" || aChar > "9") bError = true;
      if (i == 9 && aChar < "0" || aChar > "9") bError = true;                        
    }
    if ((Reference.substring(0,5) =="02/29") && Reference.substring(6,10) %4 !=0)  {
      return false;
    }
    if (bError) {
      return false;
    }
    return true;
  }
  
  
  //----------------------------------------------------------------------------------------
  
  function formatCurrency(num) {
   //
  // This is a collection of javascript functions to format a currency input.
  // and also convert the currcy string to double type string.
  //
      num = num.toString().replace(/\$|\,/g,'');
      if(isNaN(num)) num = "0";
      cents = Math.floor((num*100+0.5)%100);
      num = Math.floor((num*100+0.5)/100).toString();
      if(cents < 10) cents = "0" + cents;
      for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
      num = num.substring(0,num.length-(4*i+3))+','+num.substring(num.length-(4*i+3));   
      return ('$' + num + '.' + cents);
  }

   function currencyToStrDigit(currency){
      // this function SHOULD be used just after calling function formatCurrency
      // we assume that the input string always keep format of $0.00
      digit = currency.substring(1,currency.length)       // strip the $       
      while(digit.indexOf(',',0)!=-1){
         digit = digit.replace(',','')
         if(digit.indexOf(',',0)==-1) break;
      }
      return digit
   }
   
   //----------------------------------------------------------------------------------------
    function formatPercentage(num) {
     //
     // This is a collection of javascript functions to format a percentage input.
     // and also convert the percentage string to double type string.
     //
      num = num.toString().replace(/\%|\,/g,'');
      if(isNaN(num)) num = "0";      
      cents = Math.floor((num*100+0.5)%100);
      num = Math.floor((num*100+0.5)/100);
      if (num >100)
         num = "100";
      else
         num = num.toString();      
      if(cents < 10) cents = "0" + cents;
      return (num + '.' + cents+'%');        
   }
   
   function percentageToStrDigit(percentage){
      // this function SHOULD be used just after calling function formatPercentage
      // we assume that the input string always keep format of 0.00%
      digit = percentage.substring(percentage.length-1,percentage.length)       // strip the %      
      return digit
   }
   
   //----------------------------------------------------------------------------------------
            
   function formatDigitUp(num){ 
      if(isNaN(num)) num="0";
      num = Math.ceil((num*100)/100).toString() ;
      return num  
   }
   
   function formatDigit(num){ 
      if(isNaN(num)) num="0";
      return num  
   }
  
  
  
  
  
  
  
  

