
function validateRequired(oSrc, args) {
        if (args.Value.replace(/^\s+|\s+$/g,"") == "") {     
            args.IsValid = false;
            setErrorStyle(false, oSrc);
        } else { 
            args.IsValid = true;
            setErrorStyle(true, oSrc);
        }
    }

function validateEmail(oSrc, args) {
        if (!args.Value.match(/\w+([-+.\']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/i)) {
            args.IsValid = false;
            setErrorStyle(false, oSrc);
        } else {
            args.IsValid = true;
            setErrorStyle(true, oSrc);
        }
    }

function validateNumber(oSrc, args) {
        if (isNaN(args.Value)) {     
            args.IsValid = false;
            setErrorStyle(false, oSrc);
        } else { 
            args.IsValid = true;
            setErrorStyle(true, oSrc);
        }
    }
    
    
function validateDate(oSrc, args)  {
        var jsdate = new Date(args.Value);
        if (jsdate.toString() == "NaN" || jsdate.toString() == "Invalid Date") {
            args.IsValid = false;
            setErrorStyle(false, oSrc);
        } else {
            args.IsValid = true;
            setErrorStyle(true, oSrc);
        }
    }

    function validateWordCount(oSrc, args) {
        if (args.Value.length > 0) {
            var maxWords = $("#" + oSrc.controltovalidate).attr('MaxWords') * 1;
            var reg = new RegExp("^(\\S+\\s*){0," + maxWords + "}$", "i");
            var result = reg.test(args.Value);
            args.IsValid = result;
            setErrorStyle(result, oSrc);
        }
    }
    
    
function setErrorStyle(isValid, obj) {

    row = obj.parentNode.parentNode;

    // if the input is wrapped inside a table, we'll mark the
    // entire row with the class
    if (row.nodeName == "TR") {
        if (isValid) {
            row.className = row.className.replace(" validation_error", "");
        } else {
            if (row.className.indexOf(" validation_error") == -1)
                row.className = row.className + " validation_error"; 
        }
    } else {
        if (isValid) {
            $(obj).removeClass("validation_error_span");
            $("#" + obj.controltovalidate).removeClass("validation_error_input");
        } else {
            $(obj).addClass("validation_error_span");
            $("#" + obj.controltovalidate).addClass("validation_error_input");
        }
    }
}
