//------------------------General Validation Functions------------------------------
//------------------------============================------------------------------
  
  function GetContentId() {
    return 'ctl00_rpMainContentPanel_MainContent_';
  }
  
  function GetMyGroupsDropDownContentId() {
    return GetContentId() + 'myGroupsDropDown_';
  }
  
  function GetOtherGroupsDropDownContentId() {
    return GetContentId + 'otherGroupsDropDown_';
  }
  
//Return to Page
//=====================
  function ReturnToParentPage(e) {
    var parentWindow = window.parent;    
    parentWindow.CloseActivateAccountWindow(e);    
  }  

function ReturnToDefaultPage() {
    var parentWindow = window.parent;
    parentWindow.CloseLoginWindow();
    
  }
  
  function ReturnToDefaultPageFromImpersonation(){
    var parentWindow = window.parent;
    parentWindow.CloseImpersonationWindow();
  }

//GoTo Page events on the grid
//======================
  function HandleGotoPageKeyDown(grid, event) {
      if (event.keyCode == 13) {
        event.cancelBubble = true;
        event.returnValue = false;
        grid.GotoPage(edtGotoPage.GetValue() - 1);
        return false;
      }
    }

    function HandleGotoPageValueChanged(grid) {
      grid.GotoPage(edtGotoPage.GetValue() - 1);
    }

//Grid customisation
//==============

function ShowCustWindowForGrid() {
  if (!grid.IsCustomizationWindowVisible()) {
      grid.ShowCustomizationWindow();   
    }
}

function ShowCustWindowForViewDocGrid() {
    if (!grid.IsCustomizationWindowVisible()) {
        grid.ShowCustomizationWindow();
    }
}


function ShowCustWindowForGridUsers() {
  if (!grdUsers.IsCustomizationWindowVisible()) {
      grdUsers.ShowCustomizationWindow();   
    } 
}

function ShowCustWindowForLeaveEscAppGrid() {
  if (!grdLeaveEscalationApprovers.IsCustomizationWindowVisible()) {
      grdLeaveEscalationApprovers.ShowCustomizationWindow();   
    }     
}

function ShowCustWindowForLeaveAppGrid() {
  if (!grdLeaveApprovers.IsCustomizationWindowVisible()) {
      grdLeaveApprovers.ShowCustomizationWindow();   
    }       
}

function ShowCustWindowForLeaveUsersGrid() {
  if (!grdLeaveUsers.IsCustomizationWindowVisible()) {
      grdLeaveUsers.ShowCustomizationWindow();   
    }
}

function ShowCustWindowForOvertimeEscAppGrid() {
  if (!grdOvertimeEscalationApprovers.IsCustomizationWindowVisible()) {
      grdOvertimeEscalationApprovers.ShowCustomizationWindow();   
    }
}

function ShowCustWindowForOvertimeAppGrid() {
if (!grdOvertimeApprovers.IsCustomizationWindowVisible()) {
      grdOvertimeApprovers.ShowCustomizationWindow();   
    }
}

function ShowCustWindowForOvertimeUsersGrid() {
  if (!grdOvertimeUsers.IsCustomizationWindowVisible()) {
      grdOvertimeUsers.ShowCustomizationWindow();   
    }
}

function ShowCustWindowForClaimsEscAppGrid() {
  if (!grdClaimsEscalationApprovers.IsCustomizationWindowVisible()) {
      grdClaimsEscalationApprovers.ShowCustomizationWindow();   
    }
}

function ShowCustWindowForClaimsAppGrid() {
  if (!grdClaimsApprovers.IsCustomizationWindowVisible()) {
      grdClaimsApprovers.ShowCustomizationWindow();   
    }
}

function ShowCustWindowForClaimsUsersGrid() {
  if (!grdClaimsUsers.IsCustomizationWindowVisible()) {
      grdClaimsUsers.ShowCustomizationWindow();   
    }
}

function ShowCustWindowForPersonalChangeEscAppGrid() {
  if (!grdPersonalChangeEscalationApprovers.IsCustomizationWindowVisible()) {
      grdPersonalChangeEscalationApprovers.ShowCustomizationWindow();   
    }
}

function ShowCustWindowForPersonalChangeAppGrid() {
  if (!grdPersonalChangeApprovers.IsCustomizationWindowVisible()) {
      grdPersonalChangeApprovers.ShowCustomizationWindow();   
    }
}

function ShowCustWindowForPersonalChangeUsersGrid() {
  if (!grdPersonalChangeUsers.IsCustomizationWindowVisible()) {
      grdPersonalChangeUsers.ShowCustomizationWindow();   
    }
}

function ShowCustWindowForFamilyChangeEscAppGrid() {
  if (!grdFamilyChangeEscalationApprovers.IsCustomizationWindowVisible()) {
      grdFamilyChangeEscalationApprovers.ShowCustomizationWindow();   
    }
}

function ShowCustWindowForFamilyChangeAppGrid() {
  if (!grdFamilyChangeApprovers.IsCustomizationWindowVisible()) {
      grdFamilyChangeApprovers.ShowCustomizationWindow();   
    }
}

function ShowCustWindowForFamilyChangeUsersGrid() {
  if (!grdFamilyChangeUsers.IsCustomizationWindowVisible()) {
      grdFamilyChangeUsers.ShowCustomizationWindow();   
    }
}

function ShowCustWindowForPayslipGrid() {
  if (!gridP.IsCustomizationWindowVisible()) {
      gridP.ShowCustomizationWindow();   
    } 
}

function ShowCustWindowForIRP5Grid() {
  if (!gridR.IsCustomizationWindowVisible()) {
      gridR.ShowCustomizationWindow();   
    }
}

//-----------------------Spesific Validation Functions-----------------------------------------
//-----------------------=============================------------------------------

//-----------DoCheckChange--------------------------
//===================================
 function DoCheckChange(rowValue) {    
    CheckBoxCallback.SendCallback(rowValue);
  }

  function CheckBoxChangeCallbackComplete(s, e) {
    var value = e.result;
    if (value != "") {    
      var row = value.substr(0,value.indexOf('|'));
      var mode = value.substr(value.indexOf("|")+1, value.length - value.indexOf("|")+1);
      var chk = document.getElementById("chkClaims" + row);
      var edt = document.getElementById("edtClaims" + row);
      var lbl = document.getElementById("lblClaims" + row);
      if (chk != null && edt != null) {
        edt.SetEnabled(chk.GetEnabled() && mode != "A");
      }
      if (chk != null && lbl != null) {
        lbl.SetEnabled(chk.GetEnabled() && mode != "A");
      }
    }
}

//SUMMARY
function HandleUserItemClickEvent() {
    UserItemClickCallback.SendCallback();
}
function HandleAdminItemClickEvent() {
    AdminItemClickCallback.SendCallback();
}

//USERNAME
//========
  function HandleUserNameLostFocusEvent() {
    UserNameCallback.SendCallback(edtUserName.GetValueString()); 
  }
 
  
  function UserNameCallbackComplete(s, e) {
    var result = e.result;
    if (e.result != "") {
      edtUserName.SetErrorText(e.result);
      edtUserName.SetIsValid(false);
    } else {
      edtUserName.SetErrorText("");
      edtUserName.SetIsValid(true);
    }
  }


//PASSWORD
//========
  function HandlePasswordLostFocusEvent() {
    PasswordCallback.SendCallback(edtPassword.GetValueString()); 
  }


  function PasswordCallbackComplete(s, e) {
      var result = e.result;
      if (e.result != "") {
          edtPassword.SetErrorText(e.result);
          edtPassword.SetIsValid(false);
      } else {
          edtPassword.SetErrorText("");
          edtPassword.SetIsValid(true);
      }
  }

function HandlePasswordConfirmLostFocusEvent() {
    PasswordConfirmCallback.SendCallback(edtPasswordConfirm.GetValueString());
}
  
function PasswordConfirmCallbackComplete(s, e) {
    var result = e.result;
    if (e.result != "") {
        edtPasswordConfirm.SetErrorText(e.result);
        edtPasswordConfirm.SetIsValid(false);
    } else {
        edtPasswordConfirm.SetErrorText("");
        edtPasswordConfirm.SetIsValid(true);
    }
}
  
//CONFIRM PASSWORD
//================
  function PasswordConfirm(s, e) {
    if (e.value != edtPassword.GetValue()) {
      e.errorText = "Confirmation Password & New Password must match";
      e.isValid = false;
    }
  }
  
  //CONFIRM EMAIL
