﻿// JScript File

    //character, minimum year and maximum year
    var dtCh= "/";
    var minYear=1900;
    var maxYear=2100;
    
    //To check CapsLock key is turn On (or) Not Onkeypress event
    function checkCapsLock(e )
    {
            var myKeyCode=0;
            var myShiftKey=false;
            var myMsg='Caps Lock is On.\n\nTo prevent entering your password incorrectly,\nyou should press Caps Lock to turn it off.';
        // Internet Explorer 4+
        if ( document.all )
            {
                myKeyCode=e.keyCode;
                myShiftKey=e.shiftKey;
        // Netscape 4
            }
        else if ( document.layers )
            {
                myKeyCode=e.which;
                myShiftKey=( myKeyCode == 16 ) ? true : false;
        // Netscape 6
            }
        else if ( document.getElementById )
            {
                myKeyCode=e.which;
                myShiftKey=( myKeyCode == 16 ) ? true : false;
            }
        // Upper case letters are seen without depressing the Shift key, therefore Caps Lock is on
        if (( myKeyCode >= 65 && myKeyCode <= 90 ) && !myShiftKey )
            {
                alert( myMsg );
        // Lower case letters are seen while depressing the Shift key, therefore Caps Lock is on
            }
        else if (( myKeyCode >= 97 && myKeyCode <= 122 ) && myShiftKey )
            {
                alert( myMsg );
            }
    }
        
    //To Trim the value entered to textbox 
    function trim(s) 
    {
        return s.replace( /^\s*/, "" ).replace( /\s*$/, "" );
    }               
        
    //Function to close the window    
    function Close()
    {
        window.close();
    }

    //Function to check enter value is interger
    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 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
    }
        
    //This Function Allow user to select date by using calendar Control only
    //Once Date is selected and if any changes are made after that it validate the string
    function isDate(obj,dtStr)
    {           
        var daysInMonth = DaysArray(12)
        var pos1=dtStr.indexOf(dtCh)
        var pos2=dtStr.indexOf(dtCh,pos1+1)
        var strDay=dtStr.substring(0,pos1)
        var strMonth=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)
        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("Please use calendar to select date. \nThe date format should be : dd/mm/yyyy")
            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 (strMonth.length<1 || month<1 || month>12)
        {
            alert("Please enter a valid month")
            return false
        }
        if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
            obj.value = dtStr.substring(0,10);
            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){
            obj.value = dtStr.substring(0,10);
            alert("Please enter a valid date")
            return false
        }
        return true
    }
    
    /*Function used to compare the date entered in the Textbox with current date.*/    
    function fnCompareDate(Date1,Date2)
    {
        var arrDate1,arrDate2,dtDate1,dtDate2,intDtCmp  
        intDtCmp=0;
        if((Date1 !="") && (Date2 !=""))
        {
	        arrDate1=Date1.split("/");//splits the date entered in Textbox "-".
   	        arrDate2=Date2.split("/");//splits the current date with "-".
    	    
	        dtDate1 = new Date(arrDate1[2],arrDate1[1],arrDate1[0]);
	        dtDate2 = new Date(arrDate2[2],arrDate2[1],arrDate2[0]);
    		
	        if((dtDate1.getDate()==dtDate2.getDate()) && (dtDate1.getMonth()==dtDate2.getMonth())&& (dtDate1.getFullYear()==dtDate2.getFullYear()))
	        {	       
		        intDtCmp=1; 
	        }
	        else if(dtDate1.getFullYear()<dtDate2.getFullYear())
	        {
		        intDtCmp=-1;
	        }
	        else if((dtDate1.getMonth()<dtDate2.getMonth())&& (dtDate1.getFullYear()==dtDate2.getFullYear()))
	        {
		        intDtCmp=-1;
	        }
	        else if((dtDate1.getDate()<dtDate2.getDate()) && (dtDate1.getFullYear()==dtDate2.getFullYear()) && ((dtDate1.getMonth()==dtDate2.getMonth())))
	        {
		        intDtCmp=-1;
	        }           
	        else
	        {
		        intDtCmp=1;
	        }
        }
        return intDtCmp;       
    }       
    
    /*Function used to compare the date entered in the Textbox with current/firstdate date.*/    
    function fnCompareDate1(Date1,Date2)
    {
        var arrDate1,arrDate2,dtDate1,dtDate2,intDtCmp
    	
        intDtCmp=0;
        if((Date1 !="") && (Date2 !=""))
        {
	        arrDate1=Date1.split("/");//splits the date entered in Textbox "/".
   	        arrDate2=Date2.split("/");//splits the current date with "/".
    	    
	        dtDate1 = new Date(arrDate1[2],arrDate1[1],arrDate1[0]);
	        dtDate2 = new Date(arrDate2[2],arrDate2[1],arrDate2[0]);
    		
	        if((dtDate1.getDate()==dtDate2.getDate()) && (dtDate1.getMonth()==dtDate2.getMonth())&& (dtDate1.getFullYear()==dtDate2.getFullYear()))
	        {
		        intDtCmp=0; //if both dates are equal will not accept
	        }
	        else if(dtDate1.getFullYear()<dtDate2.getFullYear())
	        {
		        intDtCmp=-1;
	        }
	        else if((dtDate1.getMonth()<dtDate2.getMonth())&& (dtDate1.getFullYear()==dtDate2.getFullYear()))
	        {
		        intDtCmp=-1;
	        }
	        else if((dtDate1.getDate()<dtDate2.getDate()) && (dtDate1.getFullYear()==dtDate2.getFullYear()) && ((dtDate1.getMonth()==dtDate2.getMonth())))
	        {
		        intDtCmp=-1;
	        }
	        else
	        {
		        intDtCmp=1;
	        }
        }
        return intDtCmp;
        
    } 
        
    /*Function used to validate Start Date Date textbox.*/        
    function validateInitDate(curDate,fromDate)
    { 
         var dt1,dt2;
         var datecurr , date_Entered;
         var strDate, strMonth, strYear, strCurrFullDate, returnCode;
         
         dt1 = fromDate;
         //alert(dt1)
         if (dt1 != null)
         {
             dt2 = curDate;
             arrCurDate=dt2.split("/");  

             strCurrFullDate = arrCurDate[0] + "/" + arrCurDate[1] + "/" + arrCurDate[2];                 
             //alert(strCurrFullDate)  
             
             returnCode = fnCompareDate(dt1, strCurrFullDate);
             //alert(returnCode)
             if (1 == returnCode)
             {
                return true;
             }
             else if ((0 == returnCode)||(-1 == returnCode))
             {
                return false;
             }    
         }
    }
        
    /*Function used to validate Close Date Date textbox.*/        
    function validateCloseDate(curDate,toDate)
    {
         var dt1,dt2;
         var datecurr , date_Entered;
         var strDate, strMonth, strYear, strCurrFullDate, returnCode;
         
         dt1 = toDate;
         //alert(dt1)
         if (dt1 != null)
         {
             dt2 = curDate;
             arrCurDate=dt2.split("/");  

             strCurrFullDate = arrCurDate[0] + "/" + arrCurDate[1] + "/" + arrCurDate[2];   
             //alert(strCurrFullDate)   
             
             returnCode = fnCompareDate1(dt1, strCurrFullDate);
             //alert(returnCode);
             if (1 == returnCode)
             {
                return true;
             }
             else if ((0 == returnCode)||(-1 == returnCode))
             {
                return false;
             }    
         }
    }
        
    /*Function used to validate whether Second date is less than First date.*/        
    function validateBetweenDates(fromDate,toDate)
    {
         var dt1,dt2;
         var datecurr , date_Entered;
         var strDate, strMonth, strYear, strCurrFullDate, returnCode;
         
         dt1 = fromDate;
         if (dt1 != null)
         {
             dt2 = toDate;            
             arrCurDate1=dt1.split("/");  
             arrCurDate2=dt2.split("/");
                
             strCurrFullDate1 = arrCurDate1[0] + "/" + arrCurDate1[1] + "/" + arrCurDate1[2]; 
             strCurrFullDate2 = arrCurDate2[0] + "/" + arrCurDate2[1] + "/" + arrCurDate2[2];  
             
             returnCode = fnCompareDate1(strCurrFullDate1, strCurrFullDate2);
             if ((1 == returnCode) )
             {           
                return true;
             }
             else if ((-1 == returnCode) || (0 == returnCode))
             {            
                return false;
             }    
         }
    }
    
    //Calculating the Number of Days Between Any Two Dates
    function days_between(date1, date2) 
    {
        // The number of milliseconds in one day
        var ONE_DAY = 1000 * 60 * 60 * 24;

        //Convert both dates in yyyy/mm/dd format
          date1 = date1.split("/");
          date2 = date2.split("/");    
          
          var date11 = new Date(date1[2]+"/"+date1[1]+"/"+date1[0]);  
          var date22 = new Date(date2[2]+"/"+date2[1]+"/"+date2[0]);
          
        // Convert both dates to milliseconds
        var date1_ms = date11.getTime();
        var date2_ms = date22.getTime();

        // Calculate the difference in milliseconds
        var difference_ms = Math.abs(date1_ms - date2_ms);
        
        // Convert back to days and return
        var nofdays;
        nofdays = Math.round(difference_ms/ONE_DAY);
        nofdays = nofdays + 1;
        return nofdays;
    }  
    
    //To check the string is empty
    function empty_chk(obj_str,str1,  error_msg)
    {
        if(trim(str1)=="" || trim(str1)== null)
        //if(str1=="" || str1== null)
        {
           obj_str.focus();
           alert(error_msg)
           return false;
        }
         return true;
    }

   // To check whether a dropdown box is selected or not, when it has a default text.
   function checkDropDownboxSelected(objName, strErrorMsg)
    {       
       if(objName.selectedIndex == 0)
        {
            alert(strErrorMsg)  
            objName.focus();                          
            return false;
        }
        return true;
    }
  function allowcharacters(e)
  { 
    if (window.event)
        key = window.event.keyCode;
        else if (e)
        key = e.which;
        else
        return true;
        if(key!=32)
        {
         if (key<65 || key>=91)
            { 
                //if not a alphebet 
                if (key<97 || key>122)
                {
                    return false;
                }             
            }
        }
  }  
  
   // The function works on key press event, allows only alphabets & space. Can  be used for names.
   function characters(e)
   {
        var unicode;
        try
        {   /*IE*/
            unicode = e.keyCode; 
        }
        catch(err)
        {   
              try
              { 
                    /*Netscape, Mozilla, FireFox...*/
                    unicode = e.which;
              }
              catch(error)
              {
                    /*Other*/
                    unicode = event.keyCode;                      
              }
        }         
        if (unicode!=32)
        { //if the key isn't the Space key (which we should allow)            
            if (unicode<65 || unicode>=91)
            { 
                //if not a alphebet 
                if (unicode<97 || unicode>122)
                {
                    return false;
                }             
            }
        }   
   }
     
 
    // The function works on key press events, allows numbers only, not even space or any other spl characters.
    function numbersonly(e){        
        var unicode=e.charCode? e.charCode : e.keyCode                
        if (unicode<48||unicode>57) //if not a number
            return false //disable key press
    }
    
    //To check whether email ID entered is valid
    function isValidEmailAddress(obj_str,str) 
    {
        var reg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/; // not valid
        var reg2 = /^[a-zA-Z]{1,1}.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/; // valid
        if (!reg1.test(str) && reg2.test(str)) { // if syntax is valid
            return true;
        }
        alert("Invalid e-Mail format : Example@domain.com");
        obj_str.focus();
        return false;
    }

    //key press events to allow only integers and decimal points
    //also key press events to not allow  numeric after two decimal places 
    function numbersonly1(eventObj, obj)
    {
        var keyCode;
        var key = '';
        var strAllNum = "0123456789";
        // Check For Browser Type
        if (document.all){ 
        keyCode=eventObj.keyCode
        }
        else{
        keyCode=eventObj.which
        }

        var str=obj.value

        if(keyCode==46){ 
        if (str.indexOf(".")>0){
        return false
        }
        }
        if((keyCode<48 || keyCode >58) && (keyCode != 46)){ // Allow only integers and decimal points
        return false
        }
       
        if(str.indexOf('.') != -1)
               {
                if(str.indexOf('.') == str.length - 3)
                if(strAllNum.indexOf(keyCode) == -1)//two places after decimal dont allow any numeric now
                    return false;
               }
             return true
    }
    
    //key press events for alphanumeric characters
    function letternumber(e)
    {
        var key;
        var keychar;
        if (window.event)
        key = window.event.keyCode;
        else if (e)
        key = e.which;
        else
        return true;
        keychar = String.fromCharCode(key);
        keychar = keychar.toLowerCase();
        // control keys
        if ((key==null) || (key==0) || (key==8) || 
        (key==9) || (key==13) || (key==27) || (key==32) || (key==46))
        return true;
        // alphas and numbers
        else if ((("abcdefghijklmnopqrstuvwxyz0123456789").indexOf(keychar) > -1))
        return true;
        else        
        return false;
    }
    
      //key press events for alphanumeric characters with - , _  spl characters
      function namefields(e)
      {
     
      var key;
      var keychar;
      
      if (window.event)
        key = window.event.keyCode;        
        else if (e)
        key = e.which;
        else
        return true;
        
        keychar = String.fromCharCode(key);       
        keychar = keychar.toLowerCase();
        // control keys
        if ((key==null) || (key==0) || (key==8) || 
        (key==9) || (key==13) || (key==27) || (key==32) || (key==45) || (key==95))
        return true;
        // alphas and numbers
        else if ((("abcdefghijklmnopqrstuvwxyz0123456789-_").indexOf(keychar) > -1))
        return true;
        else
        return false;
      
      }
       //key press events for alphanumeric characters with /  spl characters
      function filepath(e)
      {
     
      var key;
      var keychar;
      
      if (window.event)
        key = window.event.keyCode;        
        else if (e)
        key = e.which;
        else
        return true;
        keychar = String.fromCharCode(key);       
        keychar = keychar.toLowerCase();
        // 8 - Backspace; 9 - Horizontal tab, move to next tab stop;
        // 13 - Carriage Return(Enter tab); 27 - Escape; 32 - Space; 45-Hyphen, dash, minus ; 46- Period; 47- Slant (forward slash, divide) 
        // control keys
        if ((key==null) || (key==0) || (key==8) || 
        (key==9) || (key==13) || (key==27) || (key==32) || (key==46) || (key==47))
        return true;
        // alphas and numbers
        else if ((("abcdefghijklmnopqrstuvwxyz0123456789").indexOf(keychar) > -1))
        return true;
        else
        return false;
      
      }
       function address(e)
      {
     
      var key;
      var keychar;
      if (window.event)
        key = window.event.keyCode;
        else if (e)
        key = e.which;
        else
        return true;
        
        keychar = String.fromCharCode(key);
        keychar = keychar.toLowerCase();
        // control keys
        if((key == 188) || (key == 192) ||(key == 222))
        return false; 
      
      }
      //key press events for alphanumeric characters with  spl characters
      function addressfields(e)
      {
     
      var key;
      var keychar;
      
      if (window.event)
        key = window.event.keyCode;
        else if (e)
        key = e.which;
        else
        return true;
        keychar = String.fromCharCode(key);
        keychar = keychar.toLowerCase();
        // control keys
        if ((key==null) || (key==0) || (key==8) || 
        (key==9) || (key==13) || (key==27) || (key==32) || (key==46) || (key==45) || (key==95))
        return true;
        // alphas and numbers
        else if ((("abcdefghijklmnopqrstuvwxyz0123456789-_#(){}[]|\"'?/:;,").indexOf(keychar) > -1))
        return true;
        else
        return false;
      
      }
    
    
    // The function checks whether the entry is a valid file name. eg: SeatUtilizationTest.aspx. It checks for a valid file extension
    function checkFileName(ctrlName, extn )
    {       

        var sCtrl;
        var badName="", allBlank=true, rx;
        rx=new RegExp("[^\.]\."+extn+"\s*$", "i");      

        sCtrl = ctrlName;
        
        if(sCtrl.type=='text')
       {       
         sCtrl.value=sCtrl.value.replace(/^\s+/,'').replace(/\s+$/,'');       
            if(sCtrl.value.length )
            { 
                allBlank=false;
                if( !rx.test(sCtrl.value) )        
                     badName+='\n\n' + sCtrl.value;
            } 
        } 
        
        if(sCtrl.type=='file')
       {       
         sCtrl.value=sCtrl.value.replace(/^\s+/,'').replace(/\s+$/,'');       
            if(sCtrl.value.length )
            { 
                allBlank=false;
                if( !rx.test(sCtrl.value) )        
                     badName+='\n\n' + sCtrl.value;
            } 
        } 
        
        if( allBlank )        
            alert("File name must not be empty")         

        else if( badName )        
            alert( 'A required .'+extn+' extension was not found in:' + badName );

        return (badName || allBlank) ? false : true; 
    }
    
    function isTime(e)
    {
        //var reg1 = /^\d[0-9]{1,2}\:\d[0-9]{1,2}$/;
        var unicode=e.charCode? e.charCode : e.keyCode     
        if(unicode != 58)
        { 
            if (unicode<48||unicode>57) //if not a number
                return false //disable key press    
        }
    }

    // Checks if time is in HH:MM:SS AM/PM format.
    // The seconds and AM/PM are optional.
    function IsValidDateTime(strTime) 
    {
        var timePat = /^(\d{1,2}):(\d{2})(:(\d{2}))?(\s?(AM|am|PM|pm))?$/;
        var matchArray = strTime.match(timePat);
        if (matchArray == null) 
        {
            alert("Login time is not in a valid format.");
            return false;
        }  

        hour = matchArray[1];
        minute = matchArray[2];
        second = matchArray[4];
        ampm = matchArray[6]; 

        if (second=="") { second = null; }
        if (ampm=="") { ampm = null }
  
        if (hour < 0  || hour > 23)
        {
            alert("Hour must be between 1 and 12. (or 0 and 23 for military time)");
            return false;
        }
  
        if (hour <= 12 && ampm == null) 
        {
            alert(confirm("Please indicate which time format you are using.  OK = Standard Time, CANCEL = Military Time"))
            if (confirm("Please indicate which time format you are using.  OK = Standard Time, CANCEL = Military Time")) 
            {
                alert("You must specify AM or PM.");
                return false;
             }
             else
                 return false;
        }
        if  (hour > 12 && ampm != null) 
        {
            alert("You can't specify AM or PM for military time.");
            return false;
        }
        if (minute<0 || minute > 59) 
        {
            alert ("Minute must be between 0 and 59.");
             return false;
        }
        if (second != null && (second < 0 || second > 59)) 
        {
         alert ("Second must be between 0 and 59.");
        return false;
        }
        return false;
    }

    // Checks if time is in HH:MM format.
    function IsValidTime(strTime,errMsg) 
    {
        var timePat = /^(\d{1,2}):(\d{2})$/;
        var matchArray = strTime.match(timePat);
        if (matchArray == null) 
        {
        alert(errMsg);
        return false;
        }  
        hour = matchArray[1];
        minute = matchArray[2];

        if (hour < 0  || hour > 23)
        {
            alert("Hour must be between 0 and 23.");
            return false;
        }
        if (minute<0 || minute > 59) 
        {
            alert ("Minute must be between 0 and 59.");
            return false;
        }
         return true;
     }

    // Opens a new popup window with the required page
    function popWin(url, name, args) 
    {
        if (typeof(popupWin) != "object")
        {
            popupWin = window.open(url,name,args);
        } 
        else
        {
            if (!popupWin.closed)
            { 
                popupWin.location.href = url;
            }
            else
            {
                popupWin = window.open(url, name,args);
             }
        }
        popupWin.focus();
     }   

    // Allows only Uppercase alphabets and numbers.No space or other special characters 
    function RouteNumber(e)
    {
        var key;
        var keychar;
        if (window.event)
        key = window.event.keyCode;        
        else if (e)
        key = e.which;
        else
        return true;
        keychar = String.fromCharCode(key);
        // control keys
        if ((key==null) || (key==0) || (key==8) || 
        (key==9) || (key==13) || (key==27) )
        return true;
        // alphas and numbers       
        else if ((("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789").indexOf(keychar) > -1))
        return true;
        else
        return false;
    }

    // Function checks whether the entered value is interger 
    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 checks for the maximum length of the characters entered. If it exceeds the specified no. of characters, shows error message is shown.
    function maxLength(objName, objVaue, errMsg, maxlength)
        {
            var sLength;            
            sLength = objVaue.length;
            
            if(sLength > maxlength)
            {
                objName.focus();
                alert(errMsg);
                return false;
            }            
            return true;
        }   
        
    // Function checks for the minimum length of the characters entered. If it is less than the specified no. of characters, error message is shown
    function minLength(objName, objVaue, errMsg, minlength)
        {
            var sLength;            
            sLength = objVaue.length;
            
            if(sLength < minlength)
            {
                objName.focus();
                alert(errMsg);
                return false;
            }            
            return true;
        }         
        
    // Function checks whether the entered string is a combination of interger/characters and space. If not an alpha numeric character then it displays an error message
    function isalphawithspace(objName,str,errMsg)
    {
        var numaric = str;
        for(var j=0; j<numaric.length; j++)
        {
            var alphaa = numaric.charAt(j);
            var hh = alphaa.charCodeAt(0);
            if((hh > 64 && hh<91) || (hh > 96 && hh<123) || (hh == 32))
            { 
            }
            else
            {

                objName.focus();
                alert(errMsg);
                return false;
            }
        }
        return true;
    }
    
    // Function checks whether the entered string is a combination of interger/characters and space. If not an alpha numeric character then it displays an error message
    //Does not check for "&"
    function isalphawithspaceforScreen(objName,str,errMsg)
    {
        var numaric = str;
        for(var j=0; j<numaric.length; j++)
        {
            var alphaa = numaric.charAt(j);
            var hh = alphaa.charCodeAt(0);
            if((hh > 64 && hh<91) || (hh > 96 && hh<123) || (hh == 32) || (hh == 38))
            { 
            }
            else
            {

                objName.focus();
                alert(errMsg);
                return false;
            }
        }
        return true;
    }
    
    // Function checks whether the entered string is a combination of interger/characters and space. If not an alpha numeric character then it displays an error message
    function isalphaforDept(objName,str,errMsg)
    {
        var numaric = str;
        for(var j=0; j<numaric.length; j++)
        {
            var alphaa = numaric.charAt(j);
            var hh = alphaa.charCodeAt(0);
            if((hh > 64 && hh<91) || (hh > 96 && hh<123) || (hh == 32) || (hh == 45))
            { 
            }
            else
            {

                objName.focus();
                alert(errMsg);
                return false;
            }
        }
        return true;
    }
  
    // Function checks whether the entered string is a combination of interger/characters. If it contains character with numeric values then it displays an error message
    function isNotNumeric(objName,str,errMsg)
    {
        var numaric = str;
        var iChars = '1234567890';
        
        for(var j=0; j<numaric.length; j++)
        {
            var alphaa = numaric.charAt(j);
            var hh = alphaa.charCodeAt(0);
            
            if((iChars.indexOf(alphaa)) == -1)
            {
            }
            else
            {

                objName.focus();
                alert(errMsg);
                return false;
            }
        }
        return true;
    }
    
    // Function checks whether the entered string is a combination of Speacial Characters/characters. If it contains character with Speacial Characters then it displays an error message
    function isSpecialCharacters(objName,str,errMsg)
    {
        var numaric = str;
        var iChars = '~`!@#$%^&*()_-=+|\{}[]\'";:?/.><,';
        
        for(var j=0; j<numaric.length; j++)
        {
            var alphaa = numaric.charAt(j);
            var hh = alphaa.charCodeAt(0);
            
            if((iChars.indexOf(alphaa)) == -1)
            {
            }
            else
            {

                objName.focus();
                alert(errMsg);
                return false;
            }
        }
        return true;
    }
    // Function checks whether the entered string is a combination of Speacial Characters/characters. If it contains character with Speacial Characters then it displays an error message
    function isSpecialCharacters(objName,str,errMsg)
    {
        var numaric = str;
        var iChars = '~`!@#$%^&*()=+|\{}[]\'";:?/.><,';
        
        for(var j=0; j<numaric.length; j++)
        {
            var alphaa = numaric.charAt(j);
            var hh = alphaa.charCodeAt(0);
            
            if((iChars.indexOf(alphaa)) == -1)
            {
            }
            else
            {

                objName.focus();
                alert(errMsg);
                return false;
            }
        }
        return true;
    }
    
    // Function checks whether the entered string is a combination of interger/characters. If not an alpha numeric character then it displays an error message
    function isalphanumeric(objName,str,errMsg)
    {
        var numaric = str;
        for(var j=0; j<numaric.length; j++)
        {
            var alphaa = numaric.charAt(j);
            var hh = alphaa.charCodeAt(0);
            if((hh > 47 && hh<59) || (hh > 64 && hh<91) || (hh > 96 && hh<123))
            {
            }
            else	
            {
                objName.focus();
                alert(errMsg);
                return false;
            }
        }
        return true;
    }

    // Function checks whether the entered string is a combination of characters only. If not an alpha character then it displays an error message
    function isalpha(objName,str,errMsg)
    {
        var numaric = str;
        for(var j=0; j<numaric.length; j++)
        {
            var alphaa = numaric.charAt(j);
            var hh = alphaa.charCodeAt(0);
            
            if((hh > 64 && hh<91) || (hh > 96 && hh<123))
            {
           
            }
            else	
            {
                objName.focus();
                alert(errMsg);
                return false;
            }
        }
        return true;
    }

    // Function checks whether the entered string is a combination of intergers only. If not an numeric then it displays an error message
    function isNumeric(objName,str,errMsg)
    {
        var numaric = str;
        for(var j=0; j<numaric.length; j++)
        {
            var alphaa = numaric.charAt(j);
            var hh = alphaa.charCodeAt(0);
            
            if((hh > 47 && hh<59))
            {
           
            }
            else	
            {
                objName.focus();
                alert(errMsg);
                return false;
            }
        }
        return true;
    }
    
    // Function checks whether the entered string is a combination of intergers only. If not an numeric then it displays an error message
     function isRegistrationNumber(objName,str,errMsg)
    {
        var numaric = str;
        for(var j=0; j<numaric.length; j++)
        {
            var alphaa = numaric.charAt(j);
            var hh = alphaa.charCodeAt(0);
            if((hh > 47 && hh<59) || (hh > 64 && hh<91) || (hh > 96 && hh<123) || (hh == 32) || (hh == 45) || (hh == 27)  
            || (hh == 13)  || (hh == 9) 
            || (hh == 8)  || (hh == 0)  || (hh == null))
            {

            }
            else	
            {
                objName.focus();
                alert(errMsg);
                return false;
            }
        }
        return true;
 
    }    

    // Function checks whether the entered string is a combination of intergers only. If not an numeric then it displays an error message

     function isRouteNumber(objName,str,errMsg)
    {
        var numaric = str;
        for(var j=0; j<numaric.length; j++)
        {
            var alphaa = numaric.charAt(j);
            var hh = alphaa.charCodeAt(0);
            if((hh > 47 && hh<59) || (hh > 64 && hh<91) || (hh == 27)  
            || (hh == 13)  || (hh == 9) 
            || (hh == 8)  || (hh == 0)  || (hh == null))
            {

            }
            else	
            {
                objName.focus();
                alert(errMsg);
                return false;
            }
        }
        return true;
 
    }
    
