

/*********************************
*  nesslercard CONTAINER OBJECT  *
*********************************/
var nesslercard=new Object;
nesslercard.eID='nesslercard_pi1';
nesslercard.requestURL='index.php?eID='+nesslercard['eID'];



/**********************************
*  nesslercard_customerMGM CLASS  *
**********************************/
var nesslercard_customerMGM=Class.create({
	newAccount:function(cardnumber,firstname,lastname,email) {
		new Ajax.Request(nesslercard['requestURL'],{
			parameters:'action=new_account&cardnumber='+encodeURIComponent(cardnumber)+'&firstname='+encodeURIComponent(firstname)+'&lastname='+encodeURIComponent(lastname)+'&email='+encodeURIComponent(email),
			onSuccess:function(transport) {
				if(!transport.responseJSON) {alert(transport.responseText);}
				this.showSuccess('nesslercard_message_success',transport.responseJSON['returnMessage']);
			}.bind(this),
			onFailure:function(transport) {
				if(!transport.responseJSON) {alert(transport.responseText);}
				this.showError('nesslercard_message_error',transport.responseJSON['returnMessage']);
			}.bind(this)
		});
	},
	activateAccount:function(cardnumber,hash) {
		new Ajax.Request(nesslercard['requestURL'],{
			parameters:'action=activate_account&cardnumber='+encodeURIComponent(cardnumber)+'&hash='+encodeURIComponent(hash),
			onSuccess:function(transport) {
				if(!transport.responseJSON) {alert(transport.responseText);}
				this.showSuccess('nesslercard_message_success',transport.responseJSON['returnMessage']);
			}.bind(this),
			onFailure:function(transport) {
				if(!transport.responseJSON) {alert(transport.responseText);}
				this.showError('nesslercard_message_error',transport.responseJSON['returnMessage']);
			}.bind(this)
		});
	},
	dataMismatch:function(cardnumber,gender,title,firstname,lastname,email,notes) {
		new Ajax.Request(nesslercard['requestURL'],{
			parameters:'action=data_mismatch&cardnumber='+encodeURIComponent(cardnumber)+'&gender='+encodeURIComponent(gender)+'&title='+encodeURIComponent(title)+'&firstname='+encodeURIComponent(firstname)+'&lastname='+encodeURIComponent(lastname)+'&email='+encodeURIComponent(email)+'&notes='+encodeURIComponent(notes),
			onSuccess:function(transport) {
				if(!transport.responseJSON) {alert(transport.responseText);}
				this.showSuccess('nesslercard_message_success',transport.responseJSON['returnMessage']);
			}.bind(this),
			onFailure:function(transport) {
				if(!transport.responseJSON) {alert(transport.responseText);}
				this.showError('nesslercard_message_error',transport.responseJSON['returnMessage']);
			}.bind(this)
		});
	},
	passwordReminder:function(cardnumber) {
		new Ajax.Request(nesslercard['requestURL'],{
			parameters:'action=password_reminder&cardnumber='+encodeURIComponent(cardnumber),
			onSuccess:function(transport) {
				if(!transport.responseJSON) {alert(transport.responseText);}
				this.showSuccess('nesslercard_message_success',transport.responseJSON['returnMessage']);
			}.bind(this),
			onFailure:function(transport) {
				if(!transport.responseJSON) {alert(transport.responseText);}
				this.showError('nesslercard_message_error',transport.responseJSON['returnMessage']);
			}.bind(this)
		});
	},
	changeEmail:function(newEmail,newEmail_repeat) {
		new Ajax.Request(nesslercard['requestURL'],{
			parameters:'action=change_email&newEmail='+encodeURIComponent(newEmail)+'&newEmail_repeat='+encodeURIComponent(newEmail_repeat),
			onSuccess:function(transport) {
				if(!transport.responseJSON) {alert(transport.responseText);}
				this.showSuccess('nesslercard_changeemail_message_success',transport.responseJSON['returnMessage']);
			}.bind(this),
			onFailure:function(transport) {
				if(!transport.responseJSON) {alert(transport.responseText);}
				this.showError('nesslercard_changeemail_message_error',transport.responseJSON['returnMessage']);
			}.bind(this)
		});
	},
	activateEmail:function(cardnumber,hash) {
		new Ajax.Request(nesslercard['requestURL'],{
			parameters:'action=activate_email&cardnumber='+encodeURIComponent(cardnumber)+'&hash='+encodeURIComponent(hash),
			onSuccess:function(transport) {
				if(!transport.responseJSON) {alert(transport.responseText);}
				this.showSuccess('nesslercard_message_success',transport.responseJSON['returnMessage']);
			}.bind(this),
			onFailure:function(transport) {
				if(!transport.responseJSON) {alert(transport.responseText);}
				this.showError('nesslercard_message_error',transport.responseJSON['returnMessage']);
			}.bind(this)
		});
	},
	changePassword:function(oldPW,newPW,newPW_repeat) {
		new Ajax.Request(nesslercard['requestURL'],{
			parameters:'action=change_password&oldPW='+encodeURIComponent(oldPW)+'&newPW='+encodeURIComponent(newPW)+'&newPW_repeat='+encodeURIComponent(newPW_repeat),
			onSuccess:function(transport) {
				if(!transport.responseJSON) {alert(transport.responseText);}
				this.showSuccess('nesslercard_changepassword_message_success',transport.responseJSON['returnMessage']);
			}.bind(this),
			onFailure:function(transport) {
				if(!transport.responseJSON) {alert(transport.responseText);}
				this.showError('nesslercard_changepassword_message_error',transport.responseJSON['returnMessage']);
			}.bind(this)
		});
	},
	changeData:function(gender,title,firstname,lastname,notes) {
		new Ajax.Request(nesslercard['requestURL'],{
			parameters:'action=change_data&gender='+encodeURIComponent(gender)+'&title='+encodeURIComponent(title)+'&firstname='+encodeURIComponent(firstname)+'&lastname='+encodeURIComponent(lastname)+'&notes='+encodeURIComponent(notes),
			onSuccess:function(transport) {
				if(!transport.responseJSON) {alert(transport.responseText);}
				this.showSuccess('nesslercard_changedata_message_success',transport.responseJSON['returnMessage']);
			}.bind(this),
			onFailure:function(transport) {
				if(!transport.responseJSON) {alert(transport.responseText);}
				this.showError('nesslercard_changedata_message_error',transport.responseJSON['returnMessage']);
			}.bind(this)
		});
	},
	newsletterMGM:function() {
	   var newsletter='';
		$$('.nesslercard_newsletterCategory').each(function(item){
			if($F(item)) {newsletter=newsletter+$F(item)+',';}
		});
		newsletter=newsletter.removeLastChar();
		if(newsletter.blank()) {newsletter='REMOVE_ALL';}
		new Ajax.Request(nesslercard['requestURL'],{
			parameters:'action=newsletter_mgm&newsletter='+encodeURIComponent(newsletter),
			onSuccess:function(transport) {
				if(!transport.responseJSON) {alert(transport.responseText);}
				this.hideError('nesslercard_newslettermgm_message_error');
				this.showSuccess('nesslercard_newslettermgm_message_success',transport.responseJSON['returnMessage']);
			}.bind(this),
			onFailure:function(transport) {
				if(!transport.responseJSON) {alert(transport.responseText);}
				this.hideSuccess('nesslercard_newslettermgm_message_success');
				this.showError('nesslercard_newslettermgm_message_error',transport.responseJSON['returnMessage']);
			}.bind(this)
		});
	},
	newsletterRemove:function(email) {
		new Ajax.Request(nesslercard['requestURL'],{
			parameters:'action=newsletter_remove&email='+encodeURIComponent(email),
			onSuccess:function(transport) {
				if(!transport.responseJSON) {alert(transport.responseText);}
				this.showSuccess('nesslercard_message_success',transport.responseJSON['returnMessage']);
			}.bind(this),
			onFailure:function(transport) {
				if(!transport.responseJSON) {alert(transport.responseText);}
				this.showError('nesslercard_message_error',transport.responseJSON['returnMessage']);
			}.bind(this)
		});
	},
	showSuccess:function(id,message) {
		Effect.Fade(id,{duration:0.5,afterFinish:function(){
			$(id).addClassName('nesslercard_message_success_active');
			$(id).update(message);
			Effect.Appear(id);
		}});
	},
	showError:function(id,message) {
		$(id).addClassName('nesslercard_message_error_active');
		$(id).update(message);
		Effect.Shake(id,{distance:10});
	},
	hideSuccess:function(id) {
	   $(id).removeClassName('nesslercard_message_success_active');
	   $(id).update('');
	},
	hideError:function(id) {
	   $(id).removeClassName('nesslercard_message_error_active');
	   $(id).update('');
	}
});


