var dialog1;

function init() {
	// Define various event handlers for Dialog
	var handleSubmit = function(o) {
		this.submit();
	};

	var handleCancel = function() {
		this.cancel();
	};

	var handleSuccess = function(o) {
		var response = o.responseText;
                var elephant = document.getElementById("dialog1");
                if (response.indexOf('error') == -1)
                        elephant.style.display = 'none';
		document.getElementById("resp").innerHTML = response;
	};

	var handleFailure = function(o) {
		alert("Submission failed: " + o.status);
	};

	// Instantiate the Dialog
	dialog1 = new YAHOO.widget.Dialog("dialog1", { width : "350px",
                  hideaftersubmit: false,  fixedcenter : true,
                  visible : false,  constraintoviewport : true,
		  buttons : [ { text:"Send", handler:handleSubmit, isDefault:true },
                              { text:"Cancel", handler:handleCancel } ]
	});


	// Wire up the success and failure handlers
	dialog1.callback = { success: handleSuccess, failure: handleFailure };
	
	// Render the Dialog
	dialog1.render();
}

function showDialog(whoTo){
   dialog1.show();
   var to_field  = document.getElementById("toField");
   to_field.value = whoTo;
};

YAHOO.util.Event.onDOMReady(init);

