YAHOO.namespace("Youniverse");

YAHOO.Youniverse.register = 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 Register	
	*/
	this.loadRegister = function (code, encodedTargetUrl)
	{
		var callback =
		{
		  success:this.onLoadRegister,
		  failure:this.ajaxFailure,
		  cache: false 
		};
		
		var path = dialogPath;
		
		if(code)
		{
			path += code;
		}
		if (encodedTargetUrl)
		{
			path += (code ? '/' : '0/')+encodedTargetUrl;
		}
	
		var request = YAHOO.util.Connect.asyncRequest('GET', path, callback);
	}
	/*
	* onLoad Register	
	*/
	this.onLoadRegister = function(o)
	{
		response = o.responseText;
		
		dialogBox.setBody(response);
		dialogBox.setHeight();
		dialogBox.openDialog();
		
		//setTimeout("register.setFocus()", 1000);
		
		//Validation rules
		var usernameVal = new LiveValidation('UserUsername', {validMessage: ' '});
		usernameVal.add( Validate.Length, { minimum: 3 } );
	}
	/*
	* Ajax Failure	
	*/
	this.ajaxFailure = function (o)
	{
		if (o.status > -1)
		{
			alert(msg.translate('err01'));
		}
	}
	
	/*
	* Submit register
	* @ formID is the ID of the form
	*/
	this.submitRegister = function (formID)
	{
		var formObject = document.getElementById(formID+"Form"); 
		
		YAHOO.util.Connect.setForm(formObject);
		
		var callback = 
		{ 
			success: this.onSubmitRegister, 
			failure: this.ajaxFailure
		};
		
		var cObj = YAHOO.util.Connect.asyncRequest('POST', "/user/register", callback);
		
		//Analytics
		pageTracker._trackPageview('/user/register');
	}
	
	/*
	* onSubmit Login
	* @ o is the response object
	*/
	this.onSubmitRegister = function (o)
	{
		eval(o.responseText);
	}
	
	/* 
	* Set focus of the first form item
	*/
	/*this.setFocus =function ()
	{
		document.getElementById("UserUsername").focus();
	}*/
	
	
		this.CloseFrame = function()
	{
			dialogBox.closeDialog();
		
	}
	
}