// this provides rollover functionality to the current
// events table on the homepage by fixes IE's broken :hover

tableList = function(){
	if (document.all && document.getElementById){ 
		tableRoot = document.getElementById('eventList');
		myRows = tableRoot.getElementsByTagName('TR');
		for (i=0; i < myRows.length; i++){
			var node = myRows[i];
			if (node.nodeName == "TR"){
				node.onmouseover = function(){
					this.className += ' eventOver';
				}
				node.onmouseout = function(){
					this.className = this.className.replace(" eventOver", "");
				}
			}
		}
	}
}

// Netscrape 4
if (document.layers) {var NN4 = true;}
// var NN4 = (document.layers) ? true : false

// IE
if (document.all) {var IE = true;}
// var IE = (document.all) ? true : false

// DOM
if (document.getElementById && !document.all) {var DOM = true;}
// var DOM = (document.getElementById && !document.all) ? true : false

function getElement(id){
	
		if(NN4) {
			path = document.layers[id]
		} else if(IE) {
			path = document.all[id]
		} else {
			path = document.getElementById(id)
		} 
		//return the path to the css layer depending upon the browser type
		return path; 
}


function MGC_winOpen(url, name, features) { 
	winChild = window.open(url, name, features);
	winChild.focus();
	return winChild;
}



function showHide(id,dispMode)
{
	 var elementObj = getElement(id); 
	 if (elementObj.style.display){
		 elementObj = elementObj.style;
	 }
	 if (elementObj.display){
		 if (dispMode){
			 elementObj.display = dispMode; 
		 } else {
			 if (elementObj.display == "none")
				{ 
					elementObj.display = "block"; 
				} 
			 else 
				{ 
					elementObj.display = "none"; 
				}
		 }
	 }
}

function hideSubmit(objForm, sButton, sMessage){
  // default message if one isn't passed in
  var message='Please wait...';
  
  // if a message was passed in, use it
  if(sMessage != undefined){
   message=sMessage;
  }
  
  // check for the given button in objForm
  if(objForm[sButton] != undefined) {
   // change the button's message/text
   objForm[sButton].value=message;
   // disable the button
   objForm[sButton].disabled=true;
  }
 }
 
function disableSubmit(thisForm){
	if (window.greySubmit){
		greySubmit(thisForm);
	}
	return true;
} 

function MGC_winOpenChildCentered(sURL,sWinName,sFeatures,nChildWidth,nChildHeight){
	// simply omit the top and left attributes from sFeatures to open the child window
	// centered on it's parent
	var nParentLeft = 0, nParentTop = 0; // default parent position
	var nParentHeight = 480, nParentWidth = 640; // default parent window size
	var bAppendTop = 1, bAppendLeft = 1, bAppendWidth = 1, bAppendHeight = 1;
	
	if (! sWinName || sWinName.length < 1){
		sWinName = "popup";			
	}
	
	if (! nChildWidth || nChildWidth < 1){
		nChildWidth = 300;			
	}
	if (! nChildHeight || nChildWidth < 1){
		nChildHeight = 200;			
	}
	if (! sFeatures || sFeatures.length < 1){
		sFeatures = "toolbar=0,resizable=1,scrollbars=1,directories=0,status=0,menubar=0";			
	}
	if (sFeatures.indexOf("top=") >= 0){
		bAppendTop = 0;
	}
	if (sFeatures.indexOf("left=") >= 0){
		bAppendLeft = 0;
	}
	if (sFeatures.indexOf("width=") >= 0){
		bAppendWidth = 0;
	}
	if (sFeatures.indexOf("height=") >= 0){
		bAppendHeight = 0;
	}
	
	// lowest common denominator
	if (window.innerWidth && window.innerHeight){ 
		nParentWidth = window.innerWidth; 
		nParentHeight = window.innerHeight; 
	} 
	// more accurate - IE5-
	if (document.body.clientWidth && document.body.clientHeight){ 
		nParentWidth = document.body.clientWidth; 
		nParentHeight = document.body.clientHeight; 
	} 
	// even more accurate - IE 6, Firefox with our doctype
	if (document.documentElement && document.documentElement.clientWidth && document.documentElement.clientHeight){
		nParentWidth = document.documentElement.clientWidth; 
		nParentHeight = document.documentElement.clientHeight; 
	}
	
	if (window.screenX && window.screenY){
		nParentTop = window.screenY;
		nParentLeft = window.screenX;
	}

	if (window.screenLeft && window.screenTop){
		nParentTop = window.screenTop;
		nParentLeft = window.screenLeft;
	}
	
	var nParentCenterX =  Math.floor((nParentWidth / 2) + nParentLeft);
	var nParentCenterY =  Math.floor((nParentHeight / 2) + nParentTop);
	
	var nChildLeft = nParentCenterX - (nChildWidth / 2);
	var nChildTop = nParentCenterY - (nChildHeight / 2);
	
	if (bAppendWidth){
		sFeatures = sFeatures + ",width=" + nChildWidth;
	}
	if (bAppendHeight){
		sFeatures = sFeatures + ",height=" + nChildHeight;
	}
	if (bAppendTop){
		sFeatures = sFeatures + ",top=" + nChildTop;
	}
	if (bAppendLeft){
		sFeatures = sFeatures + ",left=" + nChildLeft;
	}
	
	winChild = MGC_winOpen(sURL,sWinName,sFeatures);
	//winChild.focus();

	//return winChild;
}

