function SE_IsValidDate(dateStr, format)
{
    return IsValidDate(dateStr, format);
}
function IsValidDate(dateStr, format) {
   if (format == null) { format = "MDY"; }
   format = format.toUpperCase();
   if (format.length != 3) { format = "MDY"; }
   if ( (format.indexOf("M") == -1) || (format.indexOf("D") == -1) || (format.indexOf("Y") == -1) ) { format = "MDY"; }
   if (format.substring(0, 1) == "Y") { // If the year is first
      var reg1 = /^\d{2}(\-|\/|\.)\d{1,2}\1\d{1,2}$/
      var reg2 = /^\d{4}(\-|\/|\.)\d{1,2}\1\d{1,2}$/
   } else if (format.substring(1, 2) == "Y") { // If the year is second
      var reg1 = /^\d{1,2}(\-|\/|\.)\d{2}\1\d{1,2}$/
      var reg2 = /^\d{1,2}(\-|\/|\.)\d{4}\1\d{1,2}$/
   } else { // The year must be third
      var reg1 = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{2}$/
      var reg2 = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{4}$/
   }
   // If it doesn't conform to the right format (with either a 2 digit year or 4 digit year), fail
   if ( (reg1.test(dateStr) == false) && (reg2.test(dateStr) == false) ) { return false; }
   var parts = dateStr.split(RegExp.$1); // Split into 3 parts based on what the divider was
   // Check to see if the 3 parts end up making a valid date
   if (format.substring(0, 1) == "M") { var mm = parts[0]; } 
   else  
		if (format.substring(1, 2) == "M") { var mm = parts[1]; } 
		else { var mm = parts[2]; }
		if (format.substring(0, 1) == "D") { var dd = parts[0]; } 
		else	if (format.substring(1, 2) == "D") { var dd = parts[1]; } 
				else { var dd = parts[2]; }
				if (format.substring(0, 1) == "Y") { var yy = parts[0]; } 
				else	if (format.substring(1, 2) == "Y") { var yy = parts[1]; } 
						else { var yy = parts[2]; }
						if (parseFloat(yy) <= 50) { yy = (parseFloat(yy) + 2000).toString(); }
						if (parseFloat(yy) <= 99) { yy = (parseFloat(yy) + 1900).toString(); }
						var dt = new Date(parseFloat(yy), parseFloat(mm)-1, parseFloat(dd), 0, 0, 0, 0);
						if (parseFloat(dd) != dt.getDate()) { return false; }
						if (parseFloat(mm)-1 != dt.getMonth()) { return false; }
						if (dt < new Date("1/1/1753") || dt > new Date("12/31/9999")) { return false; }
						return true;
}

function SE_IsInteger(s)
{   var i;

	if (s == null || typeof(s) == 'undefined' || s.length == 0) return false;
    var re = new RegExp(/^-?\d*$/)
    return re.test(s);
}

// moved to utilities.js
//function SE_IsValidEmailAddress(strAddress)
//{
//	strAddress = strAddress.replace(/^\s+/,'').replace(/\s+$/,'');
//	return (MLX_ValidEmailRegExp.test(strAddress));
//}

function SE_IsPossiblePhoneNumber(phone)
{
	var reFilter = /[2-9][0-9]{2}.*[0-9]{4}/gi;
	return (reFilter.test(phone));
}

function SE_IsPossiblePhoneNumber_Accurate(sText, withAreaCode)
{
    if(!withAreaCode)
        reFilter = /^1{0,1}([\(]{0,1}[0-9]{3}[\)]{0,1}[\.| |\-]{0,1}|^[0-9]{3}[\.|\-| ]?)?[0-9]{3}(\.|\-| )?[0-9]{4}$/;
    else
        reFilter = /^1{0,1}([\(]{0,1}[0-9]{3}[\)]{0,1}[\.| |\-]{0,1}|^[0-9]{3}[\.|\-| ]?){1}[0-9]{3}(\.|\-| )?[0-9]{4}$/;
    return (reFilter.test(sText));
}

function SE_IsNumeric(sText)
{
    var reFilter = /^[-+]?\d*\.?\d*$/;
    return (reFilter.test(sText));
}

function SE_IsDomain(sText)
{
    var reFilter = /^(?:[\-A-Z0-9]+\.)+[\-A-Z0-9]{1,5}\b/gi;
    return (reFilter.test(sText));
}

