 /* Copyright (c) 2005-2006 WIPRO. All Rights Reserved.
 * 
 *  This software is the confidential and proprietary information of WIPRO
 *  ("Confidential Information"). You shall not
 *  disclose such Confidential Information and shall use it only in
 *  accordance with the terms of the license agreement you entered into
 *  with WIPRO.
 *  
 * WIPRO MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE 
 * SUITABILITY OF THE SOFTWARE, EITHER EXPRESS OR IMPLIED, 
 * INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF 
 * MERCHANTABILITY, FITNESS FOR A
 * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. WIPRO SHALL NOT BE 
 * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF 
 * USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS 
 * DERIVATIVES.
 * o
 */
 
 /*  File Name            : acllibrary.js
  *  Description          : Contains all the javascript functions related to 
  *                         Access Control List module
  *  Version              : 1.0
  *  Author               : Sandhya AmaraVenkata
  *  Created On           : 02 March 2006 
  *  Modification History : None
  */

    
 // The variables used for validating fields of form
   
  /* Function submitForm is a general function to submit the form at specified url.
     @ target - the url to which form is to be submitted
  */
//populating the cdr details
function loadCommissionerates() {

 var optionArray;
 var commString = document.forms[0].commissionerateList.value;
 // alert("In the java script"+document.forms[0].commList.value);
//  alert(commString);
  var commArray = commString.split("|");
  document.forms[0].commissionerate.options[0]=new Option("Select","");
  for(var i=0;i<commArray.length;i++)
  {
   optionArray = commArray[i].split(":");
   //added by sandhya(if(((Option(optionArray[0],optionArray[1])).value)!=""))to remove the empty value at the end
   if(((Option(optionArray[0],optionArray[1])).value)!="")	
   document.forms[0].commissionerate.options[i+1] = new Option(optionArray[0],optionArray[1]);
  }
 
  if(document.forms[0].commissionerateCode.value)  {
  
  for(i=0;i<document.forms[0].commissionerate.options.length;i++)  {
  
       if(document.forms[0].commissionerateCode.value==document.forms[0].commissionerate.options[i].text)
       document.forms[0].commissionerate.selectedIndex=i;
       
      }
  }
 // alert("the value is "+document.forms[0].divisionNameJW.value)
 // to populate the divisions on selection of commissionerates
   if(document.forms[0].divisionCode.value)  {
   
           var selectedComm = document.forms[0].commissionerate.options[document.forms[0].commissionerate.options.selectedIndex].value;
            //alert(selectedDivision);
           var divisionString = document.forms[0].divisionList.value;
           var divisionArray = divisionString.split("|");
           var divisionValuesArray;
          // alert(selectedDivision);
           // clear the list
           var divisionSelectSize =document.forms[0].division.options.length; 
           for(var i=0;i<=divisionSelectSize;i++)
           {
                document.forms[0].division.options[i]= null;
           }
           document.forms[0].division.options.length=null;
            for(var i=0;i<divisionArray.length;i++)
           {
             divisionValuesArray = divisionArray[i].split(":");
            if(selectedComm==divisionValuesArray[2])
            {
               document.forms[0].division.options[document.forms[0].division.options.length] = new Option(divisionValuesArray[0],divisionValuesArray[1]);
            }
            rangeValuesArray=null;
           }
         if(document.forms[0].divisionCode.value)  {
          for(i=0;i<document.forms[0].division.options.length;i++)  {
             if(document.forms[0].divisionCode.value==document.forms[0].division.options[i].text)
             document.forms[0].division.selectedIndex=i;
       
      }
    }  
  }
// to populate the ranges  on selection of divisions
   if(document.forms[0].rangeCode.value)  {
   
           var selectedDivision = document.forms[0].division.options[document.forms[0].division.options.selectedIndex].value;
           //alert("In the loop "+selectedDivision);
           var rangeString = document.forms[0].rangeList.value;
           var rangeArray = rangeString.split("|");
           var rangeValuesArray;
          // alert(selectedDivision);
           // clear the list
           var rangeSelectSize =document.forms[0].range.options.length; 
           for(var i=0;i<=rangeSelectSize;i++)
           {
                document.forms[0].range.options[i]= null;
           }
           document.forms[0].range.options.length=null;
            for(var i=0;i<rangeArray.length;i++)
           {
             rangeValuesArray = rangeArray[i].split(":");
            if(selectedDivision==rangeValuesArray[2])
            {
            document.forms[0].range.options[document.forms[0].range.options.length] = new Option(rangeValuesArray[0],rangeValuesArray[1]);
            }
            rangeValuesArray=null;
           }
         if(document.forms[0].range.value)  {
          for(i=0;i<document.forms[0].range.options.length;i++)  {
             if(document.forms[0].rangeCode.value==document.forms[0].range.options[i].text)
             document.forms[0].range.selectedIndex=i;
       
      }
    }  
  }
}

 // end of function
 function populateDivisions()  {

    var selectedComm = document.forms[0].commissionerate.options[document.forms[0].commissionerate.options.selectedIndex].value;
	  document.forms[0].commissionerateCode.value=document.forms[0].commissionerate.options[document.forms[0].commissionerate.options.selectedIndex].text;
 	 var divisionString = document.forms[0].divisionList.value;
	 var divisionArray = divisionString.split("|");
	 var divisionValuesArray;
	 var divisionSelectSize =document.forms[0].division.options.length; 
	 for(var i=0;i<=divisionSelectSize;i++)
	 {
	      document.forms[0].division.options[i]= null;
	 }
	 document.forms[0].division.options.length=null;
   //added by Sandhya to provide select option in division combobox as soon as selcted commissionerate(document.forms[0].division.options[document.forms[0].division.options.length]=new Option("Select",""))
   document.forms[0].division.options[document.forms[0].division.options.length]=new Option("Select","")
	  for(var i=0;i<divisionArray.length;i++)
	 {
	    divisionValuesArray = divisionArray[i].split(":");
      
		if(selectedComm==divisionValuesArray[2])
		{
    
		document.forms[0].division.options[document.forms[0].division.options.length] = new Option(divisionValuesArray[0],divisionValuesArray[1]);
		
    }/*else {
    
    document.forms[0].division.options[0]=new Option("Select","");
    }*/
		divisionValuesArray=null;
	 } 
   var rangesLength = document.forms[0].range.options.length;
  // alert(rangesLength)
   if(rangesLength>=0) {
   document.forms[0].range.options.length = 0;
   document.forms[0].range.options[0] = new Option("Select","");
   }
 }
 
 function updateDivisionCodeCode() {
 document.forms[0].divisionCode.value=document.forms[0].division.options[document.forms[0].division.options.selectedIndex].text;
 }

function loadDivisions()  {
  var optionArray;
  var divisionString = document.forms[0].divisionList.value;
 // alert(document.forms[0].divisionList.value);
 // alert(divisionString);
  var divArray = divisionString.split("|");
  document.forms[0].division.options[0]=new Option("Select","");
  for(var i=0;i<divArray.length;i++)
  {
   optionArray = divArray[i].split(":");
   //added by sandhya(if(((Option(optionArray[0],optionArray[1])).value)!=""))to remove the empty value at the end
   if(((Option(optionArray[0],optionArray[1])).value)!="")	
   document.forms[0].division.options[i+1] = new Option(optionArray[0],optionArray[1]);
  }
 
  if(document.forms[0].divisionCode.value)  {
  for(i=0;i<document.forms[0].division.options.length;i++)  {
       if(document.forms[0].divisionCode.value==document.forms[0].division.options[i].text)
       document.forms[0].division.selectedIndex=i;
       
      }
  }
   if(document.forms[0].rangeCode.value)  {
   
           var selectedDivision = document.forms[0].division.options[document.forms[0].division.options.selectedIndex].value;
            //alert(selectedDivision);
           var rangeString = document.forms[0].rangeList.value;
           var rangeArray = rangeString.split("|");
           var rangeValuesArray;
          // alert(selectedDivision);
           // clear the list
           var rangeSelectSize =document.forms[0].range.options.length; 
           for(var i=0;i<=rangeSelectSize;i++)
           {
                document.forms[0].range.options[i]= null;
           }
           document.forms[0].range.options.length=null;
            for(var i=0;i<rangeArray.length;i++)
           {
             rangeValuesArray = rangeArray[i].split(":");
            if(selectedDivision==rangeValuesArray[2])
            {
            document.forms[0].range.options[document.forms[0].range.options.length] = new Option(rangeValuesArray[0],rangeValuesArray[1]);
            }
            rangeValuesArray=null;
           }
         if(document.forms[0].rangeCode.value)  {
          for(i=0;i<document.forms[0].range.options.length;i++)  {
             if(document.forms[0].rangeCode.value==document.forms[0].range.options[i].text)
             document.forms[0].range.selectedIndex=i;
       
      }
    }  
  }
}
 // end of function
 function populateRanges()  {
 //alert(document.forms[0].division.options[document.forms[0].division.options.selectedIndex].value)
    var selectedDivision = document.forms[0].division.options[document.forms[0].division.options.selectedIndex].value;
	  document.forms[0].divisionCode.value=document.forms[0].division.options[document.forms[0].division.options.selectedIndex].text;
   //alert(selectedDivision);
 	 var rangeString = document.forms[0].rangeList.value;
	 var rangeArray = rangeString.split("|");
	 var rangeValuesArray;
	// alert(selectedDivision);
	 // clear the list
	 var rangeSelectSize =document.forms[0].range.options.length; 
	 for(var i=0;i<=rangeSelectSize;i++)
	 {
	      document.forms[0].range.options[i]= null;
	 }
	 document.forms[0].range.options.length=null;
  // This line is added by sandhya(document.forms[0].range.options[document.forms[0].range.options.length]=new Option("select"))to get the option select as soon as selection of division
   document.forms[0].range.options[document.forms[0].range.options.length]=new Option("Select")
	  for(var i=0;i<rangeArray.length;i++)
	 {
	    rangeValuesArray = rangeArray[i].split(":");
      
		if(selectedDivision==rangeValuesArray[2])
		{
    
		document.forms[0].range.options[document.forms[0].range.options.length] = new Option(rangeValuesArray[0],rangeValuesArray[1]);
		}
		rangeValuesArray=null;
	 }
    if(selectedDivision=="")  {
    document.forms[0].range.options.length = 0;
    document.forms[0].range.options[0] = new Option("Select A Division","");
    }
 }
 function updateRangeCode() {
 document.forms[0].rangeCode.value=document.forms[0].range.options[document.forms[0].range.options.selectedIndex].text;
 document.forms[0].genderCode.value=document.forms[0].genderID.options[document.forms[0].genderID.options.selectedIndex].text;
 }
 function updateDivisionCode() {
// alert("looking")
 document.forms[0].divisionCode.value=document.forms[0].division.options[document.forms[0].division.options.selectedIndex].text;
 }
 
 function openPrint(target) {
        document.forms[0].action = target;
        document.forms[0].target="newWindow";
        document.forms[0].onSubmit = openWin();
        document.forms[0].submit();
        document.forms[0].target="_self";
   } 
   function openPrintForViewUser(target,countSelected) {
        
        document.forms[0].selectedNumber.value = countSelected;
        document.forms[0].action = target;
        document.forms[0].target="newWindow";
        document.forms[0].onSubmit = openWin();
        document.forms[0].submit();
        document.forms[0].target="_self";
   } 
  function selectSearchForView(target,countSelected,selectedUserName) {
 
      document.forms[0].selectedNumber.value = countSelected;
      document.forms[0].selectedName.value = selectedUserName;
      document.forms[0].action=target;
      document.forms[0].submit();
    }   
    function selectSearchForModifyRole(target,countSelected,selectedRoleName,selectedRoleDescription,selectedRoleStatus) {
      
      document.forms[0].selectedNumber.value = countSelected;
      document.forms[0].selectedName.value = selectedRoleName;
      document.forms[0].selectedDescription.value = selectedRoleDescription;
      document.forms[0].selectedStatus.value = selectedRoleStatus;
      document.forms[0].action=target;
      document.forms[0].submit();
    }  
    function selectSearchForActivities(target,countSelected,selectedRoleName,selectedStatus) {
 
      document.forms[0].selectedNumber.value = countSelected;
      document.forms[0].selectedName.value = selectedRoleName;
      document.forms[0].selectedStatus.value = selectedStatus;
      document.forms[0].action=target;
      document.forms[0].submit();
    }
    function selectSearchForAssignRoleGroup(target,countSelected,selectedRoleGroup,selectedName,SelectedRoleGroupName) {
 
      document.forms[0].selectedNumber.value = countSelected;
      document.forms[0].selectedRoleGroupID.value = selectedRoleGroup;
      document.forms[0].selectedName.value = selectedName;
      document.forms[0].selectedRoleGroupName.value = SelectedRoleGroupName;
      document.forms[0].action=target;
      document.forms[0].submit();
    }

  function openWin() {
      window.open("","newWindow","toolbar=no,directories=no,resizable=yes,menubar=no,location=no,scrollbars=yes,width=815,height=600,top=35,left=80");
  }

