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)
{
    eval('Result = ' + transport.responseText);
	var LoginDivFS = $('fullScreenLoginContent');
	
	if(Result['success'] == 1)
	{
	    if(destinationURL) {
	        endFullScreenLogin();
	        LoginLoadingFS(transport);
	        window.location = destinationURL;
	    } else {
	        endFullScreenLogin();
	        LoginLoadingFS(transport);
	        window.location.reload();
	    }
	}
	else
	{
		$('fullScreenLoginMessage').innerHTML = "email si parola nu corespund!";
	}
}


function LoginLoadingFS(transport)
{
    var LoginDiv = $('fullScreenLoginMessage');
	LoginDiv.innerHTML = "<div style=\"width:16px; height:16px;\" class=\"ErrorText\"><img class=\"Mid\" src=\"" + webroot + "img/loadingAnimation.gif\" alt=\"Loading...\"  /></div>";
}

function HandleFailure(transport)
{
	
}


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

function recoverPasswordFS(scope)
{
	var email = $('recoveryEmailFieldFS').value;
	
	new Ajax.Request
	(
		webroot + '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'];
	
	$j("#ALERT_ajaxContent").html(content);
	ALERT_init('#ALERT_ajaxContent > a.alertbox, #ALERT_ajaxContent > div > a.alertbox');//pass where to apply alertbox
}


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';
}

function fullScreenLogin(scope)
{
    url = "/login/full-screen/ajax/true/scope/" + scope + "/";
    ALERT_show("", url);
}
