// JavaScript Document
// Instantiate the Dialog
function init() {	
	// Define various event handlers for Dialog
	var handleSubmit = function() {		
		this.submit();
	};
	var handleCancel = function() {
		YAHOO.util.Cookie.set("nsign", "done", {expires: new Date("January 12, 2025")});
		this.cancel();
	};
	var handleSuccess = function(o) {
		alert(o.responseText);
		if (o.responseText.search(/Error/) >=0 ) {
			dialog1.show();
		}
	};
	var handleFailure = function(o) {
		alert("Your submission failed. Status: " + o.status); 
		dialog1.show();
	};

	// Instantiate the Dialog
	dialog1 = new YAHOO.widget.Dialog("dlgNewsLetter", 
							{ width 		: "410px",
							  fixedcenter 	: true,
							  visible 		: false,							  
							  constraintoviewport 	: true,
							  hideaftersubmit 		: true,
							  close : false,
							  effects:[{effect:YAHOO.widget.ContainerEffect.FADE,duration:0.5}, {effect:YAHOO.widget.ContainerEffect.SLIDE,duration:0.5}],
							  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
	dialog1.validate = function() {
		var data = this.getData();		
		if (data.name == "") {
			alert("Please enter Full Name!");
			return false;
		} else if (data.email == "") {
			alert("Please enter Email!");
			return false;
		} else {
			return true;
		}
	};

	// Wire up the success and failure handlers
	dialog1.callback = { success: handleSuccess, failure: handleFailure };
	// Render the Dialog
	dialog1.render();
	dialog1.show();	
}

window.onload = function () {
	document.getElementById("dlgNewsLetter").style.display='';
	init();	
}
