function add_to_onload( func ) {
    var old_onload = window.onload;
    window.onload = function() {
        if ( typeof old_onload == 'function' ) {
        	old_onload();
        }
        func();
    }
}

function RightslinkPopUp(title, date, author, contentID)
	{	
		var url = "https://s100.copyright.com/servlet/DispatchServlet"; 
		var location = url 
			+ "?PublisherName=" + escape("Putman Media, Inc.")
			+ "&Publication=" + escape("Plant Services")
			+ "&Title=" + escape(title)
			+ "&PublicationDate=" + escape(date)
			+ "&Author=" + escape(author)
			+ "&Install=S"
			+ "&ContentID=" + escape(contentID);
		PopUp = window.open( location,  'Rightslink', 
			'location=no,toolbar=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=650,height=550');
	}

function OpenBrWindow(theURL,winName,features) {
  window.open(theURL,winName,features);
}

var displayed;
displayed = '';
function toggle(divid){
	if(displayed != '') {
	  document.getElementById(displayed).style.display = 'none';
	}	
	if(displayed != divid){
		if(document.getElementById(divid).style.display == 'none'){
			document.getElementById(divid).style.display = 'block';
		}else{
			document.getElementById(divid).style.display = 'none';
		}
	}	
	displayed = divid;
}

function HideRevealContent(tid) {

    var myelement = document.getElementById("c"+tid);

    if(myelement!=null) {
      if(myelement.style.display == "none") {
        myelement.style.display = "";
        document.getElementById("b"+tid).style.display = "none";
      }
      else {
        myelement.style.display = "none";
        document.getElementById("b"+tid).style.display = "";
      }
    }
}


// Top tabnav fix for IE6
var lastnavtab = "navtab2";
var ie6 = "";
function tabNavToggle(divid,disp,hover) {	
	// check to see if ie6 is being used
	var appVer = navigator.appVersion;
	appVer = appVer.split(';');
	if(appVer[1] == ' MSIE 6.0') {
		var ie6 = "yes";
	}	
	if (ie6 == "yes") {		
		if (disp != '') {		
			document.getElementById(lastnavtab+"a").style.backgroundPosition = "top right";
			document.getElementById(lastnavtab+"li").style.backgroundPosition = "top left";		
			if (divid != lastnavtab) {
				document.getElementById(lastnavtab).style.display = "none";
				lastnavtab = divid;
			}		
			if (disp == "block") {
				document.getElementById(divid+"a").style.backgroundPosition = "100% -42px";
				document.getElementById(divid+"li").style.backgroundPosition = "0% -42px";		
				document.getElementById(divid).style.display = disp;
			} else {
				document.getElementById(divid).style.display = disp;
			}
		}
		// if disp param is empty, there's no dropdown
		// for that li, so just change bg hover states.
		if (disp == '') {
			switch (hover) {
				case "on":
					document.getElementById(divid+"a").style.backgroundPosition = "100% -42px";
					document.getElementById(divid+"li").style.backgroundPosition = "0% -42px";
					break;
				case "off":
					document.getElementById(divid+"a").style.backgroundPosition = "top right";
					document.getElementById(divid+"li").style.backgroundPosition = "top left";
					break;
				default:
					return false;
			}		
		}		
	}	
}


// Content boxes
//var lastvoicetab = 'voices1';
var lastcommunitytab = 'community1';
var lastmmediatab = 'mmedia1';
var lastrecenttab = 'recent1';
var lastviewedtab = 'viewed1';
var lastproductstab = 'products1';
var lastrelatedtab = 'related1';
var lasttopicstab = 'topics1';
var lastsubstab = 'subs1';
var lastsktvtab = 'sktv1'
function toggleContent(box,idnum) {	
	var divid = box+idnum;
	switch (box){
  //voices content box
  //	case "voices":
  //		if (divid != lastvoicetab) {
  //			document.getElementById(lastvoicetab+"a").className = "";
  //			document.getElementById(lastvoicetab).style.display = "none";
  //			document.getElementById(divid+"a").className = "on";
  //			document.getElementById(divid).style.display = "block";
  //			lastvoicetab = divid;
  //		}
  //		break;
  //community content box
	case "community":
		if (divid != lastcommunitytab) {
			document.getElementById(lastcommunitytab+"a").className = "";
			document.getElementById(lastcommunitytab).style.display = "none";
			document.getElementById(divid+"a").className = "on";
			document.getElementById(divid).style.display = "block";
			lastcommunitytab = divid;
		}
		break;
  //multimedia content box
	case "mmedia":
		if (divid != lastmmediatab) {
			document.getElementById(lastmmediatab+"a").className = "";
			document.getElementById(lastmmediatab).style.display = "none";
			document.getElementById(divid+"a").className = "on";
			document.getElementById(divid).style.display = "block";
			lastmmediatab = divid;
		}
		break;
  //related content box
	case "related":
		if (divid != lastrelatedtab) {
			document.getElementById(lastrelatedtab+"a").className = "";
			document.getElementById(lastrelatedtab).style.display = "none";
			document.getElementById(divid+"a").className = "on";
			document.getElementById(divid).style.display = "block";
			lastrelatedtab = divid;
		}
		break;
  //topics content box
	case "topics":
		if (divid != lasttopicstab) {
			document.getElementById(lasttopicstab+"a").className = "";
			document.getElementById(lasttopicstab).style.display = "none";
			document.getElementById(divid+"a").className = "on";
			document.getElementById(divid).style.display = "block";
			lasttopicstab = divid;
		}
		break;
  //subscriptions content box
	case "subs":
		if (divid != lastsubstab) {
			document.getElementById(lastsubstab+"a").className = "";
			document.getElementById(lastsubstab).style.display = "none";
			document.getElementById(divid+"a").className = "on";
			document.getElementById(divid).style.display = "block";
			lastsubstab= divid;
		}
		break;
  //most recent content list
	case "recent":
		if (divid != lastrecenttab) {
			document.getElementById(lastrecenttab+"a").className = "";
			document.getElementById(lastrecenttab).style.display = "none";
			document.getElementById(divid+"a").className = "on";
			document.getElementById(divid).style.display = "block";
			lastrecenttab = divid;
		}
		break;
  //most viewed content list
	case "viewed":
		if (divid != lastviewedtab) {
			document.getElementById(lastviewedtab+"a").className = "";
			document.getElementById(lastviewedtab).style.display = "none";
			document.getElementById(divid+"a").className = "on";
			document.getElementById(divid).style.display = "block";
			lastviewedtab = divid;
		}
		break;
  //products content list
	case "products":
		if (divid != lastproductstab) {
			document.getElementById(lastproductstab+"a").className = "";
			document.getElementById(lastproductstab).style.display = "none";
			document.getElementById(divid+"a").className = "on";
			document.getElementById(divid).style.display = "block";
			lastproductstab = divid;
		}
		break;
  //SkillTV nav
	case "sktv":
		if (divid != lastsktvtab) {
			document.getElementById(lastsktvtab+"a").className = "";
			document.getElementById(lastsktvtab).style.display = "none";
			document.getElementById(divid+"a").className = "on";
			document.getElementById(divid).style.display = "block";
			lastsktvtab = divid;
		}
		break;
	default:
		return false;
	}
}


