YAHOO.namespace("Youniverse");

YAHOO.Youniverse.login = function()
{
	var dialogPath;
	
	/*
	* Initialise class when window dom loaded
	*/
	this.initClass = function ()
	{
	}
	
	/*
	* Set the dialog path
	* @ url String of dialog controller path	
	*/
	this.setDialogPath = function (url)
	{
		dialogPath=url;
	}
	
	/*
	* Load Login	
	*/
	this.loadLogin = function (code)
	{
		var callback =
		{
		  success:this.onLoadLogin,
		  failure:this.ajaxFailure,
		  cache: false 
		};
		
		var path = dialogPath;
		
		if(code)
		{
			path += code;
		}
		
		var request = YAHOO.util.Connect.asyncRequest('GET', path, callback);
	}
	/*
	* onLoad Login	
	*/
	this.onLoadLogin = function(o)
	{
		response = o.responseText;
		
		dialogBox.setBody(response);
		dialogBox.setHeight();
		dialogBox.openDialog();
		
		setTimeout("login.setFocus()", 1000);
	}
	/*
	* Ajax Failure	
	*/
	this.ajaxFailure = function ()
	{
		alert(msg.translate('err01'));
	}
	
	/*
	* Submit login
	* @ formID is the ID of the form
	*/
	this.submitLogin = function (formID)
	{
		var formObject = document.getElementById(formID+"Form"); 
		YAHOO.util.Connect.setForm(formObject);
		
		var callback = 
		{ 
			success: this.onSubmitLogin, 
			failure: this.ajaxFailure
		};
		var cObj = YAHOO.util.Connect.asyncRequest('POST', "/user/login", callback);
		
		pageTracker._trackPageview('/user/login');
	}
	
	/*
	* onSubmit Login
	* @ o is the response object
	*/
	this.onSubmitLogin = function (o)
	{
		eval(o.responseText);
	}
	
	/* 
	* Set focus of the first form item
	*/
	this.setFocus =function ()
	{
		document.getElementById("UserUsername").focus();
	}

	/**
	 * Set all non-hidden inputs in supplied form 'f' to be disabled
	 */
	this.disableForm = function(f)
	{
		for (var i=0; i<f.elements.length; i++) {
			if (f.elements[i].type != 'hidden') {
				f.elements[i].disabled=true;
			}
		}
	}
}