function LoginFS(destinationURL)
{
	var email = $F('emailFieldFS');
	var password = $F('passwordFieldFS');
	
	new Ajax.Request
	(
		'/login/login',
		{
			method: 'post',
			parameters: 'email=' + email + '&password=' + password,
			onSuccess: function(transport) { LoginResultFS(transport, destinationURL) },
			onLoading: LoginLoadingFS,
			onFailure: HandleFailure
		}
	);
}

function LoginResultFS(transport, destinationURL)
{
    $('fullScreenLoginLoading').hide();
    
	eval('Result = ' + transport.responseText);
	var LoginDivFS = $('fullScreenLoginContent');
	
	if(Result['success'] == 1)
	{
	    if(destinationURL) {
	        endFullScreenLogin();
	        fullScreenLoading(transport);
	        window.location = destinationURL;
	    } else {
	        endFullScreenLogin();
	        fullScreenLoading(transport);
	        window.location.reload();
	    }
	}
	else
	{
		$('fullScreenLoginErrors').innerHTML = "email si parola nu corespund!";
		$('fullScreenLoginErrors').show();
	}
}


function LoginLoadingFS(transport)
{
    if($('fullScreenLoginLoading') && $('fullScreenLoginLoading').style.display == 'none') {
        $('fullScreenLoginLoading').show();
        
        if($('fullScreenLoginErrors')) {
            $('fullScreenLoginErrors').hide();
        }
    }
}

function HandleFailure(transport)
{
	
}


//RECOVER PASS
function showRecoveryFormFS(url)
{
	new Ajax.Request
	(
		url + '/ajax/true/scope/' + $F('fsLoginScope'),
		{
			method: 'get',
			onSuccess: fullScreenLoginResult,
			onLoading: LoginLoadingFS,
			onFailure: HandleFailure
		}
	);
}

function recoverPasswordFS(scope)
{
	var email = $('recoveryEmailFieldFS').value;
	
	new Ajax.Request
	(
		'/account/recover/fs/true/scope/' + scope,
		{
			method: 'post',
			parameters: 'email=' + email,
			onSuccess: recoveryResultFS,
			onLoading: LoginLoadingFS,
			onFailure: HandleFailure
		}
	);
}

function recoveryResultFS(transport)
{
    $('fullScreenLoginLoading').hide();
    
	eval('Result = ' + transport.responseText);
	var content = Result['message'];
    var newdiv = document.createElement("div");
    newdiv.setAttribute('id', 'fsLoginForm');
    newdiv.innerHTML = content;
    
    //remove all children
    while ($('fullScreenLoginContent').firstChild) 
    {
       $('fullScreenLoginContent').removeChild($('fullScreenLoginContent').firstChild);
    };

    $('fullScreenLoginContent').appendChild(newdiv);
}

function fullScreenLogin(scope)
{
    new Ajax.Request
	(
		'/login/full-screen/ajax/true/scope/' + scope,
		{
			method: 'get',
			onSuccess: fullScreenLoginResult,
			onLoading: fullScreenLoading
		}
	);
}

function fullScreenLoginResult(transport)
{    
    $('fullScreenLoginLoading').hide();
    
    //height of black div
    var pageSizeVar = getPageSize();
    $('fullScreenLoginBack').style.height = pageSizeVar[1] + "px";
    
    var content = transport.responseText;
    var newdiv = document.createElement("div");
    newdiv.setAttribute('id', 'fsLoginForm');
    newdiv.innerHTML = content;
    
    //remove all children
    while ($('fullScreenLoginContent').firstChild) 
    {
       $('fullScreenLoginContent').removeChild($('fullScreenLoginContent').firstChild);
    };


    $('fullScreenLoginBack').style.display = 'block';
    $('fullScreenLoginContent').appendChild(newdiv);
    var pageSizeVar = getPageSize();
    var pageScroll = getPageScroll();
    if( $('fullScreenLoginDiv').style.display == 'none') {
        $('fullScreenLoginDiv').style.top = pageSizeVar[3] / 2 - 50 + "px";
        if($('fullScreenLoginBack') && $('fullScreenLoginBack').style.display != 'none' && $('fullScreenLoginDiv').style.position == 'absolute') {
    	   $('fullScreenLoginDiv').style.top = pageSizeVar[3] / 2 + pageScroll[1] - 50 + "px";
        }
    }
    $('fullScreenLoginDiv').style.display = 'block';
    
    if(navigator.appName != "Microsoft Internet Explorer") {
        new Draggable('fullScreenLoginDiv');
    }
    
    endFullScreenLoading();
}

function endFullScreenLogin()
{
    $('fullScreenLoginBack').style.display = 'none';
    $('fullScreenLoginDiv').style.display = 'none';
}
