//login function
var login = function(wtarget, data) {
	if (data.authentify == false) {
		//add message
		$('#' + wtarget).html(data.message);
    }
    else {
    	//add message
    	$('#' + wtarget).html(data.message);
		
		wait_block('panel', '');
		
		setTimeout( function () {
    		setTimeout( function () {
    	 		
    			if (parent) {
    				parent.window.location.href = data.redirect;
    	 		}
    	 		else {
    	 			window.location.href = data.redirect;
    	 		}
    	 		
    	 	}, 2000);
    	}, 2000);
    }
};

$().ready(function () {
	$(document).keypress(function (e) {
		key = (e.keyCode) ? e.keyCode : e.which;
		if (key === 13) {
			$('form').submit();
			return false;
		}
	});
});

//login function
var retrieve = function(wtarget, data) {
	if (data.retrieve == false) {
		//add message
		$('#' + wtarget).html(data.message);
    }
    else {
    	//add message
    	$('#' + wtarget).html(data.message);
		setTimeout( function () {
			wait_block('panel', '');
    		setTimeout( function () {
    	 		if (parent) {
    				parent.window.location.href = data.redirect;
    	 		}
    	 		else {
    	 			window.location.href = data.redirect;
    	 		}
    	 		
    	 	}, 2000);
    	}, 2000);
    }
};

//register function
var register = function(wtarget, data) {
	if (data.registred == false) {
		//add message
		$('#' + wtarget).html(data.message);
    }
    else {
    	//add message
	$('#login-submit').fadeOut();
    	$('#' + wtarget).html(data.message);
		setTimeout( function () {
			wait_block('panel', '');
    		setTimeout( function () {
    	 		if (parent) {
    				parent.window.location.href = data.redirect;
    	 		}
    	 		else {
    	 			window.location.href = data.redirect;
    	 		}
    	 		
    	 	}, 2000);
    	}, 20000);
    }
};
