﻿

  // This is for the Key Press Event returns true only for Backspace,Delete and Tab.
    function Keypress_Event(e)
    { 
        e = e || window.event;
        ch = e.which || e.keyCode;
        if( ch != null)
           {
              if(ch == 8 || ch == 46 || ch == 127 || ch==9 || ch==37 || ch==39)
                 return true;
              else
                 return false;   
           }                                              
    }
    function Keypress_Number(e,txtBox)
    { 
        e = e || window.event;
        ch = e.which || e.keyCode;
        var value=document.getElementById(txtBox).value
                
        if( ch != null)
           {
              if(ch == 8 || ch == 46 || ch == 127 || ch==9 || (ch > 95 && ch < 106) || ch==37 || ch==39 || ch==109 || ch==189)
                 return true;
              else if(ch==110 || ch==190) ////For Decimal
              {
                if(value.indexOf('.')>=0)
                    return false;
                else
                    return true;
              }
              else if (ch > 31 && (ch < 48 || ch > 57)) //For Alphabets                           
                 return false;                                 
              else
                return true;  
           }                                              
    }
    function Trim(str)
    { 
         while(str.charAt(0) == (" ") )
          {  
            str = str.substring(1);
          }
         while(str.charAt(str.length-1) == " " )
          {  
            str = str.substring(0,str.length-1);
          }
          return str;
    }
    function Keypress_Integer(e,txtBox)
    { 
        e = e || window.event;
        ch = e.which || e.keyCode;
        var value=document.getElementById(txtBox).value
                
        if( ch != null)
           {
              if(ch == 8 || ch == 46 || ch == 127 || ch==9 || (ch > 95 && ch < 106) || ch==37 || ch==39)
                 return true;
              else if(ch==110 || ch==190) ////For Decimal
              {               
                    return false;               
              }
              else if (ch > 31 && (ch < 48 || ch > 57)) //For Alphabets                           
                 return false;                                 
              else
                return true;  
           }                                              
    }
    
    function Keypress_Time(e)
    { 
        e = e || window.event;
        ch = e.which || e.keyCode;
        if( ch != null)
           {
              if(ch == 8 || ch == 46 || ch == 127 || ch==9 || (ch > 95 && ch < 106) ||  ch==37 || ch==39 || ch==186 )
                 return true;
              else if (ch > 31 && (ch < 48 || ch > 57))              
                 return false;
              else
                return true;  
           }                                              
    }
    function uploadImage(ctrImage,ctrlFileUpload)
    {
       // alert(ctrImage + ctrlFileUpload);
         var x= document.getElementById(ctrImage);
        
         x.src= document.getElementById(ctrlFileUpload).value;
     //  document.getElementById('ctrImage).src = document.getElementById(ctrlFileUpload).value;
     return false;
    }
    
     function fnConfirmlnkDel123()
{
   var ans;
        ans=confirm("Are you sure you want to delete this message?");
        if (ans==true)
        {return true;}
        else
        { return false; }
      
 }    
    
    function SetFocus(ctrAnything)
    {
        document.getElementById(ctrAnything).focus();
    }
    
    function validateDateDiff(FromDate,ToDate)
    {
          var sDate=new Date(FromDate);
          var eDate=new Date(ToDate);
                   
          if((FromDate != "") && (ToDate == ""))
            {
                alert('Please enter To Date.');
                return false;    
            }        
            else if((FromDate == "") && (ToDate != ""))
            {
                alert('Please enter From Date.');
                return false;    
            }
            else if(sDate > eDate)
            {                
                 alert('From Date cannot be less than To Date.');
                 return false;    
            }
            else
            {                
                return true;
            }
                                 
    }
    
    function checkdate(input)
    {        
        if(input !="")
        {
            var validformat=/^\d{2}\/\d{2}\/\d{4}$/ //Basic check for format validity
            var returnval=false;
            if (!validformat.test(input))
                alert("Invalid Date Format. Please correct and submit again.");
            else
                returnval=true;
           
            return returnval;
            
        }
        else
            return true;
    }
    
    function chkSpecialChars(input)
    {
        var iChars = "!@#$%^&*()+=-[]\\\';,./{}|\":<>?";

        for (var i = 0; i < input.length; i++) 
        {
  	        if (iChars.indexOf(input.charAt(i)) != -1) 
  	        {
  	            alert ("You are using special characters. \nThese are not allowed.\n Please remove them and try again.");
  	            return false;
  	        }
        }
        return true;
    }
    function CustomValidateSearch(source,args)
    {
        var checkfield = args.Value;
        var t= 0;
        var iChars = "&'<>\"#";
        for (var i = 0;i < checkfield.length; i++)
        {
  	        if (iChars.indexOf(checkfield.charAt(i))!= -1)
  	        {
  	           t=1;
  	        }  	        
  	        
        }
        
             
         if(t==1)
        {
          args.IsValid=false 
          
        }
        else
        {
          args.IsValid=true
         
        }
    }
    
    
