var lastpopup='';
var isNS=window.sidebar;

function hidePopup() {
   elem=document.getElementById(lastpopup);
   elem.style.display='none';
   lastpopup = '';
}

function show(obj, event, id, height, width) 
{
  var e;
  var p;
  var windowBottom;
  var windowRight;
  var top;
  var left;
  var adjLeft = false;
  var adjTop = false;
  
  // make sure we don't have more than one popup open
  if (lastpopup != '') {
      hidePopup();
  }

  // get the mouse coordinates 
  if (navigator.appName == 'Microsoft Internet Explorer') {
      top = event.clientY;
      left = event.clientX;
      // adjust for a scrolled widow
      if (document.documentElement && document.documentElement.scrollTop) { // Explorer 6 Strict
          left = left + document.documentElement.scrollLeft;
	  top = top + document.documentElement.scrollTop;
      }
      else {
	  left = left + document.body.scrollLeft;
	  top = top + document.body.scrollTop;
      }
  }
  else {
     top  = event.layerY;
     left = event.layerX;
  }

  // scoot the popup right and down a tiny bit
  top = top + 5;
  left = left + 5;
  
  // pad the height and width a bit
  height = height * 1.1;
  width = width * 1.1;
  
  // if we have a child menu with the right id make it visible
  e = document.getElementById(id);
  if (e) {
    // browser inconsistency
    if (typeof window.pageYOffset != 'undefined') {
      windowBottom = window.innerHeight + window.pageYOffset;
      windowRight = window.innerWidth + window.pageXOffset;
    }
    else if (typeof document.documentElement != 'undefined') {
      windowBottom = document.documentElement.clientHeight + document.documentElement.scrollTop;
      windowRight = document.documentElement.clientWidth + document.documentElement.scrollLeft;
    }
    else {
      windowBottom = document.body.clientHeight + document.body.scrollTop;
      windowRight = document.body.clientWidth + docment.body.scrollLeft;
    }

    // scoot the top up and left to keep the box on the screen 
    if ((height+top) > windowBottom) {
      top = windowBottom - height;
      adjTop = true;
    }

    if ((width+left) > windowRight) {
      left = windowRight - width;
      adjLeft = true;
    }
    
    // draw the popup
    e.style.position = 'absolute';
    e.style.left = left + 'px';
    e.style.top = top + 'px';
    e.style.height = height + 'px';
    e.style.zIndex = 20;
    e.style.visibility = 'visible';
    e.style.display = 'block';

    // figure out how to make the popup go away when we are done with it
    lastpopup = id;

    if (adjTop || adjLeft) {
      e.onmouseout = hidePopup;
    }
    else {
      obj.onmouseout = hidePopup;
    }
  }
}


// don't think we use this...
function unhide(whattounhide) {
   elem=document.getElementById(whattounhide);
   i=document.getElementById(whattounhide+"_img");
   currentstatus=elem.style.display;
   if (currentstatus=='block') {
      elem.style.display='none';
      i.src='images/plus.gif';
   } else {
      elem.style.display='block';
      i.src='images/minus.gif';
   }
}


function showClass(obj, e, classname) {
    show(obj, e, classname, 150, 300);
}

function showInstructor(obj, e, iname) {
    show(obj, e, iname, 250, 500);
}

function Dollar (val) {     // take str or num, return str
var str,pos,rnd=0;
  if (val < .995) rnd = 1;  // for old Netscape browsers
  str = escape (val*1.0 + 0.005001 + rnd);  // float, round, escape
  pos = str.indexOf (".");                  // should be one
  if (pos > 0) str = str.substring (rnd, pos + 3);
  return str;  // return valid PayPal dollar string
}

function ReadForm (obj1, tst) { // process un-named selects
var pos,val,txt,des,ary;
  if (tst && (obj1.a3.value == "")) {
    alert ("Make a subscription selection!");
    return;
  }
  des = obj1.basedes.value;           // base description
  pos = obj1.sub.selectedIndex;       // subscription selected
  txt = obj1.sub.options[pos].text;   // select text data
  val = obj1.sub.options[pos].value;  // select value data
  ary = val.split (",");              // isolate items in array
  obj1.t3.value  = ary[0].toUpperCase ();
  obj1.p3.value  = ary[1];
  obj1.a3.value  = Dollar (ary[2] * ary[1]);
  obj1.src.value = ary[3];
  obj1.sra.value = ary[4];
  obj1.item_name.value = des;
  obj1.item_number.value = val.toUpperCase ();
}

