﻿function Validate(form)
{
    var spans = form.getElementsByTagName("span");
    var ctrlToFocus = null;
    for(var i = 0; i < spans.length; i++)
    {
        if (spans[i].id.indexOf("rfv", 0) == 0)
        {
            var ctrl = document.getElementById(spans[i].getAttribute("ControlToValidate"));
            if (ctrl && ctrl.value.trim().length == 0)
            {
                spans[i].style.display = "inline";
                if (ctrlToFocus == null)
                    ctrlToFocus = ctrl
            }
            else
            {
                spans[i].style.display = "none";
            }
        }
    }
    if (ctrlToFocus)
    {
        ctrlToFocus.focus();
        return false;
    }
    else
    {
        return true;
    }
    
}

String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