//    ///////////////////////////////////////////////////////////////////////////
////Count Characters General
/////////////////////////////////////////////////////////////////////////////
function CharacterCountlimit(sourceTextBox, maxLength)
{

    if(sourceTextBox != null)
    {
           // try
          //  {
                sourceTextBox = document.getElementById(sourceTextBox);                
                if(sourceTextBox != null)
                {
                    var len = sourceTextBox.value.length
                    if (len<=maxLength)
                    {
                        //displayControl.value = maxLength -len;
                        return true;
                    }
                    else
                    {
                        sourceTextBox.value = sourceTextBox.value.substring(0, maxLength);
                        return false;
                    }
               }
         //  }
       //   catch(e)
        //   {
        //   alert(e.description):
          // }
    }
}

    
        ///////////////////////////////////////////////////////////////////////////
//Count Characters General
///////////////////////////////////////////////////////////////////////////
function CountCharactersGeneral(sourceTextBox, displayControl, maxLength)
{

    if(sourceTextBox != null && displayControl != null)
    {
           // try
          //  {
                sourceTextBox = document.getElementById(sourceTextBox);
                displayControl = document.getElementById(displayControl);
                if(sourceTextBox != null)
                {
                    var len = sourceTextBox.value.length
                    if (len<=maxLength)
                    {
                        //displayControl.value = maxLength -len;
                        displayControl.innerHTML = maxLength -len + " Character(s) remaining.";
                    }
                    else
                    {
                        sourceTextBox.value = sourceTextBox.value.substring(0, maxLength);
                        return false;
                    }
               }
         //  }
       //   catch(e)
        //   {
        //   alert(e.description):
          // }
    }
}

    
    function CustomValidate(source,args)
    {
        //alert('hi');
        var checkfield = args.Value;
        var t= 0;
        var iChars = "<>\#";
        for (var i = 0;i < checkfield.length; i++)
        {
  	        if (iChars.indexOf(checkfield.charAt(i))!= -1)
  	        {
  	           t=1;
  	        }  	        
  	        
        }
        
             
         if(t==1)
        {
          args.IsValid=false 
          
        }
        else
        {
          args.IsValid=true
         
        }
         
     }    
     
     function GetCDate(source,args)
     {
     
        var myDate = new Date();
        var dtMDate=args.Value;
            if (Number(dtMDate.split("/")[2])<myDate.format('yyyy'))
            {
                args.IsValid= true;
            }
            else if (Number(dtMDate.split("/")[2])==myDate.format('yyyy'))
            {
                if(Number(dtMDate.split("/")[0])<myDate.format('MM'))
                {
                    args.IsValid= true;
                }
                else if (Number(dtMDate.split("/")[0])==myDate.format('MM'))
                {
                     if(Number(dtMDate.split("/")[1])<myDate.format('dd'))
                          args.IsValid= true;
                     else
                         args.IsValid=false;
                }
                else
                { 
                    args.IsValid=false;              
                } 
            }
            else
            { 
                args.IsValid=false;              
            } 
     }   
          
     function ValidDate(source,args)
        {
        var datevalue=args.Value;
        var flag=new Boolean(true);
            // Checks for the following valid date formats:
            // MM/DD/YY   MM/DD/YYYY   MM-DD-YY   MM-DD-YYYY
            // Also separates date into month, day, and year variables
            //var datePat = /^(\d{1,2})(\/)(\d{1,2})\2(\d{2})$/;
            //var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{2}|\d{4})$/;

            // To require a 4 digit year entry, use this line instead:
            var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/;
            var matchArray = datevalue.match(datePat); // is the format ok?
            if (matchArray == null) 
            {
                  flag=false;
            }
            else
            {
                month = matchArray[1]; // parse date into variables
                day = matchArray[3];
                year = matchArray[4];
                if (month < 1 || month > 12) 
                {  
                      flag=false;
                }
                if (day < 1 || day > 31) 
                {
                        flag=false;
                }
                if ((month==4 || month==6 || month==9 || month==11) && day==31) 
                {
                        flag=false;
                }
                if (month == 2) 
                { 
                    // check for february 29th
                    var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
                    if (day>29 || (day==29 && !isleap)) 
                    {
                            flag=false;
                   }
                }
            }
            args.IsValid= flag;
    }
    
     
     
  
