/* Browser check */
var IS_DOM = (document.getElementById) ? true : false;
var IS_IE = (document.all) ? true : false;
var IS_IE50 = (navigator.userAgent.indexOf("IE 5.0") != -1);
var IS_Mac = (navigator.appVersion.indexOf("Mac") != -1);
var WS_TRUE = "True";

// misc images
var go1on = new Image(); go1on.src = sDirRoot + "img/buttons/form-go-r.gif"; 
var go1off = new Image(); go1off.src = sDirRoot + "img/buttons/form-go-0.gif";

var hae1on = new Image(); hae1on.src = sDirRoot + "img/buttons/form-hae-r.gif"; 
var hae1off = new Image(); hae1off.src = sDirRoot + "img/buttons/form-hae-0.gif";

var sok1on = new Image(); sok1on.src = sDirRoot + "img/buttons/form-sok-r.gif"; 
var sok1off = new Image(); sok1off.src = sDirRoot + "img/buttons/form-sok-0.gif";

var ok1on = new Image(); ok1on.src = sDirRoot + "img/buttons/form-ok-r.gif"; 
var ok1off = new Image(); ok1off.src = sDirRoot + "img/buttons/form-ok-0.gif";

var oExpandImage = new Image; oExpandImage.src = sDirRoot + "img/administration/interface/icon-minus.gif";
var oCollapseImage = new Image; oCollapseImage.src = sDirRoot + "img/administration/interface/icon-plus.gif";

function imgOn(imgName) {
  if (document.getElementById) {
	document.getElementById(imgName).src = eval(imgName + "on.src");
  }
}
 
function imgOff(imgName) {
  if (document.getElementById) {
    document.getElementById(imgName).src = eval(imgName + "off.src");
  }
}

function changeImages() 
{
  if (document.getElementById) {
    for (var i = 0; i < changeImages.arguments.length; i += 2) { 
  		document.getElementById(changeImages.arguments[i]).src = eval(changeImages.arguments[i + 1] + ".src"); 
	}
  }
}

function centeredPopUpWindow(mypage, myname, w, h, scroll)
{
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable'
	win = window.open(mypage, myname, winprops)
	if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}

function changeCountry(oSelector)
{
	var countrySel = oSelector;
	var forwardUrl = countrySel.options[countrySel.selectedIndex].value;
	if (forwardUrl > "")
	{
		// opens in new window window.open(forwardUrl);
		window.location = forwardUrl;
	}
}

function toggle(obj) {
	var el = document.getElementById(obj);
	if ( el.style.display != 'none' ) {
		el.style.display = 'none';
	}
	else {
		el.style.display = 'block';
	}
}

function OpenWindow(sPath, iHeight, iWidth ) {
	var winName = "newWind" + Math.round(Math.random() * 9999999);
	window.open(sPath, winName, 'height=' + iHeight + ',width=' + iWidth + ',scrollbars,resizable,top=20,left=20');
}

function getThis(sId)
{
	var oObject;
	oObject = false;
	
	if (document.getElementById) {
		if (document.getElementById(sId)) {
			oObject = document.getElementById(sId);
		}
	}
	
	return oObject;
}

function getAncestry(oElement, iLevels)
{
	sEvalString = "oElement";
	
	for (var i = 0; i < iLevels; i++) {
		sEvalString += ".parentNode";
	}
	try {
		return eval(sEvalString);
	} catch(oError) {
		return false;
	}
}

var DEBUG_STATE = true;
function debugInfo(sString)
{
	var oDebugger = getThis("debugger");
	if (DEBUG_STATE && oDebugger != false) {
		oDebugger.innerHTML += "<br />" + sString;
	}
}

function startBenchmark()
{
	dStart = new Date().getTime();
}

function endBenchmark()
{
	dEnd = new Date().getTime();
	alert("Elapsed time: " + ((dEnd - dStart)/1000) + " seconds");
}

function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

// TODO: update to not use a confirm pop-up
function confirmBox(sMessage) {
	return confirm(sMessage);
}