 function CheckNum(source, args)
{                   
    if (isNaN(args.Value) || (args.Value < 0))
    {
        args.IsValid = false;
    }              
    else
    {
        args.IsValid = true;
    }
}

function TALimit()
{
    var taObj=event.srcElement;	    
    if (taObj.value.length > 1000) return false;
}

function TAStrip()
{ 
    var taObj=event.srcElement;
    if (taObj.value.length > 1000) taObj.value=taObj.value.substring(0,1000);	    
} 

function TAStrip2000()
{ 
    var taObj=event.srcElement;
    if (taObj.value.length > 2000) taObj.value=taObj.value.substring(0,2000);	    
}  

function MaxCheck(source, args)
{       
    var x = args.Value;
                
    if (x.length > 1000)
    {
        args.IsValid = false;
    }              
    else
    {
        args.IsValid = true;
    }
}

function MaxCheck500(source, args)
{       
    var x = args.Value;
                
    if (x.length > 500)
    {
        args.IsValid = false;
    }              
    else
    {
        args.IsValid = true;
    }
}

//
// The following four functions are used in combination
//

//This function depends on a consistent naming scheme for Web Controls: textbox and textarea names begin with the
//prefix 'txt' and dropdown box names begin with the prefix 'sel'.
function EnableDetectChanges()
{
	var i;
    var id_parts;
    var type;
    
    for(i = 0; i < document.forms[0].elements.length; i++)
    {
		id_parts = document.forms[0].elements[i].id.split("_");	//WebControls have their ID combined with that of the parent ContentPlaceholder
        if(id_parts.length > 2)									//if the split yielded 3 or more elements, assume element comes from a ContentPlaceholder
        {
            type = id_parts[2].substring(0, 3);
            switch (type)
            {
                case "txt": document.forms[0].elements[i].onchange = ChangesOccurred;
                            break;
                case "sel": document.forms[0].elements[i].onselectedchanged = ChangesOccurred;
                            break;
            }
        }
    }
}

function CheckForChanges()
{
	//relies on the existence of a hidden input tag with the id "ChangesOccurred" and on the existence
	//of a Submit input tag with the id "cpl00_ContentPlaceholder_btnSubmit"	
	if(document.getElementById("ChangesOccurred").Value == "true")
		if(confirm("Would you like to Save before leaving?"))
		{
			document.getElementById("ctl00_ContentPlaceHolder_btnSubmit").click();
			alert("Your changes have been saved."); //Block for user I/O, this appapently frees the client to 
													//do a postback, which otherwise does not occur since this
													//function is used when a page is unloading. Alert box can
													//be dismissed by the user anytime, there is no need to wait
													//once the postback is underway.
		
		}
}

function ChangesOccurred()
{
	//relies on the existence of a hidden input tag with the id "ChangesOccurred"
	document.getElementById("ChangesOccurred").Value = "true";
}

//Used to avoid the save prompt when the user click on the Save/Submit button
function ClearChangesFlag()
{
	//relies on the existence of a hidden input tag with the id "ChangesOccurred"
	document.getElementById("ChangesOccurred").Value = "";
}

//This function is the clientside code for a .NET Custom Validator 
//val is the html control that initiated the event
//arg is the incoming value that is allegedly a date
function ValidateDate(val, arg) 
{   
    // use regular expression to determine if date entered is valid
    var RegExPattern = /^(?=\d)(?:(?:(?:(?:(?:0?[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0?[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})|(?:0?2(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))|(?:(?:0?[1-9])|(?:1[0-2]))(\/|-|\.)(?:0?[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{2}))($|\ (?=\d)))?(((0?[1-9]|1[012])(:[0-5]\d){0,2}(\ [AP]M))|([01]\d|2[0-3])(:[0-5]\d){1,2})?$/;
    if ((arg["Value"].match(RegExPattern)) && (arg["Value"]!='')) 
    {
        arg["IsValid"] = true;  
    } 
    else 
    {
        arg["IsValid"] = false;    
    } 
}
