﻿var g_origForgotPwdContent;
var g_origLockedAccountContent;
var g_CurrentlyDisplayedWindow = null;
 
// Call web service method to retrieve the requested password based on the email supplied.
function RetrievePassword()
{
    var elemEmailAddress = document.getElementById('txtSendToEmail');
    
    if (elemEmailAddress != null)
    {
        var elemForgotContent = document.getElementById('forgotpassword_content');
        
        // Store the Forgot Password help window's content before the web service replaces it with new content
        // so that we can restore it later if need be.       
        if (elemForgotContent != null)
            g_origForgotPwdContent = elemForgotContent.innerHTML;        
        McAfee.WebServices.AccountWebSvc.RetrieveForgottenPassword(elemEmailAddress.value,
                                                                   GetAffiliateId(),
                                                                   RetrieveForgottenPasswordResponse,
                                                                   RetrieveForgottenPasswordErrorCallback);
    }
}

// Callback method for successful retrieval of forgotten password content.
function RetrieveForgottenPasswordResponse(result) 
{
    // Deserialize AccountWebSvcResponse JSON object that contains two properties; Success and Text.
    var response = Sys.Serialization.JavaScriptSerializer.deserialize(result);

    if (response != null && response.Text != null) 
    {      
        if(location.href.substr(location.href.indexOf("appsupport")).toLowerCase())    
            response.Text =  response.Text.replace("<a","<a Target=\"_blank\"");
        if (response.Success)
            SetSuccessResponseMessage(response.Text, 'forgotpassword_content');
        else
            SetErrorResponseMessage(response.Text, 'forgotpassword_error');
    }
}

// Callback method for errors encountered during the retrieval of a forgotten password.
function RetrieveForgottenPasswordErrorCallback(error) 
{
    SetErrorResponseMessage(error.get_message(), 'forgotpassword_error');
}

// Call web service method to unlock a locked account based on the email supplied.
function RetrieveLockedAccountPassword()
{
    var elemEmailAddress = document.getElementById('txtLockedEmail');
    
    if (elemEmailAddress != null)
    {
        var elemLockedContent = document.getElementById('acctLocked_content');        
        // Store the Unlock Account help window's content before the web service replaces it with new content
        // so that we can restore it later if need be.   
        if (elemLockedContent != null)
            g_origLockedAccountContent = elemLockedContent.innerHTML;
       
        McAfee.WebServices.AccountWebSvc.ResetLockedPassword(elemEmailAddress.value,
                                                             GetAffiliateId(),
                                                             RetrieveLockedAccountResponse,
                                                             RetrieveLockedAccountErrorCallback);
    }                    
}

// Callback method for successful retrieval of locked account content.
function RetrieveLockedAccountResponse(result) 
{
    // Deserialize AccountWebSvcResponse JSON object that contains two properties; Success and Text.
    var response = Sys.Serialization.JavaScriptSerializer.deserialize(result);

    if (response != null && response.Text != null) 
    {
        if(location.href.substr(location.href.indexOf("appsupport")).toLowerCase())    
            response.Text =  response.Text.replace("<a","<a Target=\"_blank\"");
        if (response.Success)
            SetSuccessResponseMessage(response.Text, 'acctLocked_content');
        else
            SetErrorResponseMessage(response.Text, 'acctLocked_error');
    }
}

// Callback method for errors encountered during the retrieval of a locked account.
function RetrieveLockedAccountErrorCallback(error) 
{
    SetErrorResponseMessage(error.get_message(), 'acctLocked_error');
}

// Set the message of a help window to the response.
function SetSuccessResponseMessage(successResponse, elemId) 
{
    var windowDiv = document.getElementById(elemId);

    if (windowDiv != null)
        windowDiv.innerHTML = successResponse;
}

// Set the error section of a help window to the response.
function SetErrorResponseMessage(errorResponse, elemId) 
{
    var errorDiv = document.getElementById(elemId);

    if (errorDiv != null)
        errorDiv.innerHTML = errorResponse;
}

// Hide a help window
function HideContent(d, origContent)
{
    // Close the helper window
    CloseHelpWindow(d);

    // If possible, restore the help window's original content so that it's 
    // use the next time the window is displayed.
    if (origContent != null)
    {
        // Restore original conent
        var contentDivString = d + "_content";
        var contentDiv = document.getElementById(contentDivString);
        
        if (origContent != null)
            contentDiv.innerHTML = origContent;
            
        // Clear any error messages within the window
        var errorDivString = d + "_error";
        var errorDiv = document.getElementById(errorDivString);
        errorDiv.innerHTML = "";
    }
}

// Display a help window
function ShowContent(d) 
{
    if (d == null)
        return;
        
    if (d.length < 1)
        return;
    
    // If another help window is already visible, close it first before displaying
    // the requested help window.    
    if (g_CurrentlyDisplayedWindow != null)
        CloseHelpWindow(g_CurrentlyDisplayedWindow);

    var divCurr = document.getElementById(d);
    if (divCurr != null)
    {
        divCurr.style.display = "block";

        var divShield = document.getElementById('help_window_shield')
        if (divShield != null)
            divShield.style.display = "block";
    }
    
    g_CurrentlyDisplayedWindow = d;   
}

// Close a help window.
function CloseHelpWindow(d)
{
    if (d == null)
        return;
        
    if (d.length < 1)
        return;
        
    var divCurr = document.getElementById(d);
    if (divCurr != null)
        divCurr.style.display = "none";

    var divShield = document.getElementById('help_window_shield')
    if (divShield != null)
        divShield.style.display = "none";
    
    g_CurrentlyDisplayedWindow = null;
}

function Collapse()
{
    var divLoginContent = document.getElementById("formContentLogin");
    
    if (divLoginContent.style.display == "none")
        divLoginContent.style.display = "block";
    else
        divLoginContent.style.display = "none";
}

function GetAffiliateId()
{
    var elemAffId = document.getElementById("AffId");
    
    if (elemAffId != null)
        return elemAffId.value;
    else
        return "0";
}



/********************************************
     fix Columns
**********************************************/

function addEvent(elm, evType, fn, useCapture) { 
	if (elm.addEventListener) { elm.addEventListener(evType, fn, useCapture); return true; } 
	else if (elm.attachEvent) { var r = elm.attachEvent('on' + evType, fn); return r; }
	else { elm['on' + evType] = fn; }
}
//initializes the script to compare login and registration columns
function initTall(){
    var loginTop=document.getElementById('login_top');
    var loginBody=document.getElementById('loginBody');
    var regTop=document.getElementById('register_top');  
    var regBody=document.getElementById('regBody'); 
    
    // if any of the do not exist then exit
    if ((loginTop == null) || (regTop == null) || (loginBody == null) || (regBody == null)) {return;}
    else {
        setTall(loginTop, regTop);
        setTall(loginBody, regBody);
    }
}
//compares two the height of two elements and sets the hightest value for both of them
function setTall(leftCapture, rightCapture){

    if(!document.getElementById || !document.createTextNode){return;}
    
    if(leftCapture.offsetHeight>=rightCapture.offsetHeight) {
        var temp=leftCapture.offsetHeight;
        rightCapture.style.height=parseInt(temp)+'px';
    }
    else {
        var temp=rightCapture.offsetHeight;
        leftCapture.style.height=parseInt(temp)+'px';
    }
}
addEvent(window, 'load', initTall, false);
