function CheckLogin()
{
	var name = document.getElementById('mailform').value;
	ShowLoading('');
	$.post(dle_root + "engine/ajax/wowreg.php", { name: name }, function(data){
		HideLoading('');
		if (data){$("#res-reg").html(data);}
		else
		{
			var to = $("#mailform").val();
			var EMAIL_REG = /^([A-Za-z0-9_\-\.\+])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
			
			var data ="to=" + to;
			if(to == "")
			{
				$("#error-to").fadeIn(700).show();
				$("#loading").fadeOut(100).hide();
			}
			else if(false === EMAIL_REG.test(to))
			{
				$("#error-to").fadeIn(700).show();
				$("#loading").fadeOut(100).hide();
			}
			else
			{
				$("#res-reg").fadeOut(100).hide();
				$("#submit-button").fadeOut(100).hide();
				$("#error-to").fadeIn(700).hide();
				$("#mailform").fadeOut(100).hide();
				$("#loading").fadeIn(100).show();
				$.ajax
				({
					type: "POST",
					url: dle_root + "engine/ajax/send.php",
					data: data,
					success: function()
					{
						$("#loading").fadeOut(100).hide();
						$('#message-sent').fadeIn(500).show();
					}
				});
			}
		}
	});
	return false;
};

function RetreivePass()
{
	var name = document.getElementById('loginform').value;
	var mail = document.getElementById('mailret').value;
	dle_root = "/";
	ShowLoading('');
	$.post(dle_root + "engine/ajax/wowlostpass.php", { name: name, mail: mail }, function(data){
		HideLoading('');
		if (data){
		$("#output").fadeIn(700).show();
		$("#output").html(data);}
		else
		{
		$("#output").fadeOut(700).hide();
			var to = $("#mailret").val();
			var login = $("#loginform").val();
			var EMAIL_REG = /^([A-Za-z0-9_\-\.\+])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
			
			var data = "login=" + login + "&to=" + to;
			if(to == "")
			{
				$("#error-to").fadeIn(700).show();
				$("#loading-lostpass").fadeOut(100).hide();
			}
			else if(login == "")
			{
				$("#error-login").fadeIn(700).show();
				$("#loading-lostpass").fadeOut(100).hide();
			}
			else if(false === EMAIL_REG.test(to))
			{
				$("#error-to").fadeIn(700).show();
				$("#loading-lostpass").fadeOut(100).hide();
			}
			else
			{
				$("#lostpasscontent").fadeOut(100).hide();
				$("#loading-lostpass").fadeIn(800).show();
				$.ajax
				({
					type: "POST",
					url: dle_root + "engine/ajax/sendlost.php",
					data: data,
					success: function()
					{
						$("#loading-lostpass").fadeOut(100).hide();
						$('#lostpass-sent').fadeIn(500).show();
					}
				});
			}
		}
	});
	return false;
};

function ShowLoading( message )
{

	if ( message )
	{
		$("#loading-layer-text").html(message);
	}
		
	var setX = ( $(window).width()  - $("#loading-layer").width()  ) / 2;
	var setY = ( $(window).height() - $("#loading-layer").height() ) / 2;
			
	$("#loading-layer").css( {
		left : setX + "px",
		top : setY + "px",
		position : 'fixed',
		zIndex : '99'
	});
		
	$("#loading-layer").fadeTo('slow', 0.6);

};

function HideLoading( message )
{
	$("#loading-layer").fadeOut('slow');
};

function dropdownmenu(obj, e, menucontents, menuwidth){

	if (window.event) event.cancelBubble=true;
	else if (e.stopPropagation) e.stopPropagation();

	var menudiv = $('#dropmenudiv');

	if (menudiv.is(':visible')) { clearhidemenu(); menudiv.fadeOut('fast'); return false; }

	menudiv.remove();

	$('body').append('<div id="dropmenudiv" style="display:none;position:absolute;z-index:100;width:165px;"></div>');

	menudiv = $('#dropmenudiv');

	menudiv.html(menucontents.join(""));

	if (menuwidth) menudiv.width(menuwidth);

	var windowx = $(document).width() - 15;
	var offset = $(obj).offset();

	if (windowx-offset.left < menudiv.width())
			offset.left = offset.left - (menudiv.width()-obj.offsetWidth);

	menudiv.css( {
		left : offset.left + "px",
		top : offset.top+obj.offsetHeight+"px"
	});

	menudiv.fadeTo('fast', 0.9);

	menudiv.mouseenter(function(){
	      clearhidemenu();
	    }).mouseleave(function(){
	      delayhidemenu();
	});

	$(document).one("click", function() {
		hidemenu();
	});

	return false;
};

function hidemenu(e){
	$("#dropmenudiv").fadeOut("fast");
};

function delayhidemenu(){
	delayhide=setTimeout("hidemenu()",1000);
};

function clearhidemenu(){

	if (typeof delayhide!="undefined")
		clearTimeout(delayhide);
};
