
	function validate()
	{
	var bValid;
	
	bValid = IsEmptyField(document.form1.txtBillingAddress.value,"Street");
	if (bValid==false){
		return false
		}
		
		
	bValid = IsEmptyField(document.form1.txtCity.value,"City");
	if (bValid==false){
		return false
		}
	
	bValid = IsValueSelected(document.form1.cboState.value,"State");
		if (bValid==false){
		return false
		}
		
	
		
	bValid = IsEmptyField(document.form1.txtZip.value,"Zip Code");
	if (bValid==false){
		return false
		}
		
	bValid = ValidZipCode(document.form1.txtZip.value);
	if (bValid==false){
		return false
		}
		
	bValid = IsEmptyField(document.form1.txtCountry.value,"Country");
	if (bValid==false){
		return false
		}
		
	bValid = IsValueSelected(document.form1.cboMemberShipPlan.value,"Membership Plan");
		if (bValid==false){
		return false
		}
	bValid = IsBillingMethodSelected()
		if (bValid==false){
			return false
			}
	
	if (document.form1.PaymentMethod[0].checked==true)
		{
			//validate credit card fields
			
			bValid = checkCCInput();
			if (bValid==false){
				return false
				}		
			
			bValid = IsEmptyField(document.form1.txtCardholderName.value,"Cardholder Name for this Payment Method");
			if (bValid==false){
				return false
				}
			
			
		}
		
	if (document.form1.PaymentMethod[1].checked==true)	
		{
			//validate Bank Info fields
			bValid = IsEmptyField(document.form1.txtBankName.value,"Bank Name for this Payment Method");
			if (bValid==false){
				return false
				}
			
			bValid = IsEmptyField(document.form1.txtBankRoutingNumber.value,"Bank Routing Number for this Payment Method");
			if (bValid==false){
				return false
				}
				
			bValid = IsEmptyField(document.form1.txtBankAccountName.value,"Bank Account Name for this Payment Method");
			if (bValid==false){
				return false
				}
				
			bValid = IsEmptyField(document.form1.txtBankAccountNumber.value,"Bank Account Number for this Payment Method");
			if (bValid==false){
				return false
				}
		}
	}
	
	function checkCCInput() {
	
	var msg1   = new String("");
	var ccType = new Number(form1.cboCCTypes.value);
	var ccNum  = form1.txtCCN.value;
	ccNum = ccNum.length;

	if (ccType < 1 || ccType > 4 ) {
		msg1 += "The credit card type you have entered is invalid.";
		alert(msg1);
		return(false);
	}
	if (ccNum < 13 || ccNum > 20) {
		msg1 += "The credit card number must be 13 to 20 ";
		msg1 += "characters in length, depending on the card\'s type.";
		alert(msg1);
		return(false);
	}

}
	
	function IsBillingMethodSelected()
	{
		var MethodOption = -1;
		for (i=0; i<document.form1.PaymentMethod.length; i++)
		{
			if(document.form1.PaymentMethod[i].checked)
				{
				MethodOption = i;
				}
		}
		if (MethodOption == -1)
			{
				alert("You must choose Payment Method Option");
				return false
			}
	}
	
	function IsValueSelected(value,fieldname)
	{
		if (value==0)
		{
			alert("Select " + fieldname);
			return false
		}
	}
	
	function IsEmptyField(formelement,fieldname)
	{
		// check to see if the field is blank
		if (formelement == "")
			{
				alert("You must enter an " + fieldname);
				return (false);
			}
	}
	
	function ValidZipCode(passedVal)
	{
	
		if (passedVal.length != 5)
			{
				alert("Invalid Zip Code");
				return(false);
			}
		for(i=0;i<passedVal.length;i++) 
		{
			if (passedVal.charAt(i)<"0")
				{
					alert("Invalid Zip Code");
					return(false);
					break;
				}
			if (passedVal.charAt(i)>"9")
				{
					alert("Invalid Zip Code");
					return(false);
					break;
				}
		}
	}
	
	
function isblank(s) {
    for(var i = 0; i < s.length; i++) {
        var c = s.charAt(i);
        if ((c != ' ') && (c != '\n') && (c != '\t')) return false;
    }
    return true;
}

// This is the function that performs form verification. It is invoked
// from the onsubmit event handler. The handler should return whatever
// value this function returns.

function verify(f) {
    var msg;
    var empty_fields = "";
    var errors = "";

    // Loop through the elements of the form, looking for all 
    // text and textarea elements that don't have an "optional" property
    // defined. Then, check for fields that are empty and make a list of them.
    // Also, if any of these elements have a "min" or a "max" property defined,
    // verify that they are numbers and in the right range.
    // If the element has a "numeric" property defined, verify that
    // it is a number, but don't check its range.
    // Put together error messages for fields that are wrong.
    for(var i = 0; i < f.length; i++) 
    {
        var e = f.elements[i];
        if (((e.type == "text") || (e.type == "textarea")) && !e.optional) 
        {
            // first check if the field is empty
            if ((e.value == null) || (e.value == "") || isblank(e.value)) 
            {
                empty_fields += "\n          " + e.name;
                continue;
            }

            // Now check for fields that are supposed to be numeric.
            if ((e.numeric==true) || (e.min != null) || (e.max != null)) 
            { 
            
                var v = parseFloat(e.value);
                if (isNaN(v) || 
                    ((e.min != null) && (v < e.min)) || 
                    ((e.max != null) && (v > e.max)))
                    {
                    
                    errors += "- The field " + e.name + " must be a number";
                    if (e.min != null) 
                        errors += " that is greater than " + e.min;
                    if (e.max != null && e.min != null) 
                        errors += " and less than " + e.max;
                    else if (e.max != null)
                        errors += " that is less than " + e.max;
                    errors += "\n";
					}
            }
            if(e.RegExp != null){
            if(!e.RegExp.test(e.value))
            {
			errors += "- The field " + e.name + " not valid ";
			 errors += "\n";	
            }
            }
        }
       
        if ((e.type == "select-one") && !e.optional)
        {
			if ((e.value==0)||(e.value==null))
				{
				errors += "- Select " + e.name;	
				errors += "\n";
				}
        }
        
        if ((e.name == "Password") && (f.elements[i+1].name =="ConfirmPassword")) 
        {
			if (e.value != f.elements[i+1].value)
				{
				errors += "- Password and Confirm Password must match";	
				errors += "\n";
				}
        }  
    }

    // Now, if there were any errors, display the messages, and
    // return false to prevent the form from being submitted. 
    // Otherwise return true.
    if (!empty_fields && !errors) return true;

    msg  = "______________________________________________________\n\n"
    msg += "The form was not submitted because of the following error(s).\n";
    msg += "Please correct these error(s) and re-submit.\n";
    msg += "______________________________________________________\n\n"

    if (empty_fields) {
        msg += "- The following required field(s) are empty:" 
                + empty_fields + "\n";
        if (errors) msg += "\n";
    }
    msg += errors;
    alert(msg);
    return false;
}
