function debug(s)
{
    //------------------------------------------
    // set this to true for debug alert messages.
    //------------------------------------------
    var debug=false;

    if ( debug )
    {
        alert(s);
    }//end if

}

/**
 * Determine if the supplied string contains accent characters
 */
function containsAccentCharacters( s )
{
     debug("*********************\n****[ Evaluating Accent Characters ("+s.length+"]\n*********************\n");
     for (i = 0; i < s.length; i++ )
     {
          debug("===> {"+i+"}["+s.charAt(i)+"=["+s.charCodeAt(i)+"]");
          if ( s.charCodeAt(i) > 127 )
          {
               debug("THIS CHARACTER IS INVALID =>["+s.charAt(i)+"]");
               return true;
          }//end if

     }//end for

     return false;
}//end function

/**
 * Determine if the supplied string is All Numbers
 */
function isNumeric( inputString )
{
     var numbers = "0123456789";
     var s = trim( inputString );
     var c = "";
     for (i = 0; i < s.length; i++ )
     {
          c = s.charAt( i );

          if ( numbers.indexOf(c) == -1 )
          {
               return false;
          }//end if

     }//end for

     return true;


}//end if


function trim(inputString)
{

   // Removes leading and trailing spaces from the passed string. Also removes
   // consecutive spaces and replaces it with one space. If something besides
   // a string is passed in (null, custom object, etc.) then return the input.

   debug("trim=>checking length");
   if ( inputString.length == 0 )
   {
       debug("length is already 0");
       return "";
   }//end if
   var retValue = inputString;

   var ch = retValue.substring(0, 1);
   while (ch == " ")
   { // Check for spaces at the beginning of the string
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }//end while

   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ")
   { // Check for spaces at the end of the string
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }//end while

   while (retValue.indexOf("  ") != -1)
   {
       retValue = retValue.replace('  ',' ');
/*
       // Note that there are two spaces in the string - look for multiple spaces within the string
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length);
      // Again, there are two spaces in each of the strings
*/
   }//end while
   debug("Returning ["+retValue+"]");

   return retValue; // Return the trimmed string back to the user
} //end function: trim


function validEmail(email)
{
    debug("Validating Email Address");
    if ( trim(email).length==0)
    {
        return false;
    }
    debug("Preparing regular expression.");

    if (email.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) == -1)
    {
        return false;
    }//end if

    return true;

}//end function


//###############################################################################
//###############################################################################
//###############################################################################
//###############################################################################
//###############################################################################

 function doSubmitContactRequest(form)
 {
     var comments = trim( form.Comments.value );
     var error = "";

     if ( ! doBasicValidation(form,false) )
     {
         return false;
     }//end if

     if ( comments.length < 2 )
     {
         error = "Please type your comments/questions in the \"Comments\" area below.";
     }//end if



     if ( error.length > 0 )
     {
         error = "To receive a reply from Unity:\n=====================\n" + error;
         alert(error);
         return false;
     }//end if


     return true;



 }//end function

 /**
  *
  */
 function doSubmitOnlineRequestUpdates(form)
 {
    return doBasicValidation( form ,true);
 }//end function

/**
  *
  */
 function doBasicValidation(form, requireMailingAddress)
 {
     var name     = trim( form.Name.value );
     var address1 = trim( form.Address1.value );
     var city     = trim( form.City.value );
     var state    = trim( form.State.value );
     var zipCode  = trim( form.Zipcode.value );

     var email    = trim( form.EmailAddress.value );

     var error="";

     if ( name.length < 3 )
     {
         error = error + "Please provide your Full Name.\n";
     }//end if

     if ( requireMailingAddress )
     {
         if (    ( address1.length < 3 ) || ( city.length < 3 )
              || ( state.length < 2 ) || ( zipCode.length < 5 )
            )
         {
             error = error + "Please provide your Full Mailing Address.\n";
         }//end if
     }//end if

     if ( email.length <  7 )
     {
         error = error + "Please provide your Email Address.\n";
     }
     else
     {
         if ( ! validEmail( email ) )
         {
             error = error + "Please provide a valid email address.\n  For example: fred@aol.com";
         }//end if
     }//end else

     if ( trim(error).length != 0 )
     {
         error = "To receive a reply from Unity:\n=====================\n" + error;
         alert(error);
         return false;
     }//end if


     return true;


 }//end function
