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 = "resizable=1,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";
		}
	}
}

function ccmHideElementObscured(elmID, overDiv) {
if(document.all) {
	for( i = 0; i < document.all.tags( elmID ).length; i++ )
	{
	  obj = document.all.tags( elmID )[i];
	  if( !obj || !obj.offsetParent )
	  {
		continue;
	  }
  
	  // Find the element's offsetTop and offsetLeft relative to the BODY tag.
	  objLeft	= obj.offsetLeft;
	  objTop	= obj.offsetTop;
	  objParent = obj.offsetParent;
	  
	  while( objParent.tagName.toUpperCase() != "BODY" )
	  {
		objLeft	 += objParent.offsetLeft;
		objTop	 += objParent.offsetTop;
		objParent = objParent.offsetParent;
	  }
  
	  objHeight = obj.offsetHeight;
	  objWidth = obj.offsetWidth;
  
	  if(( overDiv.offsetLeft + overDiv.offsetWidth ) <= objLeft );
	  else if(( overDiv.offsetTop + overDiv.offsetHeight ) <= objTop );

	  else if( overDiv.offsetTop >= ( objTop + objHeight + obj.height ));

	  else if( overDiv.offsetLeft >= ( objLeft + objWidth ));
	  else
	  {
		obj.style.visibility = "hidden";
	  }
	}
  }
}
     

// unhides <select> and <applet> objects (for IE only)
function ccmShowElementObscured( elmID )
{
  if( document.all )
  {
	for( i = 0; i < document.all.tags( elmID ).length; i++ )
	{
	  obj = document.all.tags( elmID )[i];
	  
	  if( !obj || !obj.offsetParent )
	  {
		continue;
	  }
	
	  obj.style.visibility = "";
	}
  }
}




function ccmFindX(obj) {
	var curleft = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	} else if (obj.x) {
		curleft += obj.x;
	}
	
	return curleft;
}

function ccmFindY(obj) {
	var curtop = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	} else if (obj.y) {
		curtop += obj.y;
	}
	
	return curtop;
}

function ccmFixEvent(e) {
	if (document.all) {
		window.event.returnValue = false;
		window.event.cancelBubble = true;
		return window.event;
	} else {
		e.stopPropagation();
		e.preventDefault();
		return e;
	}
}

function ccmSetOpacity(obj, value) {
	obj.style.Opacity = (value / 100);
	obj.style.MozOpacity = (value / 100);
	obj.style.filter = "alpha(opacity=" + value + ")"; 
}
