	/* Cookie name */
	var cookieName = 'Fishnet2Agrmt';
	
	/* The global modal dialog stub */
	var g_Modal = null;

	function check_agreement()
	{
		/* Sweep unnecessary empty text nodes. */
		DOMManager.sweep();

		/*
		 * Attach supporting css bind required
		 * classes for transparency support in Opera.
		 */
		addExtensionsForOpera();

		/* Attach opacity css. */
		attachOpacityCSS();

		/* Adjust height. */
		adjustHeight();

		/* Create the modal dialog */
		g_Modal=new ModalDialog("ModalBG","DialogWindow",
			"DialogContent","dialogAcceptBtn");

		/* Re-adjust height on window resize */
		EventHandler.addEventListener(window,"resize",window_resize);
		
		//EventHandler.addEventListener(document,"dblclick",document_dblclick);
		//Check for agreement cookie.
		var agreed = getCookie(cookieName);
		agreed = (agreed && (parseInt(agreed) == 1))? true : false
		if (!agreed)
			do_modal();
		else
			setCookie(1);
	}

	function window_resize(evt)
	{
		adjustHeight();
	}

	function adjustHeight()
	{
		var intWindowHeight=WindowObject.getOuterDimension().getY();
		var intWindowWidth=WindowObject.getOuterDimension().getX();
		var dynModalBG=new DynamicLayer("ModalBG");
		var intModalHeight=dynModalBG.getHeight();
		var intModalWidth=dynModalBG.getWidth();

		if(intModalHeight<intWindowHeight)
		{
			dynModalBG.setHeight(intWindowHeight);
		}
		
		if(intModalWidth<intWindowWidth)
		{
			dynModalBG.setWidth(intWindowWidth);
		}
	}

	function addExtensionsForOpera()
	{
		/* classes for opera */
		var ModalBG=new CBObject("ModalBG").getObject();
		if(typeof(window.opera)!="undefined")
		{
			ModalBG.className="modalOpera";
		}
	}

	function attachOpacityCSS()
	{
		/*
		 * CSS for opacity support
		 * Note that this can be directly added to the body.
		 * If you do not care about blindly adhering to standards
		 * you can directly include the rules into Master.css
		 *
		 * Do I care? Yes and no.(visit http://www.sarmal.com/Exceptions.aspx
		 * to learn how I feel about it).
		 */
		var opacityCSS = document.createElement("link");
		opacityCSS.type="text/css";
		opacityCSS.rel="stylesheet";
		opacityCSS.href="modalDivOpacity.css";
		document.getElementsByTagName("head")[0].appendChild(opacityCSS);
	}

	function do_modal()
	{
		/* create an AJAX request */
		var ajax = _.ajax();
		/*
		 * Note that _.ajax(); is a shorthand notation 
		 * for new XHRequest();
		 * Visit http://sardalya.pbwiki.com/Shortcuts details.
		 */

		/* 
		 * You can add as many fields as you like to the post data. 
		 * Normally the server will use this data to create an
		 * output that makes sense which may be an XML, a JSON String
		 * or an HTML String.
		 */
		ajax.removeAllFields();
		//ajax.addField("name","John");
		//ajax.addField("surname","Doe");

		ajax.oncomplete=ajax_complete;
		ajax.onerror=ajax_error;

		g_Modal.show("Fetching data... Please wait...");

		/*
		 * Disable close action if you want to force the user 
		 * to wait for the outcome of the AJAX request.
		 * Although it is generally not recommended 
		 * this may be necessary at certain times.
		 */
		g_Modal.disableClose();

		/* Post data to the server. */
		ajax.get("agreement.htm");

		/* Stop event propagation. */
		//new EventObject(evt).cancelDefaultAction();
	}

	/* Triggered when a successful AJAX response comes from the server.*/
	function ajax_complete(strResponseText,objResponseXML)
	{
		g_Modal.show(strResponseText);
		
		/* Re-activate close button. */
		g_Modal.enableClose();
	}

	/* Triggered when server generates an error. */
	function ajax_error(intStatus,strStatusText)
	{
		g_Modal.show("Error code: ["+ intStatus+ "] error message: [" + 
			strStatusText + "].");

		/* Re-activate close button. */
		g_Modal.enableClose();
	}
	
	function setCookie(value)
	{
		document.cookie = cookieName + "=" + escape(value); //non-persistent cookie;
	}
	
	function getCookie()
	{
		if (document.cookie.length > 0)
		{
			c_start = document.cookie.indexOf(cookieName + "=");
			if (c_start != -1)
			{
				c_start = c_start + cookieName.length + 1;
				c_end = document.cookie.indexOf(";", c_start);
				
				if (c_end == -1)
					c_end = document.cookie.length;
					
				return unescape(document.cookie.substring(c_start, c_end));
			}
		}
		return "";
	}