/* UTILITY.JS
   General JavaScript functions.

    Version Information:
     20020117a = Created.
	 20020731a = Added unconditional parameter to reload in killThis().

Copyright 2003, Land Information Access Association
*/

/* Initialize Variables */
var newWin;
var popupWin = new Array();
var picWin;

/* Open New Window */
function popupWindow(winID, winWidth, winHeight, winURL) {
	if (popupWin[winID]) if (!popupWin[winID]) popupWin[winID].close();
	var winLeft = ((screen.availWidth - winWidth - 10) * .5);
	var winTop = ((screen.availHeight - winHeight - 30) * .5);
	popupWin[winID] = window.open(winURL, 'PopWin' + winID, 'status=yes,menubar=no,toolbar=no,location=no,scrollbars=yes,top=' + winTop + ',left=' + winLeft + ',width=' + winWidth + ',height=' + winHeight + ',resizable=yes');
	popupWin[winID].focus();
}

/* Open Glossary Window */
function GlossaryWindow(winPathtoRoot, winGTerm) {
	popupWindow(10,550,350, winPathtoRoot + 'CC/SDB/SDBrecord.asp?SDBaction=show&mode=GV&term=' + winGTerm );
}

/* Define Picture Object */
function picObj(file, title, width, height) {
	this.file = file;
	this.width = width;
	this.height = height;
	this.title = title;
}

/* Show Picture in New Window */
function showPic(picThing) {
	if (picWin) { if (!picWin.closed) picWin.close(); }
	var docHTML = '<html><head><title>';
	if (picThing.title) {
		docHTML += picThing.title;
	} else {
		docHTML += 'Picture';
	}
	docHTML += '</title></head>';
	docHTML += '<body><div align="center"><center>';
	if (picThing.title) docHTML += '<h3>' + picThing.title + '</h3>';
	docHTML += '<a href="javascript:window.close();">';
	docHTML += '<img src="' + picThing.file + '"'
	if (picThing.height) docHTML += ' height="' + picThing.height + '"';
	if (picThing.width) docHTML += ' width="' + picThing.width + '"';
	docHTML += ' border="0">';
	docHTML += '<br><font face="Arial,Helvetica,sans-serif" size="1">Click to Close Window</font></a>';
	docHTML += '</center></div></body></html>';
	var winProperties = 'menubar=no,toolbar=no,location=no,scrollbars=yes,resizable=yes'
	if (picThing.height) winProperties += ',height=' + (picThing.height + 50);
	if (picThing.width) winProperties += ',width=' + (picThing.width + 40);
	mapPicWin = window.open('', 'PicWin', winProperties);
	mapPicWin.document.write(docHTML);
	mapPicWin.document.close();
}

/* Refresh Primary Window, Close Secondary Window */
function killThis() {
	opener.location.reload(true);
	window.close();
}

/* Show the names of all elements on all forms */
function showElements() {
	var formName, thisForm, numElem;
	var elemNames = "";
	for (x = 0; x < document.forms.length; x++) {
		formName = document.forms[x].name;
		elemNames += 'Form ' + formName + ':\n';
		thisForm = eval('document.' + formName);
		numElem = thisForm.elements.length;
		for (i = 0; i < numElem; i++) {
			elemNames += '  ' + thisForm.elements[i].name + '\n';
		}
	}
	alert(elemNames);
}


