/**
 * @author mcconkiee
 */
//place names of form elements to validate- type=text only for this validator
var ar = ["first_name", "last_name", "company", "function", "email", "telephone"];
function validINIT(){
    document.getElementById("submit_bt").onclick = validate;
}

function validate(e){
    //tracking number for valid entries
    var count = 0;
    //total number of fields
    var total = 0;
    //find all input fields
    var ip = document.getElementsByTagName("input");
    for (var g = 0; g < ip.length; g++) {
        var thisIP = ip[g];
        //take only text fields
        if (thisIP.type == "text") {
            //increment these text fields to get total number of inputs to validate
            total++;
            //if the field has been addressed, count it as "good"
            if (vv(thisIP)) {
                count++;
            }
        }
    }
    //if the count == the total we were looking for...go
    if (count >= total) {
        document.forms[0].submit();
    }
    else {
        document.getElementById("error_message").className = "red";
    }
}

function vv(ip){

    var labelID = ip.name;
    var thisLabel = document.getElementById(labelID);
    if (ip.value == "" || ip.value.indexOf(" ") == 0) {
    
    
        thisLabel.className = "red"
        return false;
    }
    else {
        thisLabel.className = ""
        return true;
    }
}

womAdd("validINIT()")

