// addEvent allows JS to be linked to html elements without markup in the html
function addEvent(elm, evType, fn,useCapture) {
    if(elm.addEventListener) {
        elm.addEventListener(evType, fn, useCapture);
        return true;
    }
    else if (elm.attachEvent) {
        var r = elm.attachEvent('on' + evType, fn);
        return r;
    } else {
        elm['on' + evType] = fn;
    }
}

// ==================================================================================================
// autoHideLabels hides a form elements label and instead displays it in the textbox
function autoHideLabels () {

    if (!document.getElementsByTagName || !document.getElementById) return;
    var labels = document.getElementsByTagName("LABEL");
    for (var i=0, l=labels.length; i<l; i++) {

        if (labels[i].className.match("autohide")) {
            var input = document.getElementById(labels[i].htmlFor);
            if (!input) continue;

            labels[i].className += " accessibility";

			if (labels[i].firstChild) {
				input.placeholder_value = labels[i].firstChild.nodeValue;
				input.value = labels[i].firstChild.nodeValue;
				input.onfocus = function () {
					if (this.value == this.placeholder_value) {
						this.value = "";
					}
				};
				input.onblur = function () {
					if (this.value == "") {
						this.value = this.placeholder_value;
					}
				};
			}
        }

    }
    labels = null;
}
addEvent(window, "load", autoHideLabels);


// =============================================================================

function inputboxclear () {
    if (!document.getElementsByTagName || !document.getElementById) return;
    var inputs = document.getElementsByTagName("INPUT");
    for (var i=0, l=inputs.length; i<l; i++) {
        if (inputs[i].className.match("filledinput")) {
            var input = inputs[i];
			input.onfocus = function () {
				if (this.value == this.defaultValue) {
					this.value = "";
				}
			};

			input.onblur = function () {
				if (this.value == "") {
					this.value = this.defaultValue;
				}
			};
        }
    }
}
addEvent(window, "load", inputboxclear);


// =============================================================================
// opens in new window
function openInNewWindow() {
	var newWindow = window.open(this.getAttribute('href'), 'Website_Popup');
	newWindow.focus();
	return false;
}

// =============================================================================
// opens in new window - MAX
function openInNewWindow_notoolbars() {
	var newWindow = window.open(this.getAttribute('href'), 'Website_Popup', 'scrollbars=no,menubar=no,resizable=yes,toolbar=no,location=no,status=no')
	newWindow.focus();
	return false;
}


// ==================================================================================================
// popups turns links with "popup" or "popupmax" classes to open links in new window
function popups() {
    if (!document.getElementsByTagName || !document.getElementById) return;
    var links = document.getElementsByTagName("A");
    for (var i=0, l=links.length; i<l; i++) {

		// if link has a class of popup then assign it an onclick function
        if (links[i].className.match("popup")) {
            links[i].onclick = openInNewWindow;
        }

		// if link has a class of popup_notoolbars then assign it an onclick function
        if (links[i].className.match("popup_max")) {
            links[i].onclick = openInNewWindow_notoolbars;
        }

    }
    links = null;
}
addEvent(window, "load", popups);

// =====================================================================


function fixColumns(){

	var idstoPush = new Array("sho_inner", "wea_inner", "mon_inner", "vot_inner");
	var ids = new Array();
	var maxHeight = 0;

	// for each item, make sure it's on the page. If so, push into "ids"
	for (i in idstoPush) {
		if (document.getElementById(idstoPush[i])) {ids.push(idstoPush[i])};
	}

	// for each item on page, get height of div and update max height to get the largest item's height
	for (i in ids) {
		var h = document.getElementById(ids[i]).offsetHeight;
		if (h > maxHeight) maxHeight = h;
	}

	// set all items to this max height
	for (i in ids) {
		document.getElementById(ids[i]).style.height = maxHeight + "px";
		if (ids[i] == "vot_inner") {
			// if it's a vote, add 24 to make up for the other promo's bottom banner area
			document.getElementById(ids[i]).style.height = maxHeight+24 + "px";
		}
	}

}

function google_ss(w,id) {
  window.status = w;
  return true;
}

function google_cs() {
  window.status = "";
}


function hitboxtrigger_carousel(artName, slot) {
	/* run function to do hitbox stat tracking */
	_hbLink(artName, "CAROUSEL_SLOT_"+slot);
}


function fbs_click() {
	u=location.href;
	t=document.title;
	window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');
	return false;
}

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


function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

  function gotoURLres(dropDown)
	{
	  URL=dropDown.options[dropDown.selectedIndex].value;
		if(URL.length>0)
		  parent.location.href=""+URL
	}

  function formHandler1()
	{
	  if (window.Option)
		  var URL = document.teams.teams.options[document.teams.teams.selectedIndex].value;
		window.top.location.href = URL;
	}

  function popup(mylink, windowname)
    {
      if (! window.focus)return true;
      var href;
      if (typeof(mylink) == 'string')
         href=mylink;
      else
         href=mylink.href;
      window.open(href, windowname, 'width=400,height=200,scrollbars=yes');
      return false;
    }

  function popuprd(mylink, windowname)
    {
      if (! window.focus)return true;
      var href;
      if (typeof(mylink) == 'string')
         href=mylink;
      else
         href=mylink.href;
      window.open(href, windowname, 'width=200,height=500,scrollbars=yes');
      return false;
    }
