/*
 ***************************************************************************
 *** Midwest Cooperating Communications Company
 *** Copyright (C) 2010-2013
 *** 
 *** Filename: client-side.js
 *** Date:     03/2011
 *** Version:  1.0.1
 *** Purpose:  Provides JavaScript functions to MWCC website clients.
 *** Author:   Casey Cannady of Digital Barn, Inc. (www.digital-barn.com)
 *** ***************************************************************************
 */

// --------------------------------------------------
// FUNCTION::ContactValidator
// --------------------------------------------------
function ContactValidator(theForm)
{
   // Check the FirstName field
   if ((theForm.txtFirstName.value == "") ||
       (theForm.txtFirstName.value.length < 3) ||
       (theForm.txtFirstName.value.length > 255))
   {
      alert("Please enter your \"First Name\".");
      theForm.txtFirstName.focus();
      return(false);
   }
   
   // Check the LastName field
   if ((theForm.txtLastName.value == "") ||
       (theForm.txtLastName.value.length < 3) ||
       (theForm.txtLastName.value.length > 255))
   {
      alert("Please enter your \"Last Name\".");
      theForm.txtLastName.focus();
      return(false);
   }
   	
   // Check the e-mail field
   if ((theForm.txtEmail.value == "") ||
       (!ValidateEmailAddr(theForm.txtEmail.value)))
   {
      alert("Please enter your \"E-Mail\" address.");
      theForm.txtEmail.focus();
      return(false);
   }
   
   // Check the phone number field
   if ((theForm.txtPhone.value == "") || 
       (theForm.txtPhone.value.length < 7) || 
       (theForm.txtPhone.value.length > 255))
   {
      alert("Please enter your \"Phone Number\".");
      theForm.txtPhone.focus();
      return(false);
   }
   
   // Make sure the user selected a valid option
   if (theForm.selTopic.selectedIndex == 0)
   {
      alert("The \"Select a topic.\" option is not a valid selection.\nPlease choose one of the other options.");
      theForm.selTopic.focus();
      return(false);
   }
   
   // Set good return value
   return(true);
}

// --------------------------------------------------
// FUNCTION::ValidateEmailAddr
// --------------------------------------------------
function ValidateEmailAddr(strInput)
{
   var emReg = new RegExp();
   emReg = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
   if(emReg.test(strInput))
   {
      return(true);
   }
   return(false);
}