//================
  function EmailConfirm(s, e) {
    if (e.value != edtNewEmail.GetValue()) {
      e.errorText = "Confirmation Email & New Email must match";
      e.isValid = false;
    }
}

//CONFIRM USERNAME
//================
function UserNameConfirm(s, e) {
    if (e.value != edtNewUserName.GetValue()) {
        e.errorText = "Confirmation Username & New Username must match";
        e.isValid = false;
    } else {
    e.errorText = "";
    e.isValid = true;
    }
}
  
  //EMAIL EXISTS
  //============
  function EmailExistCallbackComplete(s, e) {
    var result = e.result;
    if (e.result != "") {
      edtCurrentEmail.SetErrorText(e.result);
      edtCurrentEmail.SetIsValid(false);
    } else {
      edtCurrentEmail.SetErrorText(e.result);
      edtCurrentEmail.SetIsValid(true);
    }
  }

  //USERNAME CHANGE EXISTS
  //============
  function UserNameExistCallbackComplete(s, e) {
      var result = e.result;
      if (e.result != "") {
          edtCurrentUserName.SetErrorText(e.result);
          edtCurrentUserName.SetIsValid(false);
      } else {
          edtCurrentUserName.SetErrorText(e.result);
          edtCurrentUserName.SetIsValid(true);
      }
  }
  
  //PASSWORD EXISTS
  //============
  function PasswordExistCallbackComplete(s, e) {
    var result = e.result;
    if (e.result != "") {
      edtCurrentPassword.SetErrorText(e.result);
      edtCurrentPassword.SetIsValid(false);
    } else {
      edtCurrentPassword.SetErrorText(e.result);
      edtCurrentPassword.SetIsValid(true);
    }
  }
  
//FIRST NAMES
//===========
function HandleFirstNamesLostFocusEvent() {
    FirstNamesCallback.SendCallback(edtFirstNames.GetValueString());
  }
  
  function FirstNamesCallbackComplete(s, e) {    
    if (e.result != "") {            
      edtFirstNames.SetErrorText(e.result);
      edtFirstNames.SetIsValid(false);
    } else {
      edtFirstNames.SetErrorText(e.result);
      edtFirstNames.SetIsValid(true);
    }
  }

//LAST NAME
//=======
function HandleLastNameLostFocusEvent() {
    LastNameCallback.SendCallback(edtLastName.GetValueString());
  }
  
  function LastNameCallbackComplete(s, e) {    
    if (e.result != "") {            
      edtLastName.SetErrorText(e.result);
      edtLastName.SetIsValid(false);
    } else {
      edtLastName.SetErrorText(e.result);
      edtLastName.SetIsValid(true);
    }
  }

//INITIALS
//=======
function HandleInitialsLostFocusEvent() {
    InitialsCallback.SendCallback(edtInitials.GetValueString());
  }
  
  function InitialsCallbackComplete(s, e) {    
    if (e.result != "") {            
      edtInitials.SetErrorText(e.result);
      edtInitials.SetIsValid(false);
    } else {
      edtInitials.SetErrorText(e.result);
      edtInitials.SetIsValid(true);
    }
  }

//TAX NUMBER
//========
  function HandleTaxNumberLostFocusEvent() {
    TaxNumberCallback.SendCallback(edtTaxNumber.GetValueString()); 
  }

  function TaxNumberCallbackComplete(s, e) {
    var result = e.result;
    if (e.result != "") {
      edtTaxNumber.SetErrorText(e.result);
      edtTaxNumber.SetIsValid(false);
    } else {
      edtTaxNumber.SetErrorText(e.result);
      edtTaxNumber.SetIsValid(true);
    }
  }

//ID NUMBER
//========
  function HandleIDNumberLostFocusEvent() {
    IDNumberCallback.SendCallback(edtIDNumber.GetValueString()); 
  }

  function IDNumberCallbackComplete(s, e) {
    var result = e.result;
    if (e.result != "") {
      edtIDNumber.SetErrorText(e.result);
      edtIDNumber.SetIsValid(false);
    } else {
      edtIDNumber.SetErrorText(e.result);
      edtIDNumber.SetIsValid(true);
    }
  }
  
  //BANK CLEARANCE NO
//========
  function HandleBankClearanceNoLostFocusEvent() {
    BankClearanceNoCallback.SendCallback(edtBankClearanceNo.GetValueString()); 
  }

  function BankClearanceNoCallbackComplete(s, e) {
    var result = e.result;
    if (e.result != "") {
      edtBankClearanceNo.SetErrorText(e.result);
      edtBankClearanceNo.SetIsValid(false);
    } else {
      edtBankClearanceNo.SetErrorText(e.result);
      edtBankClearanceNo.SetIsValid(true);
    }
  }

//RESIDENTIAL ADDRESS LINES
//==========================
  function HandleResAddressLinesLostFocusEvent() {
    if (edtResAddressLine7.GetValueString() != "") {
      var strAddressLines = 
        edtResAddressLine1.GetValueString() + edtResAddressLine2.GetValueString() + edtResAddressLine3.GetValueString() + 
        edtResAddressLine4.GetValueString() + edtResAddressLine5.GetValueString() + edtResAddressLine6.GetValueString();
      ResAddressLinesCallback.SendCallback(strAddressLines); 
    }
  }

  function ResAddressLinesCallbackComplete(s, e) {
    var result = e.result;
    if (e.result != "") {
      edtResAddressLine1.SetErrorText(e.result);
      edtResAddressLine1.SetIsValid(false);
      edtResAddressLine2.SetErrorText(e.result);
      edtResAddressLine2.SetIsValid(false);
      edtResAddressLine3.SetErrorText(e.result);
      edtResAddressLine3.SetIsValid(false);
      edtResAddressLine4.SetErrorText(e.result);
      edtResAddressLine4.SetIsValid(false);
      edtResAddressLine5.SetErrorText(e.result);
      edtResAddressLine5.SetIsValid(false);
      edtResAddressLine6.SetErrorText(e.result);
      edtResAddressLine6.SetIsValid(false);
    } else {
      edtResAddressLine1.SetErrorText(e.result);
      edtResAddressLine1.SetIsValid(true);
      edtResAddressLine2.SetErrorText(e.result);
      edtResAddressLine2.SetIsValid(true);
      edtResAddressLine3.SetErrorText(e.result);
      edtResAddressLine3.SetIsValid(true);
      edtResAddressLine4.SetErrorText(e.result);
      edtResAddressLine4.SetIsValid(true);
      edtResAddressLine5.SetErrorText(e.result);
      edtResAddressLine5.SetIsValid(true);
      edtResAddressLine6.SetErrorText(e.result);
      edtResAddressLine6.SetIsValid(true);
    }
  }
  
//RESIDENTIAL ADDRESS LINES
//==========================
  function HandlePosAddressLinesLostFocusEvent() {
    if (edtPosAddressLine7.GetValueString() != "") {
      var strAddressLines = 
        edtPosAddressLine1.GetValueString() + edtPosAddressLine2.GetValueString() + edtPosAddressLine3.GetValueString() + 
        edtPosAddressLine4.GetValueString() + edtPosAddressLine5.GetValueString() + edtPosAddressLine6.GetValueString();
      PosAddressLinesCallback.SendCallback(strAddressLines); 
    }
  }

  function PosAddressLinesCallbackComplete(s, e) {
    var result = e.result;
    if (e.result != "") {
      edtPosAddressLine1.SetErrorText(e.result);
      edtPosAddressLine1.SetIsValid(false);
      edtPosAddressLine2.SetErrorText(e.result);
      edtPosAddressLine2.SetIsValid(false);
      edtPosAddressLine3.SetErrorText(e.result);
      edtPosAddressLine3.SetIsValid(false);
      edtPosAddressLine4.SetErrorText(e.result);
      edtPosAddressLine4.SetIsValid(false);
      edtPosAddressLine5.SetErrorText(e.result);
      edtPosAddressLine5.SetIsValid(false);
      edtPosAddressLine6.SetErrorText(e.result);
      edtPosAddressLine6.SetIsValid(false);
    } else {
      edtPosAddressLine1.SetErrorText(e.result);
      edtPosAddressLine1.SetIsValid(true);
      edtPosAddressLine2.SetErrorText(e.result);
      edtPosAddressLine2.SetIsValid(true);
      edtPosAddressLine3.SetErrorText(e.result);
      edtPosAddressLine3.SetIsValid(true);
      edtPosAddressLine4.SetErrorText(e.result);
      edtPosAddressLine4.SetIsValid(true);
      edtPosAddressLine5.SetErrorText(e.result);
      edtPosAddressLine5.SetIsValid(true);
      edtPosAddressLine6.SetErrorText(e.result);
      edtPosAddressLine6.SetIsValid(true);
    }
  }