/*
  Function updateFieldValue is a generic function that assigns the given value to a 
  given field.
*/
function updateStatusFieldValue(field,value) {
  
  field.value = value
}
/*
  Function updateFieldValue is a generic function that assigns the given value to a 
  given field.
*/
function updateFieldValue(field,value) {
  
  field.value = value
}
/* Variable errorMessage will contain concatenated error message shown to the user when the 
   client side or javascript validations are being not being performed by Struts Validator
   Framework
 */
var errorMessage = "" 
var focusField 
/*
  Function showErrorMessage() will alert the errorMessage if present and will return false
  otherwise it will return true
*/
function showErrorMessage() {
  
  if (errorMessage.length > 0) {
    alert(errorMessage)
    errorMessage = ""
    focusField = true
    return false;
  } else {
    return true;
  }
}

/*
  Fuinction validateRequired(field,msg) is a generic script that checks the mandatory check
  for all field types except multiple selections in a list.
 */
function validateRequired(field,msg) {
  
  var value = '';
  if ((field.type == 'hidden' || field.type == 'text' || field.type == 'textarea' ||
       field.type == 'file' || field.type == 'checkbox' || field.type == 'select-one' ||
       field.type == 'password') && field.disabled == false) {
       // get field's value
       if (field.type == "select-one") {
           var si = field.selectedIndex;
           if (si >= 0) {
              value = field.options[si].value;
           }
       } else if (field.type == 'checkbox') {
           if (field.checked) {
              value = field.value;
       }
       } else {
           value = field.value;
       }
    if (trimString(value).length == 0) {
        if (errorMessage.indexOf(msg) == -1) {
          errorMessage = errorMessage + msg + "\n"
        }
        if (focusField) {
        field.focus()
        focusField = false
      }
    }
  }
}



function validateEmail(field,msg){
if(field.value) {
if (document.layers||document.getElementById||document.all)
return validateTheEmail(field,msg)
else
return true
}
}

function validateTheEmail(field,msg){

var str=field.value
var testresults
var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
if (filter.test(str))
testresults=true
else{
if (errorMessage.indexOf(msg) == -1) {
              errorMessage = errorMessage + msg + "\n"
            }
            if (focusField) {
            field.focus()
            focusField = false
          }
testresults=false
}
return (testresults)
}

 //function for validating numbers
function validateAllNumbers(field,msg){
if(field.value){
if ((isNaN(field.value))||(field.value==0)) {
      if (errorMessage.indexOf(msg) == -1) {
              errorMessage = errorMessage + msg + "\n"
            }
            if (focusField) {
            field.focus()
            focusField = false
          }
        } 
    }
 }
  
/*
  This function will validate a date in dd/MM/yyyy format
 */

    function validateDate(field,msg) {
      
           var value = field.value;
           var datePattern = 'dd/MM/yyyy'
           if ((field.type == 'hidden' ||
                field.type == 'text' ||
                field.type == 'textarea') &&
               (value.length > 0) && (datePattern.length > 0) &&
                field.disabled == false) {
                 var MONTH = "MM";
                 var DAY = "dd";
                 var YEAR = "yyyy";
                 var orderMonth = datePattern.indexOf(MONTH);
                 var orderDay = datePattern.indexOf(DAY);
                 var orderYear = datePattern.indexOf(YEAR);
                 if ((orderDay < orderYear && orderDay > orderMonth)) {
                     var iDelim1 = orderMonth + MONTH.length;
                     var iDelim2 = orderDay + DAY.length;
                     var delim1 = datePattern.substring(iDelim1, iDelim1 + 1);
                     var delim2 = datePattern.substring(iDelim2, iDelim2 + 1);
                     if (iDelim1 == orderDay && iDelim2 == orderYear) {
                        dateRegexp = new RegExp("^(\\d{2})(\\d{2})(\\d{4})$");
                     } else if (iDelim1 == orderDay) {
                        dateRegexp = new RegExp("^(\\d{2})(\\d{2})[" + delim2 + "](\\d{4})$");
                     } else if (iDelim2 == orderYear) {
                        dateRegexp = new RegExp("^(\\d{2})[" + delim1 + "](\\d{2})(\\d{4})$");
                     } else {
                        dateRegexp = new RegExp("^(\\d{2})[" + delim1 + "](\\d{2})[" + delim2 + "](\\d{4})$");
                     }
                     var matched = dateRegexp.exec(value);
                     if(matched != null) {
                        if (!isValidDate(matched[2], matched[1], matched[3])) {
                            if (errorMessage.indexOf(msg) == -1) {
                              errorMessage = errorMessage + msg + "\n"
                            }
                            if (focusField) {
                            field.focus()
                            focusField = false
                          }
                        }
                     } else {
                      if (errorMessage.indexOf(msg) == -1) {
                        errorMessage = errorMessage + msg + "\n"
                      }
                      if (focusField) {
                      field.focus()
                      focusField = false
                      }
                     }
                 } else if ((orderMonth < orderYear && orderMonth > orderDay)) {
                     var iDelim1 = orderDay + DAY.length;
                     var iDelim2 = orderMonth + MONTH.length;
                     var delim1 = datePattern.substring(iDelim1, iDelim1 + 1);
                     var delim2 = datePattern.substring(iDelim2, iDelim2 + 1);
                     if (iDelim1 == orderMonth && iDelim2 == orderYear) {
                         dateRegexp = new RegExp("^(\\d{2})(\\d{2})(\\d{4})$");
                     } else if (iDelim1 == orderMonth) {
                         dateRegexp = new RegExp("^(\\d{2})(\\d{2})[" + delim2 + "](\\d{4})$");
                     } else if (iDelim2 == orderYear) {
                         dateRegexp = new RegExp("^(\\d{2})[" + delim1 + "](\\d{2})(\\d{4})$");
                     } else {
                         dateRegexp = new RegExp("^(\\d{2})[" + delim1 + "](\\d{2})[" + delim2 + "](\\d{4})$");
                     }
                     var matched = dateRegexp.exec(value);
                     if(matched != null) {
                         if (!isValidDate(matched[1], matched[2], matched[3])) {
                              if (errorMessage.indexOf(msg) == -1) {
                                errorMessage = errorMessage + msg + "\n"
                              }
                              if (focusField) {
                              field.focus()
                              focusField = false
                            }
                          }
                     } else {
                        if (errorMessage.indexOf(msg) == -1) {
                          errorMessage = errorMessage + msg + "\n"
                        }
                        if (focusField) {
                        field.focus()
                        focusField = false
                      }
                     }
                 } else if ((orderMonth > orderYear && orderMonth < orderDay)) {
                     var iDelim1 = orderYear + YEAR.length;
                     var iDelim2 = orderMonth + MONTH.length;
                     var delim1 = datePattern.substring(iDelim1, iDelim1 + 1);
                     var delim2 = datePattern.substring(iDelim2, iDelim2 + 1);
                     if (iDelim1 == orderMonth && iDelim2 == orderDay) {
                         dateRegexp = new RegExp("^(\\d{4})(\\d{2})(\\d{2})$");
                     } else if (iDelim1 == orderMonth) {
                         dateRegexp = new RegExp("^(\\d{4})(\\d{2})[" + delim2 + "](\\d{2})$");
                     } else if (iDelim2 == orderDay) {
                         dateRegexp = new RegExp("^(\\d{4})[" + delim1 + "](\\d{2})(\\d{2})$");
                     } else {
                         dateRegexp = new RegExp("^(\\d{4})[" + delim1 + "](\\d{2})[" + delim2 + "](\\d{2})$");
                     }
                     var matched = dateRegexp.exec(value);
                     if(matched != null) {
                         if (!isValidDate(matched[3], matched[2], matched[1])) {
                            if (errorMessage.indexOf(msg) == -1) {
                              errorMessage = errorMessage + msg + "\n"
                            }
                            if (focusField) {
                            field.focus()
                            focusField = false
                          }
                         }
                     } else {
                        if (errorMessage.indexOf(msg) == -1) {
                          errorMessage = errorMessage + msg + "\n"
                        }
                        if (focusField) {
                        field.focus()
                        focusField = false
                      }
                     }
                 } else {
                    if (errorMessage.indexOf(msg) == -1) {
                      errorMessage = errorMessage + msg + "\n"
                    }
                    if (focusField) {
                    field.focus()
                    focusField = false
                  } 
                 }
          }
    }
    
 /*
  The following function will check if the given date is a valid date or not.
 */
    function isValidDate(day, month, year) {
	    if (month < 1 || month > 12) {
            return false;
        }
        if (day < 1 || day > 31) {
            return false;
        }
        if ((month == 4 || month == 6 || month == 9 || month == 11) &&
            (day == 31)) {
            return false;
        }
        if (month == 2) {
            var leap = (year % 4 == 0 &&
               (year % 100 != 0 || year % 400 == 0));
            if (day>29 || (day == 29 && !leap)) {
                return false;
            }
        }
        return true;
    }