function dropdownRedirect(whichform,whichfield){
	if (arguments.length > 0){
		if (arguments.length > 1){
			dropdown = document.forms[whichform].elements[whichfield];
		} else {
			dropdown = document.forms[whichform].elements["gotoURL"];
		}
	} else {
		dropdown = document.forms["navdropdown"].elements["gotoURL"];
	}
	
	var URL = dropdown.options[dropdown.selectedIndex].value;
	window.location.href = URL;
	return true;
}

function getElementsByClassName(oElm, strTagName, oClassNames){
    var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
    var arrReturnElements = new Array();
    var arrRegExpClassNames = new Array();
    if(typeof oClassNames == "object"){
        for(var i=0; i<oClassNames.length; i++){
            arrRegExpClassNames.push(new RegExp("(^|\\s)" + oClassNames[i].replace(/\-/g, "\\-") + "(\\s|$)"));
        }
    }
    else{
        arrRegExpClassNames.push(new RegExp("(^|\\s)" + oClassNames.replace(/\-/g, "\\-") + "(\\s|$)"));
    }
    var oElement;
    var bMatchesAll;
    for(var j=0; j<arrElements.length; j++){
        oElement = arrElements[j];
        bMatchesAll = true;
        for(var k=0; k<arrRegExpClassNames.length; k++){
            if(!arrRegExpClassNames[k].test(oElement.className)){
                bMatchesAll = false;
                break;                      
            }
        }
        if(bMatchesAll){
            arrReturnElements.push(oElement);
        }
    }
    return (arrReturnElements)
}

/* Journal - resize image-float divs to be the exact size of the image nested within them - KPK 2/6/07 */
function resizeDiv() {
	myDiv = getElementsByClassName(document, "div", "image-float");
	for (var i=0; i < myDiv.length; i++){	
		var myImg = myDiv[i].getElementsByTagName('IMG');
		var myWidth = myImg[0].getAttribute("width");
		myDiv[i].style.width = myWidth +"px";
	}
}

//kludge - Commonspot reserves body onload that interferes with any unobtrusive onload event handlers. so...functions that need to be exec onload should be executed here one at a time
function initAll() {
	resizeDiv();
}
jQuery(document).ready(function(){
	if(document.getElementById("banner")){
		var $banner = jQuery("#banner");
		var randomNumber = function(limit){
			return Math.floor(Math.random()*limit);
		}
		var banneritems = [];
		banneritems.push("img|")
		banneritems.push("img|")
		banneritems.push("img|")
		banneritems.push("swf|/images/edabanner.swf")
		var rndImage = randomNumber(banneritems.length);
		if(banneritems[rndImage].split("|")[0]==="img"){
			$banner.html('<img src="/images/banner-home'+rndImage+'.gif" />')
		}
		if(banneritems[rndImage].split("|")[0]==="swf"){
			$banner.html('<div id="flashReplace"></div>')
			swfobject.embedSWF(banneritems[rndImage].split("|")[1], "flashReplace", "500", "100", "9.0.0");
		}

	}
});