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(),
                                                                   RetrievePasswordSuccessCallback,
                                                                   RetrievePasswordErrorCallback);
    }
}

// Callback method for successful retrieval of a forgotten password.
function RetrievePasswordSuccessCallback(result)
{
    // Replace the Forgot Password help window's content with new "success message" content
    // returned by the web service.
    var windowDiv = document.getElementById('forgotpassword_content');
    
    if (windowDiv != null)
        windowDiv.innerHTML = result;
}

// Callback method for errors encountered during the retrieval of a forgotten password.
function RetrievePasswordErrorCallback(error)
{
    // Insert the error message into the Forgot Password help window's existing content.
    var errorDiv = document.getElementById('forgotpassword_error');
    
    if (errorDiv != null)
       errorDiv.innerHTML = error.get_message();
}

// 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(),
                                                             RetrieveLockedAcctPwdSuccessCallback,
                                                             RetrieveLockedAcctPwdErrorCallback);
    }                    
}

// Callback method for successful unlocking of a locked account.
function RetrieveLockedAcctPwdSuccessCallback(result)
{
    var windowDiv = document.getElementById('acctLocked_content');
    
    // Replace the Unlock Account help window's content with new "success message" content
    // returned by the web service.
    if (windowDiv != null)
        windowDiv.innerHTML = result;
}

// Callback method for errors encountered during the unlocking of a locked account.
function RetrieveLockedAcctPwdErrorCallback(error)
{
    var errorDiv = document.getElementById('acctLocked_error');
    
    // Insert the error message into the Unlock Account help window's existing content.
    if (errorDiv != null)
       errorDiv.innerHTML = error.get_message();
}


// 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
**********************************************/

var loginColumn, regColumn; 

function scriptInit() { if(!document.getElementById || !document.createTextNode){return;}}

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; }
}

function setTall(){
    loginColumn=document.getElementById('loginBody');
	regColumn=document.getElementById('regBody');

	if(loginColumn.offsetHeight>regColumn.offsetHeight) {
		
		var temp=loginColumn.offsetHeight;
		regColumn.style.height=parseInt(temp)+'px';
	}
	else 
	{
		var temp=regColumn.offsetHeight;
		loginColumn.style.height=parseInt(temp)+'px';
	}
}