/*
  Function validatePastOrPresentDate will check if the entered date is a past or present 
  date.
*/
function validatePastOrPresentDate(field,msg) {

  if ((field.type == 'hidden' ||
      field.type == 'text' ||
      field.type == 'textarea' ||
      field.type == 'select-one' ||
      field.type == 'radio') &&
      field.disabled == false) {

      var value = '';
      // get field's value
      if (field.type == "select-one") {
          var si = field.selectedIndex;
          if (si > 0) {
              value = field.options[si].value;
          }
       } else {
       value = field.value;
       }
    if (value.length >= 0) {                    
     var dd = value.substring(0,2)
     var mm = value.substring(3,5)
     var yyyy = value.substring(6,10)
     var dt=new Date(yyyy,mm-1,dd)
     var now=new Date()
     var diff=dt - now
        if (diff > 0) {
          if (errorMessage.indexOf(msg) == -1) {
            errorMessage = errorMessage + msg + "\n"
          }
          if (focusField) {
          field.focus()
          focusField = false
        } 
        }
    } 
  }
}
/*
  Function validatePastDate will check if the entered date is a past  
  date.
*/
function validatePastDate(field,msg) {

  if ((field.type == 'hidden' ||
      field.type == 'text' ||
      field.type == 'textarea' ||
      field.type == 'select-one' ||
      field.type == 'radio') &&
      field.disabled == false) {

      var value = '';
      // get field's value
      if (field.type == "select-one") {
          var si = field.selectedIndex;
          if (si >= 0) {
              value = field.options[si].value;
          }
       } else {
       value = field.value;
       }
    if (value.length > 0) {                    
     var dd = value.substring(0,2)
     var mm = value.substring(3,5)
     var yyyy = value.substring(6,10)
     var dt=new Date(yyyy,mm-1,dd)
     var now=new Date()
     var diff=dt - now
        if (diff >= 0) {
          if (errorMessage.indexOf(msg) == -1) {
            errorMessage = errorMessage + msg + "\n"
          }
          if (focusField) {
          field.focus()
          focusField = false
        } 
        }
    } 
  }
}
/*
  Function validateFutureDate will check if the entered date is a future  
  date.
*/
function validateFutureDate(field,msg) {

  if ((field.type == 'hidden' ||
      field.type == 'text' ||
      field.type == 'textarea' ||
      field.type == 'select-one' ||
      field.type == 'radio') &&
      field.disabled == false) {

      var value = '';
      // get field's value
      if (field.type == "select-one") {
          var si = field.selectedIndex;
              if (si >= 0) {
              value = field.options[si].value;
          }
       } else {
       value = field.value;
      }
    if (value.length > 0) {                    
     var dd = value.substring(0,2)
     var mm = value.substring(3,5)
     var yyyy = value.substring(6,10)
     var dt=new Date(yyyy,mm-1,dd)
     var now=new Date()
     var diff=dt - now
        if (diff < 0) {
          if (errorMessage.indexOf(msg) == -1) {
            errorMessage = errorMessage + msg + "\n"
          }
          if (focusField) {
          field.focus()
          focusField = false
        } 
        }
    } 
  }
}
/*
  Function validateMask() will perform the validation test based on the mask specified
*/

function validateMask(field,msg,mask) {

  if ((field.type == 'hidden' ||
        field.type == 'text' ||
        field.type == 'textarea' ||
        field.type == 'file') &&
         (field.value.length > 0) &&
         field.disabled == false) {

        if (! mask.exec(field.value)) {
          if (errorMessage.indexOf(msg) == -1) {
            errorMessage = errorMessage + msg + "\n"
          }
          if (focusField) {
          field.focus()
          focusField = false
        }
        }
    }
}

/*
  Function validateMaskValue() will perform the validation test based on the mask specified
*/

function validateMaskValue(field,msg,mask) {

        if (! mask.exec(field)) {
          if (errorMessage.indexOf(msg) == -1) {
            errorMessage = errorMessage + msg + "\n"
          }
          if (focusField) {
          
          focusField = false
        }
        }
    
}


/*
  Function validateAmount validates a valid amount
*/
function validateAmount(field,msg) {

  if ((field.type == 'hidden' ||
      field.type == 'text' ||
      field.type == 'textarea' ||
      field.type == 'select-one' ||
      field.type == 'radio') &&
      field.disabled == false) {

    var value = '';
      // get field's value
      if (field.type == "select-one") {
          var si = field.selectedIndex;
          if (si >= 0) {
              value = field.options[si].value;
          }
      } else {
          value = field.value;
      }

      if (value.length > 0) {
          // remove '.' before checking digits
         if (value == 0) {
                  errorMessage = errorMessage + msg + "\n"
                }
          var tempArray = value.split('.');
          //Strip off leading '0'
          var zeroIndex = 0;
          var joinedString= tempArray.join('');
          while (joinedString.charAt(zeroIndex) == '0') {
              zeroIndex++;
          }
          var noZeroString = joinedString.substring(zeroIndex,joinedString.length);

          if (!isAllDigits(noZeroString)) {
              
              if (errorMessage.indexOf(msg) == -1) {
                  errorMessage = errorMessage + msg + "\n"
                }
                if (focusField) {
                field.focus()
                focusField = false
              }

          } else {
        var iValue = parseFloat(value);
        if (isNaN(iValue) || iValue < 0) {
         if (errorMessage.indexOf(msg) == -1) {
              errorMessage = errorMessage + msg + "\n"
            }
            if (focusField) {
            field.focus()
            focusField = false
          }  
        }
       }
     }
 }
}
/* The following function checks for the number in the specified float range */
function validateFloatRange(field, fMin, fMax, msg) {
    
    if ((field.type == 'hidden' ||
        field.type == 'text' || field.type == 'textarea') &&
        (field.value.length > 0)  &&
         field.disabled == false) {

        var fValue = parseFloat(field.value);
        if (!(fValue >= fMin && fValue <= fMax)) {
            if (errorMessage.indexOf(msg) == -1) {
                errorMessage = errorMessage + msg + "\n"
              }
              if (focusField) {
              field.focus()
              focusField = false
            }
        }
    }
}
/*
  Function isAllDigits checks if the passsed argument contains all the digits or not
*/
    function isAllDigits(argvalue) {
        argvalue = argvalue.toString();
        var validChars = "0123456789";
        var startFrom = 0;
        if (argvalue.substring(0, 2) == "0x") {
           validChars = "0123456789abcdefABCDEF";
           startFrom = 2;
        } else if (argvalue.charAt(0) == "0") {
           validChars = "01234567";
           startFrom = 1;
        } else if (argvalue.charAt(0) == "-") {
            startFrom = 1;
        }

        for (var n = startFrom; n < argvalue.length; n++) {
            if (validChars.indexOf(argvalue.substring(n, n+1)) == -1) return false;
        }
        return true;
    }

/*
  Function validateStatusForm() contains client side validations
  for manage status  
*/
function validateStatusForm() {
 
  errorMessage = ""
  focusField = true
  var form = document.forms[0]
  validateRequired(form.status,"Account Staus is Mandatory.")
     
  return showErrorMessage()
}

/*
  Function userStatusReset() contains client side validations
  for manage status  
*/
function userStatusReset() {
 
  var form = document.forms[0]
  form.status.value=""       
}
/*
  Function validateChangePasswordForm() contains client side validations
  for change password  
*/
function validateChangePasswordForm() {
 
  errorMessage = ""
  focusField = true
  var form = document.forms[0]
  validateRequired(form.currentPassword,"Current Password is Mandatory.")
  validateRequired(form.newPassword,"New Password is Mandatory.")
  validateRequired(form.confirmPassword,"Confirm Password is Mandatory.")
  validateLength(form.currentPassword,"Current Password should be 6 characters.") 
  validateLength(form.newPassword,"New Password should be 6 characters.") 
  validateLength(form.confirmPassword,"Confirm Password should be 6 characters.") 
  validateCurrentAndNew(form.currentPassword,form.newPassword,"Current and New Passwords shouldnt be the same")
  validateNewAndConfirm(form.newPassword,form.confirmPassword,"New and Confirm Passwords should be the same")
  return showErrorMessage()
}

/*
  Function validateSearchUserListForm() contains client side validations
  for change password  
*/
function validateSearchUserListForm() {
 
  errorMessage = ""
  focusField = true
  var form = document.forms[0]
  validateMask(form.firstName,"First name accepts characters only.",new RegExp(/^[a-zA-Z]*$/))
  
  return showErrorMessage()
}


/*  validation for current password and new password in change password */

function validateLength(Pwd,msg) {
if(Pwd.value)  {

  if(Pwd.value.length!=6) { 
    
       if (errorMessage.indexOf(msg) == -1) {
              errorMessage = errorMessage + msg + "\n"
            }
        if (focusField) {
            Pwd.focus()
            focusField = false
          }
        }
      }
   } 