//RESIDENTIAL POSTAL CODE
//========================
  function HandleResPostalCodeLostFocusEvent() {
    var strAddressLines = 
        edtResAddressLine1.GetValueString() + edtResAddressLine2.GetValueString() + edtResAddressLine3.GetValueString() + 
        edtResAddressLine4.GetValueString() + edtResAddressLine5.GetValueString() + edtResAddressLine6.GetValueString();
    var trimmed = strAddressLines.replace(/^\s+|\s+$/g, '') ;    
    ResPostalCodeCallback.SendCallback(edtResAddressLine7.GetValueString()); 
  }

  function ResPostalCodeCallbackComplete(s, e) {
    var result = e.result;
    if (e.result != "") {
      edtResAddressLine7.SetErrorText(e.result);
      edtResAddressLine7.SetIsValid(false);
    } else {
      edtResAddressLine7.SetErrorText(e.result);
      edtResAddressLine7.SetIsValid(true);
    }
  }
  
  //POSTAL POSTAL CODE
//========================
  function HandlePosPostalCodeLostFocusEvent() {
    var strAddressLines = 
        edtPosAddressLine1.GetValueString() + edtPosAddressLine2.GetValueString() + edtPosAddressLine3.GetValueString() + 
        edtPosAddressLine4.GetValueString() + edtPosAddressLine5.GetValueString() + edtPosAddressLine6.GetValueString();
    var trimmed = strAddressLines.replace(/^\s+|\s+$/g, '') ;    
    PosPostalCodeCallback.SendCallback(edtPosAddressLine7.GetValueString()); 
  }

  function PosPostalCodeCallbackComplete(s, e) {
    var result = e.result;
    if (e.result != "") {
      edtPosAddressLine7.SetErrorText(e.result);
      edtPosAddressLine7.SetIsValid(false);
    } else {
      edtPosAddressLine7.SetErrorText(e.result);
      edtPosAddressLine7.SetIsValid(true);
    }
  }
  

//FUND1
//=====
 function HandleFund1LostFocusEvent() {
    Fund1Callback.SendCallback(cmbFund1.GetValueString()); 
  }

  function Fund1CallbackComplete(s, e) {
    var result = e.result;
    if (e.result != "") {
      cmbFund1.SetErrorText(e.result);
      cmbFund1.SetIsValid(false);
    } else {
      cmbFund1.SetErrorText(e.result);
      cmbFund1.SetIsValid(true);
    }
  }

//FUND2
//=====
 function HandleFund2LostFocusEvent() {
    Fund2Callback.SendCallback(cmbFund2.GetValueString()); 
  }

  function Fund2CallbackComplete(s, e) {
    var result = e.result;
    if (e.result != "") {
      cmbFund2.SetErrorText(e.result);
      cmbFund2.SetIsValid(false);
    } else {
      cmbFund2.SetErrorText(e.result);
      cmbFund2.SetIsValid(true);
    }
  }

//FUND3
//=====
 function HandleFund3LostFocusEvent() {
    Fund3Callback.SendCallback(cmbFund3.GetValueString()); 
  }

  function Fund3CallbackComplete(s, e) {
    var result = e.result;
    if (e.result != "") {
      cmbFund3.SetErrorText(e.result);
      cmbFund3.SetIsValid(false);
    } else {
      cmbFund3.SetErrorText(e.result);
      cmbFund3.SetIsValid(true);
    }
  }

//FUND4
//=====
 function HandleFund4LostFocusEvent() {
    Fund4Callback.SendCallback(cmbFund4.GetValueString()); 
  }

  function Fund4CallbackComplete(s, e) {
    var result = e.result;
    if (e.result != "") {
      cmbFund4.SetErrorText(e.result);
      cmbFund4.SetIsValid(false);
    } else {
      cmbFund4.SetErrorText(e.result);
      cmbFund4.SetIsValid(true);
    }
  }

//FUND5
//=====
 function HandleFund5LostFocusEvent() {
    Fund5Callback.SendCallback(cmbFund5.GetValueString()); 
  }

  function Fund5CallbackComplete(s, e) {
    var result = e.result;
    if (e.result != "") {
      cmbFund5.SetErrorText(e.result);
      cmbFund5.SetIsValid(false);
    } else {
      cmbFund5.SetErrorText(e.result);
      cmbFund5.SetIsValid(true);
    }
  }

//PERCENTAGE1
//===========
 function HandlePercentage1LostFocusEvent() {
    Percentage1Callback.SendCallback(edtPercentageSplit1.GetValueString()); 
  }

  function Percentage1CallbackComplete(s, e) {
    var result = e.result;
    if (e.result != "") {
      edtPercentageSplit1.SetErrorText(e.result);
      edtPercentageSplit1.SetIsValid(false);
    } else {
      edtPercentageSplit1.SetErrorText(e.result);
      edtPercentageSplit1.SetIsValid(true);
    }
  }

//PERCENTAGE2
//===========
 function HandlePercentage2LostFocusEvent() {
    Percentage2Callback.SendCallback(edtPercentageSplit2.GetValueString()); 
  }

  function Percentage2CallbackComplete(s, e) {
    var result = e.result;
    if (e.result != "") {
      edtPercentageSplit2.SetErrorText(e.result);
      edtPercentageSplit2.SetIsValid(false);
    } else {
      edtPercentageSplit2.SetErrorText(e.result);
      edtPercentageSplit2.SetIsValid(true);
    }
  }
  
  //PERCENTAGE3
//===========
 function HandlePercentage3LostFocusEvent() {
    Percentage3Callback.SendCallback(edtPercentageSplit3.GetValueString()); 
  }

  function Percentage3CallbackComplete(s, e) {
    var result = e.result;
    if (e.result != "") {
      edtPercentageSplit3.SetErrorText(e.result);
      edtPercentageSplit3.SetIsValid(false);
    } else {
      edtPercentageSplit3.SetErrorText(e.result);
      edtPercentageSplit3.SetIsValid(true);
    }
  }

//PERCENTAGE4
//===========
 function HandlePercentage4LostFocusEvent() {
    Percentage4Callback.SendCallback(edtPercentageSplit4.GetValueString()); 
  }

  function Percentage4CallbackComplete(s, e) {
    var result = e.result;
    if (e.result != "") {
      edtPercentageSplit4.SetErrorText(e.result);
      edtPercentageSplit4.SetIsValid(false);
    } else {
      edtPercentageSplit4.SetErrorText(e.result);
      edtPercentageSplit4.SetIsValid(true);
    }
  }
  
  //PERCENTAGE5
//===========
 function HandlePercentage5LostFocusEvent() {
    Percentage5Callback.SendCallback(edtPercentageSplit5.GetValueString()); 
  }

  function Percentage5CallbackComplete(s, e) {
    var result = e.result;
    if (e.result != "") {
      edtPercentageSplit5.SetErrorText(e.result);
      edtPercentageSplit5.SetIsValid(false);
    } else {
      edtPercentageSplit5.SetErrorText(e.result);
      edtPercentageSplit5.SetIsValid(true);
    }
  }

