/**
 * Ways to display a consistant dialog box.
 */
var UKISA = UKISA || {};
UKISA.site = UKISA.site || {};

UKISA.site.Dialog = {
	context: null,
	Content: function(ct, title, options) {
		var panel, hd, db, ft, instance, content;

		// Kill any old YUI Panel
		if (this.context) {
			this.context.destroy();
			this.context = null;
		}

		// This creates the custom shadow around the Panel box.
		panel = document.createElement("div");

		hd = panel.cloneNode(false);
		bd = panel.cloneNode(false);
		ft = panel.cloneNode(false);

		panel.id = "ukisa-dialog";
		panel.className = "yui-panel-container yui-dialog shadow";
		hd.className = "hd";
		bd.className = "bd";
		ft.className = "ft";

		panel.appendChild(hd);
		panel.appendChild(bd);
		panel.appendChild(ft);

		document.body.appendChild(panel);

		instance = this;

		// Define various event handlers for Dialog
		var handleSubmit = function() {
			this.submit();
		};
		var handleCancel = function() {
			this.cancel();
		};



		this.context = new YAHOO.widget.Dialog("ukisa-dialog", { 
			fixedcenter: true,
			modal: true,
			visible : false, 
			close: true,
			underlay: "shadow",
			constraintoviewport: true,
			zIndex: 1100,
			
			autofillheight: "body"
		});

		if (title && title.length) {
			this.context.setHeader(title);
		}
		
		// turn it into an asynchronous form
		
				var handleSuccess = function(o) {
				var response = o.responseText;
				//alert(response);
				//alert(o.argument);
				UKISA.site.Modal.Content(o.argument[0], o.argument[1]);
			
				};
				var handleFailure = function(o) {
					alert("Submission failed: " + o.status);
				};
		
				
				// Wire up the success and failure handlers
				this.context.callback = { success: handleSuccess,
					failure: handleFailure, argument: [options,title] };
		
		
		// end turn it into a form
		

		title = title || "this";

		ct = document.getElementById(ct);
		
		if (ct) {
			content = ct.cloneNode(true);
		}

		this.context.setBody(content);	
		this.context.render();
		this.context.show();

		return false;
	}
};

UKISA.site.Download = {
	context: null,
		Content: function(ct, title, options) {	
		var swfield;
		swfield = document.getElementById("softwaretype");
		swfield.value = title;
		UKISA.site.Dialog.Content('submit-details', title ,ct);
	}
}
