var isDHTML = 0;
var isID = 0;
var isAll = 0;
var isLayers = 0;

if (document.getElementById) {isID = 1; isDHTML = 1;}
else {
if (document.all) {isAll = 1; isDHTML = 1;}
else {
browserVersion = parseInt(navigator.appVersion);
if ((navigator.appName.indexOf('Netscape') != -1) && (browserVersion == 4)) {isLayers = 1; isDHTML = 1;}
}}

function findDOM(objectID,withStyle) {
	if (withStyle == 1) {
		if (isID) { return (document.getElementById(objectID).style) ; }
		else {
			if (isAll) { return (document.all[objectID].style); }
		else {
			if (isLayers) { return (document.layers[objectID]); }
		};}
	}
	else {
		if (isID) { return (document.getElementById(objectID)) ; }
		else {
			if (isAll) { return (document.all[objectID]); }
		else {
			if (isLayers) { return (document.layers[objectID]); }
		};}
	}
}

function findLivePageWidth() {
	if (window.innerWidth != null)
		return window.innerWidth;
	if (document.body.clientWidth != null)
		return document.body.clientWidth;
	return (null);
}

function popUp(evt,objectID){
	if (isDHTML) { // Makes sure this is a DHTML browser
		var livePageWidth = findLivePageWidth();
		//alert(livePageWidth);
		domStyle = findDOM(objectID,1);
		dom = findDOM(objectID,0);
		state = domStyle.visibility;
		if (dom.offsetWidth) elemWidth = dom.offsetWidth;
		else { if (dom.clip.width)	elemWidth = dom.clip.width; }
		if (state == "visible" || state == "show")  { domStyle.visibility = "hidden"; }
		else {
			if (evt.pageY) { //Calculates the position for Navigator 4
				topVal = evt.pageY + 4;
				leftVal = evt.pageX - (elemWidth / 2);
			}
			else {
				if (evt.y) { // Calculates the position for IE4
					topVal = evt.y + 4 + document.body.scrollTop;
					leftVal = evt.x - (elemWidth / 2) + document.body.scrollLeft;
				}
			}
		/*If the element goes off the page to the left, this moves it back */
			if(leftVal < 2) { leftVal = 2; }
			else {
				if ((leftVal + elemWidth) > livePageWidth) { leftVal = leftVal - (elemWidth / 2); }
			}
			domStyle.top = topVal; // Positions the element from the top
			domStyle.left = leftVal; // Positions the element from the left
			domStyle.visibility = "visible"; // Makes the element visable
		}
	}
}

   var viewerWin=null;

   //Opens a pop-up browser window for displaying an image
   function openViewerWin(imageURL, winTitle, width, height) {
      if (window.createPopup) {  // Deal with new security in WinXP SP2.
         var panel = window.createPopup();
         var panelBody = panel.document.body;
         panelBody.style.backgroundColor = "black";
         panelBody.style.border = "window-inset 3px";
         panelBody.innerHTML = "<img src='" + imageURL + "' alt='" + winTitle + "'>";
         panel.show(50, 50, width, height, document.body);
      }
      else {  // window.open() is not an issue
         winOptions="height=" + height + ", width=" + width;
         winOptions += ", toolbar=no, directories=no, status=no, scrollbars=no, resizable=no";
         viewerWin=window.open('', 'ViewerWin', winOptions);
         viewerWin.document.open();
         viewerWin.document.writeln("<html>");
         viewerWin.document.writeln("<head>");
         viewerWin.document.writeln("<title>" + winTitle + "</title>");
         viewerWin.document.writeln("<meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'>");
         viewerWin.document.writeln("</head>");
         viewerWin.document.writeln("<body bgcolor='#000000' text='#000000'>");
         viewerWin.document.writeln("<div style='position: absolute; z-index: 1; left: 0px; top: 0px'>");
         viewerWin.document.writeln("<img src='" + imageURL + "' alt='" + winTitle + "'>");
         viewerWin.document.writeln("</div>");
         viewerWin.document.writeln("</body>");
         viewerWin.document.writeln("</html>");
         viewerWin.document.close();
         viewerWin.focus();
      }
   }

   // Opens a pop-up browser window for displaying a Web page
   function openBrowserWin(pageURL, winTitle, width, height) {
   	if (viewerWin != null) {
   		viewerWin.close();
   		viewerWin = null;
   	}
      winOptions = "height=" + height + ", width=" + width;
      winOptions += ", toolbar=no, directories=no, status=no, scrollbars=yes, resizable=yes";
      viewerWin=window.open(pageURL, 'BrowserWin', winOptions);
      viewerWin.focus();
   }

// Prevents the return key from prematurely submitting a form
function stopRKey(evt) {
	var evt  = (evt) ? evt : ((event) ? event : null);
	var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
	if ((evt.keyCode == 13) && (node.type=="text")) { return false; }
}
document.onkeypress = stopRKey;