/*  Some Global Functions
	- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -	*/
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

function insertAfter(newElement,targetElement) {
  var parent = targetElement.parentNode;
  if (parent.lastChild == targetElement) {
    parent.appendChild(newElement);
  } else {
    parent.insertBefore(newElement,targetElement.nextSibling);
  }
}

function addClass(element,value) {
  if (!element.className) {
    element.className = value;
  } else {
    newClassName = element.className;
    newClassName+= " ";
    newClassName+= value;
    element.className = newClassName;
  }
}
	
/* Highlight odd table rows if the table has an ID of stripeTables
	- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -	*/

function stripeTables() {
  if (!document.getElementById) return false;
  if (!document.getElementById("stripeTable")) return false;
  var tables = document.getElementById("stripeTable");
    var odd = false;
    var rows = tables.getElementsByTagName("tr");
    for (var j=0; j<rows.length; j++) {
      if (odd == true) {
        addClass(rows[j],"odd");
        odd = false;
      } else {
        odd = true;
    }
  }
}
function highlightRows() {
  if (!document.getElementById) return false;
  if (!document.getElementById("stripeTable")) return false;
  if (!document.getElementsByTagName) return false;
  var thistable = document.getElementById("stripeTable");
  var rows = thistable.getElementsByTagName("tr");
  for (var i=0; i<rows.length; i++) {
    rows[i].oldClassName = rows[i].className
    rows[i].onmouseover = function() {
      addClass(this,"highlight");
    }
    rows[i].onmouseout = function() {
      this.className = this.oldClassName
    }
  }
}

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, "", "top=40,left=40,width=500,height=400,scrollbars=1"); return false;
      }
    }
  }
}

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+"; domain=janes.com; 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);
}

/* List of events that load when the page loads
	- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -	*/
addLoadEvent(stripeTables);
addLoadEvent(highlightRows);
addLoadEvent(doPopups);