/*  validation for current password and new password in change password */

function validateCurrentAndNew(currentPwd,newPwd,msg) {
if(currentPwd.value&&newPwd.value)  {
   if(currentPwd.value==newPwd.value) { 
    
       if (errorMessage.indexOf(msg) == -1) {
              errorMessage = errorMessage + msg + "\n"
            }
        if (focusField) {
            newPwd.focus()
            focusField = false
          }
        }
      }
   } 
/*  validation for new password and confirm password in change password */

function validateNewAndConfirm(newPwd,confirmPwd,msg) {

if(newPwd.value&&confirmPwd.value)  {

   if(newPwd.value!=confirmPwd.value)  {
    
       if (errorMessage.indexOf(msg) == -1) {
              errorMessage = errorMessage + msg + "\n"
            }
      if (focusField) {
            confirmPwd.focus()
            focusField = false
          }
        }
     }
   } 
   
/*
  Function validateCreateUserForm() contains client side validations
  for Create user  
*/
function validateCreateUserForm() {
  
  errorMessage = ""
  focusField = true
  var form = document.forms[0]
  validateRequired(form.division,"Division is Mandatory.")
  validateRequired(form.range,"Range is Mandatory.")
  validateRequired(form.firstName,"First Name is Mandatory.")
  validateMask(form.firstName,"First name accepts characters only.",new RegExp(/^[a-zA-Z]*$/))
  validateMask(form.middleName,"Middle name accepts characters only.",new RegExp(/^[a-zA-Z]*$/))
  validateMask(form.lastName,"Last name accepts characters only.",new RegExp(/^[a-zA-Z]*$/))
  validateRequired(form.designation,"Designation is Mandatory.")
  validateRequired(form.mailID,"Email ID is Mandatory.")
  validateEmail(form.mailID,"Email ID is not validate.")
  validateMask(form.phoneNo,"Phone nuber is not valid.",new RegExp(/^([0-9]*$)$/))
  validateMask(form.mobileNo,"mobile number should be valid 10 digits number.",new RegExp(/^([0-9]{10})$/))  
  validateRequired(form.dtOfJng,"Date of Joining is Mandatory.")
  validateDate(form.dtOfJng,"Date of Joining should be DD/MM/YYYY format.")
  validatePastOrPresentDate(form.dtOfJng,"Date of Joining should be less than or equal to Current date.")
  validateRequired(form.dtOfBirth,"Date of Birth is Mandatory.")
  validateDate(form.dtOfBirth,"Date of Birth should be DD/MM/YYYY format.")
  validatePastDate(form.dtOfBirth,"Date of Birth should be Past date.")
  validateFromDateToDate(form.dtOfBirth,form.dtOfJng,"Date of birth should prior to the date of joining")
  validateRequired(form.genderID,"Gender is Mandatory.")
//  validateRequired(form.userType,"User Type is Mandatory.")
   
  return showErrorMessage()
}
/*
  Function comUserReset() contains client side validations
  for Create user  
*/
function comUserReset() {
  
  var form = document.forms[0]
  form.firstName.value=""
  form.middleName.value=""
  form.lastName.value=""
  form.designation.value=""
  form.mailID.value=""
  form.phoneNo.value=""
  form.mobileNo.value=""
  form.dtOfJng.value=""
  form.dtOfBirth.value=""
  form.genderID.value=""
  form.division.value=""
  populateRanges()
  
}

/*
  Function modifyUserReset() contains client side validations
  for Create user  
*/
function modifyUserReset() {
  
  var form = document.forms[0]
  form.firstName.value=""
  form.middleName.value=""
  form.lastName.value=""
  form.designation.value=""
  form.mailID.value=""
  form.phoneNo.value=""
  form.mobileNo.value=""
  form.dtOfJng.value=""
  form.dtOfBirth.value=""
  form.genderID.value=""
  form.division.value=""
  populateRanges()
  
}

/*
  Function hqAdminUserReset() contains client side validations
  for Create user  
*/
function hqAdminUserReset() {
  
  var form = document.forms[0]
  form.firstName.value=""
  form.middleName.value=""
  form.lastName.value=""
  form.designation.value=""
  form.mailID.value=""
  form.phoneNo.value=""
  form.mobileNo.value=""
  form.dtOfJng.value=""
  form.dtOfBirth.value=""
  form.genderID.value=""
  form.commissionerate.value=""
   populateDivisions()
  
}
/*
  Function modifyhqAdminUserReset() contains client side validations
  for Create user  
*/
function modifyhqAdminUserReset() {
  
  var form = document.forms[0]
  form.firstName.value=""
  form.middleName.value=""
  form.lastName.value=""
  form.designation.value=""
  form.mailID.value=""
  form.phoneNo.value=""
  form.mobileNo.value=""
  form.dtOfJng.value=""
  form.dtOfBirth.value=""
  form.genderID.value=""
  form.commissionerate.value=""
   populateDivisions()
  
}
/*
  Function hqUserReset() contains client side validations
  for Create user  
*/
function hqUserReset() {
  
  var form = document.forms[0]
  form.firstName.value=""
  form.middleName.value=""
  form.lastName.value=""
  form.designation.value=""
  form.mailID.value=""
  form.phoneNo.value=""
  form.mobileNo.value=""
  form.dtOfJng.value=""
  form.dtOfBirth.value=""
  form.genderID.value=""
  form.userType.value=""
}
/*
  Function modifyhqUserReset() contains client side validations
  for Create user  
*/
function modifyhqUserReset() {
  
  var form = document.forms[0]
  form.firstName.value=""
  form.middleName.value=""
  form.lastName.value=""
  form.designation.value=""
  form.mailID.value=""
  form.phoneNo.value=""
  form.mobileNo.value=""
  form.dtOfJng.value=""
  form.dtOfBirth.value=""
  form.genderID.value=""
}

/*
  Function validateCreateUserForm() contains client side validations
  for Create user  
*/
function validateHQCreateUserForm() {
  
  errorMessage = ""
  focusField = true
  var form = document.forms[0]
  
  validateRequired(form.firstName,"First Name is Mandatory.")
  validateMask(form.firstName,"First name accepts characters only.",new RegExp(/^[a-zA-Z]*$/))
  validateMask(form.middleName,"Middle name accepts characters only.",new RegExp(/^[a-zA-Z]*$/))
  validateMask(form.lastName,"Last name accepts characters only.",new RegExp(/^[a-zA-Z]*$/))
  validateRequired(form.designation,"Designation is Mandatory.")
  validateRequired(form.mailID,"Email ID is Mandatory.")
  validateEmail(form.mailID,"Email ID is not valid")
  validateMask(form.phoneNo,"Phone nuber is not valid.",new RegExp(/^([0-9]*$)$/))
  validateMask(form.mobileNo,"mobile number should be valid 10 digits number.",new RegExp(/^([0-9]{10})$/))  
  validateRequired(form.dtOfJng,"Date of Joining is Mandatory.")
  validateDate(form.dtOfJng,"Date of Joining should be DD/MM/YYYY format.")
  validatePastOrPresentDate(form.dtOfJng,"Date of Joining should be less than or equal to Current date.")
  validateRequired(form.dtOfBirth,"Date of Birth is Mandatory.")
  validateDate(form.dtOfBirth,"Date of Birth should be DD/MM/YYYY format.")
  validatePastDate(form.dtOfBirth,"Date of Birth should be Past date.")
  validateFromDateToDate(form.dtOfBirth,form.dtOfJng,"Date of birth should prior to the date of joining")
  validateRequired(form.genderID,"Gender is Mandatory.")
  validateRequired(form.userType,"User Type is Mandatory.")
   
  return showErrorMessage()
}
/*
  Function validateCreateUserForm() contains client side validations
  for Create user  
*/
function validateCreateAdminUserForm() {
  
  errorMessage = ""
  focusField = true
  var form = document.forms[0]
  validateRequired(form.commissionerate,"commissionerate is Mandatory.")
  validateRequired(form.division,"Division is Mandatory.")
  validateRequired(form.range,"Range is Mandatory.")
  validateRequired(form.firstName,"First Name is Mandatory.")
  validateMask(form.firstName,"First name accepts characters only.",new RegExp(/^[a-zA-Z]*$/))
  validateMask(form.middleName,"Middle name accepts characters only.",new RegExp(/^[a-zA-Z]*$/))
  validateMask(form.lastName,"Last name accepts characters only.",new RegExp(/^[a-zA-Z]*$/))
  validateRequired(form.designation,"Designation is Mandatory.")
  validateRequired(form.mailID,"Email ID is Mandatory.")
  validateEmail(form.mailID,"Email ID is not valid")
  validateMask(form.phoneNo,"Phone nuber is not valid.",new RegExp(/^([0-9]*$)$/))
  validateMask(form.mobileNo,"mobile number should be valid 10 digits number.",new RegExp(/^([0-9]{10})$/))  
  validateRequired(form.dtOfJng,"Date of Joining is Mandatory.")
  validateDate(form.dtOfJng,"Date of Joining should be DD/MM/YYYY format.")
  validatePastOrPresentDate(form.dtOfJng,"Date of Joining should be less than or equal to Current date.")
  validateRequired(form.dtOfBirth,"Date of Birth is Mandatory.")
  validateDate(form.dtOfBirth,"Date of Birth should be DD/MM/YYYY format.")
  validatePastDate(form.dtOfBirth,"Date of Birth should be Past date.")
  validateFromDateToDate(form.dtOfBirth,form.dtOfJng,"Date of birth should prior to the date of joining")
  validateRequired(form.genderID,"Gender is Mandatory.")
//  validateRequired(form.userType,"User Type is Mandatory.")
   
  return showErrorMessage()
}
/*
  Function validateModifyAdminUserForm() contains client side validations
  for Create user  
*/
function validateModifyAdminUserForm() {
  
  errorMessage = ""
  focusField = true
  var form = document.forms[0]
  validateRequired(form.commissionerate,"commissionerate is Mandatory.")
  validateRequired(form.division,"Division is Mandatory.")
  validateRequired(form.range,"Range is Mandatory.")
  validateRequired(form.firstName,"First Name is Mandatory.")
  validateMask(form.firstName,"First name accepts characters only.",new RegExp(/^[a-zA-Z]*$/))
  validateMask(form.middleName,"Middle name accepts characters only.",new RegExp(/^[a-zA-Z]*$/))
  validateMask(form.lastName,"Last name accepts characters only.",new RegExp(/^[a-zA-Z]*$/))
  validateRequired(form.designation,"Designation is Mandatory.")
  validateRequired(form.mailID,"Email ID is Mandatory.")
  validateEmail(form.mailID,"Email ID is not valid")
  validateMask(form.phoneNo,"Phone nuber is not valid.",new RegExp(/^([0-9]*$)$/))
  validateMask(form.mobileNo,"mobile number should be valid 10 digits number.",new RegExp(/^([0-9]{10})$/))  
  validateRequired(form.dtOfJng,"Date of Joining is Mandatory.")
  validateDate(form.dtOfJng,"Date of Joining should be DD/MM/YYYY format.")
  validatePastOrPresentDate(form.dtOfJng,"Date of Joining should be less than or equal to Current date.")
  validateRequired(form.dtOfBirth,"Date of Birth is Mandatory.")
  validateDate(form.dtOfBirth,"Date of Birth should be DD/MM/YYYY format.")
  validatePastDate(form.dtOfBirth,"Date of Birth should be Past date.")
  validateFromDateToDate(form.dtOfBirth,form.dtOfJng,"Date of birth should prior to the date of joining")
  validateRequired(form.genderID,"Gender is Mandatory.")
//  validateRequired(form.userType,"User Type is Mandatory.")
   
  return showErrorMessage()
}
/*
  Function updateFieldValue will assign the corresponding values to the combo box as soon as the jsp loads.
*/
function onLoadFieldValue() {

  document.forms[0].elements['divisionCode'].value = document.forms[0].elements['divisionID'].options[document.forms[0].elements['divisionID'].selectedIndex].text;
  document.forms[0].elements['rangeCode'].value = document.forms[0].elements['rangeID'].options[document.forms[0].elements['rangeID'].selectedIndex].text;
  document.forms[0].elements['genderCode'].value = document.forms[0].elements['genderID'].options[document.forms[0].elements['genderID'].selectedIndex].text;
 }
 
