// JScript File
function showSecurityFields(ADChk,webChk,pnlNormalUser,pwdReqDiv,cnfmPwdReqDiv,secretQuestionReqDiv,secretAnsReqDiv)
{
   var checkedAD=document.getElementById(ADChk);   
   var check =document.getElementById(webChk);   
   if(checkedAD !=null && checkedAD.checked)//Check wheather ADUser Check box is checked or not
   {      
      document.getElementById(pnlNormalUser).style["display"]="none";              
   }
   else if(checkedAD !=null && !checkedAD.checked)
   {      
      document.getElementById(pnlNormalUser).style["display"]="inline";       
   }
      
   if(check !=null && !check.checked)//Check wheather WebAccessible Check box is checked or not
   {      
      if(pwdReqDiv !=null && cnfmPwdReqDiv !=null)
      {
        document.getElementById(pwdReqDiv).style["display"]="none";
        document.getElementById(cnfmPwdReqDiv).style["display"]="none";        
      }
     document.getElementById(secretQuestionReqDiv).style["display"]="none";
     document.getElementById(secretAnsReqDiv).style["display"]="none";
   }
   else if(check !=null && check.checked)
   {
      if(pwdReqDiv !=null && cnfmPwdReqDiv !=null)
      {
        document.getElementById(pwdReqDiv).style["display"]="inline";
        document.getElementById(cnfmPwdReqDiv).style["display"]="inline";        
      }
     document.getElementById(secretQuestionReqDiv).style["display"]="inline";
     document.getElementById(secretAnsReqDiv).style["display"]="inline";
   }   
}

function ValidateRequiredControls(ADChk,webChk,User,usrPwd,cnfmPwd,secretAns,UsrReq,pwdReq,cnfmPwdReq,secretQues,secretAnsReq,ddlSecQuestion)
{
   var isValid=false;   
   var checkedAD=document.getElementById(ADChk);
   var check =document.getElementById(webChk);
   if (User != null && usrPwd != null && cnfmPwd == null) 
   {
       return false;
   }        
   if (User != null && usrPwd != null && cnfmPwd != null)
   {      
      var dataUserName=document.getElementById(User).value;
      var txtPwd=document.getElementById(usrPwd).value;
      var txtPwdConfirm=document.getElementById(cnfmPwd).value;
   }   
   var txtSecretAnswer=document.getElementById(secretAns).value; 
   
   if(ddlSecQuestion !=null)
   {
      var questionIndex=document.getElementById(ddlSecQuestion).selectedIndex;       
   }   
   if(checkedAD !=null && checkedAD.checked)//ADUser
   {       
      if(User!=null && usrPwd !=null && cnfmPwd !=null)//Add mode
      {
        //ADUser Name must.So Enable RequiredfiledValidator.
        ValidatorEnable(document.getElementById(UsrReq),true);      
        if(!(dataUserName.length)>0)
        {
          isValid=false;
        }
        else
        {
          isValid= true;
        }
      }
      else//Edit mode (Requiredfield not needed).
      {
         isValid=true;
      }
               
   }
   else if(check!=null && check.checked)//WebAccessible User
   {       
      if(User!=null && usrPwd !=null && cnfmPwd !=null)//Add mode
      {
        //Enable RequiredfiledValidator for UserName,Password,SecretQuestionAnswer
        ValidatorEnable(document.getElementById(UsrReq),true);     
        ValidatorEnable(document.getElementById(pwdReq),true);
        ValidatorEnable(document.getElementById(cnfmPwdReq),true);
        ValidatorEnable(document.getElementById(secretAnsReq),true);
              
        if(questionIndex<=0)
        {
           ValidatorEnable(document.getElementById(secretQues),true);
        }
        if(!(dataUserName.length)>0 || (!(txtPwd.length)>0)||(!(txtPwdConfirm.length)>0)||(!(txtSecretAnswer.length)>0) || questionIndex<=0)
        {              

          isValid= false;//if Password/Confirm Password/Seceret Answer is blank set false
        }
        else
        {
          isValid=true;
        }
      }
      else//In Edit mode Secretquestion answer only required.
      {
        ValidatorEnable(document.getElementById(secretAnsReq),true); 
        if(questionIndex<=0)
        {
           ValidatorEnable(document.getElementById(secretQues),true);
        } 
        if((!(txtSecretAnswer.length)>0) || questionIndex<=0)
        {
           isValid=false;
        }
        else
        {
           isValid=true;
        }
      }
   }     
   else if(check!=null && !(check.checked))//(User is not a WebAccessible)
   {
      //In Insert mode User name only required
      if(User!=null && usrPwd !=null && cnfmPwd !=null)
      {
        ValidatorEnable(document.getElementById(UsrReq),true);
        if(!(dataUserName.length)>0)
        {
          isValid= false;
        }
        else
        {
          isValid=true;
        }
      }
      else//In Edit mode (No required fields)
      {
         isValid=true;
      }     
   }
   return isValid;     
}

// Visible/Invisible the ADUser and WebAccessible fields
// this method only applicable for these two controls
function disableControls(ADUserCtrlID,pnlWebAccessCtrlID,display)
{
    var pnlADUser,pnlWebAccessible;            
    pnlADUser=document.getElementById(ADUserCtrlID);
    pnlWebAccessible=document.getElementById(pnlWebAccessCtrlID);
    if(pnlADUser!=null)
    {
        pnlADUser.style.display=display;
    }
    if(pnlWebAccessible!=null)
    {
        pnlWebAccessible.style.display=display;
    }        
}

// Required and Format validation for Email address fileds
// this method only applicable for user creation/modify screens
function ValidateEmailAddr(rfvEmailCtrlID,regEmailCtrlID)
{
    var rfvEmail,regEmail,isValid=false;
    rfvEmail=document.getElementById(rfvEmailCtrlID);
    regEmail=document.getElementById(regEmailCtrlID);
    if(rfvEmail != null && regEmail !=null)
    {
        ValidatorEnable(rfvEmail,true);
        ValidatorEnable(regEmail,true);
        if(rfvEmail.isvalid && rfvEmail.isvalid)
        {
          isValid=true;  
        }
    }
    return isValid;
} 

