﻿function validate(fieldnames,elements,types)
{
    var splitFieldNames = fieldnames.split(",");
    var splitElements = elements.split(",");
    var splitTypes = types.split(",");
    var valid = false;
    
    for(i = 0; i < splitElements.length; i++)
    {
        var obj = eval("document.getElementById('" + splitElements[i] + "')");
        
        if(splitTypes[i] == "text")
        {
            if(obj.value == "")
            {
                alert("The following information was not provided: " + splitFieldNames[i]);
                obj.focus();
                return false;
            }
        }
        else if(splitTypes[i] == "email")
        {
            if(obj.value == "")
            {
                alert("The following information was not provided: " + splitFieldNames[i]);
                obj.focus();
                return false;
            }
            else
            {
                if(obj.value.indexOf("@") < 0 ||obj.value.indexOf(".") < 0)
                {
                    alert("The following information was not valid: " + splitFieldNames[i]);
                    obj.focus();
                    return false;
                }
            }
        }
        else if(splitTypes[i] == "checkbox")
        {
            if(!obj.checked)
            {
                alert("The following information was not provided: " + splitFieldNames[i]);
                obj.focus();
                return false;
            }
        }
    }
    
    return true;
}