/*
  Function validateModifyUserForm() contains client side validations
  for modify user  
*/

function validateModifyUserForm() {
  
  errorMessage = ""
  focusField = true
  var form = document.forms[0]
  
  validateRequired(form.division,"Division is Mandatory.")
  validateRequired(form.range,"Range is Mandatory.")
  validateRequired(form.firstName,"First Name is Mandatory.")
  validateMask(form.firstName,"First name accepts characters only.",new RegExp(/^[a-zA-Z]*$/))
  validateMask(form.middleName,"Middle name accepts characters only.",new RegExp(/^[a-zA-Z]*$/))
  validateMask(form.lastName,"Last name accepts characters only.",new RegExp(/^[a-zA-Z]*$/))
  validateRequired(form.designation,"Designation is Mandatory.")
  validateRequired(form.mailID,"Email ID is Mandatory.")
  validateEmail(form.mailID,"Email ID is not valid")
  validateMask(form.phoneNo,"Phone nuber is not valid.",new RegExp(/^([0-9]*$)$/))
  validateMask(form.mobileNo,"mobile number should be valid 10 digits number.",new RegExp(/^([0-9]{10})$/))
  validateRequired(form.dtOfJng,"Date of Joining is Mandatory.")
  validateDate(form.dtOfJng,"Date of Joining should be DD/MM/YYYY format.")
  validatePastOrPresentDate(form.dtOfJng,"Date of Joining should be less than or equal to Current date.")
  validateRequired(form.dtOfBirth,"Date of Birth is Mandatory.")
  validateDate(form.dtOfBirth,"Date of Birth should be DD/MM/YYYY format.")
  validatePastDate(form.dtOfBirth,"Date of Birth should be Past date.")
  validateFromDateToDate(form.dtOfBirth,form.dtOfJng,"Date of birth should prior to the date of joining")
  validateRequired(form.genderID,"Gender is Mandatory.")
 // validateRequired(form.userType,"User Type is Mandatory.")
   
  return showErrorMessage()
}
/*
  Function validateModifyUserForm() contains client side validations
  for modify user  
*/

function validateModifyHQUserForm() {
  
  errorMessage = ""
  focusField = true
  var form = document.forms[0]
  
  validateRequired(form.firstName,"First Name is Mandatory.")
  validateMask(form.firstName,"First name accepts characters only.",new RegExp(/^[a-zA-Z]*$/))
  validateMask(form.middleName,"Middle name accepts characters only.",new RegExp(/^[a-zA-Z]*$/))
  validateMask(form.lastName,"Last name accepts characters only.",new RegExp(/^[a-zA-Z]*$/))
  validateRequired(form.designation,"Designation is Mandatory.")
  validateRequired(form.mailID,"Email ID is Mandatory.")
  validateEmail(form.mailID,"Email ID is not valid")
  validateMask(form.phoneNo,"Phone nuber is not valid.",new RegExp(/^([0-9]*$)$/))
  validateMask(form.mobileNo,"mobile number should be valid 10 digits number.",new RegExp(/^([0-9]{10})$/))
  validateRequired(form.dtOfJng,"Date of Joining is Mandatory.")
  validateDate(form.dtOfJng,"Date of Joining should be DD/MM/YYYY format.")
  validatePastOrPresentDate(form.dtOfJng,"Date of Joining should be less than or equal to Current date.")
  validateRequired(form.dtOfBirth,"Date of Birth is Mandatory.")
  validateDate(form.dtOfBirth,"Date of Birth should be DD/MM/YYYY format.")
  validatePastDate(form.dtOfBirth,"Date of Birth should be Past date.")
  validateFromDateToDate(form.dtOfBirth,form.dtOfJng,"Date of birth should prior to the date of joining")
  validateRequired(form.genderID,"Gender is Mandatory.")
  validateRequired(form.userType,"User Type is Mandatory.")
   
  return showErrorMessage()
}

/*
  Function validateAssignRoleGroupUser contains client side validations
  for Assign Role group to user
*/
function validateAssignRoleGroupUserForm() {
  
  errorMessage = ""
  focusField = true
  var form = document.forms[0]
//  alert("coming")
  validateRequired(form.roleGroup,"Role Group is Mandatory.")
   
  return showErrorMessage()
}

/*
  Function assignRoleGroupReset contains client side validations
  for Assign Role group to user
*/
function assignRoleGroupReset() {
  
  var form = document.forms[0]

  form.roleGroup.value=""
}

/*
  Function loginReset contains client side validations
  for Assign Role group to user
*/
function loginReset() {
  
  var form = document.forms[0]

  form.userName.value=""
}

/*
  Function assignRoleGroupReset contains client side validations
  for Assign Role group to user
*/
function assignPrevilegesReset() {
  
  var form = document.forms[0]

  form.moduleID.value=""
}



/*
  Function validateCreateAssignprevilegesForm contains client side validations
  for CreateAssignPrevilegesForm
*/
function validateCreateAssignprevilegesForm() {
  
  errorMessage = ""
  focusField = true
  var msg=""
  var form = document.forms[0]
 
  validateRequired(form.moduleID,"please select one module and go.")
  if(form.selectedModuleID.value) {
 
     validateModuleID(form.moduleID,form.selectedModuleID,"Rendered Activities are not correspond to the Selected module.\nClick on GO to get the Activities of Selected module \n Or Change the selcted Module to the module having the rendered Activities")
 
 }
 if(form.moduleID.value)  {
 
    validateActivities()
 }
  /* var activtyTable = document.getElementById("activitiesTable")
  var activtySelected = ""
  var i=""
  
  var rowCont=activtyTable.rows.length-2
  
 if(rowCont==2) {
  msg = msg + "\nYou didnt Assign any Activity under this Module to this Role.\n Please select a module and click on GO to Assign Activities "
  }
  if (msg!="") {
    msg = "Please Confirm:\n" + msg + "\nAre you sure you want to proceed without Assigning any Activities to this module?"
    response=confirm(msg)
    msg=""
    return response
  } */
  return showErrorMessage() 
}

function validateActivities() {

  var msg=""
  var form = document.forms[0]
  var activtyTable = document.getElementById("activitiesTable")
  var activtySelected = ""
  var i=""
  
  var rowCont=activtyTable.rows.length-2
  
 if(rowCont==2) {
  msg = msg + "\nYou didnt Assign any Activity under this Module to this Role.\nPlease click on GO to get Activities to the Selcted Module"
  }
   if (errorMessage.indexOf(msg) == -1) {
              errorMessage = errorMessage + msg + "\n"
            }
}
/*  validation for role divisions and ranges  */

function validateModuleID(actualModule,selectedModule,msg) {

    if(!(actualModule.value==selectedModule.value)) {
    
       if (errorMessage.indexOf(msg) == -1) {
              errorMessage = errorMessage + msg + "\n"
            }
  } 
     
      
      }
/*validation for rolegroup roles*/

function validateChkBox(chkBoxName,msg) {
    var form = document.forms[0]
    var availableRolesTable = document.getElementById("availableRolesTable")
    var j = 0;
    
    if(chkBoxName.value) {
    
      if(chkBoxName.checked) {
          j++;
        } 
  } 
    for(var i=0; i<chkBoxName.length; i++) {
            
      if (chkBoxName[i].checked == true) {
      form.elements['availableGroupRoles[' + i + '].roleSelected'].value="1"
          j++;          
        }
      else
        form.elements['availableGroupRoles[' + i + '].roleSelected'].value=""
      }
      
      if(j==0)
       if (errorMessage.indexOf(msg) == -1) {
              errorMessage = errorMessage + msg + "\n"
            }
   }