function validateDate(obj,str,errMsg)
{    
    var datePat = /^\d{1,2}\/\d{1,2}\/\d{4}$/;
    ///^(\d{2})\/\(\d{2})\/\(\d{4})$/;
    var matchArray = str.match(datePat);

    if (matchArray == null) 
    {
        //alert("Entered date is not in a valid format.");
        obj.focus();
        alert(errMsg);
        return false;
    }
    return true; 
}
  
    // The function to check whether passed string contains spaces
    function hasWhiteSpace(str) 
    {
        var i;
        for(i=0;i<str.length;i++)
        {
                if(str.charAt(i)==' ')
                {
                    return false;
                }
        }

    }

    // Function checks whether the entered string is a combination of intergers and decimals only. If not an numeric then it displays an error message
    
    function isNumericWithDecimal(objName,str,errMsg)
    {
        var numaric = str;
        for(var j=0; j<numaric.length; j++)
        {
            var alphaa = numaric.charAt(j);
            var hh = alphaa.charCodeAt(0);
            if((hh > 47 && hh<59)||(hh == 46))
            {          

            }
            else 
            {
                objName.focus();
                alert(errMsg);
                return false;
            }
        }
        return true;
    }

  function NumericWithDecimal(e)
    {
        var key;
        var keychar;
        if (window.event)
        key = window.event.keyCode;        
        else if (e)
        key = e.which;
        else
        return true;
        keychar = String.fromCharCode(key);
        //keychar = keychar.toLowerCase();
        
        // control keys
        if ((key==null) || (key==0) || ((key > 47 && key<59)||(key == 46)) )
            return true;
        else
            return false;
    }


    // Function checks whether the entered string is a combination of interger/characters, space,numbersSign,coma,hyphen,dot. If not an alpha numeric character then it displays an error message [space32 #35 ,44 -45 .46 ]
    function isalphanumericwithSpecialChars(objName,str,errMsg)
    {
        var numaric = str;
        for(var j=0; j<numaric.length; j++)
        {
            var alphaa = numaric.charAt(j); 
            var hh = alphaa.charCodeAt(0);
            if((hh > 47 && hh<59) || (hh > 64 && hh<91) || (hh > 96 && hh<123) || (hh == 32) || (hh == 35) || (hh == 44) || (hh == 45) || (hh == 46))
            {
            }
            else	
            {
                objName.focus();
                alert(errMsg);
                return false;
            }
        }
        return true;
    }
    // The function works on key press event, allows only alphabets,- & space. Can  be used for names.
   function characterswithsplcharacter(e)
   {
        var unicode;
        try
        {   /*IE*/
            unicode = e.keyCode; 
        }
        catch(err)
        {   
              try
              { 
                    /*Netscape, Mozilla, FireFox...*/
                    unicode = e.which;
              }
              catch(error)
              {
                    /*Other*/
                    unicode = event.keyCode;                      
              }
        }  
         if (unicode!=45)
        {        
            if (unicode!=32)
            { //if the key isn't the Space key (which we should allow)            
                if (unicode<65 || unicode>=91)
                { 
                    //if not a alphebet 
                    if (unicode<97 || unicode>122)
                    {
                        return false;
                    }             
                }
            } 
        }  
   }
     
    // Function checks whether the entered string is a combination of single quote and <>.
    function isSingleQuote(objName,str,errMsg)
    {
        var numaric = str;
        
        for(var j=0; j<numaric.length; j++)
        {
            var alphaa = numaric.charAt(j); 
            var hh = alphaa.charCodeAt(0);
            
            if(hh==39)
            {
                objName.focus();
                alert(errMsg);
                return false;
            }
            if(hh==60)
            {
                objName.focus();
                alert(errMsg);
                return false;
            }
            if(hh==62)
            {
                objName.focus();
                alert(errMsg);
                return false;
            }
        }
        return true;
    }   
    
    //Key press event for alphanumericwithSpecialChars
    function alphanumericwithSpecialChars(e)
    {    
        var key;
        var keychar;
        if (window.event)
        key = window.event.keyCode;
        else if (e)
        key = e.which;
        else
        return true;
        //alert(key)
        keychar = String.fromCharCode(key);
        keychar = keychar.toLowerCase();
        // control keys
        if ((key==null) || (key==0) || (key==8) || 
        (key==9) || (key==13) || (key==27) || (key==32) || (key==35) || (key==46) || (key==44) || (key==45))
        return true;
        // alphas and numbers
        else if ((("abcdefghijklmnopqrstuvwxyz0123456789").indexOf(keychar) > -1))
        return true;
        else
        return false;        
    }
    
    //To check whether one time is greater than other.    
    function checkTimeDiff(time1,time2,errMsg)
    {               
        var sTime1, sTime2, sTimeDiff;
        sTime1 = time1.value;
        sTime2 = time2.value;
                    
        if(sTime1 >= sTime2)
        {
            alert(errMsg);   
            time1.focus();
            return false;             
        }
        return true;     
    }
    
    //For triming the Text Box Values.
    String.prototype.trim = function ()
    {
        return this.replace(/^\s*/, "").replace(/\s*$/, "");
    }
    
    
    /****************************************************************************************************************
  Function Name   : compDates
  Author          : Irshad Bhat
  Created Date    : 12/06/2008
  Description     : Check for To Date to be greater than or equal to the From Date.
 
  Revision History:
-----------------------------------------------------------------------------------------------------------------
  Date Changed          Changed By        Version           Comments
-----------------------------------------------------------------------------------------------------------------
*****************************************************************************************************************/
function compDates(fromDate, toDate, dateFormat)
{
	var arrFromDate,arrToDate;
	arrFromDate = fromDate.split('/');
	arrToDate = toDate.split('/');
	
    if(dateFormat == "%d/%m/%Y")
    {   
	    if((parseInt(arrToDate[2],10)<parseInt(arrFromDate[2],10)) || ((parseInt(arrToDate[2],10) == parseInt(arrFromDate[2],10)) && (parseInt(arrToDate[1],10)<parseInt(arrFromDate[1],10))) || (parseInt(arrToDate[2],10)==parseInt(arrFromDate[2],10) && parseInt(arrToDate[1],10)==parseInt(arrFromDate[1],10) && parseInt(arrToDate[0],10)<parseInt(arrFromDate[0],10)))
	    {
	        alert ("To Date Cannot be less than From Date");
	        return false;
	    }
	    else
	        return true;	    
    }
    else
    {
	    if((parseInt(arrToDate[2],10)<parseInt(arrFromDate[2],10)) || ((parseInt(arrToDate[2],10) == parseInt(arrFromDate[2],10)) && (parseInt(arrToDate[0],10)<parseInt(arrFromDate[0],10))) || (parseInt(arrToDate[2],10)== parseInt(arrFromDate[2],10) && parseInt(arrToDate[0],10)==parseInt(arrFromDate[0],10) && parseInt(arrToDate[1],10)<parseInt(arrFromDate[1],10)))
	    {
	        alert ("To Date Cannot be less than From Date");
	        return false;
	    }
	    else
	        return true;	            
    }	    
}

