var ForgottenAjax = Class.create();
ForgottenAjax.prototype = {

	id: 'forgotten',
	page: projectUrl +'/site/forgottenPassword',

	execute: function(object) {

		this.hide();
		this.reset();

	}

}

Object.extend(ForgottenAjax.prototype, CommonAjax);

var ConfirmationEmailAjax = Class.create();
ConfirmationEmailAjax.prototype = {

	page: projectUrl +'/site/sendConfirmationEmail',

	parameters: function() {

		return {
			'login': $('authentificationLogin').value,
			'password': $('authentificationPassword').value
		}

	}

}

Object.extend(ConfirmationEmailAjax.prototype, CommonAjax);

DoSignUpAjax = Class.create();
DoSignUpAjax.prototype = {

	id: 'doSignUp',
	page: projectUrl +'/site/doSignUp',

	execute: function(object) {

		this.reset();

	}

}
Object.extend(DoSignUpAjax.prototype, CommonAjax);

doCkeckSignOnAjax = Class.create();
doCkeckSignOnAjax.prototype = {

	id: null,
	page: projectUrl +'/member/account/doCkeckSignOn?fieldName=',

	construct: function(element) {

		var formField = element.name;
		this.page += formField;

	},

	execute: function(object) {

		var errorFieldColor = "#bc0f1f";
		var validFieldColor = "#007500";

		if(object.error != null) {

			$('message'+object.fieldName).innerHTML = object.error;
			$('message'+object.fieldName).style.color = errorFieldColor;
			$(object.fieldName).style.outline="2px solid "+errorFieldColor;

		} else {

			if($(object.fieldName).value != '') {
				$(object.fieldName).style.outline="2px solid "+validFieldColor;
			} else {
				$(object.fieldName).style.outline="";
			}
			$('message'+object.fieldName).innerHTML = "";

			// Password fields to check
			var passwordArray = new Array("doSignUpPassword", "doSignUpPasswordBis");

			if(	($(passwordArray[0]).value != '')
				&& ($(passwordArray[1]).value != '')
			) {
				// If two password doesn't match set an error message
				if($(passwordArray[0]).value != $(passwordArray[1]).value) {
						$('message'+passwordArray[1]).style.color = errorFieldColor;
						$('message'+passwordArray[1]).innerHTML = object.diffPassword;
						$(passwordArray[1]).style.outline="2px solid "+errorFieldColor;
				}
			}

		}

	}

}
Object.extend(doCkeckSignOnAjax.prototype, CommonAjax);

DoChangePasswordAjax = Class.create();
DoChangePasswordAjax.prototype = {

	id: 'changePassword',
	page: projectUrl +'/member/account/doChangePassword',

	execute: function(object) {

		this.hide();
		this.reset();

	}

}
Object.extend(DoChangePasswordAjax.prototype, CommonAjax);

DoChangeEmailAjax = Class.create();
DoChangeEmailAjax.prototype = {

	id: 'changeEmail',
	page: projectUrl +'/member/account/doChangeEmail',

	execute: function(object) {

		this.hide();

		if($('accountEmail').innerHTML != object.eUserConnected.account.email) {

			$('accountEmail').innerHTML = object.eUserConnected.account.email;

			$('changeProfileEmail').value = object.eUserConnected.account.email;

		}

		this.reset();

		Event.observe(document.body, 'click', checkMessageBoxClosed.bind(this));

	}

}
Object.extend(DoChangeEmailAjax.prototype, CommonAjax);

DoCheckEmailAjax = Class.create();
DoCheckEmailAjax.prototype = {

	id: 'checkEmail',
	page: projectUrl +'/member/account/doCheckEmail',

	execute: function(object) {

		this.hide();
		this.reset();

	}

}
Object.extend(DoCheckEmailAjax.prototype, CommonAjax);


DoChangeTimeZoneAjax = Class.create();
DoChangeTimeZoneAjax.prototype = {

	id: 'changeTimeZone',
	page: projectUrl +'/member/account/doChangeTimeZone',

	execute: function(object) {

		this.hide();
		this.reset();

		$('accountTimeZone').innerHTML = object.accountTimeZone;

	}

}

Object.extend(DoChangeTimeZoneAjax.prototype, CommonAjax);

var ChangeProfileBox = {

	show: function() {
		if($('changeProfileContent').innerHTML == '') {
			Ajax.JSON(new ChangeProfileAjax());
		}
	}

}

var ChangeProfileAjax = Class.create();
ChangeProfileAjax.prototype = {

	id: 'changeProfile',
	page: projectUrl +'/member/account/changeProfile',

	execute: function(object) {
		this.content();
	}

}

Object.extend(ChangeProfileAjax.prototype, CommonAjax);

function checkMessageBoxClosed(pe){
	if(!$('messageBox').visible()) {
		pe.stop();
		window.location.replace(projectUrl +'/member/account/');
	}
}
function addListener(element, type, expression) {

	bubbling = false;

	if(window.addEventListener) { // Standard

		element.addEventListener(type, expression, bubbling);
		return true;

	} else if(window.attachEvent) { // IE

		element.attachEvent('on' + type, window.location.reload);
		return true;

	} else return false;

}

DoChangeProfilePassAjax = Class.create();
DoChangeProfilePassAjax.prototype = {

	id: 'changeProfilePass',
	page: projectUrl +'/member/account/doChangeProfilePass',

	construct : function(arguments) {
		if($("paymentLoadingDiv")) {
			$("paymentLoadingDiv").show();
		}
	},
	
	execute: function(object) {
		this.reload('message=changeProfile');
	},

	handleMessage: function(object) {
	}

}
Object.extend(DoChangeProfilePassAjax.prototype, CommonAjax);

DoChangeProfileAjax = Class.create();
DoChangeProfileAjax.prototype = {

	id: 'changeProfile',
	page: projectUrl +'/member/account/doChangeProfile',

	execute: function(object) {

		this.hide();
		Event.observe(document.body, 'click', checkMessageBoxClosed.bind(this));

	}

}
Object.extend(DoChangeProfileAjax.prototype, CommonAjax);
//---------------------------------------------------------------------------------------

DoChangeSettingsAjax = Class.create();
DoChangeSettingsAjax.prototype = {

	id:'changeSettings',
	page: projectUrl +'/member/account/doChangeSettings',

	execute: function(object) {
		if(typeof(object.userPreference) != 'undefined' && typeof(object.newValue) != 'undefined') {
			if($('userSettings-'+object.userPreference)) {
				$('userSettings-'+object.userPreference).innerHTML = object.newValue;
			}
			if($('userSettingsAction-'+object.userPreference)) {
				$('userSettingsAction-'+object.userPreference).innerHTML = object.switchButton;
			}
		}
	}
}

Object.extend(DoChangeSettingsAjax.prototype, CommonAjax);

DoDeleteAjax = Class.create();
DoDeleteAjax.prototype = {

	id: 'doDelete',
	page: projectUrl +'/member/account/doDelete',

	execute: function(object) {

	}

}
Object.extend(DoDeleteAjax.prototype, CommonAjax);
