/*var waitUntilLoaded;

function AjaxMain()
{
	var loader;
	if (loader = $("loader"))
	{
		if (loader.style.display != "none")
		{
			waitUntilLoaded = setTimeout("Main();", 1000);
		}
	}
	else
	{
		//Las librerías y  la página están cargadas, elimina cualquier TimeOut de espera que halla quedado por error.
		clearTimeout( waitUntilLoaded );

		ajaxEngine.registerRequest("CheckUserLoggedIn", "/AjaxProcess.php");
		ajaxEngine.registerAjaxObject("User", new User());

		ajaxEngine.registerRequest("CheckMessages", "/AjaxProcess.php");
		ajaxEngine.registerAjaxObject("Messages", new User.Messages.New());

		ajaxEngine.sendRequest("CheckUserLoggedIn","action=CheckUserLoggedIn");

		var Check = new PeriodicalExecuter
		(
			function()
			{
				ajaxEngine.sendRequest("CheckUserLoggedIn",{
					parameters: "action=CheckUserLoggedIn",
					method: 'post'
				});
			},
			5
		);
	}
}

var AjaxServerHandler = "/AjaxProcess.php";

User = Class.create();
User.prototype =
{
	initialize: function()
	{
		this.logged = false;
		this.userName = "";
	},
	ajaxUpdate: function(ajaxResponse)
	{
		var oElem = ajaxResponse.getElementsByTagName("user")[0];
		if (oElem.getAttribute("logged") === "true")
		{
			this.logged = true;
			this.userName = oElem.getAttribute("username");
			this.checkMessages();
		}
		else
		{
			this.userNotLogged();
		}
	},
	userNotLogged: function ()
	{
		if (window.location.href.indexOf("/modifydata.php") > -1)
		{
			window.close();
		}
	},
	checkMessages: function()
	{
		ajaxEngine.sendRequest("CheckMessages", {
			parameters: "action=CheckMessages",
			method: 'post'
		});
	}
};

User.Messages = Class.create();

User.Messages.New = Class.create();
User.Messages.New.prototype =
{
	initialize: function()
	{
		this.UnreadMessages = 0;
		this.HasNewMessages = false;
		this.Animation = new User.Messages.Animation();
		this.oNewMessageNumber = document.createElement("span");
		this.oNewMessageNumber.style.fontWeight = "bold";
		this.oNewMessageNumber.id = "newMessageCount";
		this.oNewMessageNumber.name = "newMessageCount";
	},
	ajaxUpdate: function(ajaxResponse)
	{
		var oElem = ajaxResponse.getElementsByTagName("messages")[0];

		this.UnreadMessages = oElem.getAttribute("unreadMessages");

		var created = true;
		try
		{
			created = ($("newMessageCount").tagName == "span");
		}
		catch (e)
		{
			created = false;
		}
		this.UnreadMessages = this.UnreadMessages - 0;
		if ( this.UnreadMessages > 0 )
		{
			if (!created)
			{
				var inboxLB = $("userAgenda").getElementsByTagName("br")[0];
				$("userAgenda").insertBefore(this.oNewMessageNumber, inboxLB);

			}
			$("newMessageCount").innerHTML = " ("+this.UnreadMessages.toString()+")";
		}
		else
		{
			document.removeChild($("newMessageCount"));
		}

		if (oElem.getAttribute("new") === "true")
		{
			this.HasNewMessages = true;
			this.notifyUser();
		}
		else
		{
			this.HasNewMessages = false;
		}
	},
	notifyUser: function()
	{
		this.Animation.Restart();
		this.Animation.Start();
	}
};

User.Messages.Animation = Class.create();
User.Messages.Animation.prototype =
{
	initialize: function()
	{
		this.MessageDivMouseOverClose = false;
		this.heightIncrement = 0;
		this.waiting = false;
		this.goingUp = true;
		this.NotifyClosed = false;
		this.DivId = "checkMsgDiv";
		this.TimeoutHandler = null;

		var created = true;
		try
		{
			created = (document.getElementById("checkMsgDiv").tagName == "div");
		}
		catch (Exception)
		{
			created = false;
		}
		if (!created)
		{
			var oNotifyDiv = document.createElement("div");
			var oNotifyClose = document.createElement("img");

			with( oNotifyDiv )
			{
				id = "checkMsgDiv";
				name = "checkMsgDiv";
				style.display = "none";
				with (style)
				{
					width = "200px";
					height = "0px";
					backgroundImage = "url(/lookfeel/images/msgBoxAdviser_back.jpg)";
					overflow = "hidden";
					border = "2px solid #892034";
					bottom = "0px";
					right = "0px";
					textAlign = "right";
					cursor = "pointer";
				}
			}
			if (isIE())
			{
				oNotifyDiv.style.position = "absolute";
			}
			else
			{
				oNotifyDiv.style.position = "fixed";
			}
			with(oNotifyClose)
			{
				src = "/lookfeel/images/newMessageCloseButton.gif";
				alt = "Cerrar";
				title = "Cerrar";
				id = "checkMsgDivBtn";
				name = "checkMsgDivBtn";
				width = 18;
				height = 17;
				border = 0;
				style.margin = "10px";
			}
			oNotifyDiv.appendChild(oNotifyClose);
			document.body.appendChild(oNotifyDiv);
			this.TimeoutHandler = setTimeout(this.MessageDivAssignEvents.bind(this), 10);
		}
	},
	MessageDivAssignEvents: function()
	{
		document.getElementById("checkMsgDiv").onclick = function()
		{
			if (!MessageDivMouseOverClose)
				openUserMessages("inbox");
		};
		document.getElementById("checkMsgDivBtn").onclick = this.CloseNotify.bind(this);
		document.getElementById("checkMsgDivBtn").onmouseover = function()
		{
			MessageDivMouseOverClose = true;
		};
		document.getElementById("checkMsgDivBtn").onmouseout = function()
		{
			MessageDivMouseOverClose = false;

		};

		this.NotifyClosed = false;
	},
	CloseNotify:function()
	{
		this.NotifyClosed = true;
		clearTimeout( this.TimeoutHandler );
		$(this.DivId).style.display = "none";
		this.waiting = false;
		this.goingUp = true;
		this.heightIncrement = 0;
	},
	Start: function()
	{
		if (this.heightIncrement < 200 && this.goingUp && !this.NotifyClosed)
		{
			$(this.DivId).style.display = "block";
			this.heightIncrement += 4;
			$(this.DivId).style.height = this.heightIncrement;
			this.TimeoutHandler = setTimeout(this.Start.bind(this), 3);
		}
		else if(!this.waiting && !this.NotifyClosed)
		{
			$(this.DivId).style.display = "block";
			this.waiting = true;
			this.goingUp = false;
			this.TimeoutHandler = setTimeout(this.Start.bind(this), 7000);
		}
		else if (!this.goingUp && this.heightIncrement > 0 && !this.NotifyClosed)
		{
			$(this.DivId).style.display = "block";
			this.heightIncrement -= 4;
			$(this.DivId).style.height = this.heightIncrement;
			this.TimeoutHandler = setTimeout(this.Start.bind(this), 3);
		}
		else if (!this.NotifyClosed)
		{
			$(this.DivId).style.display = "none";
			this.waiting = false;
			this.goingUp = true;
			this.heightIncrement = 0;
			this.NotifyClosed = false;
			clearTimeout( this.TimeoutHandler );
		}
	},
	Restart: function()
	{
		clearTimeout( this.TimeoutHandler );
		this.MessageDivMouseOverClose = false;
		this.heightIncrement = 0;
		this.waiting = false;
		this.goingUp = true;
		this.NotifyClosed = false;
		this.DivId = "checkMsgDiv";
		this.TimeoutHandler = null;
		$(this.DivId).style.display = "none";
	}
}

EventUtil.addEventHandler(window, "load", AjaxMain);

*/


function AvailableUserCheck()
{
	if (!$SE($F("username")))
	{
		params = "action=checkUserAvailable&user=" + $F("username");

		var MyAjax = new Ajax.Request("/AjaxProcess.php",
		{
			method: 'post',
			parameters: params,
			onComplete: AvailableUserCallback
		});
	}
}

function AvailableUserCallback(response)
{
	eval (response.responseText);
	if (userExists)
	{
		SetUnavailable();
	}
	else
	{
		BasicUtils.Show($("divAvailable"));
		BasicUtils.Hide($("divUnavailable"));
		$("username").style.background = "";
		$("username").style.color = "";
	}
}
/**
 *
 * @access public
 * @return void
 **/
function SetUnavailable()
{
		BasicUtils.Show($("divUnavailable"));
		BasicUtils.Flash($("divUnavailable"));
		BasicUtils.Hide($("divAvailable"));
		$("username").focus();
		$("username").style.background = "#8C0000";
		$("username").style.color = "#FFFFFF";
}
