	// Check Date
    function Date_Validator(strDtVal1)
    {
        var strDtVal2 = strDtVal1;

        if (strDtVal2.length == 0)
        {
            return (1);
        }

        if (strDtVal2.length  > 10)
        {
            return (2);
        }

        var checkOK = "0123456789-/";
        var checkStr = strDtVal2;
        var allValid = true;
        for (i = 0;  i < checkStr.length;  i++)
        {
            ch = checkStr.charAt(i);
            for (j = 0;  j < checkOK.length;  j++)
                if (ch == checkOK.charAt(j))
                    break;
                if (j == checkOK.length)
                {
                    allValid = false;
                    break;
                }
        }
        if (!allValid)
        {
            return (3);
        }

        var chkVal = strDtVal2;
        var prsVal = chkVal;
        if (chkVal == "" )
        {
            return (4);
        }

        firstSlash = chkVal.indexOf("/",0)
        lastSlash = chkVal.lastIndexOf("/")
        middleSlash = chkVal.indexOf("/",firstSlash)
        monthVal = chkVal.substring(0,firstSlash)
        dayVal  = chkVal.substring(firstSlash+1,lastSlash)
        yearVal = chkVal.substring(lastSlash+1,chkVal.length) 
        
        if ( (firstSlash == -1 ) || ( lastSlash == -1 )  || (lastSlash  == firstSlash) )
        {
            return (9);
        }	 

        yearVal = yearVal + '';
        if (yearVal.length == 0)
        {
            return (13);
        }

        if ( ( (eval(middleSlash) != -1 ) && (  eval(middleSlash) > eval(lastSlash) ) ) )
        {
        // return (10);
        }

        if ( (eval(yearVal) < 1980 )||(eval(yearVal) > 9999 ) )
        {
            return (5);
        }
        else
        {
            if ( ( ( eval(yearVal) % 4 == 0 ) && ( eval(yearVal) % 100 != 0 ) ) || ( eval(yearVal) % 400 == 0 )  )
            {	
                leapYear = true;
            }
            else
            {
                leapYear = false;
            }
        }
        if ( (eval(monthVal) < 1) || (eval(monthVal) > 12 ) )
        {
            return (6);
        }
        else
        {
            if ( eval(monthVal) == 2)
            {
                February = true;
            }
            else
            {
                February = false;
            }
        }
        if ( (leapYear == true) && ( February == true) )
        {
            if ( (eval(dayVal) < 1) || (eval(dayVal) > 29) )
            {
                return (7);
            }
        }
        else if ( eval(monthVal) == 2)
        {
            if ( (eval(dayVal) < 1) || (eval(dayVal) > 28) )
            {
                return (8);
            }
        }
        else if ((eval(monthVal) == 1) || (eval(monthVal) == 3) || (eval(monthVal) == 5) || (eval(monthVal) == 7) || (eval(monthVal) == 8) || (eval(monthVal) == 10) || (eval(monthVal) == 12)) 
        {
            if ( (eval(dayVal) < 1) || (eval(dayVal) > 31) )
            {
                return (11);
            }
        }
        else if ((eval(monthVal) == 4) || (eval(monthVal) == 6) || (eval(monthVal) == 9) || (eval(monthVal) == 11)) 
        {
            if ( (eval(dayVal) < 1) || (eval(dayVal) > 30) )
            {
                return (12);
            }
        }
        // If every thing is correct then return true
        return (0);
    }

	function ErrMessage(iType, fldName1)
	{
        var fldName = fldName1;
        if (iType == 1)
            alert("Please enter a value for the " + fldName + " field.");
        else if (iType == 2)
            alert("Please enter at most 10 characters in the "+ fldName +" field.");
        else if (iType == 3)
            alert("Please enter only digit and \"/\" characters in the "+ fldName +" field.");
        else if (iType == 4)
            alert("Please enter a value less than or equal to \"12/12/9999\" and greater than or equal to \"12/12/1980\" in the "+ fldName +" field.\n \r Valid date format is mm/dd/yyyy");
        else if (iType == 5)
            alert("Please enter a value greater than or equal to \"1980\" and less than or equal to \"9999\" in the Year part of "+ fldName +" field.\n \r Valid date format is mm/dd/yyyy");
        else if (iType == 6)
            alert("Please enter a value less than or equal to \"12\" and greater than or equal to \"1\" in the Month part of "+ fldName +" field.\n \r Valid date format is mm/dd/yyyy");
        else if (iType == 7)
            alert("Please enter a value less than or equal to \"29\" and greater than or equal to \"1\" in the Day part of "+ fldName +" field.\n \r Valid date format is mm/dd/yyyy");
        else if (iType == 8)
            alert("Please enter a value less than or equal to \"28\" and greater than or equal to \"1\" in the Day part of "+ fldName +" field.\n \r Valid date format is mm/dd/yyyy");
        else if (iType == 9)
            alert("Please enter only digit and \"/\" characters in the "+ fldName + " field. \n \r Valid date format is mm/dd/yyyy");
        else if (iType == 10)
            alert("Please enter only digit and \"/\" characters in the "+ fldName +" field. \n \r Valid date format is mm/dd/yyyy");
        else if (iType == 11)
            alert("Please enter a value less than or equal to \"31\" and greater than or equal to \"1\" in the Day part of "+ fldName +" field.\n \r Valid date format is mm/dd/yyyy");
        else if (iType == 12)
            alert("Please enter a value less than or equal to \"30\" and greater than or equal to \"1\" in the Day part of "+ fldName +" field.\n \r Valid date format is mm/dd/yyyy");
        else if (iType == 13)
            alert("Please enter the year in the "+ fldName +" field. \n \r Valid date format is mm/dd/yyyy");
        
        if (iType != 0)
        {
            return (false);
        }
    }

    function roundOff(value, precision)
    {
		var result = "";
		var whole = "";
		var decPoint = 0;
		
		if (Number(value) < 1)
		{
			if (Number(value) < 0.45)
				result = "0";
			else
				result = parseFloat(Number(value));
		}
		else
		{
			value = "" + value //convert value to string
			precision = parseInt(precision);

			whole = "" + Math.round(value * Math.pow(10, precision));
			decPoint = whole.length - precision;
			if(decPoint != 0)
			{
	            result = whole.substring(0, decPoint);
	            result += ".";
	            result += whole.substring(decPoint, whole.length);
			}
			else
			{
			    result = whole;
			}
        }
        return result;
    }

    function chkNumeric(objName,minval,maxval,comma,period,hyphen)
    {
	    // only allow 0-9 be entered, plus any values passed
	    // (can be in any order, and don't have to be comma, period, or hyphen)
	    // if all numbers allow commas, periods, hyphens or whatever,
	    // just hard code it here and take out the passed parameters
	    var checkOK = "0123456789" + comma + period + hyphen;
	    var checkStr = objName;
	    var allValid = true;
	    var decPoints = 0;
	    var allNum = "";

	    for (i=0;i<checkStr.value.length;i++)
	    {
		    ch = checkStr.value.charAt(i);
		    for (j=0;j<checkOK.length;j++)
			    if (ch == checkOK.charAt(j))				
				    break;
			    if (j == checkOK.length)
			    {
				    allValid = false;
				    break;
			    }
    			
		    if (ch != ",")
		    allNum += ch;
    			
	    }

	    if (!allValid)
	    {	
		    alertsay = "Please enter only these values \""
		    alertsay = alertsay + checkOK + "\" in this field."
		    alert(alertsay);
		    return (false);
	    }

	    // set the minimum and maximum
	    var chkVal = allNum;
	    var prsVal = Number(allNum);
	    if ((chkVal != "") && ((prsVal < minval) || (prsVal > maxval)))
	    {
		    alertsay = "Please enter a value greater than or "
		    alertsay = alertsay + "equal to \"" + minval + "\" and less than or "
		    alertsay = alertsay + "equal to \"" + maxval + "\" in this field."
		    alert(alertsay);
		    return (false);
	    }
    }
    
    function IsNumeric(sText)
    {
        var ValidChars = "0123456789.";
        var IsNumber=true;
        for (i = 0; i < sText.length && IsNumber == true; i++)
        {
            if (ValidChars.indexOf(sText.charAt(i)) == -1) 
            {
                IsNumber = false;
            }
        }
        return IsNumber;
    }
    
    //Trims Field
    function trim(strText) {
        while (strText.substring(0, 1) == ' ' || strText.substring(0, 1) == '\r' || strText.substring(0, 1) == '\n') // this will get rid of leading spaces & carriage returns
            strText = strText.substring(1, strText.length);
        while (strText.substring(strText.length - 1, strText.length) == ' ' || strText.substring(strText.length - 1, strText.length) == '\r' || strText.substring(strText.length - 1, strText.length) == '\n') // this will get rid of trailing spaces & carriage returns
            strText = strText.substring(0, strText.length - 1);
        return strText;
    }
    function TrimAllText() {
        var inputs = document.getElementsByTagName('input');
        for (var k = 0; k < inputs.length; k++) {
            var input = inputs[k];
            if (input.type == 'text') {
                input.value = trim(input.value);
            }
        }

        inputs = document.getElementsByTagName('textarea');
        for (k = 0; k < inputs.length; k++) {
            inputs[k].value = trim(inputs[k].value);
        }
    }
    
    ///////////////////Date Function///////////////////
    function isInteger1(s)
    {
        return (s.toString().search(/^-?[0-9]+$/) == 0);
    }
    
	function isInteger(s)
	{
		var i;
	    for (i = 0; i < s.length; i++){
	        // Check that current character is number.
	        var c = s.charAt(i);
	        if (((c < "0") || (c > "9"))) return false;
	    }
	    // All characters are numbers.
	    return true;
	}
	function stripCharsInBag(s, bag)
	{
		var i;
	    var returnString = "";
	    // Search through string's characters one by one.
	    // If character is not in bag, append to returnString.
	    for (i = 0; i < s.length; i++){   
	        var c = s.charAt(i);
	        if (bag.indexOf(c) == -1) returnString += c;
	    }
	    return returnString;
	}
	function daysInFebruary (year)
	{
		// February has 29 days in any year evenly divisible by four,
	    // EXCEPT for centurial years which are not also divisible by 400.
	    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
	}
	function DaysArray(n)
	{
		for (var i = 1; i <= n; i++)
		{
			this[i] = 31;
			if (i==4 || i==6 || i==9 || i==11) 
			{
			    this[i] = 30
			}
			if (i==2)
			{
			    this[i] = 29
			}
	   } 
	   return this
	}
	function isDate(dtStr)
	{
	    var dtCh= "/";
	    var minYear=1900;
	    var maxYear=2100;
		var daysInMonth = DaysArray(12)
		var pos1=dtStr.indexOf(dtCh)
		var pos2=dtStr.indexOf(dtCh,pos1+1)
		var strMonth=dtStr.substring(0,pos1)
		var strDay=dtStr.substring(pos1+1,pos2)
		var strYear=dtStr.substring(pos2+1)

		if (strDay.length != 2 || strMonth.length != 2)
		{
			alert("Date format should be MM/DD/YYYY");
			return false;
		}

		strYr=strYear
		if (strDay.charAt(0)=="0" && strDay.length>1)
		    strDay=strDay.substring(1)
		if (strMonth.charAt(0)=="0" && strMonth.length>1)
		    strMonth=strMonth.substring(1)
		for (var i = 1; i <= 3; i++)
		{
			if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
		}
		month=parseInt(strMonth)
		day=parseInt(strDay)
		year=parseInt(strYr)
		
		if (pos1==-1 || pos2==-1)
		{
			alert("The date format should be : mm/dd/yyyy")
			return false
		}
		if (strMonth.length<1 || month<1 || month>12)
		{
			alert("Please enter a valid month")
			return false
		}
		if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month])
		{
			alert("Please enter a valid day")
			return false
		}
		if (strYear.length != 4 || year==0 || year<minYear || year>maxYear)
		{
			alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
			return false
		}
		if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false)
		{
			alert("Please enter a valid date")
			return false
		}
		if (dtStr.toString().length>10)
		{
			alert("Please enter a valid date")
			return false
		}
		return true
	}