/**
 * register.js
 * JQuery code needed to interact with the register form.
 */

// $Id$

//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
// define the behavior of the register form.
$(document).ready(function(){

	$("#fms-form-register").ajaxForm({            
		target: "",
		beforeSubmit: validateRegisterForm,
		success     : onRegisterSuccess
	});
});

//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
// This function will simply do the graphical logic, all validations are done on the server side.
//
// formData:
// formData is an array of objects representing the name and value of each field 
// that will be sent to the server;  it takes the following form: 
// 
// [ 
//     { name:  username, value: valueOfUsernameInput }, 
//     { name:  password, value: valueOfPasswordInput } 
// ] 
//
// JqForm:
// jqForm is a jQuery object which wraps the form DOM element 
//
// options:
// this is the Options Object passed into ajaxForm/ajaxSubmit
function validateRegisterForm(formData, jqForm, options) {

	$("#fms-register-wrapper").block({ 
		message: '<div class="loading" style="width:100%; height:100%; background-color:#296060;"></div>', 
		css    : {
			width : '796px', 
			height: '500px',
			cursor: 'default',
			'background-color': '#296060'
		} 
	});

	return true;
}

//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
// This function will process the returning value of the submitions to see if the operation
// was successfull or not.
//
// result:
// the responseText or responseXML value (depending on the value of the dataType option).
function onRegisterSuccess(result){
	
	//parse the result so that we know if there was an error or everything went fine
	var str = result.substr(0, 5);	
	
	if(str == "false"){
		
		$(".blockMsg").html(result.substr(6, result.length));
	}
	else{
		$(".blockMsg").html(result);
		$(".blockMsg").slideDown('fast');
	}
}

//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
// This function will unblock the register form.
function unblockRegisterForm(){
	$("#fms-register-wrapper").unblock();
}