// Form Verification
function submit_page() {
    foundError = false;
    // FIRST CHECK FOR BLANK FIELDS

	form = window.document.buyablock;

    // Make sure the company field is not blank
    if(isFieldBlank(form.company)) {
        alert("You left the Company field blank.");
        foundError = true;
    }

    // Make sure the name field is not blank
    if(foundError == false && isFieldBlank(form.name) == true) {
        alert("You left the Name field blank.");
        foundError = true;
    }

    // Make sure the address field is not blank
    if(foundError == false && isFieldBlank(form.address1) == true) {
        alert("You left the Address field blank.");
        foundError = true;
    }

    // Make sure the city field is not blank
    if(foundError == false && isFieldBlank(form.city) == true) {
        alert("You left the City field blank.");
        foundError = true;
    }

    // Make sure the country field is not blank
    if(foundError == false && isFieldBlank(form.countrycode) == true) {
        alert("Please choose a Country.");
        foundError = true;
    }

    // Make sure the phone field is not blank
    if(foundError == false && isFieldBlank(form.phone) == true) {
        alert("You left the Phone field blank.");
        foundError = true;
    }

    // NOW LET'S CHECK THAT THE EMAIL FIELD IS VALID

    // Now make sure the email is valid
    if(foundError == false && isValidEmail(form.email) == false) {
        alert("You did not enter a valid email address.");
        foundError = true;
    }

    if(foundError == false)
		return true;
    else
    	return false;
}

// Check for a blank field
function isFieldBlank(theField) {
    if(theField.value == "")
        return true;
    else
        return false;
}

// Check for a valid email address (Does it contain a "@" and valid form)
function isValidEmail(theField) {
	var str=theField.value
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	if (filter.test(str))
		testresults=true
	else{
		testresults=false
	}
	return (testresults)
}
   
