window.onload = init_function;

function init_function()
{
    forms_validate_init();
}

function forms_validate_init()
{
    var submit_button = document.getElementById("contact_form_submit");
    submit_button.onclick = start_checks;
}

function start_checks(e)
{
    var validate_obj = new form_validate;
    var form_input_obj;
    
    form_input_obj = document.getElementById("name");
    form_input_obj.label_name = "Name";
    validate_obj.addtextbox(form_input_obj);
    
    form_input_obj = document.getElementById("phone");
    form_input_obj.label_name = "Phone";
    validate_obj.addphone(form_input_obj);
    
    form_input_obj = document.getElementById("email");
    form_input_obj.label_name = "Email";
    validate_obj.addemail(form_input_obj);
    
    form_input_obj = document.getElementById("details");
    form_input_obj.label_name = "Details";
    validate_obj.addtextarea(form_input_obj);
    
    var error_ary = validate_obj.check_form();
    if(error_ary != false)
    {
        var error_string = "Please Complete the following fields: <br /><strong>";
        for(var i=0; error_ary.length > i; i++)
        {
            error_string += error_ary[i] + ", ";
        }
        
        // --- rtrim last comma and space
        error_string = error_string.replace(/,\s$/,"") + "</strong>";
        
        // --- make an alertbox
        var new_alertbox = new alert_box(error_string);
        
        if(!e)
        {
            e = window.event;
            e.returnValue = false;
        }
                
        return false;
    }
    else
    {
        if(!e)
        {
            e = window.event;
            e.returnValue = true;
        }
                
        return true;
    }
}