// dojo imports
dojo.require("dojo.parser");
dojo.require("dijit.Dialog");
dojo.require("dijit.dijit");
dojo.require("dojox.layout.ContentPane");

dojo.addOnLoad(function() {
	// customize the dialog dijit instance
	dijit.byId("dialogNode").titleBar.style.display = "none";
	dijit.byId("dialogNode").containerNode.style.border = "none";
	dijit.byId("dialogNode").containerNode.style.padding = "0px";
	dijit.byId("dialogNode").containerNode.style.backgroundColor = "transparent";
});

function changeFrameHeight(height)
{
	var dialogInnerContent = document.getElementById('dialogInnerContent');

	//dialogInnerContent.document.body.style.height = height;     //inner body height
	dialogInnerContent.style.height = height + "px";                   //iframe height


}

function displayDialog(url) {
	// retrieve content via ajax call
	dojo.xhrGet({
  		url: url.split("#")[0],
		timeout: 60000,
		load: function(response, ioArgs) {
			// load and parse successful response data
			dijit.byId("dialogInnerContent").setContent(response);
			// display dialog
			dijit.byId("dialogNode").show();
			// reset scrollTo position for this container
			dojo.byId("iframeContainer").scrollTop = 0;
			// if an anchor link is specified, scroll to that position
			if (url.indexOf("#") != -1) {
				var anchorName = url.split("#")[1].split(/[\&\?]/)[0];				
				dojo.forEach(dojo.query("a[name='" + anchorName + "']"), function(node) {
					// scroll to y possition of anchor link minus y position of content container
					dojo.byId("iframeContainer").scrollTop = dojo.coords(node).y - dojo.coords(dojo.byId("dialogInnerContent")).y;
				});
			}
			return response;
		},
		error: function(response, ioArgs) {
			// error response
			dijit.byId("dialogInnerContent").setContent(response.responseText);
			// display dialog
			dijit.byId("dialogNode").show();
			return response;
		}
	});
}