

YAHOO.namespace("example.container");

YAHOO.util.Event.onDOMReady(function () {

/*
var settings = {
			tl: { radius: 20 },
			tr: { radius: 20 },
			bl: { radius: 20 },
			br: { radius: 20 },
			antiAlias: true
		}

		var divObj = document.getElementById("dialog1");

		curvyCorners(settings, divObj);
	*/
	// Define various event handlers for Dialog
	var handleSubmit = function() {
		this.submit();
	};
	var handleCancel = function() {
		this.cancel();
	};
	var handleSuccess = function(o) {
		var response = o.responseText;
		if(response == "OK")
			YAHOO.example.container.panel1.show();
		else if(response == "DUP")
			YAHOO.example.container.panel2.show();
		else  
			alert("Submission failed: ");
		//response = response.split("<!")[0];
		//document.getElementById("resp").innerHTML = response;
	};
	var handleFailure = function(o) {
		//YAHOO.example.container.panel1.show();
		alert("Submission failed: " + o.status);
	};

		// Remove progressively enhanced content class, just before creating the module
		YAHOO.util.Dom.removeClass("dialog1");

	// Instantiate the Dialog
	YAHOO.example.container.dialog1 = new YAHOO.widget.Dialog("dialog1", 
							{ width : "405px",
								visible : false,
								close:false,
								constraintoviewport : true,
								fixedcenter : true,
								underlay : "none",
							//	modal : true,
								draggable : true,
								effect:{effect:YAHOO.widget.ContainerEffect.FADE,duration:0.5}
								//effect:{effect:YAHOO.widget.ContainerEffect.FADE,duration:0}
							});
							
		// Instantiate the Thank you Panel
	YAHOO.example.container.panel1 = new YAHOO.widget.Panel("panel1", 
							{ width : "405px",
								visible : false,
								close:false,
								constraintoviewport : true,
								fixedcenter : true,
							//	modal : true,
								draggable : true,
								effect:{effect:YAHOO.widget.ContainerEffect.FADE,duration:0.5}
							});
							
		// Instantiate the already subscribed Panel
	YAHOO.example.container.panel2 = new YAHOO.widget.Panel("panel2", 
							{ width : "405px",
								visible : false,
								close:false,
								constraintoviewport : true,
								fixedcenter : true,
							//	modal : true,
								draggable : true,
								effect:{effect:YAHOO.widget.ContainerEffect.FADE,duration:0.5}
							});

	// 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();
		// YAHOO.example.container.dialog1.cfg.setProperty("effect", {effect:YAHOO.widget.ContainerEffect.FADE,duration:0});
		 var msg = "";
		 if (data.title == "")
			msg += "\n   Your Title     ";
		if (data.firstname == "")
			msg += "\n   Your First name     ";
		if (data.surname == "")
			msg += "\n   Your Surname     ";
		if(data.email == "" || (!isEmail(data.email)))
			msg += "\n   A valid email address     ";
		if(!DS_selectedDate)
			msg += "\n   A valid date of birth     ";
		
		if(msg != ""){
			alert("Please supply the following:          \n" + msg);
			return false;
		}else{
			return true;
		}
	};
	
		// Render the Panels
	YAHOO.example.container.panel1.render();
	YAHOO.example.container.panel2.render();
	
	// Wire up the success and failure handlers
	YAHOO.example.container.dialog1.callback = { success: handleSuccess,
								 failure: handleFailure };
	
	// Render the Dialog  
	YAHOO.example.container.dialog1.render();
	
	YAHOO.util.Event.addListener("show", "click", function() {
		YAHOO.example.container.dialog1.show();
		//YAHOO.example.container.panel1.cfg.setProperty("effect", {effect:YAHOO.widget.ContainerEffect.FADE,duration:0});
		//YAHOO.example.container.panel2.cfg.setProperty("effect", {effect:YAHOO.widget.ContainerEffect.FADE,duration:0});
		formElements = YAHOO.example.container.dialog1.getFocusableElements();
		YAHOO.example.container.dialog1.setTabLoop(formElements[1], formElements[9]);
		YAHOO.example.container.dialog1.form.reset();
		setTimeout("formElements[3].focus()", 1000);
	}, YAHOO.example.container.dialog1, true);
	
	YAHOO.util.Event.addListener("hide", "click", YAHOO.example.container.dialog1.hide, YAHOO.example.container.dialog1, true);
	
	YAHOO.util.Event.addListener("hide2", "click", function() {
		//	YAHOO.example.container.panel1.cfg.setProperty("effect", {effect:YAHOO.widget.ContainerEffect.FADE,duration:0.5});
			YAHOO.example.container.panel1.hide();
	//		YAHOO.example.container.dialog1.cfg.setProperty("effect", {effect:YAHOO.widget.ContainerEffect.FADE,duration:0.5});
	}, YAHOO.example.container.panel1, true);
	
		YAHOO.util.Event.addListener("hide3", "click", function() {
	//		YAHOO.example.container.panel2.cfg.setProperty("effect", {effect:YAHOO.widget.ContainerEffect.FADE,duration:0.5});
			YAHOO.example.container.panel2.hide();
	//		YAHOO.example.container.dialog1.cfg.setProperty("effect", {effect:YAHOO.widget.ContainerEffect.FADE,duration:0.5});
	}, YAHOO.example.container.panel2, true);
	//YAHOO.util.Event.addListener("submt", "click", YAHOO.example.container.dialog1.submit, YAHOO.example.container.dialog1, true);
});


setTimeout("show_pop()", 8000);

function show_pop()
{
		YAHOO.example.container.dialog1.show();
		formElements = YAHOO.example.container.dialog1.getFocusableElements();
		YAHOO.example.container.dialog1.setTabLoop(formElements[1], formElements[9]);
		YAHOO.example.container.dialog1.form.reset();
		setTimeout("formElements[3].focus()", 1000);
}