
Promo200910 = function(){ this.init(); }

Promo200910.prototype.init = function()
{
	$("input[name=whatMovie]").labelInput("What movie?");
	$("input[name=whatBot]").labelInput("What else?");
	$("textarea[name=mailingAddress]").labelInput("Mailing address");
	$("input[name=yourEmail]").labelInput("E-mail address");
	$("input[name=yourName]").labelInput("Your name");

	$("input[name=submit]").bind("click", this, this.handleSubmit);	
}

Promo200910.prototype.getValue = function(name)
{
	var j = $("[name=" + name + "]");
	if (j.hasClass("empty"))
	{
		return null;
	}
	return j.val();
}

Promo200910.prototype.handleSubmit = function(e)
{
	var self = e.data;
	e.preventDefault();
	self._handleSubmit();
}

Promo200910.prototype._handleSubmit = function()
{
	var ajaxParams = this.getDefaultAjaxParams();
	ajaxParams.success = this.handlePromoReturn.hitch(this);
	ajaxParams.data = {
		"whatMovie":      this.getValue("whatMovie"), 
		"whatBot":        this.getValue("whatBot"),
		"subscribe":      this.getValue("subscribe"),
		"mailingAddress": this.getValue("mailingAddress"),
		"yourEmail":      this.getValue("yourEmail"), 
		"yourName":       this.getValue("yourName")
		};
	jQuery.ajax(ajaxParams);
};

Promo200910.prototype.handlePromoReturn = function(response, success)
{
	if (success == "success")
	{
		this.replaceFormWithResponse(response);
	}
};

Promo200910.prototype.replaceFormWithResponse = function(response)
{
	$('#giveaway_2009_10_landmark').html(response);
}
	
Promo200910.prototype.getDefaultAjaxParams = function()
{
	return { 
		dataType: "html",
		type: "POST",
		url: "/resources/modules/giveaway_2009_10_landmark.php",
		error: this.ajaxError
		};
};


var oPromo200910;
$(document).ready(function(){
   oPromo200910 = new Promo200910();
 });

function hitch(object, method)
{
	return function ()
	{
		if ("function" == typeof method)
		{
			return method.apply(object, arguments);
		} else {
			return obj[method].apply(object, arguments);
		}
	};
}

