﻿//***************************************************************************************************************           
// Return a boolean value indicating whether value is alphebet(a-z or A-Z).
//***************************************************************************************************************     
     function IsText(str)
        {
            for (var i = 0; i < str.length; i++) 
            {
               var ch = str.substring(i, i + 1);
                if (((ch < "a" || "z" < ch) && (ch < "A" || "Z" < ch)) && ch != ' ') 
                {
                 return false;
                }
            }
            return true;
        }
//***************************************************************************************************************           
// Trim the value.created by pankaj garg.
//*************************************************************************************************************** 
        function trim(str)
            {
            if(!str || typeof str != 'string')
            return null;

            return str.replace(/^[\s]+/,'').replace(/[\s]+$/,'').replace(/[\s]{2,}/,' ');
           }
           
//***************************************************************************************************************           
// Return a boolean value indicating whether value is null.
//*************************************************************************************************************** 
          
            function IsValueNull(pValue)
            {
                if (trim(pValue)==null || trim(pValue)=="" )
                   return true;
                   return false;
            }

//***************************************************************************************************************           
// Return a boolean value indicating whether value is zero.
//***************************************************************************************************************           
            function IsCurrentReadingZero(pValue)
            {
                if (Number(pValue)==0)
                   return true;
                   return false;
            }
            
//***************************************************************************************************************           
//Return a boolean value indicating whether value is numeric.
//***************************************************************************************************************           
            function IsCurrentReadingNaN(pValue)
            {
                if (isNaN(pValue))
                   return true;
                   return false;
            }
//***************************************************************************************************************           
//Return a boolean value indicating whether value is text.
//***************************************************************************************************************              

          function IsNumeric(str)
            {
              var i;
               for (i = 0; i < str.length; i++)
                {   
                    var c = str.charAt(i);
                    if (((c < "0") || (c > "9"))) return false;
                }
              return true;
            }
//***************************************************************************************************************           
//Return a boolean value indicating whether value is email address.
//***************************************************************************************************************               
          function IsValidEmail(stremail)
            {
                if (stremail.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) == -1)
                return false;
                else
                return true;
            }

//***************************************************************************************************************           
//Return a boolean value indicating whether value is negative.
//***************************************************************************************************************           
            function IsNegative(pValue)
                {
                    if ( Number(pValue) < 0)
                       return true;
                       return false;
                }
                
         
//***************************************************************************************************************                    
         // this function for difference between tow dates.
//***************************************************************************************************************           
        function GetDateDiff(date_1,date_2)
        {   
        
             var picker_1 =new Array();  //yyyy-mm-dd
             var picker_2 =new Array();  //yyyy-mm-dd
             picker_1=date_1.split("-");
             picker_2=date_2.split("-");
             var date1=new Date(Number(picker_1[0]),(Number(picker_1[1])-1),Number(picker_1[2]));
             var date2=new Date(Number(picker_2[0]),(Number(picker_2[1])-1),Number(picker_2[2]));
             var one_day=1000*60*60*24
             var diff =(Math.ceil((date1.getTime()-date2.getTime())/(one_day)))
             return diff
        }                

//***************************************************************************************************************                    
//Return a boolean value indicating whether uploaded file valid with file pre define extentions.
//***************************************************************************************************************    
        function CheckFileExt(ctrl) 
        {
            var file = ctrl.value;
            var type = "";
            var validExtensions = new Array(".csv", ".ldif",".doc",".txt");
            var allowSubmit = false;
            if (file.indexOf("\\") == -1)
            {
                alert("Please upload the resume file with extensions " + (validExtensions.join("  ").toUpperCase()));
                return false;;
            }
            else
            {
                type = file.slice(file.indexOf("\\") + 1);
                var ext = file.slice(file.lastIndexOf(".")).toLowerCase();
                for (var i = 0; i < validExtensions.length; i++) 
                {
                    if (validExtensions[i] == ext) 
                    { 
                      allowSubmit = true; 
                    }
                }
            }
            if (allowSubmit == false)
            {
                alert("Only files with extensions " + (validExtensions.join("  ").toUpperCase()) + " are allowed.");
                return false;
            }
            else
            {
               return true
            }       
            return allowSubmit;
        }

       

