﻿/// ---------------------------------------------------------------------------------------
/// Revision History
/// Date        Author       Comment
/// ----------  -----------  --------------------------------------------------------------
/// 10/15/2008  sgnile      New validation.js file to support custom validators
/// 03/11/2010  sgnile      Added new validator for email addresses
/// 
/// ---------------------------------------------------------------------------------------


/// supports the max length custom validation as shown on the ProductProfile.aspx page.
function validateLength(oSrc,args)
{
	var length = parseInt(oSrc.attributes.MaxLength.value);
	
	if(args.Value.length > length)
		{
			args.IsValid = false;
			
			var ilength = args.Value.length - length;
			var msg = "You have exceeded the maximum character limit for this field by" + " " + ilength + " " + "characters.";
//			oSrc.innerText = msg;
			oSrc.title = msg;
		}
		else
		{
			args.IsValid = true;
		}

}

function validateShifts(oSrc, args) {

    var result = true;
    var hdnId = oSrc.id.substring(0, oSrc.id.lastIndexOf("_")+1) + "hdnIds";
    var hdnIds = document.getElementById(hdnId);

    var shiftIds = hdnIds.value.split(",");
    var shiftCount = shiftIds.length;
    if (shiftCount > 0) {
        for (var i = 0; i < shiftCount; i++) {
            if (shiftIds[i] == args.Value) {
                result = false;
//                oSrc.ErrorMessage = "You have already chosen this shift, please select another";
                break;
            }
        }
    }
    args.IsValid = result;
}

function validateEmailAddress(oSrc, args) {
    
    if (args.Value.match(/[a-z0-9!#$%&'*+\/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+\/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/i)) {
        // Successful match
        args.IsValid = true;
    } else {
        // Match attempt failed
    args.IsValid = false;
}

}
