YAHOO.namespace("example.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];
//		alert(response);
		document.getElementById("resp").innerHTML = response;
	};
	var handleFailure = function(o) {
		alert("Błąd: " + o.status);
	};
	
	// Instantiate the Dialog
	YAHOO.example.container.dialog1 = new YAHOO.widget.Dialog("dialog1", 
							{ width : "30em",
							  fixedcenter : true,
			  				  close:true, 
			 				  zindex:4,
			 				  modal:true,  
							  visible : false, 
							  constraintoviewport : true,
							  buttons : [
							  			 { text:"Anuluj", handler:handleCancel } ,
							  			 { text:"Wyślij", handler:handleSubmit, isDefault:true }
								      ]
							});

	// 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.email == "" && data.phone == "") {
			alert("Wpisz telefon lub adres email.");
			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();
	YAHOO.util.Event.addListener("show", "click", YAHOO.example.container.dialog1.show, YAHOO.example.container.dialog1, true);
	YAHOO.util.Event.addListener("show2", "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);