
/* Last Modified $Date: 4/23/04 3:30p $ by $Author: Ssantry $ (Version history stored in Source Control) */

// set up browser detect vars
var isNS4 = (navigator.appName.indexOf("Netscape") != -1 && navigator.appVersion.charAt(0) == "4");
var isMOZ = (navigator.appName.indexOf("Netscape") != -1 && parseInt(navigator.appVersion.charAt(0)) >= 5);
var isIE = (navigator.appName.indexOf("Microsoft") != -1);

/**
 * Open a new window.
 *
 * @param	url --	URL to be loaded into the new window
 * @param	name -- 	name of the window, for the window's title bar
 * @param	w -- 	width of the new window, in pixels
 * @param	h -- 	height of the new window, in pixels
 * @param	scroll -- 	whether new window has scrollbars; values are "yes" or "no"
 */
function openWindow(url, name, w, h, scroll) {
    
	var winl = ((top.window.screen.width - w) / 2);
	var wint = ((top.window.screen.height - h) / 2);

	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl;
    if (scroll) winprops += ',scrollbars='+scroll

    win = window.open(url, name, winprops);

	if (win) win.focus();
    
	return win;
}

function openSmWindow(url, name) {
    if (!name) name = "smWindow";
    return openWindow(url, name, 400, 300, "yes");
}

function openLgWindow(url, name) {
    if (!name) name = "lgWindow";
    return openWindow(url, name, 600, 500, "yes");
}

function NewWindow(mypage, myname, w, h, scroll, mainwindow, isModeless) {
    alert("****DEBUG: NewWindow() is deprecated for front-end use, please use openWindow(), openSmWindow(), or openLgWindow() ****");
}


// adapted from MM_findObj
function findObject(name, doc) {

	// get document, if it hasn't been passed
	if (!doc) doc = document;

	// declare object reference
	var obj;

	// check document and document.all collections	
	if (!(obj = doc[name]) && doc.all) {
		obj = doc.all[name];
	}
	
	// check document.layers collection
	if (!obj && document.layers) {
		for (var i = 0; !obj && i < doc.layers.length; i++) {	
			obj = findObject(name, doc.layers[i].document);
		}
	}
		
	if (!obj && doc.getElementById) {
		obj = doc.getElementById(name);
	}
	
	return obj;
}

/**
 * This function returns a random number in the specified range
 *
 * @param	range- max integer value of the random number
 */
function pickRandom(range) {
	if (Math.random) {
		return Math.round(Math.random() * (range-1));
	}
	else {
		var now = new Date();
		return (now.getTime() / 1000) % range;
	}
}

function setSelectVal(elem, val) {

    for (var i = 0; i < elem.options.length; i++) {
    
        if (elem.options[i].value == val) {
        
            elem.selectedIndex = i;
            break;
        }    
    }
}