/*
  Function validateCreateComRole contains client side validations
  for Create Role in Commissionerate level
*/
function validateCreateComRoleForm() {
  
  errorMessage = ""
  focusField = true
  var form = document.forms[0]
  
  validateChkBoxesOfComRoleDivisions(form.divisionIndexes,"select atleast one Divison")
  return showErrorMessage()
}
/*
  Function createComRoleFirstReset contains client side validations
  for Create Role in Commissionerate level
*/
function createHQRoleFirstReset() {
  
  var form = document.forms[0]
  resetChkboxCreateHQRoleFirst(form.commissionerateIndexes)
  
}
/*
  Function createComRoleFirstReset contains client side validations
  for Create Role in Commissionerate level
*/
function createHQRoleSecondReset() {
  
  var form = document.forms[0]
  resetChkboxCreateHQRoleSecond(form.divisionIndexes)
  
}
/*
  Function createComRoleFirstReset contains client side validations
  for Create Role in Commissionerate level
*/
function createHQRoleThirdReset() {
  
  var form = document.forms[0]
  resetChkboxCreateHQRoleThird(form.rangeIndexes)
  
}
/*
  Function createComRoleFirstReset contains client side validations
  for Create Role in Commissionerate level
*/
function createComRoleFirstReset() {
  
  var form = document.forms[0]
  resetChkboxCreateComRoleFirst(form.divisionIndexes)
  
}
/*
  Function createComRoleSecondReset contains client side validations
  for Create Role in Commissionerate level
*/
function createComRoleSecondReset() {
  
  var form = document.forms[0]
  resetChkboxCreateComRoleSecond(form.rangeIndexes)
  
}

/*
  Function validateModifyComRole contains client side validations
  for Modify Role in Commissionerate level
*/
function validateModifyComRoleForm() {
  
  errorMessage = ""
  focusField = true
  var form = document.forms[0]
  
  validateRequired(form.roleName,"Role Name is Mandatory.")
  validateRequired(form.roleDescription,"Role Description is Mandatory.")
  validateRequired(form.status,"Status is Mandatory.")
  validateChkBoxesOfComRoleDivisions(form.divisionIndexes,"select atleast one Divison")
  return showErrorMessage()
}

/*  validation for role divisions  in commissionerate level */

function validateChkBoxesOfComRoleDivisions(chkBoxName,msg) {

    var form = document.forms[0]
    var j = 0;
   
    for(var i=0; i<chkBoxName.length; i++) {
            
      if (chkBoxName[i].checked == true) {
      form.elements['availableDivisions[' + i + '].selectedDivision'].value="1"
          j++;          
        }
      else
        form.elements['availableDivisions[' + i + '].selectedDivision'].value="0"  
      }
      
      if(j==0)
       if (errorMessage.indexOf(msg) == -1) {
              errorMessage = errorMessage + msg + "\n"
            }
   
   }
   
/*  validation for role divisions  in commissionerate level */

function resetChkboxCreateComRoleFirst(chkBoxName) {

    var form = document.forms[0]
    
    for(var i=0; i<chkBoxName.length; i++) {
            
      chkBoxName[i].checked = false 
      form.elements['availableDivisions[' + i + '].selectedDivision'].value=""
      
      }
      
   }

/*  validation for role divisions  in commissionerate level */

function resetChkboxCreateHQRoleFirst(chkBoxName) {

    var form = document.forms[0]
    
    for(var i=0; i<chkBoxName.length; i++) {
            
      chkBoxName[i].checked = false 
      form.elements['availableCommissionerates[' + i + '].selectedCommissionerate'].value=""
      
      }
      
   }

/*  validation for role divisions  in commissionerate level */

function resetChkboxCreateHQRoleSecond(chkBoxName) {

    var form = document.forms[0]
    
    for(var i=0; i<chkBoxName.length; i++) {
            
      chkBoxName[i].checked = false 
      form.elements['availableDivisions[' + i + '].selectedDivision'].value=""
      
      }
      
   }
   
/*  validation for role divisions  in commissionerate level */

function resetChkboxCreateHQRoleThird(chkBoxName) {

    var form = document.forms[0]
    
    for(var i=0; i<chkBoxName.length; i++) {
            
      chkBoxName[i].checked = false 
      form.elements['availableRanges[' + i + '].selectedRange'].value=""
      
      }
      
   }

/*  validation for role divisions  in commissionerate level */

function resetChkboxCreateComRoleSecond(chkBoxName) {

    var form = document.forms[0]
    
    for(var i=0; i<chkBoxName.length; i++) {
            
      chkBoxName[i].checked = false 
      
      form.elements['availableRanges[' + i + '].selectedRange'].value=""
      
      }
      
   }


/*
  Function validateCommonCreateRole contains client side validations
  for Create Common Role
*/
function validateCreateCommonRoleForm() {
  
  errorMessage = ""
  focusField = true
  var name = ""
  var firstLetter = ""
  var form = document.forms[0]
  
  validateRequired(form.roleName,"Role Name is Mandatory.")
  if(form.roleName!=null) {
  
  name=form.roleName.value
  firstLetter=name.charAt(0)
  validateMaskValue(firstLetter,"Special characters are not allowed in first position of RoleName.",new RegExp(/^[a-zA-Z0-9]*$/))
  
  }
  validateRequired(form.roleDescription,"Role Description is Mandatory.")
    
  return showErrorMessage()
}
/*
  Function createCommonRoleReset() contains client side validations
  for Create user  
*/
function createCommonRoleReset() {
  
  var form = document.forms[0]
  form.roleName.value=""
  form.roleDescription.value=""
  
}
/*
  Function modifyCommonRoleReset() contains client side validations
  for Create user  
*/
function modifyCommonRoleReset() {
  
  var form = document.forms[0]
  form.roleName.value=""
  form.roleDescription.value=""
  
}
/*
  Function validateSearchRoleListForm contains client side validations
  for Create Common Role
*/
function validateSearchRoleListForm() {
  
  errorMessage = ""
  focusField = true
  var name = ""
  var firstLetter = ""
  var form = document.forms[0]
  
  if(form.roleName!=null) {
  
  name=form.roleName.value
  firstLetter=name.charAt(0)
  validateMaskValue(firstLetter,"Special characters are not allowed in first position of RoleName.",new RegExp(/^[a-zA-Z0-9]*$/))
  
  }
      
  return showErrorMessage()
}
/*
  Function validateSearchRoleGroupListForm contains client side validations
  for Create Common Role
*/
function validateSearchRoleGroupListForm() {
  
  errorMessage = ""
  focusField = true
  var name = ""
  var firstLetter = ""
  var form = document.forms[0]
  
  if(form.roleGroupName!=null) {
  
  name=form.roleGroupName.value
  firstLetter=name.charAt(0)
  validateMaskValue(firstLetter,"Special characters are not allowed in first position of RoleGroupName.",new RegExp(/^[a-zA-Z0-9]*$/))
  
  }
      
  return showErrorMessage()
}

/*
  Function validateModifyCreateRole contains client side validations
  for Modify Common Role
*/
function validateModifyCommonRoleForm() {
  
  errorMessage = ""
  focusField = true
  var name = ""
  var firstLetter = ""
  var form = document.forms[0]
  
  validateRequired(form.roleName,"Role Name is Mandatory.")
  
  if(form.roleName!=null) {
  
  name=form.roleName.value
  firstLetter=name.charAt(0)
  validateMaskValue(firstLetter,"Special characters are not allowed in first position of RoleName.",new RegExp(/^[a-zA-Z0-9]*$/))
  
  }
  
  validateRequired(form.roleDescription,"Role Description is Mandatory.")
 // validateRequired(form.status,"Status is Mandatory.")
  
  return showErrorMessage()
}

/*
  Function validateCreateRole contains client side validations
  for Create Role
*/
function validateCreateRoleForm() {
  
  errorMessage = ""
  focusField = true
  var form = document.forms[0]
  
  validateChkBoxesOfRole(form.commissionerateIndexes,"select atleast one Commissionerate")
  return showErrorMessage()
}
/*
  Function validateModifyRole contains client side validations
  for Modify Role
*/
function validateModifyRoleForm() {
  
  errorMessage = ""
  focusField = true
  var form = document.forms[0]
  
  validateRequired(form.roleName,"Role Name is Mandatory.")
  validateRequired(form.roleDescription,"Role Description is Mandatory.")
  validateRequired(form.status,"Status is Mandatory.")
  validateChkBoxesOfRole(form.commissionerateIndexes,"select atleast one Commissionerate")
  return showErrorMessage()
}
/*
  Function validateCreateRole contains client side validations
  for Create Role
*/
function assignOneForSeclectedActivity() {
  
  errorMessage = ""
  focusField = true
  var form = document.forms[0]
  
  validateChkBoxesOfPrevileges(form.activityIndexes,form.subActivityIndexes)
  return showErrorMessage()
}
/*  validation for role divisions and ranges  */

function validateChkBoxesOfPrevileges(activityIndexes,subActivityIndexes) {
//alert("starting validateChkBoxesOfPrevileges")
//alert("activityIndexes length is"+activityIndexes.length)
//alert("subActivityIndexes length is"+subActivityIndexes.length)
    var form = document.forms[0]
  
    for(var i=0; i<activityIndexes.length; i++) {
            
      if (activityIndexes[i].checked == true) {
      form.elements['activitiesList[' + i + '].activitySelected'].value="1"
         }
      else
        form.elements['activitiesList[' + i + '].activitySelected'].value=""  
      }
      
    for(var k=0; k<subActivityIndexes.length; k++) {
            
      if (subActivityIndexes[k].checked == true) {
      form.elements['subActivitiesList[' + k + '].activitySelected'].value="1"
         }
      else
        form.elements['subActivitiesList[' + k + '].activitySelected'].value=""  
      }
      
     
   }
/*
  Function validateCreateRoleSecondForm contains client side validations
  for Create Second Role
*/
function validateCreateRoleSecondForm() {
  errorMessage = ""
  focusField = true
  var form = document.forms[0]
  
  validateRoleDivisionChkBoxes(form.divisionIndexes,"select atleast one Division")
  return showErrorMessage()
 
}
/*
  Function validateModifyRoleSecondForm contains client side validations
  for Modify Second Role
*/
function validateModifyRoleSecondForm() {
  errorMessage = ""
  focusField = true
  var form = document.forms[0]
  
  validateRoleDivisionChkBoxes(form.divisionIndexes,"select atleast one Division")
  return showErrorMessage()
 
}
/*  validation for role divisions and ranges  */

