var testwin = '';

function popup(sURL, w){
  if(!testwin.closed && testwin.location) {
    if(!testwin.opener ) testwin.opener = self;
    testwin.close();
  }
  testwin = window.open(sURL, "testwin", "menubar=no, toolbar=no, status=no, location=no, directories=no, width=" + w + ", height=640");

  if(window.focus) { (testwin.focus) }
  return false;
}

function popup2(sURL, w){
  if(!testwin.closed && testwin.location) {
    if(!testwin.opener ) testwin.opener = self;
    testwin.close();
  }
  testwin = window.open(sURL, "testwin", "menubar=no, toolbar=no, status=no, location=no, directories=no, width=" + w + ", height=405");

  if(window.focus) { (testwin.focus) }
  return false;
}

function popup3(sURL, w, h){
  if(!testwin.closed && testwin.location) {
    if(!testwin.opener ) testwin.opener = self;
    testwin.close();
  }
  testwin = window.open(sURL, "testwin", "menubar=no, toolbar=no, status=no, location=no, directories=no, width=" + w + ", height=" + h);

  if(window.focus) { (testwin.focus) }
  return false;
}

//add mouseover/mouseout to table rows in Table of Contents
function howto_content_hover () {

  var el = $('tableofcontents_tbl');
  var tds;

  if(parseFloat(Prototype.Version) < 1.6){
    tds = el.getElementsBySelector('td');
  } else {
    //Version 1.6 and above prototype
    tds = el.select('li');
  }

  tds.each(function (e) {
    var cur_class = e.className;
    var main_class = 'howto_content_tab';
    var hover_class = 'howto_content_tab_hover';
    var sel_class = 'howto_content_select';
    //Get the href from the link within the TD
    var a;
    if(parseFloat(Prototype.Version) < 1.6){
      a = e.getElementsBySelector('a')[0];
    } else {
      //Version 1.6 and above prototype
      a = e.select('a')[0];
    }

    e.observe('mouseover', function() {

      if(e.hasClassName(main_class)) {
        e.removeClassName(main_class);
        e.addClassName(hover_class);
      }

      if(a.href){
        window.status = a.href;
      }
    }.bindAsEventListener(e));

    e.observe('mouseout', function() {
      if(e.hasClassName(hover_class)){
        e.removeClassName(hover_class);
        e.addClassName(main_class);
      }

      window.status = '';

    }.bindAsEventListener(e));

    e.observe('click', function() {

      if(a.href){
        location.href = a.href;
      }

    }.bindAsEventListener(e));
  });
}