// For jump menu selects within content boxes
lastblogtab = 'blog1';
lastvoicestab = 'voices1';
function rboxmidSelect(prefix,targ,selObj,restore){ //v3.0
	var selected = selObj.selectedIndex+1;
	var divid = prefix+selected;	
	switch (prefix){
  //blog select
	case "blog":
		document.getElementById(lastblogtab).style.display = "none";
		document.getElementById(divid).style.display = "block";
		lastblogtab = divid;
		break;
  //voices select
	case "voices":
		document.getElementById(lastvoicestab).style.display = "none";
		document.getElementById(divid).style.display = "block";
		lastvoicestab = divid;
		break;
	default:
		return false;
	}
}


/* Deal with IE problems on hover for left nav*/


startList = function() {

	startListLeft();
	startListTop();
}

startListLeft = function() {

if (document.all&&document.getElementById) {
navRoot = document.getElementById("leftnav");
for (i=0; i<navRoot.childNodes.length; i++) {
node = navRoot.childNodes[i];
if (node.nodeName=="LI") {
node.onmouseover=function() {
this.className+=" over";
  }
  node.onmouseout=function() {
  this.className=this.className.replace(" over", "");
   }
   }
  }
 }
}

/* Deal with IE problems on hover for top nav*/
startListTop = function() {

if (document.all&&document.getElementById) {
navRoot = document.getElementById("topnav");
for (i=0; i<navRoot.childNodes.length; i++) {
node = navRoot.childNodes[i];
if (node.nodeName=="LI") {
node.onmouseover=function() {
this.className+=" over";
  }
  node.onmouseout=function() {
  this.className=this.className.replace(" over", "");
   }
   }
  }
 }
}

// set up axel and ord for DART
var axel = Math.random() + "";
var ord = Math.floor(axel * 100000000000000);

function refreshPopular() {
	(new Ajax()).doGet('/services/most_popular_processor.html');
}

function createCookie(name,value,days,host,path) {
	var expires = "";
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		expires = "; expires="+date.toGMTString();
	}
	
	var domain = '';
	if (host) {
		domain = "; domain="+host;
	}

	var folder = '';
	if (path) {
		folder = "; path="+path;
	}
	document.cookie = name+"="+value+expires+domain+folder;
}

function handle_validate_data(data)
{
	switch(data['status']) {
	case('success'):
		createCookie(data['name'], data['value'], 23, data['cookie_domain']);
		location.replace('/member/manage_account.html?q=user/' + data['uid'] + '/edit');
		break;
	case('expired'):
		param = '/member/register.php?status=expired';
		break;
	case('used'):
		param = '/member/login.php?status=used';
		break;
	}
	modalwindow();
	$('#modal_wrap').jqmShow();
}


// var print_count = 0;
function print_page()
{
  window.print();
  // window.close();
}

// Modal functions
var fade_close=function(hash){ hash.w.fadeOut('350',function(){ hash.o.remove(); }); };
var fade_open=function(hash) { hash.w.fadeIn('350'); };

function modalwindow()
{
	$('#modal_wrap').jqm({
		ajax: param,
		ajaxText: '<img id="ajax_loading" src="http://www.plantservices.com/images/user/ajax_loading.gif" height="100" width="100">',
		closeClass: 'modal_close',
		onHide: fade_close,
		onShow: fade_open,
		overlay: 80,
		overlayClass: 'modal_overlay',
		toTop: true,
		trigger: '.modal_trigger'
	});
}


// Manage Account -- focus form fields

var field = '';
var lasthash = '';

var onshow = function(){
		doshow();
};

function doshow() {
		if(field != '') {
				var selector = 'input#' + field;
				if(field == 'edit-pass-pass1') {
						var selector = 'input#' + field + ', input#edit-pass-pass2'; 
				}
				$(selector).addClass('highlight');
		}
		var focusid = field;
		if(focusid != '') {
				document.getElementById(focusid).focus();
		}
}

// initialize the variable everywhere
var put_registered = false;
