// GLOBAL VARIABLES
// -----------------------------------------------------------------------------

// array containing all the LiveValidation objects 
var validationObjects = null;

// VALIDATION INITIALIZATION
// -----------------------------------------------------------------------------

// initializes the validation for the form
function formValidation()
{
	var errorMsgList = new ErrorMsgList();
	
	validationObjects = new Object();
	
	if(document.getElementById('id_edituseremail')!=null) {
		var editemail = new LiveValidation('id_edituseremail', { validMessage: " ", onInvalid: function(){ customOnInvalid(this, errorMsgList.getMsg('email'));}, wait: 500});
		editemail.add(Validate.Presence);
		editemail.add(Validate.Email);
		validationObjects['id_edituseremail'] = editemail;
	}
}

// VALIDATION HELPER METHODS
// -----------------------------------------------------------------------------
// helper method for validation to create a box for the livevalidation library
function customOnInvalid(obj, errorMessage)
{
	obj.insertMessage(createSpanMessage(errorMessage, "LV_invalid_message_absolute")); 
	obj.addFieldClass();
}

// helper method for validation to create a box with icon and text
function createSpanMessage(message, className)
{
	var spanWrapper = document.createElement('span');	
	var spanMessage = document.createElement('span');
	var messageNode = document.createTextNode(message);
	
	spanMessage.appendChild(messageNode);
	spanMessage.className = className;
	spanWrapper.appendChild(spanMessage);
	
	return spanWrapper; 
}


// CHECK VALIDATION 
// -----------------------------------------------------------------------------

// check if the form is validated and enable/disable next button
function checkValidated()
{
	var validationArray = new Array();
	for(var key in validationObjects)
		validationArray[validationArray.length] = validationObjects[key];

	if(LiveValidation.massValidate(validationArray))
		return true;
	else
		return false;
}

/** EDIT PROFILE and REGISTERING  */
function validateProfileUser() 
{
	formValidation();
	
	if (checkValidated()) {
		//document.logform.action='my/edituser.action';
		document.myForm.submit();
	}
}