//ACTIVATE ACCOUNT
//================
              
  function HandleActivateAccountClickEvent() {
    ActivateAccountCallback.SendCallback();
  }
  
  function ActivateAccountCallbackComplete(s, e) {
    var result = e.result;
    if (result.charAt(0)=="/") {
      ReturnToParentPage(result);
    }
  }
  
  function HandleCancelActivateAccountClickEvent() {
    CancelActivateAccountCallback.SendCallback();
  }
  
  function CancelActivateAccountCallbackComplete(s, e) {
    var result = e.result;
    if (result.charAt(0)=="/") {
      ReturnToParentPage(result);
    }
  }
  
  //DECLINE REASON
  //==============
  
  function HandleDeclineReasonLostFocusEvent() {    
    edtDeclineReason.Validate();     
  }

  function DeclineReasonCallbackComplete(s, e) {
    var result = e.result;
    if (e.result != "") {
      edtDeclineReason.SetErrorText(e.result);
      edtDeclineReason.SetIsValid(false);
    } else {
      edtDeclineReason.SetErrorText(e.result);
      edtDeclineReason.SetIsValid(true);
    }
  }
  
  //FROM DATE AND TO DATE
  //======================
  function ValidateFromDateAndCompareToDate() {
    edtFromDate.Validate();  
    edtToDate.Validate();
    if (edtFromDate.GetIsValid()) { 
      if (edtFromDate.GetDate() > edtToDate.GetDate()) { 
        edtFromDate.SetIsValid(false); 
      } 
    } 
  }
  
  function ValidateToDateAndCompareFromDate() {
    edtToDate.Validate();  
    edtFromDate.Validate();
    if (edtToDate.GetIsValid()) { 
      if (edtToDate.GetDate() < edtFromDate.GetDate()) { 
        edtToDate.SetIsValid(false); 
      } 
    } 
  }
  
  //APP CONFIGURATION - DATA OPTIONS - NAME DISPLAY CHANGES
  //========================================================
  
  function DisplayNameTypeChange() {
  var strName = 'e.g ';
    if (cbxTitle.GetChecked()) {
      strName = strName + 'Mrs ';
    }
    if (cbxInit.GetChecked()) {
      strName = strName + "CA ";
    }
    if (cbxFirstNamesIfKnownAsEmpty.GetChecked()) {
      strName = strName + "Cathy ";
      cbxKnownAs.SetChecked(false);
      cbxKnownAs.SetEnabled(false);
      cbxFirstNames.SetChecked(false);
      cbxFirstNames.SetEnabled(false);
    } else {
    cbxKnownAs.SetEnabled(true);
    cbxFirstNames.SetEnabled(true);
      if (cbxKnownAs.GetChecked()) {
        strName = strName + "Cathy ";
      }
      if (cbxFirstNames.GetChecked()) {
        strName = strName + "Catherine Anne ";
      }
    }
    if (cbxLastName.GetChecked()) {
      strName = strName + "Westwood ";
    }
    if (cbxUsername.GetChecked()) {
      strName = strName + "(cathyw) ";
    }
    lblNameDisplayType.SetText(strName);
  }
  //USER DETAILS
  //=============
  function LeaveGroupChange() {
    if (cbxApplyToAll.GetChecked()) {
      cmbPersonalGroup.SetSelectedItem(cmbLeaveGroup.GetSelectedItem());
      cmbFamilyGroup.SetSelectedItem(cmbLeaveGroup.GetSelectedItem());
      cmbOvertimeGroup.SetSelectedItem(cmbLeaveGroup.GetSelectedItem());
      cmbClaimsGroup.SetSelectedItem(cmbLeaveGroup.GetSelectedItem()); 
    }
    cmbPersonalGroup.SetEnabled(!cbxApplyToAll.GetChecked());
    cmbFamilyGroup.SetEnabled(!cbxApplyToAll.GetChecked());
    cmbOvertimeGroup.SetEnabled(!cbxApplyToAll.GetChecked());
    cmbClaimsGroup.SetEnabled(!cbxApplyToAll.GetChecked()); 
  }
  
  function LeaveApplyToAllInit() {
//    if (cmbLeaveGroup.GetSelectedItem() != null &&
//    cmbFamilyGroup.GetSelectedItem() != null &&
//    cmbPersonalGroup.GetSelectedItem() != null &&
//    cmbClaimsGroup.GetSelectedItem() != null &&
//    cmbOvertimeGroup.GetSelectedItem() != null) {
//      var isSame = false;
//      if (cmbFamilyGroup.GetSelectedItem().text == cmbLeaveGroup.GetSelectedItem().text) {
//        isSame = true;
//      } else {
//       isSame = false;
//      }
//      if (isSame) {
//        if (cmbPersonalGroup.GetSelectedItem().text == cmbLeaveGroup.GetSelectedItem().text) {
//         isSame = true;
//        } else {
//          isSame = false;
//        } 
//      }
//      if (isSame) {
//        if (cmbClaimsGroup.GetSelectedItem().text == cmbLeaveGroup.GetSelectedItem().text) {
//         isSame = true;
//        } else {
//          isSame = false;
//        } 
//      }    
//      if (isSame) {
//        if (cmbOvertimeGroup.GetSelectedItem().text == cmbLeaveGroup.GetSelectedItem().text) {
//         isSame = true;
//        } else {
//          isSame = false;
//        } 
//      }
//      
//      if (isSame) {
//        cbxApplyToAll.SetChecked(true);
//      }    
//    }
  } 
        
  function LeaveApplyToAllChange() {
    if (cbxApplyToAll.GetChecked()) {
      cmbPersonalGroup.SetSelectedItem(cmbLeaveGroup.GetSelectedItem());
      cmbFamilyGroup.SetSelectedItem(cmbLeaveGroup.GetSelectedItem());
      cmbOvertimeGroup.SetSelectedItem(cmbLeaveGroup.GetSelectedItem());
      cmbClaimsGroup.SetSelectedItem(cmbLeaveGroup.GetSelectedItem()); 
    }
    cmbPersonalGroup.SetEnabled(!cbxApplyToAll.GetChecked());
    cmbFamilyGroup.SetEnabled(!cbxApplyToAll.GetChecked());
    cmbOvertimeGroup.SetEnabled(!cbxApplyToAll.GetChecked());
    cmbClaimsGroup.SetEnabled(!cbxApplyToAll.GetChecked()); 
    }
      
    function ResetPasswordInit() {
      if (typeof(cmbImpersonator) != 'undefined') {
        if (cmbImpersonator.GetSelectedIndex() != 0 && cmbImpersonator.GetSelectedIndex() != -1) {
          if (typeof(hlResetPassword) != 'undefined') {
            hlResetPassword.SetVisible(false);
          }
        }
      } else if (edtUserName.GetText() == 'Admin') {
        if (typeof(hlResetPassword) != 'undefined') {
          hlResetPassword.SetVisible(true);
        }
      } else  {        
        if (typeof(hlResetPassword) != 'undefined') {
          hlResetPassword.SetVisible(false);
        }
      }
    } 
    
    function SendActivationEmailInit() {
      if (typeof(cmbImpersonator) != 'undefined') {
        if (cmbImpersonator.GetSelectedIndex() != 0 && cmbImpersonator.GetSelectedIndex() != -1) {
          cbxSendActivationEmail.SetVisible(false);
        }
      } else {
        cbxSendActivationEmail.SetVisible(false);
      }              
    }
    
    function ButtonSendActivationEmailInit() {
      if (typeof(cmbImpersonator) != 'undefined') {
        if (cmbImpersonator.GetSelectedIndex() != 0 && cmbImpersonator.GetSelectedIndex() != -1) {
          if (typeof(btnSendActivationEmail) != 'undefined') {
            btnSendActivationEmail.SetVisible(false);
          }
        }
      } else {
        if (typeof(btnSendActivationEmail) != 'undefined') {
          btnSendActivationEmail.SetVisible(false);
        }
      }
    }
    
    function ButtonActivateAccountInit() { 
      if (typeof(cmbImpersonator) != 'undefined') {
        if (cmbImpersonator.GetSelectedIndex() != 0 && cmbImpersonator.GetSelectedIndex() != -1) {
          if (typeof(btnActivateAccount) != 'undefined') {
            btnActivateAccount.SetVisible(false);
          }
        }
      } else {
        if (typeof(btnActivateAccount) != 'undefined') {
          btnActivateAccount.SetVisible(false);
        }
      }
    } 
    
    function ButtonDeactivateAccountInit() { 
      if (typeof(cmbImpersonator) != 'undefined') {
        if (cmbImpersonator.GetSelectedIndex() != 0 && cmbImpersonator.GetSelectedIndex() != -1) {
          btnDeactivateAccount.SetVisible(false);
        }
      } else {
        btnDeactivateAccount.SetVisible(false);
      }
  }

  //IMPERSONATION
