
NlSignup = Class.create({
	initialize: function() {
		this.elT = $('newsletter');
		this.elB = $('btn_submit');
		this.elF = $('nl_feedback');
		if (this.elT && this.elB && this.elF)
			this.setup();
	},
	setup: function() {
		this.path = "nl_signup.php";
		this.elB.observe("click", this.signup.bindAsEventListener(this));
	},
	successHandler: function(transport) {
		var response = transport.responseText || "no response text";
		this.elF.innerHTML = response;
		this.elF.setStyle({display: 'block'});
	},
	failureHandler: function() {
		if (this.path == "nl_signup.php")
		{
			this.path = "../nl_signup.php";
			this.signup();
		}
		else
		{
			this.elF.innerHTML = 'Es ist ein &Uuml;bertragungsfehler aufgetreten.';
			this.elF.setStyle({display: 'block'});
		}
	},
	signup: function(event) {
		if (event)
			event.stop();
		this.elF.innerHTML = 'sende Anmeldung...';
		this.elF.setStyle({display: 'block'});
		new Ajax.Request(this.path, {
			method: 'post',
			parameters: {newsletter: this.elT.value, ajax: 1},
			onSuccess: this.successHandler.bindAsEventListener(this),
			onFailure: this.failureHandler.bindAsEventListener(this)});
	}});

document.observe("dom:loaded", function() {
	new NlSignup();
});