/****************************************************************************************************************
  Function Name   : compDates2
  Author          : Irshad Bhat
  Created Date    : 12/06/2008
  Description     : Check for To Date to be greater than or equal to the From Date.
 
  Revision History:
-----------------------------------------------------------------------------------------------------------------
  Date Changed          Changed By        Version           Comments
-----------------------------------------------------------------------------------------------------------------
*****************************************************************************************************************/
function compDates2(fromDate, toDate, dateFormat)
{
	var arrFromDate,arrToDate;
	arrFromDate = fromDate.split('/');
	arrToDate = toDate.split('/');
	
    if(dateFormat == "%d/%m/%Y")
    {   
	    if((parseInt(arrToDate[2],10)<parseInt(arrFromDate[2],10)) || ((parseInt(arrToDate[2],10) == parseInt(arrFromDate[2],10)) && (parseInt(arrToDate[1],10)<parseInt(arrFromDate[1],10))) || (parseInt(arrToDate[2],10)==parseInt(arrFromDate[2],10) && parseInt(arrToDate[1],10)==parseInt(arrFromDate[1],10) && parseInt(arrToDate[0],10)<parseInt(arrFromDate[0],10)))
	    {	        
	        return false;
	    }
	    else
	        return true;	    
    }
    else
    {
	    if((parseInt(arrToDate[2],10)<parseInt(arrFromDate[2],10)) || ((parseInt(arrToDate[2],10) == parseInt(arrFromDate[2],10)) && (parseInt(arrToDate[0],10)<parseInt(arrFromDate[0],10))) || (parseInt(arrToDate[2],10)== parseInt(arrFromDate[2],10) && parseInt(arrToDate[0],10)==parseInt(arrFromDate[0],10) && parseInt(arrToDate[1],10)<parseInt(arrFromDate[1],10)))
	    {	        
	        return false;
	    }
	    else
	        return true;	            
    }	    
}