//===============
  function HandleImpersonatorCallback() {
    ImpersonatorCallback.SendCallback(cmbImpersonator.GetSelectedIndex()); 
  }
   
  function ImpersonatorCallbackComplete(s, e) {
    var result = e.result;
    cbxRoleAdministrator.SetEnabled(cmbImpersonator.GetSelectedIndex() < 1);
    cbxRoleLeaveApprover.SetEnabled(cmbImpersonator.GetSelectedIndex() < 1);
    cbxRolePersonalApprover.SetEnabled(cmbImpersonator.GetSelectedIndex() < 1);
    cbxRoleFamilyApprover.SetEnabled(cmbImpersonator.GetSelectedIndex() < 1);
    cbxRoleEssUser.SetEnabled(cmbImpersonator.GetSelectedIndex() < 1);
    cbxRoleOvertimeApprover.SetEnabled(cmbImpersonator.GetSelectedIndex() < 1);
    cbxRoleClaimsApprover.SetEnabled(cmbImpersonator.GetSelectedIndex() < 1);
    cbxRoleGlobalReporting.SetEnabled(cmbImpersonator.GetSelectedIndex() < 1);
    cbxRoleImpersonator.SetEnabled(cmbImpersonator.GetSelectedIndex() < 1);
    DoNominatedRowsInitialize();
    if (cmbImpersonator.GetSelectedIndex() > 0) {
      cbxRoleAdministrator.SetChecked(false);
      cbxRoleLeaveApprover.SetChecked(false);
      cbxRolePersonalApprover.SetChecked(false);
      cbxRoleFamilyApprover.SetChecked(false);
      cbxRoleOvertimeApprover.SetChecked(false);
      cbxRoleClaimsApprover.SetChecked(false);
      cbxRoleGlobalReporting.SetChecked(false);
      cbxRoleImpersonator.SetChecked(false);      
    }
    var aNominationIsVisible = IsANominatedRowVisible();
           
    if (GetRowNominatedApprovers() != null) {
      if (aNominationIsVisible) {
        GetRowNominatedApprovers().style.visibility = 'visible';
        
      } else {
        GetRowNominatedApprovers().style.visibility = 'hidden';        
      }
    }
    
    if (GetRowNominatedApproversSpacer() != null) {
      if (aNominationIsVisible) {
        GetRowNominatedApproversSpacer().style.visibility = 'visible';        
      } else {
        GetRowNominatedApproversSpacer().style.visibility = 'hidden';
      }
    }
    
    if (GetRowOutOfOffice() != null) {
      if (aNominationIsVisible) {
        GetRowOutOfOffice().style.visibility = 'visible';
        lblOutFrom.SetVisible(true);
        edtFromDate.SetVisible(true);
        lblOutTo.SetVisible(true);
        edtToDate.SetVisible(true);
      } else {
        GetRowOutOfOffice().style.visibility = 'hidden';
        lblOutFrom.SetVisible(false);
        edtFromDate.SetVisible(false);
        lblOutTo.SetVisible(false);
        edtToDate.SetVisible(false);
      }
    }
    //user is linked to provider
    if (e.result == "T") {
      if (cmbImpersonator.GetSelectedIndex() > 0) {
        var txt = "IMPORTANT: This user is registered and activated.  Specifying an impersonator for this user will force the user to be deactivated.  " +
          "Only the impersonator will be able to do transactions on this user's behalf.";
        lblImpersonationMessage.SetText(txt);
        lblImpersonationMessage.SetVisible(true);
        hlResetPassword.SetVisible(false);
        if (GetRowResetPassword() != null) {
          GetRowResetPassword().style.visibility = 'hidden';
          hlResetPassword.SetVisible(false);
        }
        btnDeactivateAccount.SetVisible(false);
      } else {
        lblImpersonationMessage.SetText("");
        lblImpersonationMessage.SetVisible(false);
        hlResetPassword.SetVisible(true);
        if (GetRowResetPassword() != null) {
          GetRowResetPassword().style.visibility = 'visible';
          hlResetPassword.SetVisible(true);
        }
        btnDeactivateAccount.SetVisible(true);
      }    
    } else {
      //user not linked to provider
      if (cmbImpersonator.GetSelectedIndex() > 0) {
        lblImpersonationMessage.SetText("");
        if (typeof(btnActivateAccount) != 'undefined') {
          btnActivateAccount.SetVisible(false);
        }
        cbxSendActivationEmail.SetVisible(false);
        if (typeof(btnSendActivationEmail) != 'undefined') {
          btnSendActivationEmail.SetVisible(false);        
        }
      } else {
        lblImpersonationMessage.SetText("IMPORTANT: This user is registered but not activated and cannot log in.  Remember to activate this user or send an activation email.");
        lblImpersonationMessage.SetVisible(false);
        if (typeof(btnActivateAccount) != 'undefined') {
          btnActivateAccount.SetVisible(true);
        }
        cbxSendActivationEmail.SetVisible(true);        
      }
    }
  }
  
  function IsANominatedRowVisible() {
  var isNomRowVisible = false;
  
  var nomRow = GetRowNominatedLeaveApprover();  
  if (nomRow != null) {
    if (nomRow.style.visibility == 'visible') {
      isNomRowVisible = true;
    }
  }
  
  if (!isNomRowVisible) {
    nomRow = GetRowNominatedPersonalApprover();  
    if (nomRow != null) {
      if (nomRow.style.visibility == 'visible') {
        isNomRowVisible = true;
      }
    }
  }
  
  if (!isNomRowVisible) {
    nomRow = GetRowNominatedFamilyApprover();  
    if (nomRow != null) {
      if (nomRow.style.visibility == 'visible') {
        isNomRowVisible = true;
      }
    }
  }
  
  if (!isNomRowVisible) {
    nomRow = GetRowNominatedOvertimeApprover();  
    if (nomRow != null) {
      if (nomRow.style.visibility == 'visible') {
        isNomRowVisible = true;
      }
    }
  }
  
  if (!isNomRowVisible) {
    nomRow = GetRowNominatedClaimsApprover();  
    if (nomRow != null) {
      if (nomRow.style.visibility == 'visible') {
        isNomRowVisible = true;
      }
    }
  }  
  return isNomRowVisible;  
  }
  
  function DoNoEmailAddressInit(noEmailChecked) {
    edtPassword.SetVisible(noEmailChecked); 
    edtPasswordConfirm.SetVisible(noEmailChecked);
    lblPassword.SetVisible(noEmailChecked); 
    lblConfirmPassword.SetVisible(noEmailChecked);
    //cbxSendActivationEmail.SetVisible(!noEmailChecked);
  }
  
  function DoNoEmailAddressChecked(noEmailChecked) {
    edtEmail.SetEnabled(!noEmailChecked); 
    edtPassword.SetVisible(noEmailChecked); 
    edtPasswordConfirm.SetVisible(noEmailChecked); 
    lblPassword.SetVisible(noEmailChecked); 
    lblConfirmPassword.SetVisible(noEmailChecked);
    //cbxSendActivationEmail.SetVisible(!noEmailChecked);
    if (cbxNoEmailAddress.GetChecked()) {
      edtEmail.SetIsValid(true); 
    }
  }
  
  function DoRolesAndGroupVisibility() {
    if (lblIsEmpUser.GetText() == "No") {
      GetRowRolesOnly().style.visibility = 'visible';
      GetRowRolesAndGroups().style.visibility = 'hidden';
    } else {
      GetRowRolesOnly().style.visibility = 'hidden';
      GetRowRolesAndGroups().style.visibility = 'visible';
    }
  }
  
  function DoNominatedRowsInitialize() {
    var isVisible;
    var hasImpersonator;
    if (typeof(cmbImpersonator) != 'undefined') {
      hasImpersonator = (cmbImpersonator.GetSelectedIndex() > 0);
    } else {
      hasImpersonator = false;
    }
    
    isVisible = (cbxRoleLeaveApprover.GetChecked() && !hasImpersonator);        
    if (GetRowNominatedLeaveApprover() != null) {    
      if (isVisible) {      
        GetRowNominatedLeaveApprover().style.visibility = 'visible';
        lblNominatedLeaveApprover.SetVisible(true);
        cmbNominatedLeaveApprover.SetVisible(true);
       } else {
         GetRowNominatedLeaveApprover().style.visibility = 'hidden';
         lblNominatedLeaveApprover.SetVisible(false);
        cmbNominatedLeaveApprover.SetVisible(false);
       }
     }
     
     isVisible = (cbxRolePersonalApprover.GetChecked() && !hasImpersonator);
     if (GetRowNominatedPersonalApprover() != null) {    
       if (isVisible) {      
        GetRowNominatedPersonalApprover().style.visibility = 'visible';
        lblNominatedPersonalApprover.SetVisible(true);
        cmbNominatedPersonalChangeApprover.SetVisible(true);
       } else {
         GetRowNominatedPersonalApprover().style.visibility = 'hidden';
         lblNominatedPersonalApprover.SetVisible(false);
        cmbNominatedPersonalChangeApprover.SetVisible(false);
       }
     }
     
     isVisible = (cbxRoleFamilyApprover.GetChecked() && !hasImpersonator);
     if (GetRowNominatedFamilyApprover() != null) {    
       if (isVisible) {      
        GetRowNominatedFamilyApprover().style.visibility = 'visible';
        lblNominatedFamilyApprover.SetVisible(true);
        cmbNominatedFamilyChangeApprover.SetVisible(true);
       } else {
         GetRowNominatedFamilyApprover().style.visibility = 'hidden';
         lblNominatedFamilyApprover.SetVisible(false);
        cmbNominatedFamilyChangeApprover.SetVisible(false);
       }
     }
     
      isVisible = (cbxRoleOvertimeApprover.GetChecked() && !hasImpersonator);
     if (GetRowNominatedOvertimeApprover() != null) {    
       if (isVisible) {      
        GetRowNominatedOvertimeApprover().style.visibility = 'visible';
        lblNominatedOvertimeApprover.SetVisible(true);
        cmbNominatedOvertimeApprover.SetVisible(true);
       } else {
         GetRowNominatedOvertimeApprover().style.visibility = 'hidden';
         lblNominatedOvertimeApprover.SetVisible(false);
        cmbNominatedOvertimeApprover.SetVisible(false);
       }
     }
     
     isVisible = (cbxRoleClaimsApprover.GetChecked() && !hasImpersonator);
     if (GetRowNominatedClaimsApprover() != null) {    
       if (isVisible) {      
        GetRowNominatedClaimsApprover().style.visibility = 'visible';
        lblNominatedClaimsApprover.SetVisible(true);
        cmbNominatedClaimsApprover.SetVisible(true);
       } else {
         GetRowNominatedClaimsApprover().style.visibility = 'hidden';
         lblNominatedClaimsApprover.SetVisible(false);
        cmbNominatedClaimsApprover.SetVisible(false);
       }
     }
  }
  
  function RoleImpersonatorChange() {
    if (cbxRoleImpersonator.GetChecked()) {
      if (typeof(cmbImpersonator) != 'undefined') {
        cmbImpersonator.SetSelectedIndex(0);
        cmbImpersonator.SetEnabled(false);
      }
    } else {
      if (typeof(cmbImpersonator) != 'undefined') {
        cmbImpersonator.SetEnabled(true);
        InitImpersonation();
      }
    }
  }
  
  function OtherRolesInitialize() {
  var hasImpersonator;
    if (typeof(cmbImpersonator) != 'undefined') {
      hasImpersonator = (cmbImpersonator.GetSelectedIndex() > 0);
    } else {
      hasImpersonator = false;
    }
    if (hasImpersonator) {
      cbxRoleGlobalReporting.SetChecked(false); 
      cbxRoleGlobalReporting.SetEnabled(false); 
      cbxRoleImpersonator.SetChecked(false); 
      cbxRoleImpersonator.SetEnabled(false); 
      cbxRoleAdministrator.SetEnabled(false);
      cbxRoleAdministrator.SetChecked(false);
      cbxRoleEssUser.SetChecked(true);
      cbxRoleEssUser.SetEnabled(false);
    } else {
      cbxRoleGlobalReporting.SetEnabled(true); 
      //cbxRoleImpersonator.SetEnabled(true); 
      if (typeof(cmbImpersonator) != 'undefined') {
        //for administrator, will already be disabled on client side, don't need to come in here then
        cbxRoleAdministrator.SetEnabled(true);
      }
    }      
  }
  
  function InitImpersonation() {
    if ((cbxRoleLeaveApprover.GetChecked() && !cbxRoleLeaveApprover.GetEnabled()) ||
    (cbxRoleFamilyApprover.GetChecked() && !cbxRoleFamilyApprover.GetEnabled()) ||
    (cbxRolePersonalApprover.GetChecked() && !cbxRolePersonalApprover.GetEnabled()) ||
    (cbxRoleClaimsApprover.GetChecked() && !cbxRoleClaimsApprover.GetEnabled()) ||
    (cbxRoleOvertimeApprover.GetChecked() && !cbxRoleOvertimeApprover.GetEnabled()))
     {
       cmbImpersonator.SetEnabled(false);
    }
  }
   
  
  function GetRowRolesOnly() {
    var rolesOnly = document.getElementById('rowRolesOnly');
    if (rolesOnly == null) {
      var fullName = GetContentId() + 'rowRolesOnly';
      rolesOnly = document.getElementById(fullName);
    }
    return rolesOnly;
  }
  
  function GetRowRolesAndGroups() {
    var rolesAndGroups = document.getElementById('rowRolesAndGroups');
    if (rolesAndGroups == null) {
      var fullName = GetContentId() + 'rowRolesAndGroups';
      rolesAndGroups = document.getElementById(fullName);
    }
    return rolesAndGroups;
  }
  
  function GetRowNominatedApprovers() {
    var nomApp = document.getElementById('rowNominatedApprovers');
    if (nomApp == null) {
      var fullName = GetContentId() + 'rowNominatedApprovers';
      nomApp = document.getElementById(fullName);
    }
    return nomApp;
  }
  
  function GetRowResetPassword() {
    var nomApp = document.getElementById('rowResetPassword');
    if (nomApp == null) {
      var fullName = GetContentId() + 'rowResetPassword';
      nomApp = document.getElementById(fullName);
    }
    return nomApp;
  }
  
  function GetRowNominatedApproversSpacer() {
    var nomApp = document.getElementById('rowNominatedApproversSpacer');
    if (nomApp == null) {
      var fullName = GetContentId() + 'rowNominatedApproversSpacer';
      nomApp = document.getElementById(fullName);
    }
    return nomApp;
  }
  
  function GetRowOutOfOffice() {
    var nomApp = document.getElementById('rowOutOfOffice');
    if (nomApp == null) {
      var fullName = GetContentId() + 'rowOutOfOffice';
      nomApp = document.getElementById(fullName);
    }
    return nomApp;
  }
  
  function GetRowNominatedLeaveApprover() {
    var nomApp = document.getElementById('rowNominatedLeaveApprover');
    if (nomApp == null) {
      var fullName = GetContentId() + 'rowNominatedLeaveApprover';
      nomApp = document.getElementById(fullName);
    }
    return nomApp;
  }
  
  function GetRowNominatedPersonalApprover() {
    var nomApp = document.getElementById('rowNominatedPersonalApprover');
    if (nomApp == null) {
      var fullName = GetContentId() + 'rowNominatedPersonalApprover';
      nomApp = document.getElementById(fullName);
    }
    return nomApp;
  }
  
  function GetRowNominatedFamilyApprover() {
    var nomApp = document.getElementById('rowNominatedFamilyApprover');
    if (nomApp == null) {
      var fullName = GetContentId() + 'rowNominatedFamilyApprover';
      nomApp = document.getElementById(fullName);
    }
    return nomApp;
  }
  
  function GetRowNominatedOvertimeApprover() {
    var nomApp = document.getElementById('rowNominatedOvertimeApprover');
    if (nomApp == null) {
      var fullName = GetContentId() + 'rowNominatedOvertimeApprover';
      nomApp = document.getElementById(fullName);
    }
    return nomApp;
  }
  
  function GetRowNominatedClaimsApprover() {
    var nomApp = document.getElementById('rowNominatedClaimsApprover');
    if (nomApp == null) {
      var fullName = GetContentId() + 'rowNominatedClaimsApprover';
      nomApp = document.getElementById(fullName);
    }
    return nomApp;
  }
  
  function RolesApproversChange() {
    var hasImpersonator;
    if (typeof(cmbImpersonator) != 'undefined') {
      hasImpersonator = (cmbImpersonator.GetSelectedIndex() > 0);
    } else {
      hasImpersonator = false;
    }
    if (hasImpersonator) {
      cbxRoleLeaveApprover.SetChecked(false); 
      cbxRoleLeaveApprover.SetEnabled(false); 
      cbxRoleFamilyApprover.SetChecked(false); 
      cbxRoleFamilyApprover.SetEnabled(false); 
      cbxRolePersonalApprover.SetChecked(false); 
      cbxRolePersonalApprover.SetEnabled(false); 
      cbxRoleOvertimeApprover.SetChecked(false); 
      cbxRoleOvertimeApprover.SetEnabled(false); 
      cbxRoleClaimsApprover.SetChecked(false); 
      cbxRoleClaimsApprover.SetEnabled(false); 
    }
    DoNominatedRowsInitialize();   
    var aNominationIsVisible = IsANominatedRowVisible();
    if (aNominationIsVisible) {     
      if (GetRowNominatedApprovers() != null) {
        GetRowNominatedApprovers().style.visibility = 'visible';
      }
      if (GetRowNominatedApproversSpacer() != null) {
        GetRowNominatedApproversSpacer().style.visibility = 'visible';
      }
      if (GetRowOutOfOffice() != null) {
        GetRowOutOfOffice().style.visibility = 'visible';
        lblOutFrom.SetVisible(true);
        edtFromDate.SetVisible(true);
        lblOutTo.SetVisible(true);
        edtToDate.SetVisible(true);
      }
    } else {
      if (GetRowNominatedApprovers() != null) {
        GetRowNominatedApprovers().style.visibility = 'hidden';
      }
      if (GetRowNominatedApproversSpacer() != null) {
        GetRowNominatedApproversSpacer().style.visibility = 'hidden';
      }
      if (GetRowOutOfOffice() != null) {
        GetRowOutOfOffice().style.visibility = 'hidden';
        lblOutFrom.SetVisible(false);
        edtFromDate.SetVisible(false);
        lblOutTo.SetVisible(false);
        edtToDate.SetVisible(false);
      }
    } 
  }
  
  function UserEmailLostFocus() {
    if (typeof(cmbImpersonator) != 'undefined') {
      if (cmbImpersonator.GetSelectedIndex() != 0 && cmbImpersonator.GetSelectedIndex() != -1) {
       edtEmail.SetIsValid(true);
     } else {
       edtEmail.Validate(); 
     }
    } else {
      edtEmail.Validate();
    }    
  }
  
