IE = (document.all)?true:false;
IE6 = (document.all && document.fireEvent && document.createComment)?true:false;
IE7 = false;

// emulate HTMLElement.click() method in Firefox
if (typeof HTMLElement!="undefined" && !HTMLElement.prototype.click){
	HTMLElement.prototype.click = function () {
    oEvent = document.createEvent( "MouseEvents" );  
    oEvent.initMouseEvent("click",true,true,window,1,1,1, 1,1,false,false,false,false,0,this);
    this.dispatchEvent( oEvent ); 
	}
}

function findPosX(obj) { // get an objects X (left) location
	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 findPosY(obj,checkForPositioning) { // get an objects Y (top) location
	var curtop = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curtop += obj.offsetTop;    
      if (checkForPositioning) {
        if (obj.offsetParent.currentStyle.position != "static") {
          return curtop;
        }
      }
			obj = obj.offsetParent;
		}
	}	else if (obj.y) {	curtop += obj.y; }
	return curtop;
}

function addEvent(obj, evType, fn, useCapture){
  if (obj.addEventListener){
    obj.addEventListener(evType, fn, useCapture);
    return true;
  } else if (obj.attachEvent){
    var r = obj.attachEvent("on"+evType, fn);
    return r;
  } else {
    alert("Handler could not be attached");
  }
}

function removeEvent(obj, evType, fn, useCapture){
  if (obj.removeEventListener){
    obj.removeEventListener(evType, fn, useCapture);
    return true;
  } else if (obj.detachEvent){
    var r = obj.detachEvent("on"+evType, fn);
    return r;
  } else {
    alert("Handler could not be removed");
  }
}

function getStyle(el,styleProp) {
        if (window.getComputedStyle) // mozilla
                var y = window.getComputedStyle(el,null).getPropertyValue(styleProp);
        else if (el.currentStyle) //ie
                var y = eval('el.currentStyle.' + styleProp);
        return y;
}

// utility function for getElementById. takes in as many ids as you care to pass it
function $() {
  var elements = new Array();
  for (var i = 0; i < arguments.length; i++) {
    var element = arguments[i];
    if (typeof element == 'string') { element = document.getElementById(element); }
    if (arguments.length == 1) { return element; }
    elements.push(element);
  }
  return elements;
}

function getElementsByClassName(oElm, strTagName, strClassName){
	var arrElements = (strTagName == "*" && document.all)? document.all : oElm.getElementsByTagName(strTagName);
	var arrReturnElements = new Array();
	strClassName = strClassName.replace(/\-/g, "\\-");
	var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
	var oElement;
	for(var i=0; i<arrElements.length; i++){
		oElement = arrElements[i];		
		if (oRegExp.test(oElement.className)) { arrReturnElements.push(oElement); }	
	}
	return (arrReturnElements)
}

function getNextElementSibling(node,el) {
  while (node.nextSibling) {
    if (el) {
      if (node.nextSibling.nodeName == el.toUpperCase()) {  return node.nextSibling; }
    } else {
      if (node.nextSibling.nodeType == 1) {  return node.nextSibling; }
    }
    node = node.nextSibling;
  }
  return false;
}
function getPreviousElementSibling(node,el) {
  while (node.previousSibling) {
    if (node.previousSibling.nodeName == el.toUpperCase()) {
      return node.previousSibling;
    }
    node = node.previousSibling;
  }
  return false;
}

function setFullHeight() {
  if(window.IgnoreFullHeightScript == 'YES')
    return;
  var clientHeight = (IE6)?document.documentElement.clientHeight:(IE)?document.body.clientHeight:window.innerHeight;
  var ftr = document.getElementById("footer");  
  if (document.body.baseScrollHeight < clientHeight) {
    ftr.style.paddingTop = (document.documentElement.clientHeight - document.body.baseScrollHeight) + "px";
  }
}

function ShowHeadImage(imgSrc) {
    var mastHeadIcon = document.getElementById('mastHeadIcon');
    if(mastHeadIcon)
        mastHeadIcon.src = imgSrc;
}

function createModalWindow(src, width, height)
{

	var IE  = (document.all) ? true : false;

	if (IE)
	{
	
		var IE6 = (document.all && document.fireEvent && document.createComment) ? true : false;
		var IE7 = (document.documentElement && typeof document.documentElement.style.maxHeight != "undefined") ? true : false;

		var cHeight = (IE6) ? document.documentElement.clientHeight : (IE) ? document.body.clientHeight : window.innerHeight;
		var cWidth  = (IE6) ? document.documentElement.clientWidth : (IE) ? document.body.clientWidth : window.innerWidth;
		var sHeight = document.body.parentNode.scrollTop;
		var blockDivType = 'DIV';
		var blockDiv = document.createElement(blockDivType);
		blockDiv.className = "cxpModalPopupBG";
		blockDiv.innerHTML = "&nbsp;";
	    
		var iframe = document.createElement('IFRAME');
		iframe.className = "cxpModalPopup";
		iframe.frameBorder = 0;
		iframe.style.border = "solid 1px #000000";
		iframe.style.left = ((cWidth/2) - (width/2)) + "px";
		iframe.style.top = (sHeight + (cHeight/2) - (height/2)) + "px";
		iframe.style.width = width  + 'px';
		iframe.style.height = height + 'px';
		iframe.src = "blank.html";

		window.modalPopup = iframe;
		window.modalPopupBG = blockDiv;	

		if (IE)
		{
			document.body.insertBefore(blockDiv, document.body.childNodes[0]);
			document.body.insertBefore(iframe, document.body.childNodes[0]);
		}
		else
		{
			document.body.appendChild(iframe);
			document.body.appendChild(blockDiv);
		}

		blockDiv.style.width = cWidth + 'px';
		blockDiv.style.height = document.body.parentNode.scrollHeight + 'px';

		if (src.indexOf('?') != -1)
			src = src + '&UID=' + (new Date()).getTime();
		else
			src = src + '?UID=' + (new Date()).getTime();
		    
		iframe.src = src;

		return false;

	}
	else
	{
		return true;
	}

}

function destroyModalWindow()
{
	if (window.modalPopup
		&& window.modalPopupBG)
	{
		window.modalPopup.parentNode.removeChild(window.modalPopup);
		window.modalPopupBG.parentNode.removeChild(window.modalPopupBG);
	}
}