RFR.Application.GadgetAppLoginatorRegisterOnMain = function(app,id)
{
	this.id=id;
	this.app=app;


	this.getPasswordByEmail = function()
    {
    	var text = '</br>Please input email you registered in system.<br/>'
    	           + 'We will send your password to this email<br/><br/>'
    	           + '<input type="text" style="width:200px;" id="' + $rfr.gadgetMap[this.id].id + '_emailValue" onkeypress="$rfr.gadgetMap[\'' + this.id + '\'].onCheckEnter(event);"></br></br>'
    	           + '<input type="button" style="width:100px;" value="Get password" onclick="$rfr.gadgetMap[\'' + this.id + '\'].sendPassword($(\'' + $rfr.gadgetMap[this.id].id + '_emailValue\').value);"></br></br>';
        this.publishRequestWindow(text);
        $(this.id + '_emailValue').focus();
    }
    
    
    this.publishRequestWindow = function(content)
    {
        if (this.app.requestWindow)
        {
            this.app.requestWindow.close();
        }

        this.app.requestWindow = new WPopup();
        this.app.requestWindow.width  = 300;
        this.app.requestWindow.height = 100;
        this.app.requestWindow.title  = 'Get password by email';
    
        this.app.requestWindow.content = this.pushInCenter(content, this.app.requestWindow);
        
        this.app.requestWindow.open();
    }
    
    
    this.onSendPassword = function(response)
	{
		try
		{
		    var text = response.text + '<br/><br/>';
		    if (response.success)
		    {
		        text += '<input type="button" style="width:100px;" value="Close" onclick="$rfr.gadgetMap[\'' + this.id + '\'].close();"></br></br>';
		    }
		        else
		        {
    		        text += '<input type="button" style="width:100px;" value="Try again" onclick="$rfr.gadgetMap[\'' + this.id + '\'].tryAgain();">&nbsp;&nbsp;';
    		        text += '<input type="button" style="width:100px;" value="Cancel" onclick="$rfr.gadgetMap[\'' + this.id + '\'].cancel();"></br></br>';
		        }
            this.publishRequestWindow(text);
		}
		    catch(e)
		    {
    			$rfr.con().add(e);
    		}
	}

    
    this.onSendPasswordFailed = function(response)
	{
		try
		{
        	var text = '</br>Error!<br/><br/>'
        	           + '<input type="button" style="width:100px;" value="Close" onclick="$rfr.gadgetMap[\'' + this.id + '\'].close();"></br></br>';
            this.publishRequestWindow(text);
			$rfr.con().add(response.t_message, 'error');
		}
		    catch(e)
		    {
    			$rfr.con().add(e);
    		}
	}

    
    this.sendPassword = function(email)
    {
        if (email == '')
        {
            return;
        }
        this.publishRequestWindow('Sending request...');
		var request    = this.app.createRequest();
		request.action = 'sendPassword';
		request.email  = email;
		this.app.sendRequest(request, this.onSendPassword.bind(this), this.onSendPasswordFailed.bind(this));
    }
    
    
    this.close = function()
    {
        if (this.app.requestWindow)
        {
            this.app.requestWindow.close();
        }
    }
    
    
    this.cancel = function()
    {
        if (this.app.requestWindow)
        {
            this.app.requestWindow.close();
        }
    }
    
    
    this.tryAgain = function()
    {
        this.getPasswordByEmail();
    }
	
    
    this.pushInCenter = function(str, mainWindow)
    {
        return '<div style="width:' + mainWindow.width + 'px;height:' + mainWindow.height + 'px;text-align:center;display:table-cell;vertical-align:middle;padding:6px;">'
               + str
               + '</div>';
    }
    
    
    this.onCheckEnter = function(e)
    {
        try
        {
            var keychar;
            if(window.event) // IE
                keychar = e.keyCode;
            else if(e.which) // Netscape/Firefox/Opera
                keychar = e.which;
            if (keychar == 13)
            {
                this.sendPassword($(this.id + '_emailValue').value);
            }
        }
		    catch (e)
		    {
		        $rfr.con().add(e);
		    }
    }


    
}