YAHOO.namespace("fs.container");

function init() {

	// Define various event handlers for Dialog
	var handleSubmit = function() {
		this.submit();
	};
	var handleCancel = function() {
		this.cancel();
	};
	var handleSuccess = function(o) {
		var response = o.responseText;
		response = response.split("<!")[0];
		document.getElementById("resp").innerHTML = response;
	};
	var handleFailure = function(o) {
		alert("Submission failed: " + o.status);
	};

	// Instantiate the Dialog
	YAHOO.fs.container.sendmail = new YAHOO.widget.Dialog("sendmail", 
							{ width : "30em",
							  fixedcenter : true,
							  visible : false, 
							  constraintoviewport : true,
							  buttons : [ { text:"Submit", handler:handleSubmit, isDefault:true },
								      { text:"Cancel", handler:handleCancel } ]
							});

	// Validate the entries in the form to require that both first and last name are entered
	YAHOO.fs.container.sendmail.validate = function() {
		var data = this.getData();
		if (data.firstname == "" || data.lastname == "") {
			alert("Please enter your first and last names.");
			return false;
		} else {
			return true;
		}
	};

	// Wire up the success and failure handlers
	YAHOO.fs.container.sendmail.callback = { success: handleSuccess,
						     failure: handleFailure };

	// Render the Dialog
	YAHOO.fs.container.sendmail.render();

	YAHOO.util.Event.addListener("show", "click", YAHOO.fs.container.sendmail.show, YAHOO.fs.container.sendmail, true);
	YAHOO.util.Event.addListener("hide", "click", YAHOO.fs.container.sendmail.hide, YAHOO.fs.container.sendmail, true);
}

YAHOO.util.Event.onDOMReady(init);
