﻿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] == "currentdate")
        {
            if(obj.value == "")
            {
                alert("The following information was not provided: " + splitFieldNames[i]);
                obj.focus();
                return false;
            }
            else
            {
                var input = new Date(obj.value);
                var current = new Date();
                
                if(input < current)
                {
                    alert("Please make sure the date is in the future");
                    obj.focus();
                    return false;
                }
            }
        }
        else if (splitTypes[i] == "dropdown") {
        if (obj.selectedIndex == 0) {
                alert("The following information was not provided: " + splitFieldNames[i]);
                obj.focus();
                return false;
            }
        }
    }
    
    return true;
}