function validateRoleDivisionChkBoxes(chkBoxName,msg) {

    var form = document.forms[0]
    var j = 0;  
    
    if(chkBoxName.value) {
    
      if(chkBoxName.checked) {
          j++;
        } 
  } 
     for(var i=0; i<chkBoxName.length; i++) {      
      
      if (chkBoxName[i].checked == true) {
           j++;          
           }
      
        }
     
        if(j==0)
       if (errorMessage.indexOf(msg) == -1) {
              errorMessage = errorMessage + msg + "\n"
            }
      }
 
 /*
  Function validateCreateRoleSecondForm contains client side validations
  for Create Second Role
*/
function validateCreateRoleThirdForm() {
  errorMessage = ""
  focusField = true
  var form = document.forms[0]
  
  validateRoleRangeChkBoxes(form.rangeIndexes,"select atleast one Range")
  return showErrorMessage()
 
}
 /*
  Function validateModifyRoleThirdForm contains client side validations
  for Modify Third Role
*/
function validateModifyRoleThirdForm() {
  errorMessage = ""
  focusField = true
  var form = document.forms[0]
  
  validateRoleRangeChkBoxes(form.rangeIndexes,"select atleast one Range")
  return showErrorMessage()
 
}

/*
  Function validateCreateComRoleSecondForm contains client side validations
  for Create Second Role in commissionerate level
*/
function validateCreateComRoleSecondForm() {
  errorMessage = ""
  focusField = true
  var form = document.forms[0]
  
  validateRoleRangeChkBoxes(form.rangeIndexes,"select atleast one Range")
  return showErrorMessage()
 
}
/*
  Function validateModifyComRoleSecondForm contains client side validations
  for Modify Second Role in commissionerate level
*/
function validateModifyComRoleSecondForm() {
  errorMessage = ""
  focusField = true
  var form = document.forms[0]
  
  validateRoleRangeChkBoxes(form.rangeIndexes,"select atleast one Range")
  return showErrorMessage()
 
}

/*  validation for role divisions and ranges  */

function validateRoleRangeChkBoxes(chkBoxName,msg) {

    var form = document.forms[0]
    var j = 0;  
    
    if(chkBoxName.value) {
    
      if(chkBoxName.checked) {
          j++;
        } 
  } 
     for(var i=0; i<chkBoxName.length; i++) {      
      
      if (chkBoxName[i].checked == true) {
           j++;          
           }
      
        }
     
        if(j==0)
       if (errorMessage.indexOf(msg) == -1) {
              errorMessage = errorMessage + msg + "\n"
            }
      }
   
/*  validation for role divisions and ranges  */

function validateChkBoxesOfRole(chkBoxName,msg) {

    var form = document.forms[0]
  //  var avalableCommissionerateTable = document.getElementById("availableCommissionerateTable")
    var j = 0;
   
    for(var i=0; i<chkBoxName.length; i++) {
            
      if (chkBoxName[i].checked == true) {
      form.elements['availableCommissionerates[' + i + '].selectedCommissionerate'].value="1"
          j++;          
        }
      else
        form.elements['availableCommissionerates[' + i + '].selectedCommissionerate'].value="0"  
      }
      
      if(j==0)
       if (errorMessage.indexOf(msg) == -1) {
              errorMessage = errorMessage + msg + "\n"
            }
   
   }
   
/*
  Function validateCreateRoleGroup contains client side validations
  for CreatesearchRoleGroupListForm
*/
function validateCreateRoleGroupForm() {
  
  errorMessage = ""
  focusField = true
  var name = ""
  var firstLetter = ""
  var form = document.forms[0]
  
  validateRequired(form.roleGroupName,"Group Name is Mandatory.")
  
  if(form.roleGroupName!=null) {
  
  name=form.roleGroupName.value
  firstLetter=name.charAt(0)
  validateMaskValue(firstLetter,"Special characters are not allowed in first position of RoleGroupName.",new RegExp(/^[a-zA-Z0-9]*$/))
  
  }
  validateRequired(form.roleGroupDescription,"Group Description is Mandatory.")
 // validateRequired(form.roleGroupStatus,"Status is Mandatory.")
  validateChkBox(form.indexes,"select atleast one Role")
  return showErrorMessage()
}

/*
  Function createRoleGroupReset() contains client side validations
  for Create RoleGroup  
*/
function createRoleGroupReset() {
  
  var form = document.forms[0]
  form.roleGroupName.value=""
  form.roleGroupDescription.value=""
  resetCreateRoleGroupChkBox(form.indexes)
  
}

/*validation for rolegroup roles*/

function resetCreateRoleGroupChkBox(chkBoxName) {
    var form = document.forms[0]
    var availableRolesTable = document.getElementById("availableRolesTable")
    var j = 0;
    
    if(chkBoxName.value) {
    
      chkBoxName.checked=false
         
  } 
    for(var i=0; i<chkBoxName.length; i++) {
            
      chkBoxName[i].checked = false
      form.elements['availableGroupRoles[' + i + '].roleSelected'].value=""
             
      }
     
   }
/*
  Function modifyRoleGroupReset contains client side validations
  for modifyRoleGroupReset
*/
function modifyRoleGroupReset() {
  
  var form = document.forms[0]
  
  if(!((form.roleGroupStatus.value)==("CREATED"))) {
  form.roleGroupStatus.value=""
  }
  form.roleGroupDescription.value=""
  resetCreateRoleGroupChkBox(form.indexes)
 
}

/*
  Function validateCreateRoleGroup contains client side validations
  for CreatesearchRoleGroupListForm
*/
function validateModifyRoleGroupForm() {
  
  errorMessage = ""
  focusField = true
  
  var form = document.forms[0]
  
  validateRequired(form.roleGroupDescription,"Group Description is Mandatory.")
  validateRequired(form.roleGroupStatus,"Status is Mandatory.")
 
  validateChkBox(form.indexes,"select atleast one Row")
  return showErrorMessage()
}
 
/*    validation for the selection of atleast one role group    */
function validateList(objTargetElement,objSourceElement,msg) {

if(objTargetElement.length==0){
 if (errorMessage.indexOf(msg) == -1) {
              errorMessage = errorMessage + msg + "\n"
            }
            if (focusField) {
            objSourceElement.focus()
            focusField = false
          }
}

}

function getSelectedTexts (select) {

  var r = new Array();
  for (var i = 0; i < select.options.length; i++)
       r[r.length] = select.options[i].text;
  return r;
}
function getSelectedValues (select) {

  var r = new Array();
  for (var i = 0; i < select.options.length; i++)
       r[r.length] = select.options[i].value;
  return r;
}



/* Function submitFormForList will work when during listing users and roleGroups
*/
function submitFormForList(target) {
var form = document.forms[0]
var selected = 0;

  if(form.selectedNumber.value) {
      if(form.selectedNumber.checked) {
          document.forms[0].action=target
          document.forms[0].submit()
        } else  {        
            alert("please select row")
          }
  } if(form.selectedNumber.length) {
          for(var i=0;i<form.selectedNumber.length;i++) {
              if(form.selectedNumber[i].checked)  {
                    selected++;
                    document.forms[0].action=target
                    document.forms[0].submit()
              } 
           }  if(selected==0) {
                   alert("please select row")
                }
      }
}
/* Function submitFormForPrevileges check whether the user selected module r not
*/
function submitFormForPrevileges(target) {
var form = document.forms[0]
var selected = 0;

  if(form.moduleID.value) {
  
          form.selectedModuleID.value=form.moduleID.value
          document.forms[0].action=target
          document.forms[0].submit()
      } else  {        
            alert("please select module")
          }
  } 

/* Function submitForm submits a form to a given action
*/
function submitForm(target) {

document.forms[0].action=target
document.forms[0].submit()
}
function validatePassword(field,msg) {

var form = document.forms[0]
var invalid = " "; // Invalid character is a space
var minLength = 6; // Minimum length

if((form.password.value&&form.confirmPassword.value)){

// check for minimum length
if (form.password.value.length < minLength) {

if (errorMessage.indexOf(msg) == -1) {
          errorMessage = errorMessage + "you should enter atleast 6 characters in password/confirmPassword field \n"
        }
        if (focusField) {
        field.focus()
        focusField = false
      }
      
}
// check for spaces
else if(form.password.value.indexOf(invalid) > -1) {

if (errorMessage.indexOf(msg) == -1) {
          errorMessage = errorMessage + "empty spaces are not allowed in password/confirmPassword field \n"
        }
        if (focusField) {
        field.focus()
        focusField = false
      }
      
}
else {
if (form.password.value != form.confirmPassword.value) {

if (errorMessage.indexOf(msg) == -1) {
          errorMessage = errorMessage + "the password doesnt match with the confirm password \n"
        }
        if (focusField) {
        field.focus()
        focusField = false
      }
   }
  }
 }
}




/*
  The following function adds a row of Amount Of Evasion Involved in Prosecution only if the data
  entered is valid.
*/

function addEvasionInvolvedInProsecution() {
    (validateEvasionInvolvedInProsecution('addrow')) ? addRow('evasionDetailsTable',11,3) : showErrorMessage()
  return
}

/* The following function checks that the from date must be less than to date */

function validateFromDateToDate(fromDateField, toDateField, msg) {

if(fromDateField.value&&toDateField.value) {
    
 var fromDay = fromDateField.value.substring(0,2)
 var fromMonth = fromDateField.value.substring(3,5) - 1
 var fromYear = fromDateField.value.substring(6,10)
 var toDay = toDateField.value.substring(0,2)
 var toMonth = toDateField.value.substring(3,5) - 1
 var toYear = toDateField.value.substring(6,10)
 var fromDateValue = new Date(fromYear, fromMonth, fromDay)
 var toDateValue = new Date(toYear, toMonth, toDay)
 if (!(fromDateValue < toDateValue)) {
          if (errorMessage.indexOf(msg) == -1) {
            errorMessage = errorMessage + msg + "\n"
          }
          if (focusField) {
          toDateField.focus()
          focusField = false
        }
    }
  }
}

function showNewWindow(url,textType)  {
    
    
    document.forms[0].textType.value = textType;
    document.forms[0].action = url;
    document.forms[0].target="newWindow";
    document.forms[0].onSubmit = openWin();
    document.forms[0].submit();
    document.forms[0].target="_self";
  }
