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

/*
 * Base JavaScript Files to handle common tasks
 */

/* prepend article tools to contentWell */
$(document).ready(function() {
	$('#contentWell .articleTools ul').append('<li class="clickabilityEmail"><a href="#" onclick="return(ET());" onMouseOver="return(ETMouseOver());" onMouseOut="return(ETMouseOut());">Email</a></li><li class="clickabilitySave"><a href="#" onclick="return(ST());" onMouseOver="return(STMouseOver());" onMouseOut="return(STMouseOut());">Save</a></li><li class="clickabilityPrint"><a href="#" onclick="return(PT());" onMouseOver="return(PTMouseOver());" onMouseOut="return(PTMouseOut());">Print</a></li><li class="reprint"><a href="http://www.icopyright.com/' + icopy + '?icx_id=' + siteURL + '">Reprint</a></li>'); 
});

/* add _blank to any link with class="popup" */
$(document).ready(function() { 
	$('a.popup').click(function() {
		this.target = "_blank";
	});
});

/* fix IE6's inability to have :hover on anything other than an anchor tag */
$(document).ready(function() { 
    $("#topNav li").bind("mouseenter mouseleave", function(){
        $(this).toggleClass("over");
    });
});


/* popups */
function doPopups() {
  if (!document.getElementsByTagName) return false;
  var links=document.getElementsByTagName("a");
  for (var i=0; i < links.length; i++) {
    if (links[i].className.match("popup")) {
      links[i].onclick=function() {
        window.open(this.href, "");
        return false;
      }
    }
  }
}
addLoadEvent(doPopups);



/* grab search terms from google */
/*
$(document).ready(function() {
  if (!document.referrer) return;
  var matches = document.referrer.match(/[?&]q=([^&]*)/);
  if (!matches) return;
  var terms = unescape(matches[1].replace(/\+/g, ' '));
  var re = new RegExp().compile('(' + terms + ')', 'i');
  $("#content *").each(function() {
    if ($(this).children().size() > 0) return;
    if ($(this).is("xmp, pre")) return;
    var html = $(this).html();
    var newhtml = html.replace(re, '<span class="qterm">$1</span>');
    $(this).html(newhtml);
  });
});
*/

$(document).ready(function() {
  if (!document.referrer) return;
  var matches = document.referrer.match(/[?&]q=([^&]*)/);
  if (!matches) return;
  var search404Term = unescape(matches[1].replace(/\+/g, ' '));
  $("#404searchSite").val(search404Term);
});



/*====
 * replace search box input with label text
 *================================================ */

$(document).ready(function() { 
	var searchLabel = $('div#searchBox label').remove().text();
	var searchLabelBtm = $('div#searchBoxBtm label').remove().text();
	if ($('#searchSite').val() == '') {
		$('#searchSite').addClass('placeholder').val(searchLabel).focus(function() {
			if (this.value == searchLabel) {
				$(this).removeClass('placeholder').val('');
			};
		}).blur(function() {
			if (this.value == '') { 
				$(this).addClass('placeholder').val(searchLabel);
			};
		});
		$('#search form').submit(function() {
			if ($('#searchSite').val() == searchLabel) {
				$('#searchSite').val('');
			}
		});
	}
	if ($('#btmSearchSite').val() == '') {
		$('#btmSearchSite').addClass('placeholder').val(searchLabelBtm).focus(function() {
			if (this.value == searchLabelBtm) {
				$(this).removeClass('placeholder').val('');
			};
		}).blur(function() {
			if (this.value == '') { 
				$(this).addClass('placeholder').val(searchLabelBtm);
			};
		});
		$('#btmSearch form').submit(function() {
			if ($('#btmSearchSite').val() == searchLabelBtm) {
				$('#btmSearchSite').val('');
			}
		});
	}

});


