/**
 * @author mad
 marion a. douglas
 mariond@ufl.edu
 IFAS Communication Services
 352-392-2411
 */
YAHOO.namespace("example.container");

function init() {
	
	// Define various event handlers for Dialog
	var handleSubmit = function() {
		var GMTdate = new Date();
		GMTdate = new Date('December 31, 2015');
		setCookie("TookCalendarSurvey","yes", "", GMTdate.toGMTString());
		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.example.container.dialog1 = new YAHOO.widget.Dialog("dialog1", 
																{ width : "400px",
																  fixedcenter : true,
																  visible : false, 
																	underlay: "matte",
																	modal: true,
																  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.example.container.dialog1.validate = function() {
		var data = this.getData();
		if (data.age == "") 
		{
			alert("Please enter your age in years.");
			return false;
		}
		else if (data.zip == "")
		{
		    alert("Please enter your zip code.");
		    return false;
		}
		else 
		{
			return true;
		}
				    
	};

	// Wire up the success and failure handlers
	YAHOO.example.container.dialog1.callback = { success: handleSuccess,
												 failure: handleFailure };
	
	// Render the Dialog
	YAHOO.example.container.dialog1.render();
	
	var alreadyResponded = getCookieValue("TookCalendarSurvey");
	//alert(alreadyResponded + " = responded");
	if (alreadyResponded != null)
	{
		//alert("You've been here before");
	}
	else
	{
		//alert("Never heard of you");
		YAHOO.example.container.dialog1.show();
	/*	var GMTdate = new Date();
		GMTdate = new Date('December 31, 2015');
		setCookie("TookCalendarSurvey","yes", "", GMTdate.toGMTString());
	*/
	}

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

YAHOO.util.Event.onDOMReady(init);
