function ValidateForm(f) {
	var pattern = "";
	validateMsg = "";
	validateCount = 0;
	focusSet = 0;

// Check that all fields are populated correctly
	
	if ( f.first_name.value == "" ) {
		validateMsg += "    First Name\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.first_name.focus();
			focusSet = 1;
		}
	}
	if ( f.last_name.value == "" ) {
		validateMsg += "    Last Name\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.last_name.focus();
			focusSet = 1;
		}
	}
	if ( f.email.value == "" ) {
		validateMsg += "    E-mail\n";
		validateCount += 1;
		f.email.focus();
		focusSet = 1;
	}
	if ( f.address1.value == "" ) {
		validateMsg += "    Address 1\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.address1.focus();
			focusSet = 1;
		}
	}
	if ( f.city.value == "" ) {
		validateMsg += "    City\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.address1.focus();
			focusSet = 1;
		}
	}
	if ( f.country.value == "US" ) {
		if ( f.state.value == "" ) {
			validateMsg += "    State\n";
			validateCount += 1;
			if ( ! focusSet ) {
				f.country.focus();
				focusSet = 1;
			}
		}
		if ( f.zip.value == "" ) {
			validateMsg += "    Zip Code\n";
			validateCount += 1;
			if ( ! focusSet ) {
				f.zip.focus();
				focusSet = 1;
			}
		}
		else if ( f.zip.value.match(/\d{5}/) == null &&
			  f.zip.value.match(/\d{9}/) == null ) {
			     alert("Please enter only the numbers of your 5-digit or 9-digit zip code");
			     f.zip.focus();
			     return false;
		}		
		if ( f.phone_areacode.value.length != 3  || 
		     f.phone_part_1.value.length != 3  || 
		     f.phone_part_2.value.length != 4 ) {
			validateMsg += "    Phone\n";
			validateCount += 1;
			if ( ! focusSet ) {
				f.phone_area_code.focus();
				focusSet = 1;
			}
		}
		else if ( f.phone_areacode.value.match(/\d{3}/) == null || 
			  f.phone_part_1.value.match(/\d{3}/) == null || 
			  f.phone_part_2.value.match(/\d{4}/) == null ) {
			     alert("Please enter only the numbers of your phone number");
			     f.phone_areacode.focus();
			     return false;
		}
	}

	if ( f.invamt.value == "" ) {
		validateMsg += "    Amount Due\n";
		validateCount += 1;
		if ( ! focusSet ) {
			f.invamt.focus();
			focusSet = 1;
		}
	}

// Announce any missing fields

	if ( validateCount > 0 ) {
		var instructions = "Please complete the following required field";
		if ( validateCount > 1 ) {
			instructions += "s:\n";
		}
		else {
			instructions += ":\n";
		}
		alert( instructions + validateMsg );
		return false;
	}

// Assemble the BUSINESS e-mail address - disassembled to prevent spam

	f.business.value = f.e_handle.value + "@" + f.e_domain.value + "." + f.e_extension.value;

// Assemble item name using invoice number or service address

	if ( f.invnum.value.length > 0 ) {
		f.item_name.value = "Lawn Care Service for Invoice Number " + f.invnum.value;
	}
	else {
		f.item_name.value = "Lawn Care Service for " + f.saddress.value;
	}

// Populate additional input elements to be passed back for receipt

	f.custom.value = f.address1.value + ":" + f.city.value + ":" + f.state.value + ":" + 
			 f.zip.value + ":" + f.address2.value + ":" + 
			 f.invnum.value + ":" + f.saddress.value;

	f.amount.value = f.calc_amount.value;

if ( f.payoption.value == "paypal" )
		alert("You will now be redirected to a Secure PayPal window\n" + 
			"to make your payment by credit card or from your PayPal account.");
	else // check
		alert("You will now be redirected to a Secure Check Payment window.\n" +
			"If you are prompted by a Security Alert pop-up window, please click OK to proceed.");
	
// If paying by check, open the check window, otherwise do nothing and return true

	return true; //openCheckWindow(f);
}

function calculate_total(f)

{

// For PayPal payments only , mark up amount by 2.9% convenience charge + .30 per invoice

            if ( f.payoption[1].checked ) {

                        f.calc_amount.value = (f.invamt.value * 1.029) +.30;

                        //alert (f.calc_amount.value);

                        f.calc_amount.value = Math.round(f.calc_amount.value * 1000)/1000;

                        //alert (f.calc_amount.value);

                        f.calc_amount.value = cent(f.calc_amount.value);

                        //alert (f.calc_amount.value);

            }

            else {

                        f.calc_amount.value = f.invamt.value;

            }

}

 

function cent(amount) {

// returns the amount in the .99 format 

    amount -= 0;

    amount = (Math.round(amount*100))/100;

    return (amount == Math.floor(amount)) ? amount + '.00' : (  (amount*10 == Math.floor(amount*10)) ? amount + '0' : amount);

}


function pop_saddress(f)
{
	f.saddress.value = f.address1.value;
}

function pop_scity(f)
{
	f.scity.value = f.city.value;
}
