<!--

//=====================================================================
//
//===================================================================== 
function ValidateListCustomersForm()
{
  var phoneStr = document.listCustomer.cust_phone.value;

  if(phoneStr.length <= 0)
    return true;

  phoneStr = phoneStr.replace(/-/g, '');

  if (isNaN(phoneStr) || (phoneStr.length != 10))
  {
    alert("Please enter a valid phone number (ie. 613-555-5555 or 6135555555)");
    document.listCustomer.cust_phone.focus();
    return false;
  }

  var areaCode = phoneStr.substring(0,3);
  var phonePrefix = phoneStr.substring(3,6);
  var phoneSuffix = phoneStr.substring(6);

  phoneStr = areaCode + '-' + phonePrefix + '-' + phoneSuffix;
  document.listCustomer.cust_phone.value = phoneStr;
  return true;
}

//=====================================================================
//
//===================================================================== 
function ValidateFindInvoiceForm()
{
  var invID = document.findInvoice.invoice_id.value;

  if (!invID || isNaN(invID) ) 
  { 
    alert("Please enter a valid invoice id");
    document.findInvoice.invoice_id.focus();
    return false;
  }

  document.findInvoice.find_invoice.focus();
  document.findInvoice.find_invoice.blur();

  return true;
}

//=====================================================================
//
//=====================================================================
function ValidateListInvoicesForm()
{
  var phoneStr = document.listInvoices.cust_phone.value;
 
  if(phoneStr.length > 0)
  {
     phoneStr = phoneStr.replace(/-/g, '');

    if (isNaN(phoneStr) || (phoneStr.length != 10))
    {
      alert("Please enter a valid phone number (ie. 613-555-5555 or 6135555555)");
      document.listInvoices.cust_phone.focus();
      return false;
    }

    var areaCode = phoneStr.substring(0,3);
    var phonePrefix = phoneStr.substring(3,6);
    var phoneSuffix = phoneStr.substring(6);

    phoneStr = areaCode + '-' + phonePrefix + '-' + phoneSuffix;
    document.listInvoices.cust_phone.value = phoneStr;
  }

  var startDate = "";
  var today = new Date();
  
  var curr_day   = today.getDate();
  var curr_month = today.getMonth() + 1;
  var curr_year  = today.getFullYear();

  var selection = document.listInvoices.listdates.value;

  if(selection == "last7d" || selection == "last2w")
  {
    var numOfDays;     
    if(selection == "last7d")
      numOfDays = 7;
    else  
      numOfDays = 14;     

    if(curr_day <= numOfDays)
    {
      if(curr_month == 1) {
        curr_year--;
        curr_month = 12;
        curr_day = (curr_day - numOfDays) + 31;
      }   
      else if(curr_month == 3)
      {
        curr_month--;
        curr_day = (curr_day - numOfDays) + 28; 
      }
      else if(curr_month == 2 || curr_month == 6 || curr_month == 9 || curr_month == 11)
      {
        curr_month--;
        curr_day = (curr_day - numOfDays) + 31; 
      }
      else
      {
        curr_month--;
        curr_day = (curr_day - numOfDays) + 30; 
      }
    }
    else
    {
      curr_day -= numOfDays;
    }
  }
  else if(selection == "last3m")
  {
    if (curr_month <= 3)
    {
      curr_year--;
      curr_month = (curr_month - 3) + 12;
    }
    else
    {
      curr_month -= 3; 
    }
  }
  else if(selection == "last6m")
  {
    if (curr_month <= 6)
    {
      curr_year--;
      curr_month = (curr_month - 6) + 12;
    }
    else
    {
      curr_month -= 6; 
    }    
  }
  else if(selection == "currentm")
  {
    curr_day = 1; 
  }

  
  if(curr_day < 10)
    curr_day = "0" + curr_day;

  if(curr_month < 10)
    curr_month = "0" + curr_month;
   
  startDate = curr_year + "-" + curr_month + "-" + curr_day;
  document.listInvoices.startDate.value = startDate;
  
  return true;   
}

//-->
