function isValidEmail(strValue)
{
//This function will 
  var regExp = /^(.+@[^\.].*\.[a-z]{2,})(;.+@[^\.].*\.[a-z]{2,})*$/
     // set the default return value
     var blnResult = true;
     var arrMatch = strValue.match(regExp);

     if (arrMatch == null)
          blnResult = false;

     return (blnResult);
}


function isPostalCode(entry)
{
  strlen = entry.length; 
  if (strlen != 6) {return false;}
  entry=entry.toUpperCase();        // in case of lowercase characters
  // Check for legal characters in string - note index starts at zero
  if ('ABCEGHJKLMNPRSTVWXYZ'.indexOf(entry.charAt(0)) < 0) {return false;}
  if ('0123456789'.indexOf(entry.charAt(1)) < 0) {return false;}
  if ('ABCEGHJKLMNPRSTVWXYZ'.indexOf(entry.charAt(2)) < 0) {return false;}
  if ('0123456789'.indexOf(entry.charAt(3)) < 0) {return false;}
  if ('ABCEGHJKLMNPRSTVWXYZ'.indexOf(entry.charAt(4)) < 0) {return false;}
  if ('0123456789'.indexOf(entry.charAt(5)) < 0) {return false;}
  return true; 
}
function ValidateForm(form)
{

if ( (trimAll(form.email.value)) == "")
  {
    alert("Please insert an email address");
    form.email.focus();
    return false;
  }

    //Validate the email address
    //if (!isValidEmail(your.email.value)) {
    if (!/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,6})+$/.test(form.email.value)){
      alert("Please insert a valid email address.");
      form.email.focus();
      return false;
    }
    
      
    
    //email and Confrmemail must be the same
    if ( form.email.value != form.Confrmemail.value )
    {
      alert("Please enter the same Email for fields 'Your Email' and 'Confirm Your Email'. They are case-sensitive.")
      form.email.focus();
      return false;
    }

   
   


   




if ( (trimAll(form.toemail.value)) == "")
  {
    alert("Please insert an email address");
    form.toemail.focus();
    return false;
  }

    //Validate the email address
    //if (!isValidEmail(form.toemail.value)) {
    if (!/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,6})+$/.test(form.toemail.value)){
      alert("Please insert a valid email address for friend.");
      form.toemail.focus();
      return false;
    }
    
    
    
    //email and Confrmtoemail must be the same
    if ( form.toemail.value != form.Confrmtoemail.value )
    {
      alert("Please enter the same Email for fields 'Friends Email' and 'Confirm Friends Email'. They are case-sensitive.")
      form.toemail.focus();
      return false;
    }

   

  return true;
}//end ValidateForm


function SelectAll(selectall, fields)
{
  if (selectall.checked) {
  for (i = 0; i < fields.length; i++)
    fields[i].checked = true;
  }
  else {
  for (i = 0; i < fields.length; i++)
    fields[i].checked = false;
 }

}  
//Javascript Trim equivalent
function trimAll(sString) 
{
   while (sString.substring(0,1) == ' ')
   {
      sString = sString.substring(1, sString.length);
   }
   while (sString.substring(sString.length-1, sString.length) == ' ')
   {
      sString = sString.substring(0,sString.length-1);
   }
   return sString;
}
