
function f_open_window_max( aURL, aWinName, aMessage ) {
   if ( aMessage != '' )
	   alert(aMessage);

   var wOpen;
   var sOptions;

   var width = screen.availWidth;
   var height = screen.availHeight;
   if ( width > 1280 )
   	 width = 1280;
   if ( height > 1024 )
   	 height = 1024;
   sOptions = 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1';
   sOptions = sOptions + ',width=' + (width - 10).toString();
   sOptions = sOptions + ',height=' + (height - 122).toString();
   sOptions = sOptions + ',screenX=0,screenY=0,left=0,top=0';

   wOpen = window.open( '', aWinName, sOptions );
   wOpen.location = aURL;
   wOpen.focus();

//wOpen.moveTo( 0, 0 );
  // wOpen.resizeTo( width, height );
   return wOpen;
}

function popUp(URL, Message) {
   	var wOpen;
   	var sOptions;
   
   	if (readCookie('TermsOfUse') == null ) {
		alert('You must first agree to the GIS Disclaimer before viewing this map.');
		// redirect to disclaimer
		window.location = 'disclaimer.aspx';
	} else {
		// open the popup
		day = new Date();
		id = day.getTime();
		f_open_window_max( URL, id.toString(), Message );
	}
}

function checkDisclaimer() {
	
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

	$(document).ready(function() {
  		$('#dialog').jqm();
		$('#additional-dialog').jqm();
		
		$(".termsofuse-button").click(function() {
			if ($(".termsofuse").attr('checked') == true) {
				// if checked
				$("span#lblRequired").hide();
				acceptDisclaimer();
			} else {
				// show error
				$("span#lblRequired").show();
			}
			return false;
		});
		$('#btnOk').click(function() {
			showDestination();
			return false;
		});
	});
	
	function acceptDisclaimer() {
		$.cookie('TermsOfUse', true, { expires: 1 }); // set cookie
		showDestination();		
	}
	
	function showDestination(url) {
		$('#dialog').jqmHide();
		$('#additional-dialog').jqmHide();
		day = new Date();
		id = day.getTime();
		if ((url == null) || (url == '')) 
			url = $("input[id='hfUrl']").val();
		f_open_window_max( url, id.toString(), '' );
		//return false;
	}
	
	function showDisclaimer(url, message) {
		if ( message != '' ) {
			$('#additional-dialog-text').text(message);
			$('#additional-text').text(message);
			$('#additional-text').show();
		} else {
			$('#additional-text').hide();
		}
		$("input[id$='hfUrl']").val(url);
		if ($.cookie('TermsOfUse') == null ) {
			$('#dialog').jqmShow();
		} else {
			if ( message != '' ) {
				$('#additional-dialog').jqmShow();
			}  else {
				showDestination();
			}
		}
	}