/* DEBUG LEVEL
 * 0 = None
 * 1 = Critical
 * 2 = Warning
 * 3 = Info
 */
var DEBUG_LEVEL = 3;

function popup(url, name, args) {
	__debug_info ('url=' + url + '; name=' + name + '; args=' + args);
	var w = window.open(url, name, args);
	if (window.focus) {
		w.focus();
	}
	return false;
}

function addEvent(obj, type, fn){  // the add event function
	if (obj.addEventListener)
		obj.addEventListener(type, fn, false);
	else if (obj.attachEvent) {
		obj["e"+type+fn] = fn;
		obj[type+fn] = function() {
		obj["e"+type+fn](window.event);
		};
		obj.attachEvent("on"+type, obj[type+fn]);
	}
}

function getChecked(id) {
	var e = document.getElementById(id);
	if (e) {
		if (e.type == 'radio') {
			return e.checked;
		}
	}
	return false;
}

function getElementsByType(type) {
	a = new Array();
	for (var j = 0; j < document.forms[0].length; j++) {
		if (document.forms[0].elements[j].type == type) {
			a[a.length] = document.forms[0].elements[j];
		}
	}
	return a;
}

function positionDiv(id, x, y) {
    var imgX;
	var imgY;
	var BrowserType = "";
	var clW = 0
	var WidthIsOdd = false;		
		
	if(document.layers) { BrowserType="NN4" }
	if(document.all) { BrowserType="IE"  }
	if(!document.all && document.getElementById) { BrowserType="NN6" }
	if (BrowserType=="") { BrowserType="IE"  }
	// get total clientWidth
	clW = document.body.clientWidth;
	// determine if the width is odd, this is a crazy way to do this
	if (String(clW /2).indexOf('.') > -1) { WidthIsOdd = true }
	// if not IE and width is odd, then subtract clW by one		
	if (BrowserType!="IE" && WidthIsOdd) { clW -= 1}
			
	imgX = (clW / 2);	// find the center of the window
	imgX = imgX - x
	imgY = y;

	if (BrowserType == "IE") {
		document.all[id].style.left = imgX;
		document.all[id].style.top = imgY;
	} else if (BrowserType == "NN4") {
		document.layers[id].left = imgX;
		document.layers[id].top = imgY
	} else if (BrowserType == "NN6") {
		document.getElementById(id).style.left = imgX;
		document.getElementById(id).style.top = imgY;
	}	
}

function setChecked(id, value) {
	var e = document.getElementById(id);
	if (e) {
		e.checked = value;
	}
}

function setClassName(id, className) {
	var e = document.getElementById(id);
	if (e) {
		e.className = className;
	}
}

function setValue(id, value) {
	var e = document.getElementById(id);
	if (e) {
		e.value = value;
	}
}

function toggleRadio(id1, id2) {
	if (getChecked(id1) == true) {
		setChecked(id2, true);
	} else {
		setChecked(id1, true);
	}
}

function __debug_info(msg) {
	if (DEBUG_LEVEL >= 3) {
		alert(msg);
	}
}