function SE_IsURL(sText)
{
    var reFilter = /^(https?:\/\/)?[-A-Z0-9.]+(\/[-A-Z0-9+&@#/%=~_|!:,.;]*)?(\?[-A-Z0-9+&@#/%=~_|!:,.;]*)?/gi;
    return (reFilter.test(sText));
}

function SE_IsZipCode(sText)
{
    var reFilter = /^\d{5}$|^\d{5}-\d{4}$/;
    return (reFilter.test(sText));
}

function SE_HasHTML(sText)
{
    var reFilter = /<\/?[a-z][a-z0-9]*[^<>]*>/gi;
    return (reFilter.test(sText));
}

function SE_IsValidHexidecimalColorCode(objValue)
{
	objValue = objValue.replace(/^\s+/,'').replace(/\s+$/,'');
	var reFilter = /^#[a-fA-F0-9]{6}/;
	return (reFilter.test(objValue));
}

function SE_IsValidColorName(value)
{
    var validColors = ",Gainsboro,Green,Lime,Teal,Aqua,Navy,Blue,Purple,Fuchsia,Maroon,Red,Olive,Yellow,White,Silver,Gray,Black,DarkOliveGreen,DarkGreen,DarkSlateGray,SlateGray,DarkBlue,MidnightBlue,Indigo,DarkMagenta,Brown,DarkRed,Sienna,SaddleBrown,DarkGoldenrod,Beige,Honeydew,DimGray,OliveDrab,ForestGreen,DarkCyan,LightSlateGray,MediumBlue,DarkSlateBlue,DarkViolet,MediumVioletRed,IndianRed,Firebrick,Chocolate,Peru,Goldenrod,LightGoldenrodYellow,MintCream,DarkGray,YellowGreen,SeaGreen,CadetBlue,SteelBlue,RoyalBlue,BlueViolet,DarkOrchid,DeepPink,RosyBrown,Crimson,DarkOrange,Burlywood,DarkKhaki,LightYellow,Azure,LightGrey,LawnGreen,MediumSeaGreen,LightSeaGreen,DeepSkyBlue,DodgerBlue,SlateBlue,MediumOrchid,PaleVioletRed,Salmon,OrangeRed,SandyBrown,Tan,Gold,Ivory,GhostWhite,Gainsboro,Chartreuse,LimeGreen,MediumAquamarine,DarkTurquoise,CornflowerBlue,MediumSlateBlue,Orchid,HotPink,LightCoral,Tomato,Orange,Bisque,Khaki,Cornsilk,Linen,WhiteSmoke,GreenYellow,DarkSeaGreen,Turquoise,MediumTurquoise,SkyBlue,MediumPurple,Violet,LightPink,DarkSalmon,Coral,NavajoWhite,BlanchedAlmond,PaleGoldenrod,Oldlace,Seashell,GhostWhite,PaleGreen,SpringGreen,Aquamarine,PowderBlue,LightSkyBlue,LightSteelBlue,Plum,Pink,LightSalmon,Wheat,Moccasin,AntiqueWhite,LemonChiffon,FloralWhite,Snow,AliceBlue,LightGreen,MediumSpringGreen,PaleTurquoise,LightCyan,LightBlue,Lavender,Thistle,MistyRose,Peachpuff,PapayaWhip,"
    return validColors.toLowerCase().indexOf(value.toLowerCase()) != -1;
}

    // -- limit text entry in a textarea or asp:TextBox in multiline mode
	// In code behind, use the following:
    // SonicEagle.Common.Tools.SetTextAreaMaxSize(System.Web.UI.WebControls.TextBox txtBox, int maxSize)

    var SE_PrePasteText = "";
	var SE_PostPasteText = "";
	var SE_IsAfterPaste = false;
	
	function SE_LimitSize(ctl, size)
	{
	    if (event)
	    {
	        switch (event.type)
	        {
	            case "drop":
	                if (event.dataTransfer)
	                {
	                    var droppedText = event.dataTransfer.getData("TEXT");
	                    if ((droppedText.length + ctl.value.length) > size)
	                    {
	                        SE_HandleSizeExceedance(ctl, size);
	                    }
	                }
    	            break;
	            case "paste":	            
	                SE_PrePasteText = ctl.value;
	                SE_IsAfterPaste = true;
	                //Call the blur method (the field will necessarily have focus), the handling of which is where the pasted text will be evaluated.
	                setTimeout("document.getElementById('" + ctl.id + "').blur()", 10);
	                break;
	            case "blur":
	                if (SE_IsAfterPaste)
	                {
	                    SE_PostPasteText = ctl.value;
	                    if (SE_PostPasteText.length > size)
	                    {
	                        ctl.value = SE_PrePasteText;
	                        SE_HandleSizeExceedance(ctl, size);
	                    }
	                    else
	                        ctl.focus();
	                    SE_PrePasteText = "";
	                    SE_IsAfterPaste = false;
	                }
    	            break;
	            case "keypress":
	                if (ctl.value.length >= size)
	                {
	                    SE_HandleSizeExceedance(ctl, size);
	                }
    	            break;
	        }   
	    }
	}
	
	function SE_HandleSizeExceedance(ctl, size)
	{
	    alert("Please limit entry to " + size + " characters.");
	    ctl.focus();
        SE_CancelEvent();
	}
	
	function SE_TestRegEx(pattern, flags, testValue)
	{
	    var re = new RegExp(pattern, flags);
	    return (re.test(testValue));
	}
	
	function MLX_Validator()
    {
        this.firstProblem = null;
        this.errorMessage = "";
        this.handleError = MLX_ValidateHandleFoundError;
        this.result = MLX_Validate_Result;
        this.confirm = MLX_Validate_Confirm;
    }
    
    function MLX_ValidateHandleFoundError(ctlTest, errMsg)
    {
        this.errorMessage += (this.errorMessage == "" ? "" : "\n") + errMsg;
        if (this.firstProblem == null)
            this.firstProblem = ctlTest;
    }
    
    function MLX_Validate_Result()
    {
        if (this.errorMessage != "")
        {
            alert(this.errorMessage);
            if (this.firstProblem.focus)
            {
                // the control may not be visible but I don't know of a way to
                // reliably determine if it is or not - so I used the crappy hack - mja
                try {this.firstProblem.focus();}
                catch(e) {}
            }
            return false;
        }
        return true;
    }
    
    function MLX_Validate_Confirm()
    {
        if (this.errorMessage != "")
        {
            if(!confirm(this.errorMessage))
            {
                if (this.firstProblem.focus)
                {
                    // the control may not be visible but I don't know of a way to
                    // reliably determine if it is or not - so I used the crappy hack - mja
                    try {this.firstProblem.focus();}
                    catch(e) {}
                }
                return false;
            }
        }
        return true;
}