<!--

// This code from Danny Goodman,
// http://developer.iplanet.com/viewsource/goodman_modal/goodman_modal.html

// Altered for terrashare purposes DGJ

// Generate a modal dialog.

function openDialog(url, width, height, returnFunc, args) 
{
	if (!dialogWin.win || (dialogWin.win && dialogWin.win.closed)) 
	{
		// Initialize properties of the modal dialog object.

    dialogWin.returnFunc = returnFunc;
    dialogWin.returnedValue = "";
    dialogWin.args = args;
    dialogWin.url = url;
    dialogWin.width = width;
    dialogWin.height = height;

    // Keep name unique so Navigator doesn't overwrite an existing dialog.     
    dialogWin.name = "ad_popup"; // (new Date()).getSeconds().toString()

		// Above line altered to *force* the same window! D.G.Jones

    // Assemble window attributes and try to center the dialog.

    if (Nav4) 
		{
    	// Center on the main window.

      dialogWin.left = 	window.screenX + 
												((window.outerWidth - dialogWin.width) / 2);

      //dialogWin.top = 	window.screenY + 
												//((window.innerHeight - dialogWin.height) / 2);

      dialogWin.top = 	window.screenY + 130; // from the top of the current

      var attr = 	"screenX=" + dialogWin.left + 
									",screenY=" + dialogWin.top + ",resizable=no,width=" + 
									dialogWin.width + ",height=" + dialogWin.height;
		} 
		else 
		{
    	// The best we can do is center in screen.

      dialogWin.left = (screen.width - dialogWin.width) / 2;
      //dialogWin.top = (screen.height - dialogWin.height) / 2;

      dialogWin.top = 130; // Guess. . .

      var attr = 	"left=" + dialogWin.left + 
									",top=" + dialogWin.top + ",resizable=no,width=" + 
									dialogWin.width + ",height=" + dialogWin.height;
		}

    // Generate the dialog and make sure it has focus.

    dialogWin.win=window.open(dialogWin.url, dialogWin.name, attr);

		if(Nav)
		{
    	dialogWin.win.focus();
		}

	} 
	else 
	{
		if(Nav)
		{
  		dialogWin.win.focus();
		}
	}
}


// Event handler to inhibit Navigator form element and Internet Explorer
// link activity when dialog window is active.

function deadend() 
{
	if (dialogWin.win && !dialogWin.win.closed) 
	{
		if(Nav)
		{
			dialogWin.win.focus();
		}
   	return false;
  }
}


// Since links in Internet Explorer 4 can't be disabled, preserve 
// IE link onclick event handlers while they're "disabled." 
// Restore when reenabling the main window.

var IELinkClicks

// Disable form elements and links in all frames for IE.

function disableForms() 
{
  IELinkClicks = new Array();

  for (var h = 0; h < frames.length; h++) 
	{
   	for (var i = 0; i < frames[h].document.forms.length; i++) 
		{
     	for (var j = 0; j < frames[h].document.forms[i].elements.length; j++) 
			{
       	frames[h].document.forms[i].elements[j].disabled = true;
      }
    }

   	IELinkClicks[h] = new Array();

    for (i = 0; i < frames[h].document.links.length; i++) 
		{
     	IELinkClicks[h][i] = frames[h].document.links[i].onclick;
      frames[h].document.links[i].onclick = deadend();
    }
	}
}

// Restore IE form elements and links to normal behavior.

function enableForms() 
{
	for (var h = 0; h < frames.length; h++) 
	{
		for (var i = 0; i < frames[h].document.forms.length; i++) 
		{
    	for (var j = 0; j < frames[h].document.forms[i].elements.length; j++) 
			{
      	frames[h].document.forms[i].elements[j].disabled = false;
      }
    }

    for (i = 0; i < frames[h].document.links.length; i++) 
		{
    	frames[h].document.links[i].onclick = IELinkClicks[h][i];
    }
  }
}

// Grab all Navigator events that might get through to form elements while 
// dialog is open. For Internet Explorer, disable form elements.

function blockEvents() 
{
	if (Nav4) 
	{
		window.captureEvents	(	Event.CLICK | 
														Event.MOUSEDOWN | 
														Event.MOUSEUP | 
														Event.FOCUS
													);

		window.onclick = deadend;
	} 
	else 
	{
		disableForms()
	}

	if(Nav)
	{
		window.onfocus = checkModal;
	}
	else
	{
		window.onFocus = checkModal();
	}


}

// As dialog closes, restore the main window's original event mechanisms.

function unblockEvents() 
{
	if (Nav4) 
	{
		window.releaseEvents	(	Event.CLICK | 
														Event.MOUSEDOWN | 
														Event.MOUSEUP | 
														Event.FOCUS
													);

		window.onclick = null;
    window.onfocus = null;
	} 
	else 
	{
		enableForms();
	}
}


function checkModal() 
{
	if (dialogWin.win && !dialogWin.win.closed) 
	{
		if(Nav)
		{
			dialogWin.win.focus();
		}
	}
}

//-->

