var Quickform = Class.create();

Quickform.prototype = {

	classname: "Quickform",
	
	initialize: function($subject,$container,$collector) {	
		$subject ? this.$subject = $subject : this.$subject = "";
		$container ? this.$container = $($container) : this.$container = $(document.body);
		$collector ? this.$collector = $collector : this.$collector = "";
		this._uiCreate();
	},
	
	_uiCreate: function() {
		if (!this.$container) {
			return false;
		}
				
		var $o = this.$container.cumulativeOffset();
		this.$x = $o[0];
		this.$y = $o[1];
		
		var $d = this.$container.getDimensions();
		this.$w = $d[0];
		this.$h = $d[1];
		
		this.$ui = new Windowframe('',this.$x, this.$y,'250','',1,1);
		
		this.$ui.setBackgroundColor("#648737");
				
		var $tmp = "<div id='qfui' class='quickform'><h4>"+this.$subject+"</h4><p>Please enter your email address to receive updates on our Ft. Worth grand opening*</p><form id='quickformform'><input type='text' name='qfemail' id='qfemail'></input><br/><input type='submit' name='qfcancel' id='qfcancel' value='No thanks!' /><input type='submit' name='qfsubmit' id='qfsubmit' value='add to mailing list' /></form></div>";
		
		this.$ui.$content.update($tmp);
		Event.observe(document,"keypress",this.submitData.bindAsEventListener(this));
		Event.observe($("qfsubmit"),"click",this.submitData.bindAsEventListener(this));
		
	},
	
	submitData: function(e) {	
		if (e.type == "keypress") {
			if (e.keyCode==13) {
				e.stop();
				e.preventDefault();
			} else {
				return false;
			}
		}
		
		e.preventDefault();		
		this.$recipient = $F("qfemail");
		
		if (checkEmail(this.$recipient)) {

			/* begin ajax post request */
			var $ajx = new Ajax.Request(
					this.$collector,
					{
						method:'post',			
						parameters: {
							subscriberemail:this.$recipient
						},

						onFailure: function(response) {
							window.alert("We're sorry, but our server isn't responding. Please try your request again shortly.");
							this.$ui.kill();
						},

						onComplete: function(response) {
							if (response.responseText == "existing") {
								alert("You're already on our list. Thanks for your interest!");
								this.$ui.kill();
							} else if (response.responseText == "1") {
								alert("You have been added to our email update list. Thanks for your interest!");
								this.$ui.kill();
							} else if (response.responseText == "0") {
								alert("The email address you supplied does not appear to be valid. Please try again.");
								this.$ui.kill();
							}
						}.bind(this)
					}
				);
			/* end ajax post request */		
		
		}
		
	},
	
	kill: function() {
	}

}