﻿/* Build namespace */
if (NMR == undefined) var NMR = {};
if (NMR.Common == undefined) NMR.Common = {};
if (NMR.Common.Web == undefined) NMR.Common.Web = {};
if (NMR.Common.Web.GenericControls == undefined) NMR.Common.Web.GenericControls = {};

/*
<summary>
Constructor function, passes arguments to constructor in prototype
</summary>
*/
NMR.Common.Web.GenericControls.ChangePasswordReminder = function()
{
    // Call base constructor
    myBase(this, NMR.Common.Web.GenericControls.GenericBase.prototype.create, arguments);
    
    // Call constructor
    this.create.apply(this, arguments);
}

/*
<summary>
Defines the clientside JavaScript object for the ChangePassword control
</summary>
*/
NMR.Common.Web.GenericControls.ChangePasswordReminder.prototype = {

    isHidden: null,
    
    /* Bound child control objects */
    changePassword: null,

    /*
    <summary>
    </summary>
    */
    create: function()
    {
        this.isHidden = arguments[4];
        this.bindingStack.addControlBinding(arguments[5],'changePassword');
        this.attachEventHandlers(false);
    },
    
    /*
    <summary>
    </summary>
    */
    attachEventHandlers: function(detach)
    {
        myBase(this, NMR.Common.Web.GenericControls.GenericBase.prototype.attachEventHandlers, arguments);
        var me = this;
        if(!detach)
        {
            // Attach DOM event handlers
            if(document.addEventListener)
            {
                // for Firefox
                window.addEventListener("load",function(){me.recalculatePosition();}, false); 
                window.addEventListener("resize",function(){me.recalculatePosition();}, false); 
            }
            else if(document.attachEvent) 
            {   
                // for IE
                window.attachEvent("onload", function(){me.recalculatePosition();});
                window.attachEvent("onresize", function(){me.recalculatePosition();});
            }
        }   
        else
        {
            // Detach DOM event handlers
            if(document.removeEventListener)
            {
                // for Firefox
                window.removeEventListener("resize",function(){me.recalculatePosition();}, false);
                window.removeEventListener("load",function(){me.recalculatePosition();}, false);
            }
            else if(document.detachEvent)
            {
                // for IE
                window.detachEvent("onresize", function(){me.recalculatePosition();});
                window.detachEvent("onload", function(){me.recalculatePosition();});
            }
        }   
    },
    
    /*
    <summary>
    </summary>
    */
    recalculatePosition: function()
    {
        if(!this.isHidden)
        {
            var mdl = document.getElementById("cprModal");
            mdl.style.top = 0;
            mdl.style.left = 0;
            var posX = 0;
            var posY = 0;
            if(document.all)
            {
                mdl.style.width = parseInt(window.document.documentElement.scrollWidth)+ "px";
                mdl.style.height = parseInt(window.document.documentElement.scrollHeight) + "px";
                posX = parseInt(window.document.documentElement.clientWidth / 2);
                posY = parseInt(window.document.documentElement.clientHeight / 2);
            }
            else
            {
                mdl.style.width = parseInt(window.outerWidth) + parseInt(window.pageXOffset) + "px";
                mdl.style.height = parseInt(window.outerHeight) +  parseInt(window.pageYOffset) + "px";
                posX = parseInt(window.innerWidth / 2);
                posY = parseInt(window.innerHeight / 2);
            }   
            document.getElementById(this.clientObjectId + "_base").style.top = ((posY > 200)?(posY - 100):posY) + "px";
            document.getElementById(this.clientObjectId + "_base").style.left = ((posX > 200)?(posX - 100):posY) + "px";
        }
    },
    
    /*
    <summary>
    Redirects to the Change Password dialog, and hides the Change Password Reminder dialog.
    </summary>
    */
    showCPDialog: function()
    {
        var mdl = document.getElementById("cprModal");
        mdl.className = "hdnCpRem";
        document.getElementById(this.clientObjectId + "_base").style.display = "none";
        this.changePassword.showDialog();
    },
    
    /*
    <summary>
    Hides the Change Password Reminder dialog
    </summary>
    */
    hideDialog: function()
    {
        var mdl = document.getElementById("cprModal");
        mdl.className = "hdnCpRem";
        document.getElementById(this.clientObjectId + "_base").style.display = "none";
    }
    
};
NMR.Common.Web.GenericControls.ChangePasswordReminder.prototype = prototypeExtend(NMR.Common.Web.GenericControls.GenericBase.prototype,NMR.Common.Web.GenericControls.ChangePasswordReminder.prototype);   
