function CheckChar(loginid){
    invalidChars = " /:,;";
  
    for (i=0; i< invalidChars.length;i++){
      badChar = invalidChars.charAt(i)
      if (loginid.indexOf(badChar,0) > -1){
        return false
      }
    }
  return true
}
  
function CheckNumber(number){
  for  (i=0; i< number.length;i++){
    if ((number.charAt(i)) < "0"){
      return false
    }
    if ((number.charAt(i)) > "9"){
      return false
    }
  }
  return true
}
  
function validate(theform, subscribe, paid){
  var blnRetval, intAtSign, intDot, intComma, intSpace, intLastDot, intDomain, intStrLen;
    error_msg = "";

  intAtSign=theform.email.value.indexOf('@');
  intDot=theform.email.value.indexOf('.',intAtSign);
  intComma=theform.email.value.indexOf(',');
  intSpace=theform.email.value.indexOf(' ');
  intLastDot=theform.email.value.lastIndexOf('.');
  intDomain=intDot-intAtSign;

  intStrLen=theform.email.value.length;

  if ( subscribe==1 )  {
	  //alert(subscribe);
    if ( !theform.subscribe.checked) {
      error_msg = "Subscribing member box is mandatory.\n";
      alert( error_msg );
      theform.subscribe.focus();

      return false;
    }
  }

  if (theform.email.value == '' ) {
    alert("Please Input Your Email Address.");
    theform.email.focus();
    return false;
  }     
  else if (intAtSign == -1 || intAtSign == 0 || intComma != -1 || intSpace != -1 || intDot <= 2 || intDomain <= 1 ||  intStrLen-(intLastDot+1) < 2 ) {
    alert('Your Email Address is invalid!');
    theform.email.focus();
    return false;
  }

  if (theform.userpassword.value.length == 0){
    error_msg = "Password is mandatory.\n";
    alert(error_msg);
    theform.userpassword.focus();
    return false;
  }
  if (theform.userpassword.value.length < 6){
    error_msg = "Min. 6 chars is required for Password.\n";
    alert(error_msg);
    theform.userpassword.focus();
    return false;
  }
  if (theform.verifyuserpassword.value.length == 0){
    error_msg = "Verify Password is mandatory.\n";    
    alert(error_msg);
    theform.verifyuserpassword.focus();
    return false;
  }

  if (theform.userpassword.value != ""){
    if (theform.verifyuserpassword.value != ""){
      if (theform.userpassword.value != theform.verifyuserpassword.value){
        error_msg = "Entered passwords do not match.\n";
        alert(error_msg);
        theform.userpassword.focus();
        return false;
      }
    }
  }    

  if (theform.firstname.value.length == 0){
    error_msg += "First name is mandatory.\n";  
    alert(error_msg);
    theform.firstname.focus();
    return false;
  }

  if (theform.lastname.value.length == 0){
    error_msg += "Last name is mandatory.\n";  
    alert(error_msg);
    theform.lastname.focus();
    return false;
  }

  if (theform.hometel.value.length == 0){
    error_msg += "Home Phone Number is mandatory.\n";
    alert(error_msg);
    theform.hometel.focus();
    return false;
  } 

  if (!CheckNumber(theform.hometel.value)){
    error_msg += "Home Phone Number is not an number.\n";  
    alert(error_msg);
    theform.hometel.focus();
    return false;
  }

  if (theform.worktel.selectedindex == 0){
    error_msg += "Work Phone Number is mandatory.\n";
    alert(error_msg);
    theform.worktel.focus();

    return false;
  } 

  if (theform.mailaddr1.value.length == 0){
    error_msg += "Mailing address is mandatory.\n";  
    alert(error_msg);
    theform.mailaddr1.focus();

    return false;
  }

  if ( paid != 1 )  {
    if (theform.cardtype.value == 0){
      error_msg += "Card Type is mandatory.\n";
      alert(error_msg);
      theform.cardtype.focus();

	  return false;
    } 

    if (theform.cardnum.value == 0){
      error_msg += "Card Number is mandatory.\n";      
      alert(error_msg);
      theform.cardnum.focus();

      return false;
    }

    if (!CheckChar(theform.cardnum.value)) {
      error_msg += "Card Number cannot contain any invalid characters.\n";
      alert(error_msg);
      theform.cardnum.focus();

      return false;
    }

    if (!CheckNumber(theform.cardnum.value)) {
      error_msg += "Card Number cannot contain letters.\n";
      alert(error_msg);
      theform.cardnum.focus();

      return false;
    }

    if (theform.expmonth.value == 0){
      error_msg += "Expire Month is mandatory.\n";
      alert(error_msg);
      theform.expmonth.focus();

      return false;
    }

    if (theform.expyear.value == 0){
      error_msg += "Expire Year is mandatory.\n";
      alert(error_msg);
      theform.expyear.focus();

      return false;
    }
  }

  return true;
}



function copy_addr(theform) {
  theform.dlvyaddr1.value = theform.mailaddr1.value;
  theform.dlvyaddr2.value = theform.mailaddr2.value;
  theform.dlvyaddr3.value = theform.mailaddr3.value;
}