﻿//Loads user status message
function LoadUserStatus()
{
    //Create an ajax call to get status message
    var AjaxRequest;
    AjaxRequest =  CreateAjaxRequest(AjaxStatusUrl + "&action=getcurrent","GET","");
    AjaxRequest.OnLoaded = function()
    {
        var userStatus = AjaxRequest.GetText();
        if (userStatus != "")
        {
          
            //Show read div and hide write div
            HideDiv('StatusWrite');
            ShowDiv('StatusRead');
            
             
            //set status message label
            document.getElementById('userstatus2').innerHTML = userStatus;
            AjaxRequest = null;
        }
        else
        {
            GetEmptyStatusMessage();
        }
    }
    AjaxRequest.OnFailure = function()
    {
        AjaxRequest = null;
    }
 } 
 
 // if user doesnt have a status message get an empty message
 function GetEmptyStatusMessage()
 {
    //Show read div and hide write div
    HideDiv('StatusRead');
    ShowDiv('StatusWrite');
    
    //Create an ajax call to get the empty status text
    var AjaxRequest;
    AjaxRequest =  CreateAjaxRequest(AjaxStatusUrl + "&action=emptystatus","GET","");
    AjaxRequest.OnLoaded = function() 
    { 
        
        document.getElementById('txtStatusMessage').value = AjaxRequest.GetText();
        document.getElementById('txtStatusMessage').select();
        AjaxRequest = null;
 
    }
        
          AjaxRequest.OnFailure = function()
    {
        AjaxRequest = null;
    }
 }
 
 //Clear Status Message
  function ClearStatusMessage()
 {
    //Create an ajax call to get the empty status text
    var AjaxRequest;
    AjaxRequest =  CreateAjaxRequest(AjaxStatusUrl + "&action=clearstatus","GET","");
    AjaxRequest.OnLoaded = function() 
    { 
        //show the empty status message
        GetEmptyStatusMessage();
        AjaxRequest = null;
 
    }
        
          AjaxRequest.OnFailure = function()
    {
        AjaxRequest = null;
    }
 }
 
 
 function UpdateUserStatus()
{   
    //Get updated text
    var NewStatusText = document.getElementById("txtStatusMessage").value;
    
    

    //Create an ajax call to get status message 
    var AjaxRequest;
    AjaxRequest =  CreateAjaxRequest(AjaxStatusUrl + "&action=setstatus","POST","newstatus=" + NewStatusText);
    
    AjaxRequest.OnLoaded = function() 
    { 
        var userStatus = AjaxRequest.GetText();
     
        if (userStatus != "")
        {
            //Show read div and hide write div
            HideDiv('StatusWrite');
            ShowDiv('StatusRead');
            
             
            //set status message label
            document.getElementById('userstatus2').innerHTML = userStatus;
            AjaxRequest = null;
        }
        else
        {
            GetEmptyStatusMessage();
        }
    }
    AjaxRequest.OnFailure = function()
    {
        AjaxRequest = null;
    }
 } 
 
   function EditUserStatus() 
    {
    //Create an ajax call to get status message 
    var AjaxRequest;
    AjaxRequest =  CreateAjaxRequest(AjaxStatusUrl + "&action=GetStatusForEdit","GET","");
    AjaxRequest.OnLoaded = function() 
    { 
        var userStatus = AjaxRequest.GetText();

        if (userStatus != "")
        {
          
            //Show write div and hide read div
            HideDiv('StatusRead');
            ShowDiv('StatusWrite');
            
             
            //set status message label
            document.getElementById('txtStatusMessage').value = userStatus;
            AjaxRequest = null;
        }
        else
        {
            GetEmptyStatusMessage();
        }
    }
    AjaxRequest.OnFailure = function()
    {
        AjaxRequest = null;
    }
    }
 
 
//method that calls the Validate layer form when the ENTER key is pressed and stops the action onblure for the same control
function StatusKeyPress(e)
{  
    var oEvent = window.event ? window.event : e;
    var isDOM = (document.getElementById ? true : false);
    var isNS4 = (document.layers ? true : false);

    if (document.all != 'undefined') key = oEvent.keyCode;
    else if (isDOM) key = oEvent.charCode;
    else if (isNS4) key = oEvent.which;

    if(key == 13)
    {            
        UpdateUserStatus();
        
        // for stoping the .Net auto post back in the IE and Firefox --  SARA AA 16/10/2007
        e.returnValue = false;  
        e.cancel = true;  // for IE
        e.cancelBubble = true; // for IE
        e.preventDefault(); // for FF
        
        return false;
    }
}