/****************************************************************************************************************
  Function Name   : compClosureDate
  Author          : Irshad Bhat
  Created Date    : 12/06/2008
  Description     : Check for To Date to be greater than or equal to the From Date.
 
  Revision History:
-----------------------------------------------------------------------------------------------------------------
  Date Changed          Changed By        Version           Comments
-----------------------------------------------------------------------------------------------------------------
*****************************************************************************************************************/
function compClosureDate(fromDate, toDate, dateFormat)
{
	var arrFromDate,arrToDate;
	arrFromDate = fromDate.split('/');
	arrToDate = toDate.split('/');
	
    if(dateFormat == "%d/%m/%Y")
    {   
	    if((parseInt(arrToDate[2],10)<parseInt(arrFromDate[2],10)) || ((parseInt(arrToDate[2],10) == parseInt(arrFromDate[2],10)) && (parseInt(arrToDate[1],10)<parseInt(arrFromDate[1],10))) || (parseInt(arrToDate[2],10)==parseInt(arrFromDate[2],10) && parseInt(arrToDate[1],10)==parseInt(arrFromDate[1],10) && parseInt(arrToDate[0],10)<parseInt(arrFromDate[0],10)))
	    {
	        //alert ("To Date Cannot be less than From Date");
	        return false;
	    }
	    else
	        return true;	    
    }
    else
    {
	    if((parseInt(arrToDate[2],10)<parseInt(arrFromDate[2],10)) || ((parseInt(arrToDate[2],10) == parseInt(arrFromDate[2],10)) && (parseInt(arrToDate[0],10)<parseInt(arrFromDate[0],10))) || (parseInt(arrToDate[2],10)== parseInt(arrFromDate[2],10) && parseInt(arrToDate[0],10)==parseInt(arrFromDate[0],10) && parseInt(arrToDate[1],10)<parseInt(arrFromDate[1],10)))
	    {
	        //alert ("To Date Cannot be less than From Date");
	        return false;
	    }
	    else
	        return true;	            
    }	    
}
function textCounter(field,cntfield,maxlimit)

 {
 
    if (field.value.length > maxlimit) // if too long...trim it!
    field.value = field.value.substring(0, maxlimit);
    // otherwise, update 'characters left' counter
    else
    cntfield.value = maxlimit - field.value.length;
  }
  // To check whether Read Permission is given.. and make all button controls disabled
    
  function getPagePermission(pid)
    { 
            if(pid =="1")
            {
                var elem = document.forms[0].elements;
                //alert(elem.length);
                for(var i = 0; i < elem.length; i++)
                {
                    if(elem[i].type == "submit")
                    {
                    //document.getElementById(elem[i].name).disabled = true;
                    document.getElementById(elem[i].name).style.display='none';
                    document.getElementById(elem[i].name).style.cursor ="display:none";
                    }
                            
                }
            }
        
    }
    
    //OnKeyPress(hit) of ENTER tab(13), this function is called to submit the page.
    function DisplayKey(e) 
    {
        if (e.keyCode) 
        keycode=e.keyCode;
        else 
        keycode=e.which;
        
        if (keycode==13) 
        {
          document.form1.submit();  
        }  
}