//-----------------------Spesific Functions Per Page------------------------------
//-----------------------====================------------------------------

//-----------------------PersonalDetailsSummaryCtrl.ascx--------------------------
  function PersonalDetailShowPopup(id) {
    PDPopupStatusClientControl.ShowAtElementByID('td' + id);
    PDPopupCallback.SendCallback(id);
  }

  // Popup notification via a callback
  function PersonalDetailPopupCallbackComplete(s, e) {
    var contentText = e.result;
    PDPopupStatusClientControl.SetContentHTML(contentText);
  }

//-----------------------OvertimeSummaryCtrl.ascx------------------------------
  function OvertimeSummaryShowPopup(id) {
    OvertimeSummaryPopupStatusClientControl.ShowAtElementByID('td' + id);
    OvertimeSummaryPopupCallback.SendCallback(id);
  }

  // Popup notification via a callback
  function OvertimeSummaryPopupCallbackComplete(s, e) {
    var contentText = e.result;
    OvertimeSummaryPopupStatusClientControl.SetContentHTML(contentText);
  }

//-----------------------LeaveSummaryCtrl.ascx---------------------------------
  function LeaveSummaryShowPopup(id) {
    LeaveSummaryPopupStatusClientControl.ShowAtElementByID('td' + id);
    LeaveSummaryPopupCallback.SendCallback(id);
  }

  // Popup notification via a callback
  function LeaveSummaryPopupCallbackComplete(s, e) {
    var contentText = e.result;
    LeaveSummaryPopupStatusClientControl.SetContentHTML(contentText);
  }

