//
// $Id$
//
// Site javascript code
//

function WindowOnload(f) {
	var prev = window.onload;
	window.onload = function() { if (prev) prev(); f(); }
}

function fixExternalLinks() {
	// Fetch all the a elements in the document.
	var links = document.getElementsByTagName('a');

	// Loop through the a elements in reverse order for speed.
	for (var i = links.length; i != 0; i--) {

		// Pull out the element for this iteration.
		var a = links[i-1];

		// If the element doesn't have an href, skip it.
		if (!a.href) continue;

		// If the element has a className that contains
		// 'external' assign target window of _blank
		if (a.className && a.className.indexOf('external') != -1) {
			a.target = '_blank';
		}
	}
}

function popup(url, id, w, h, x, y, resize, scrollbar, menubar, status, toolbar) {
	var opt = '';
	var noDef;

	if (navigator.userAgent.toLowerCase().indexOf("safari")!=-1) {
		w += 3;              // avoid scroll bars
		h += 3;
	}

	if (w != noDef) {
        opt += 'width=' + w + ',';
        if (x == noDef)
			x = (screen.width - w) / 2;
        opt += 'left=' + x  + ',';
	}

	if (h != noDef) {
        opt += 'height=' + h + ',';
        if (y == noDef)
			y = (screen.height - h) / 2;
        opt += 'top=' + y + ',';
	}

	if (resize != noDef)          opt += 'resizable=no,';
	if (scrollbar != noDef)       opt += 'scrollbars=' + scrollbar + ',';
	if (menubar != noDef) opt += 'menubar=' + menubar + ',';
	if (status != noDef)          opt += 'status=' + status + ',';
	if (toolbar != noDef) opt += 'toolbar=' + toolbar + ',';

	var win = window.open(url, id, opt);

	if (win)
        win.focus();
	else
		alert("You appear to have a pop-up blocker that prevents the requested window from opening. Please enable pop-ups for this site and try again. Thank you.");
	//      alert("Failed to open window: " + url + "\nID = " + id + "\nOpts = \n" + opt);
}
