String.prototype.trim = function(){ return this.replace(/^\s*|\s*$/g,''); }
String.prototype.ltrim = function(){ return this.replace(/^\s*/g,''); }
String.prototype.rtrim = function(){ return this.replace(/\s*$/g,''); }

function isAlpha(p_strValue) {
    //Define Matching expression
    var l_regExp = /^[a-zA-Z\ \'\-\.\,]*$/;
    var l_strValue = p_strValue.trim()
    if (l_strValue.match(l_regExp)) 
        return true; 
    else 
        return false;
}

function isNumeric(p_strNum) {   
    if (p_strNum.match(/^\d+$/)) 
        return true; 
    else 
        return false;
}

function isValidZipCode(p_strZip) {
    //Define Matching expression
    var l_regExp = /(^\d{5}$)|(^\d{5}-\d{4}$)/
    
    if (p_strZip.match(l_regExp)) 
        return true; 
    else 
        return false;
}

function validate(pForm) {
    l_strWarning = ""
	
    if(pForm.name.value.trim() == '') l_strWarning += "Name: Cannot be empty.\n";
    if(!isAlpha(pForm.name.value)) l_strWarning += "Name: Must contain alphabetic characters.\n";

    var l_strEmailWarning = '';
    l_strEmailWarning = emailCheck(pForm.Email.value, l_strEmailWarning);
    if (l_strEmailWarning != "") {
		l_strWarning += "Email:" + l_strEmailWarning + '.\n';
	}
	else {
		if (pForm.Email.value != pForm.Email2.value){
			l_strWarning += "Email addresses do not match.\n";
		}
	}
    if(pForm.questionComment.value.trim() == '') l_strWarning += "Question or Comment: Cannot be empty.";
	
	if (l_strWarning != "") {
        /*document.getElementById("formError").style.display = "block";
        document.getElementById("formError2").style.display = "block";
        document.getElementById("formError").innerHTML= "<strong>The form cannot be submitted because\nthe following fields are invalid/incomplete:</strong><ul>" + l_strWarning + "</ul>";
		document.getElementById("formError2").innerHTML= "The form cannot be submitted, scroll to the top for details.";*/
		alert(l_strWarning);
        return false;
    } else {
        pForm.submit();
    }	
}

function validateCatalogRequest(pForm) {
    l_strWarning = ""
	
    if(pForm.name.value.trim() == '') l_strWarning += "Name: Cannot be empty.\n";
    if(!isAlpha(pForm.name.value)) l_strWarning += "Name: Must contain alphabetic characters.\n";
	
    if(pForm.streetAddress.value.trim() == '') l_strWarning += "Address: Cannot be empty.\n";
	
    if(pForm.city.value.trim() == '') l_strWarning += "City: Cannot be empty.\n";	
	
    if(pForm.state.value.trim() == '') l_strWarning += "State: Please select your state.\n";		

    if(pForm.zip.value.trim() == '') l_strWarning += "Zip Code: Cannot be empty.\n";
    if(!isValidZipCode(pForm.zip.value)) l_strWarning += "Zip Code: Appears to be invalid.\n";
	
	if (l_strWarning != "") {
        /*document.getElementById("formError").style.display = "block";
        document.getElementById("formError2").style.display = "block";
        document.getElementById("formError").innerHTML= "<strong>The form cannot be submitted because\nthe following fields are invalid/incomplete:</strong><ul>" + l_strWarning + "</ul>";
		document.getElementById("formError2").innerHTML= "The form cannot be submitted, scroll to the top for details.";*/
		alert(l_strWarning);
        return false;
    } else {
        pForm.submit();
    }	
}