var LRUtil = 
{
    /*
    ********************************************
     Purpose :	Validates the fields for number
    ********************************************
    */ 
    IsNumber: function(UserValue)
    {
        var lFlag  = true
        if (UserValue.indexOf(",", 0) >= 0 || UserValue.indexOf("-", 0) >= 0)
	        lFlag = false
        else
	        lFlag = true
        return 	lFlag
    },
    /*
    **********************************************************************************
     Purpose :	Validates the fields for sapces
			    If all characters are space , returns false
			    else returns true
    ***********************************************************************************
    */
    checkSpace: function(strValue)
    {
        var lflag = false;
        for(i=0;i<strValue.length;i++)
        {
	        if (strValue.charAt(i) != " " && strValue.charAt(i) != "\t" )
	        {
		        lflag = true
		        break
	        }
        }
        return lflag
    },
    /*
    **********************************************************************************
     Purpose :	Removes all spaces in a String
    ***********************************************************************************
    */
    TrimSpace: function (strText)
    {
      var intLength = strText.length
      var intStartPos = 0
      var intEndPos = intLength 
      var strOut =  ""
	    for (i=0;i<intEndPos;i++)
	    {
		    if (strText.charAt(i)!= " ")
		    {
			    strOut	= strOut + strText.charAt(i)
		    }
	    }
	    return strOut
    },
    
    ValidEmail: function (FieldVal) 
    {
	    if (window.RegExp) 
	    {
		    var strCheck1 = "^[a-zA-Z0-9\-\_\.\'\]+@[a-zA-Z0-9\-\_\.]+[.]+[a-zA-Z0-9\-\_\.]+$"
		    var objCheck1 = new RegExp(strCheck1);
		    if (objCheck1.test(FieldVal))
		    {
			    return true;
		    }
		    else
			    return false;
	    }
	    else 
	    {
		    if(FieldVal.indexOf("@") >= 0)
			    return true;
		    else
			    return false;
	    }
    },
    Trim: function (s) 
    {
        while ((s.substring(0,1) == ' ') || (s.substring(0,1) == '\n') || (s.substring(0,1) == '\r'))
        {
            s = s.substring(1,s.length);
        }
        while ((s.substring(s.length-1,s.length) == ' ') || (s.substring(s.length-1,s.length) == '\n') || (s.substring(s.length-1,s.length) == '\r'))
        {
            s = s.substring(0,s.length-1);
        }
        return s;
    },
    validate_alphanumeric_data: function (urstr)
    {
      var i;
      var result;

      for (i=0; i<urstr.length; i++) {
        if (
          ((urstr.charAt(i) >= "A") && (urstr.charAt(i) <= "Z")) ||
          ((urstr.charAt(i) >= "a") && (urstr.charAt(i) <= "z")) ||
          ((urstr.charAt(i) >= "0") && (urstr.charAt(i) <= "9")) ||
          ((urstr.charAt(i) == "-"))
          )
          result = true;
        else 
          return false;
      }

      if (result == true)
        return true;
    },
    Pop_Win: function(pURL, pName, pW, pH, pSCR)
    {
	    var PWin = window.open(pURL,pName,'left=0,top=0,resizable=1,width=' + pW + ',height=' + pH + ',scrollbars=' + pSCR);
	    PWin.focus();
    },

    ClosePage: function()
    {
	    window.close();
    },

    isInteger: function(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;
    },

    stripCharsInBag: function(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;
    },

    daysInFebruary: function (year)
    {
	    // February has 29 days in any year evenly divisible by four,
        // EXCEPT for centurial years which are not also divisible by 400.
        var strYear = new String(year);
        switch (strYear.length)
        {
		    case 1:
			    strYear = "200" + strYear;
			    break;
		    case 2:
			    strYear = "20" + strYear;
			    break;
	    }		
	    year = parseInt(strYear); 
        return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
    },

    DaysArray: function(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
    },

    isDate: function(dtStr, pMsg)
    {
	    var dtCh= "/";
	    var dtCh1= "-";
	    var minYear=1900;
	    var maxYear=2100;

	    var daysInMonth = DaysArray(12)
	    var pos1=dtStr.indexOf(dtCh)
	    if (pos1==-1){
		    pos1=dtStr.indexOf(dtCh1)
		    dtCh= dtCh1;
		    }
	    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)
	    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)

	    month=parseInt(strMonth)
	    day=parseInt(strDay)
	    year=parseInt(strYr)
	    if (pMsg != "")
		    pMsg = pMsg + "\n\n";
	    else
		    pMsg = "";
    		
	    if (!checkSpace(dtStr)){
		    alert(pMsg + "Should not be empty" )
		    return false
	    }
	    if (pos1==-1 || pos2==-1){
		    alert(pMsg + "The date format should be : mm-dd-yy")
		    return false
	    }
	    if (strMonth.length<1 || month<1 || month>12){
		    alert(pMsg + "Please enter a valid month")
		    return false
	    }
	    if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		    alert(pMsg + "Please enter a valid day")
		    return false
	    }
	    if (strYear.length != 2 && strYear.length != 4)
	    {
		    alert("Please enter a valid 2 or 4 digit year")
		    return false
	    }
	    if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		    alert(pMsg + "Please enter a valid date")
		    return false
	    }
        return true
    },

    CDateLR: function(pDate)
    {
	    if (checkSpace(pDate))
	    {
		    var reg = /-/g;
		    pDate = pDate.replace(reg, "/");
		    var dtCh = "/";
		    var pos1=pDate.indexOf(dtCh)
		    var pos2=pDate.indexOf(dtCh,pos1+1)
		    var strMonth=pDate.substring(0,pos1)
		    var strDay=pDate.substring(pos1+1,pos2)
		    var strYear=pDate.substring(pos2+1)
		    if (strYear.length == 2)
			    strYear = "20" + strYear;

		    pDate = strMonth + "/" + strDay + "/" + strYear;
	    }
	    else
		    pDate = ""

	    return pDate;
    }
}