//-----------------------FamilyDetailsSummaryCtrl.ascx---------------------------
  function FamilyDetailsShowPopup(id) {
    FamilyDetailsPopupStatusClientControl.ShowAtElementByID('td' + id);
    FamilyDetailsPopupCallback.SendCallback(id);
  }

  // Popup notification via a callback
  function FamilyDetailsPopupCallbackComplete(s, e) {
    var contentText = e.result;
    FamilyDetailsPopupStatusClientControl.SetContentHTML(contentText);
  }

//-----------------------CurrentRequestSummaryCtrl.ascx-------------------------
function ShowStatusPopup(element, keyValue) {
    StatusPopupControl.Hide();
    StatusPopupControl.ShowAtElement(element);
    window.RequestGrid.GetValuesOnCustomCallback(keyValue, RequestGridCallbackComplete);
  }

  // Popup notification via a callback
  function RequestGridCallbackComplete(value) {
    var contentText = value;
    StatusPopupControl.SetContentHTML(contentText);
  }
  
  //  function ShowStatusPopup(id) {
//    StatusPopupControl.ShowAtElementByID('td' + id);
//    StatusPopupCallback.SendCallback(id);
//  }

//-----------------------ClaimsSummaryCtrl.ascx--------------------------------
function ClaimSummaryShowPopup(id) {
    ClaimSummaryPopupStatusClientControl.ShowAtElementByID('td' + id);
    ClaimSummaryPopupCallback.SendCallback(id);
  }

  // Popup notification via a callback
  function ClaimSummaryPopupCallbackComplete(s, e) {
    var contentText = e.result;
    ClaimSummaryPopupStatusClientControl.SetContentHTML(contentText);
  }

//-----------------------Site,Master------------------------------------------

function getViewportSize() {
    var size = [0, 0];
    if (typeof window.innerWidth != 'undefined') {
     size = [ window.innerWidth, window.innerHeight ];
    } else if (typeof document.documentElement != 'undefined' &&
             typeof document.documentElement.clientWidth != 'undefined' &&
             document.documentElement.clientWidth != 0) {
     size = [ document.documentElement.clientWidth, document.documentElement.clientHeight ];
    } else {
     size = [ document.getElementsByTagName('body')[0].clientWidth,
              document.getElementsByTagName('body')[0].clientHeight ];
    }
    return size;
  }
  
   function resize() {
     var currentSize = getViewportSize();
     if (currentSize[0] != p_prevSize[0] || currentSize[1] != p_prevSize[1]) {
       p_prevSize = currentSize;
       doResize(currentSize);
     }
   }
   
  function doResize(size) {
     var contentdiv = document.getElementById("divMainContentPanel");
     var headerRowdiv = document.getElementById("divHeaderRow");
     var footerRowdiv = document.getElementById("divFooterRow");
     if (contentdiv != null) {
       contentdiv.style.height = (size[1] - (headerRowdiv.offsetHeight * 1.5) - (footerRowdiv.offsetHeight * 1.5) - 
       contentdiv.offsetTop) + "px";
     }
   }
   
   function init() {
    window.p_prevSize = getViewportSize();
    doResize(window.p_prevSize);
    setInterval(resize, 1000);
   }
   
  function DoItemsClick(e) {
    if (e.item.GetText() == "Login") {
     OpenLoginDialogCallback.SendCallback();
    } else if(e.item.GetText() == "Impersonate") {
      OpenImpersonationCallback.SendCallback();
    } else if (e.item.GetText() == "Logout"){
      e.item.SetNavigateUrl('');
      LogoutCallback.SendCallback();
    } else if (e.item.GetText() == "Activate Account") {
      OpenActivateAccountCallback.SendCallback();    
    } 
  }
   
   function HandleNavBarItemClick(s, e) {   
     DoItemsClick(e);
   }
    
   function HandleNavBarHeaderClick(s, e) {    
     DoItemsClick(e); 
   }
   
   function HandleMenuItemClick(s, e) {
     DoItemsClick(e); 
   }
   
   function ShowActivateAccountWindow(appurl) {   
    ActivateAccountPopup.SetContentUrl(appurl + "ActivateAccountDialog.aspx");
    ActivateAccountPopup.Show();
  }
  
  function CloseActivateAccountWindow(appurl) {
    ActivateAccountPopup.Hide();
    window.location.href = appurl;       
  }
  
   function ShowLoginWindow(appurl) {
    LoginPopup.SetContentUrl(appurl + "LoginDialog.aspx");
    LoginPopup.Show();
  }
  
  function ShowImpersonationWindow(defaulturl) {    
    ImpersonationPopup.SetContentUrl(defaulturl + "ImpersonationDialog.aspx");
    ImpersonationPopup.Show();    
  }
  
  function CloseLoginWindow() {
    LoginPopup.Hide();
    window.location.reload();
  }
  
  function CloseImpersonationWindow(){
    ImpersonationPopup.Hide();
    window.location.href = "Default.aspx";       
  }
  
  function LogoutCallbackComplete(s, e) {
    window.location.href = e.result;
  }
  
  function OpenImpersonationCallbackComplete(s, e) {
    //window.location.href = e.result;
    ShowImpersonationWindow(e.result);
  }
  
  function OpenActivateAccountDialogCallbackComplete(s, e) {
    ShowActivateAccountWindow(e.result);     
  }
  
   function OpenLoginDialogCallbackComplete(s, e) {
    ShowLoginWindow(e.result);     
  }
  
//-----------------------ComposeEmail.aspx------------------------------------

