function validateForm(f) {
    highlightcolour = "#cc6666"
    normalcolour = "#FFF"
    valid = true;
    var errorsDiv = document.getElementById("errors");
    alertStr = "<br/>";
    requiredFields = "Title, titleSelect", "First Name, firstName", "Last Name, lastName", "Security code, strCAPTCHA"

    // validate fields in required fields array
	
    // validate required title
    /*if (f.titleSelect.value.length < 1) {
        f.titleSelect.style.background = highlightcolour;
        alertStr = alertStr + 'Title <% response.write formLabel.item("jsRequiredField").item(locale) %><br/>';
        valid = false;
    } else {
        f.titleSelect.style.background = normalcolour;
    }*/

    // validate required first name
    if (f.firstName.value.length < 1){ 
        f.firstName.style.background = highlightcolour;
        alertStr = alertStr + 'First Name is a required field.<br/>';
        valid = false;
    }else{
        f.firstName.style.background = normalcolour;
    }

    // validate required last name
    if (f.lastName.value.length < 1){ 
        f.lastName.style.background = highlightcolour;
        alertStr = alertStr + 'Last Name is a required field.<br/>';
        valid = false;
    }else{
        f.lastName.style.background = normalcolour;
    }

    // validate required organization
    /*if (f.organization.value.length < 1) {
        f.organization.style.background = highlightcolour;
        alertStr = alertStr + 'Organization is a required field.<br/>';
        valid = false;
    } else {
        f.organization.style.background = normalcolour;
    }*/

    // validate required email length
    if (f.emailAddress.value.length < 1) {
        f.emailAddress.style.background = highlightcolour;
        f.emailAddress.style.background = highlightcolour;
        alertStr = alertStr + 'Email is a required field.<br/>';
        valid = false;
    } else {
    // validate required email
        if (f.emailAddress.value.search("@") == -1 || f.emailAddress.value.search("[.*]") == -1) {
            f.emailAddress.style.background = highlightcolour;
            alertStr = alertStr + 'Email address is an invalid format.<br/>';
            valid = false;
        } else {
            f.emailAddress.style.background = normalcolour;
        }

    }

    // validate required address1
    /*if (f.address1.value.length < 1) {
        f.address1.style.background = highlightcolour;
        alertStr = alertStr + 'Address is a required field.<br/>';
        valid = false;
    } else {
        f.address1.style.background = normalcolour;
    }

    // validate required address1
    if (f.city.value.length < 1) {
        f.city.style.background = highlightcolour;
        alertStr = alertStr + 'City is a required field.<br/>';
        valid = false;
    } else {
        f.city.style.background = normalcolour;
    }*/

    // validate required state
    if (f.state.selectedIndex == 0) {
        // an option has been selected
        f.state.style.background = highlightcolour;
        alertStr = alertStr + 'State is a required field.<br/>';
        valid = false;
    } else {
        // no option selected
        f.state.style.background = normalcolour;
    }


    // validate zipCode length
    /*if (f.zipCode.value.length < 1) {
        f.zipCode.style.background = highlightcolour;
        alertStr = alertStr + 'Zip code is a required field.<br/>';
        valid = false;
    } else {
        f.zipCode.style.background = normalcolour;
    }*/

    // validate required Information
    /*if (validateInfo(f) == 0) {
        f.info.style.background = highlightcolour;
        alertStr = alertStr + 'Information is a required field.<br/>';
        valid = false;
    } else {
        // no option selected
        f.info.style.background = normalcolour;
    }*/

    
    // validate CAPTCHA length
    if (f.strCAPTCHA.value.length < 1) {
        f.strCAPTCHA.style.background = highlightcolour;
        alertStr = alertStr + 'Security code is a required field.<br/>';
        valid = false;
    } else {
        f.strCAPTCHA.style.background = normalcolour;
    }
    
    if (valid == false) {
    	//Comment out the next line for more detailed error messages.
    	alertStr = "Fields highlighted in red are required fields and are either empty or have errors. Please correct them before continuing."
        //Display error message in error div
    	errorsDiv.innerHTML = alertStr;
    	errorsDiv.style.display="block";
        //Return users to top of page if too long to fit in window
        window.scrollTo(0, 0);
    }
    return valid;
}

function validateInfo(f) {
    selected = 0;
    for (var i = 0; i < f.info.options.length; i++) {
        //alert(f.info.options[i].selected);
        if (f.info.options[i].selected == true) {
            selected++;
        }
    }
    return selected;
}
