﻿// JScript File
// For KGChangePasswordControl
function KGChangePasswordControl_ChangePasswordClick()
{
  var args = 'action=ChangeDisplayMode|mode=Update';
  KGChangePasswordControl_CallbackTrigger(args);
}

function KGChangePasswordControl_CancelUpdateClick()
{
  var args = 'action=ChangeDisplayMode|mode=Display';
  KGChangePasswordControl_CallbackTrigger(args);
}

function KGChangePasswordControl_UpdateClick(_btn)
{
  var hiddenFieldId = _btn.getAttribute("HiddenFieldId");
  var hiddenField = document.getElementById(hiddenFieldId);
  var inputControlIds = eval( '(' + hiddenField.value + ')' );
  
  var args = 'action=Update';
  args += '|currentPassword=' + ReadTextBoxValue(inputControlIds.currentPassword);
  args += '|newPassword=' + ReadTextBoxValue(inputControlIds.newPassword);
  args += '|confirmNewPassword=' + ReadTextBoxValue(inputControlIds.confirmNewPassword);


  KGChangePasswordControl_CallbackTrigger(args);
}

function KGChangePasswordControl_CallbackDone_Wrapped(args, context, controlDivId)
{
  // Check for a session time out before completing the callback
  if (CheckSessionTimeout())
    return;
  
  var controlDiv = document.getElementById(controlDivId);
  
  if(controlDiv != null)
    controlDiv.innerHTML = args;
  else
    KGUserProfileControl_CallbackError('Can not find UserProfileForm element.', context, controldivId);    
}

function KGChangePasswordControl_CallbackError_Wrapped(args, context, controlDivId)
{
  // debugger;
  // Here we are dealing with authentication timeout before callback, 
  // the message from the server is 'elogin' signify an error with 
  // authentication. The response will be trimmed to form the args 
  // 'login' here..... 
  if(args == 'login')
  {
    window.location='home.aspx';
  }
  else
  {
    var controlDiv = document.getElementById(_controlDivId);
    
    if(controlDiv != null)
    {
      controlDiv.innerHTML = args;
    }
    else
    {
      alert('Can not find contentDiv for ChangePassword control.');
    } 
  }
}