function ChangeToText(){
    EmailCallback.SendCallback();
  }
  
  function EmailCallbackComplete(s, e) {
    edtTo.SetValue(e.result);
  }
  
  function ReturnToSettingsPage() {
    var parentWindow = window.parent;
    parentWindow.CloseEmailWindow();
  }
  
  function HandleSendEmailClickEvent(s, e) {
    SendEmailCallback.SendCallback();
  }
  
  function SendEmailCallbackComplete(s, e) {
    var result = e.result;
    if (e.result == "") {
      ReturnToSettingsPage();
    }
  }

//-----------------------LoginDialog.aspx--------------------------------------

  function HandleLoginClickEvent(s, e) {
    btnOK.SetEnabled(false);
    btnCancel.SetEnabled(false);
    lblLoginError.SetText("");
    LoginCallback.SendCallback();
  }
  
  function LoginCallbackComplete(s, e) {
    var result = e.result;
    if (result.substr(0,1) == "/") {    
      ReturnToParentPage(result);
    } else {
      lblLoginError.SetText(e.result);
      tbPassword.SetText('');
      btnOK.SetEnabled(true);
      btnCancel.SetEnabled(true);    
    }
  }

//-----------------------ImpersonationDialog.aspx-----------------------------

  function HandleImpersonationClickEvent(s, e) {
    ImpersonationCallback.SendCallback();
  }
  
  function ImpersonationCallbackComplete(s, e) {
    var result = e.result;
    if (document.getElementById("cmbUsername")) {
      if (e.result != "") {    
        cmbUsername.SetErrorText(e.result);
        cmbUsername.SetIsValid(false);
      } else {
        cmbUsername.SetErrorText(e.result);
        cmbUsername.SetIsValid(false);
      }
    }
        
    if (e.result == "") {
      ReturnToDefaultPageFromImpersonation();
    }
  }

//-----------------------MySettings.aspx--------------------------------------
function ShowEmailPopup(){
    var contentUrl = "../Popups/ComposeEmail.aspx?"
    if(typeof(cmbNominatedLeaveApprover) != "undefined"){
      contentUrl = contentUrl + "Leave=" + cmbNominatedLeaveApprover.GetValue() + "&";
    }
    if(typeof(cmbNominatedClaimsApprover) != "undefined"){
      contentUrl = contentUrl + "Claims=" + cmbNominatedClaimsApprover.GetValue() + "&";
    }
    if(typeof(cmbNominatedOvertimeApprover) != "undefined"){
      contentUrl = contentUrl + "Overtime=" + cmbNominatedOvertimeApprover.GetValue() + "&";
    }
    if(typeof(cmbNominatedPersonalChangeApprover) != "undefined"){
      contentUrl = contentUrl + "Personal=" + cmbNominatedPersonalChangeApprover.GetValue() + "&";
    }
    if(typeof(cmbNominatedFamilyChangeApprover) != "undefined"){
      contentUrl = contentUrl + "Family=" + cmbNominatedFamilyChangeApprover.GetValue() + "&";
    }
    
    contentUrl = contentUrl + "FromDate=" + edtFromDate.GetFormattedDate() + "&";
    contentUrl = contentUrl + "ToDate=" + edtToDate.GetFormattedDate();
    
    EmailPopup.SetContentUrl(contentUrl);
    EmailPopup.Show();
  }
  
  function HandleToDateLostFocusEvent(s, e) {
    ValidDatesCallback.SendCallback(edtToDate.GetFormattedDate()); 
  }
  
  function ValidDatesCallbackComplete(s, e) {
    var result = e.result;
    if (e.result != "") {
      if(e.result == "Please select From Date"){
        edtFromDate.SetErrorText(e.result);
        edtFromDate.SetIsValid(false);
      } else {
        edtToDate.SetErrorText(e.result);
        edtToDate.SetIsValid(false);
      }
    }else{
      edtFromDate.SetIsValid(true);
      edtToDate.SetIsValid(true);
    }
  }
  
  function CloseEmailWindow() {
    EmailPopup.Hide();
  }  

//-----------------------SynchroniseUsers.aspx-----------------------------
function DoSyncEvent(s, e) {
    btnSync.SetText('Synchronising...');
    //btnSync.SetEnabled(false);
    btnSync.SetVisible(false);
    lblDone.SetVisible(true);
    //lblDone.SetText("Busy Synchronising for users.");  
    //lblDone.SetVisible(false);
    SyncCallback.SendCallback();         
  }

  function SyncCallbackComplete(s, e) {      
  //btnSync.SetText('Syncronising...');
  //btnSync.SetEnabled(true);
  //lblWait.SetVisible(false);
  //lblDone.SetVisible(true);
  lblDone.SetText("Busy Synchronising for " + e.result + " users.");  
}

//-----------------------ImportData.aspx-------------------------------------  
//moved to page


  //-----------------------GroupDetails.aspx------------------------------
  //-----------------------=============------------------------------
  function ShowLeaveApproversEditGrid(){
      grdLeaveApprovers.AddNewRow();
    }
    
    function ShowOvertimeApproversEditGrid(){
      grdOvertimeApprovers.AddNewRow();
    }
    
    function ShowClaimsApproversEditGrid(){
      grdClaimsApprovers.AddNewRow();
    }
    
    function ShowPersonalChangeApproversEditGrid(){
      grdPersonalChangeApprovers.AddNewRow();
    }
    
    function ShowFamilyChangeApproversEditGrid(){
      grdFamilyChangeApprovers.AddNewRow();
    }
    
    function ShowLeaveEscalationApproversEditGrid(){
      grdLeaveEscalationApprovers.AddNewRow();
    }
    
    function ShowOvertimeEscalationApproversEditGrid(){
      grdOvertimeEscalationApprovers.AddNewRow();
    }
    
    function ShowClaimsEscalationApproversEditGrid(){
      grdClaimsEscalationApprovers.AddNewRow();
    }
    
    function ShowPersonalChangeEscalationApproversEditGrid(){
      grdPersonalChangeEscalationApprovers.AddNewRow();
    }
    
    function ShowFamilyChangeEscalationApproversEditGrid(){
      grdFamilyChangeEscalationApprovers.AddNewRow();
    }
    
    function LeavePositionChanged(s, e){
      if(typeof(cbxLeaveNotifyOnly) != "undefined"){
        if(s.GetNumber() == 1){
          cbxLeaveNotifyOnly.SetChecked(false);
          cbxLeaveNotifyOnly.SetEnabled(false);
        }else{
          cbxLeaveNotifyOnly.SetEnabled(true);
        }
      }
    }
    
    function ClaimsPositionChanged(s, e){
      if(typeof(cbxClaimsNotifyOnly) != "undefined"){
        if(s.GetNumber() == 1){
          cbxClaimsNotifyOnly.SetChecked(false);
          cbxClaimsNotifyOnly.SetEnabled(false);
        }else{
          cbxClaimsNotifyOnly.SetEnabled(true);
        }
      }
    }
    
    function OvertimePositionChanged(s, e){
      if(typeof(cbxOvertimeNotifyOnly) != "undefined"){
        if(s.GetNumber() == 1){
          cbxOvertimeNotifyOnly.SetChecked(false);
          cbxOvertimeNotifyOnly.SetEnabled(false);
        }else{
          cbxOvertimeNotifyOnly.SetEnabled(true);
        }
      }
    }
    
    function PersonalChangePositionChanged(s, e){
      if(typeof(cbxPersonalChangeNotifyOnly) != "undefined"){
        if(s.GetNumber() == 1){
          cbxPersonalChangeNotifyOnly.SetChecked(false);
          cbxPersonalChangeNotifyOnly.SetEnabled(false);
        }else{
          cbxPersonalChangeNotifyOnly.SetEnabled(true);
        }
      }
    }
      
    function FamilyChangePositionChanged(s, e){
      if(typeof(cbxFamilyChangeNotifyOnly) != "undefined"){
        if(s.GetNumber() == 1){
          cbxFamilyChangeNotifyOnly.SetChecked(false);
          cbxFamilyChangeNotifyOnly.SetEnabled(false);
        }else{
          cbxFamilyChangeNotifyOnly.SetEnabled(true);
        }
      }
    }
 
  
  //----------------------Regular Expressions------------------------------
//-----------------------===============------------------------------

//Integers Only

function RegExpIntOnly(editField) {
  // \D returns any non-digit.  this function must return false
  var x = new RegExp("/\D/");  
  return x.text(editField);
}