/* Function cancelOperation is used to cancel a specific operation
   @ path - Specifies the location of the page to which the user should be taken when an operation
            is cancelled
   @ message - used to provide a context specific message
*/
function cancelOperation(path, message) {
  if(confirm("Are you sure you want to cancel the " + message)) {
    location.href=path
  }
}
/* Function addRow is a general function to add a row of input elements
   @ tableID - unique id given to the table
   @ cols - no of columns in that table
   @ firstrow - index of the first row that has input elements
   @ The following script requires that the buttons ADD & DELETE should be in a new table
*/
function addRow(tableID, cols, firstrow) {
  
	var xtable=document.getElementById(tableID)
  var xrow=xtable.insertRow(xtable.rows.length)
  var rownum=xtable.rows.length - firstrow
  var cell=new Array(cols)
  var html
  for(i=0;i<cols;i++) {
    cell[i]=xrow.insertCell(i) //Insert Cell
    if(rownum%2==0) {
      applyStyleLeftTopData6(cell[i])
    } else {
      applyStyleLeftTopData4(cell[i])
    }
    if(i==cols-1) { //Check if the cell is in the last column then apply appropriate border
    cell[i].style.borderRightWidth="1px";
    }
    // Get the HTML from first row for corresponding cell & clear the input elements
    html=xtable.rows[firstrow].cells[i].innerHTML 
    if(html.toUpperCase().indexOf("<SELECT")!=-1) {
      html=removeSelected(html)  
    } 
    if(html.toUpperCase().indexOf("<INPUT")!=-1) { 
    html=removeValue(html)
    }
    if(i > 1) { //Reset the indexes, all of them are present from 2nd column onwards
      index=rownum-1
      replaceableString="[" + index + "]"
      html=html.replace(/\[\d{1,}\]/g,replaceableString)
    }
    if(i == 1) { //For 2nd column which is Serial number in every table
    cell[i].innerHTML=rownum
    } else {
    cell[i].innerHTML=html
    }
  }
}
/* Function deleteRow is a general function to delete a row of input elements
   @ tableID - unique id given to the table
   @ cols - no of columns in that table
   @ firstrow - index of the first row that has input elements
   @ chkBoxName - Name of the checkbox that identifies the row to delete
   @ The following script requires that the buttons ADD & DELETE should be in a new table
*/
function deleteRow(tableID, cols, firstrow, chkBoxName)  {
  var xtable=document.getElementById(tableID);
  var i;				
	var ctr=0;
	var x=chkBoxName
	var len=chkBoxName.length
  if(isNaN(len) || (len==1)) {
    alert("Atleast one row must be present. You cannot delete all rows.")
    return
  }
  for(i=0;i<len;i++) {
	   if(x[i].checked==true)  {
      ctr++;
     }
  }
  if(ctr<=0) {
    alert("Please select a row to delete.")
    return
  } else {
  if(!confirm("You have selected " + ctr + " rows to delete. Are you sure, you want to continue?"))
    return
  }
  
	for(i=0;i<len;i++) {
	   if(x[i].checked==true)  {
            if(xtable.rows.length > firstrow + 1) {
              xtable.deleteRow(firstrow + i);
              } else {
              alert("Atleast one row must be present. You cannot delete all rows.")
              break;
              }
            	i--;
            	len--;
            
           }	
	}

      //Reset The Serial Numbers, Indexes An Apply Correct Styles
     var sno=0
     for(i=firstrow;i<xtable.rows.length;i++) {
        sno++;
        newindex=sno-1
        replaceableString="[" + newindex + "]"
        for(j=0;j<cols;j++) {
          temp=xtable.rows[i].cells[j].innerHTML
          if (j==0) {
          xtable.rows[i].cells[j].innerHTML=temp //Display checkbox as it is  
          } else if(j==1) {
          xtable.rows[i].cells[j].innerHTML=sno   //Reset Serial Number
          } else { // Reset the indexes
          temp=temp.replace(/\[\d{1,}\]/g,replaceableString)
          xtable.rows[i].cells[j].innerHTML=temp
          }
          if((sno)%2==0) { // Apply Styles
                applyStyleLeftTopData6(xtable.rows[i].cells[j]);		
              } else {
              applyStyleLeftTopData4(xtable.rows[i].cells[j]);		
              }
        }
        xtable.rows[i].cells[cols-1].style.borderRightWidth="1px";
       }
}

/* Function removeValue will remove the value attribute from the
   fields of type text only
*/
function removeValue(field) {
  
  valueIndex=field.indexOf("value=");
  if (valueIndex!=-1) {
      spaceIndex=field.indexOf(" ",valueIndex);
      field=field.substring(0,valueIndex) + field.substring(spaceIndex + 1)
    }
  return field
}


/* Function removeSelected will remove the selected attribute from the
   fields of type select only
*/
function removeSelected(field) {
  
  if (navigator.appName.indexOf("Netscape") != -1 &&
        navigator.userAgent.indexOf("Firefox") != -1  
        ) {
  //  field = field.replace(/\sselected/g,"")
    //alert('field1:' + field)

    field = field.replace(/\sselected=\"selected\"/g,"")

    return field

  }else{
    field = field.replace(/\sselected/g,"")
    return field
  
  }
  
}


/* Function validateAttachment is used to alert the user when he
   does not attaches any document
   @ fileName - value of the file field in form
   @ relevantTo - used to provide a context specific 
*/
var msg=""

function validateAttachment(fileName,relevantTo) {
	
	fileName=trimString(fileName);
	if(fileName=="") {
		msg = msg + "\nYou have not attached any document relevant to " + relevantTo + "."
	}
}

/* Function validateNoting is used to alert the user when he does
   not provides either notings or attachment in support of notings
   or both
   @ comments - comments/notings typed
   @ fileName - value of the notings attachment file field in the form
   @ attachFile - value of the relevant documents attachment file in the form
   @ relevantTo - used to provide a context specific 
*/

function validateNotingAndAttachment(comments,fileName,attachFile,relevantTo) {
 	comments=trimString(comments);
	fileName=trimString(fileName);
	if(comments=="") {

		if(fileName=="") {

			msg="You have neither provided any noting nor attached any supporting noting document."
			
		} else {

			msg="Although you have attached a file pertaining to noting, however you have not provided any valid notes."
			
		}
	} else {

		if(fileName=="") {
			msg="Although you have provided noting, however you have not attached any document in its support."
		} 
	}
  validateAttachment(attachFile,relevantTo)
  if (msg!="") {
    msg = "Please Confirm:\n" + msg + "\nAre you sure you want to proceed?"
    response=confirm(msg)
    msg=""
    return response
  } else {
  return true
  }
}
function validateNext() {
 msg = "Please Confirm:\n Before moving to the next page confirm that you saved all the data \notherwise you lose the data which is not saved \nAre you sure you want to proceed?"
    response=confirm(msg)
    msg=""
    return response
    
}
/* Function trimString is used to trim the strings

*/

function trimString(s) {
  
  return s.replace( /^\s*/, "" ).replace( /\s*$/, "" );
  /*while (sString.substring(0,1) == ' ')	{
    sString = sString.substring(1, sString.length);
	}

	while (sString.substring(sString.length-1, sString.length) == ' ')  {
		sString = sString.substring(0,sString.length-1);
	}
  return sString;*/
}

/* Function for restricting textarea
*/

function restrictTextArea(field,maxlimit) {
    if (field.value.length > maxlimit) {
        field.value = field.value.substring(0, maxlimit);
    }
}

/* Function applyStyleLeftTopData4 will apply a style to a cell
*/
function applyStyleLeftTopData4(obj) {
	obj.style.fontFamily="arial";
	obj.style.fontSize="9pt";
	obj.style.fontWeight="normal"
	obj.style.borderColor="#e9967a";
  obj.style.borderStyle="outset";
	obj.style.borderLeftWidth="1px";
	obj.style.borderRightWidth="0px";
 	obj.style.borderTopWidth="1px";
  obj.style.borderBottomWidth="0px";
	obj.style.paddingLeft="3px";
	obj.style.background="#fffacd";
	obj.align="center";
}		
/* Function applyStyleLeftTopData4 will apply a style to a cell
*/   
function applyStyleLeftTopData6(obj) {
	obj.style.fontFamily="arial";
	obj.style.fontSize="9pt";
	obj.style.fontWeight="normal"
	obj.style.borderColor="#e9967a";
  obj.style.borderStyle="outset";
	obj.style.borderLeftWidth="1px";
  obj.style.borderRightWidth="0px";
  obj.style.borderTopWidth="1px";
  obj.style.borderBottomWidth="0px";
	obj.style.paddingLeft="3px";
	obj.style.background="#FFFAF0";
	obj.align="center";
}	

function validateLoginFormInJS(){

  errorMessage = ""
  focusField = true
  var form = document.forms[0]
  validateRequired(form.userName,"User Name is required.")
  validateMask(form.userName,"Please enter the Login ID in correct format.\nAlphabets should be in smalls. \nIt should be 6-12 Characters long.\nFirst character should be alphabet.\nCan contain the special character (_)",new RegExp(/^([a-z])([0-9]|[a-z]|[_]){5,11}$/));
  //validateEmail(form.userName,"User Name should be an emailID.")
  validatePwdForEmptySpace(form.userName,"User Name field should not contain spaces.")
  validateRequired(form.password,"Password is required.")
  validatePwdForEmptySpace(form.password,"Password field should not contain spaces.")
  validateLength(form.password,"Password should be 6 characters.") 
  
  return showErrorMessage()

}
function checkpopupwindow(){

if(window.opener!=null){

  alert("Your session may be expired,and you cant login in a popup window.Please open a fresh window for login.")
 
  window.opener.document.forms[0].submit();
  window.close()
  
}
}
//validatePwdForEmptySpace
  function validatePwdForEmptySpace(field,msg) {
 
   if(field.value)  {
   
   var sPWD=field.value
   var iMaxLen = field.value.length
   var sPWDCheckStr;
   var blCheck ;
   var sPWDCheckChar ;
  if(iMaxLen!= 0) { 
  
     for( i=0 ; i < iMaxLen ; i++) {
     
         sPWDCheckChar      = sPWD.charAt(i);
         sPWDCheckStr = new String(sPWDCheckChar);
        if(( sPWDCheckStr == " ") || ( sPWDCheckStr == null) || ( sPWDCheckStr == ''))   {
          
             blCheck = 0;
             
           
              }
          }
          if(blCheck==0){
          
             if (errorMessage.indexOf(msg) == -1) {
                    errorMessage = errorMessage + msg + "\n"
                  }
              if (focusField) {
                  field.focus()
                  focusField = false
                }
          
          }
       
        }//end of imax len
      }
   } 
  