var CCM_IMAGE_PATH = "/images";
var CCM_TOOLS_PATH = "/tools/required";

function registerTopNavImage(imgName) {
	eval("img" + imgName + "_on = new Image()");
	eval("img" + imgName + "_on.src = \"/images/topnav/" + imgName + "_on.gif\"");
	eval("img" + imgName + "_off = new Image()");
	eval("img" + imgName + "_off.src = \"/images/topnav/" + imgName + "_off.gif\"");
}

function ccmAddLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

function turnOnImage(imgID) {
	img = document.getElementById(imgID);
	img.src = eval(imgID + "_on.src");
}

function turnOffImage(imgID) {
	img = document.getElementById(imgID);
	img.src = eval(imgID + "_off.src");
}

function ccmOpenWindow(pUrl, pw, ph) {
    // function pops a window given a url, width and height, and centers it in the monitor
    args = ccmOpenWindow.arguments;
    winName = (args[3]) ? args[3] : 'popup';

    sw = screen.availWidth;
    sh = screen.availHeight;

    leftpos = (sw - pw) / 2;
    toppos = (sh - ph) / 2;

	if (!popwin || popwin.closed) {
		pStr = "scrollbars=1,left=" + leftpos + ",top=" + toppos + ",width=" + pw + ",height=" + ph;
		var popwin = window.open(pUrl,winName,pStr);
		popwin.focus();
	} else {
		popwin.location = pUrl;
		popwin.focus();
	}
	
	return popwin;
}

function ccmShowElement(tag, containerObj) {
	if (containerObj != null) {
		tags = containerObj.getElementsByTagName(tag);
		for (i = 0; i < tags.length; i++) {
			obj = tags[i];
			obj.style.visibility = "visible";
		}
	}
}

function ccmHideElement(tag, containerObj) {
	if (containerObj != null) {
		tags = containerObj.getElementsByTagName(tag);
		for (i = 0; i < tags.length; i++) {
			obj = tags[i];
			obj.style.visibility = "hidden";
		}
	}
}
