function checkPost () {
    if(checkForWhiteSpace(document.postClassified.user.value)) {
        alert("Please enter your name");
        document.postClassified.user.focus();
        return false;
    }
    var emailString = document.postClassified.email.value;
    if(!emailString.match(/^[^@]+@([-\w]+\.)+[A-Za-z]{2,4}$/)) {
        alert("Please enter a valid email address");
        document.postClassified.email.focus();
        return false;
    }
    
    if(checkForWhiteSpace(document.postClassified.town.value)) {
        alert("Please enter your city");
        document.postClassified.town.focus();
        return false;
    }        
    if(document.postClassified.state.selectedIndex == 0) {
        alert("Please select a state");
        document.postClassified.state.focus();
        return false;
    }
    if(document.postClassified.type.selectedIndex == 0) {
        alert("Please select a listing type");
        document.postClassified.type.focus();
        return false;
    } 
    if(document.postClassified.Animal.selectedIndex == 0) {
        alert("Please select a pet type");
        document.postClassified.Animal.focus();
        return false;
    }       
    if(checkForWhiteSpace(document.postClassified.Dsc.value)) {
        alert("Please enter a description");
        document.postClassified.Dsc.focus();
        return false;
    }
    if(checkForWhiteSpace(document.postClassified.password.value)) {
        alert("Please enter a password for deletion");
        document.postClassified.password.focus();
        return false;
    }
    if(document.postClassified.password.value != document.postClassified.password2.value) {
        alert("The passwords you have entered do not match");
        document.postClassified.password.focus();
        return false;
    }
    return true;
}

// Check whether string s is empty.
function checkForEmpty(s) {
    return ((s === null) || (s.length === 0));
}


function checkForWhiteSpace (s) {
    var i;
    var whitespace = " \t\n\r";
    // Is s empty?
    if (checkForEmpty(s)) { return true; }

    for (i = 0; i < s.length; i=i+1) {
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (whitespace.indexOf(c) == -1) { return false; }
    }

    // All characters are whitespace.
    return true;
}

