var winPage = null
var popupNames = new Array()
var popupWindows = new Array()

//Add basePath for MAC bug.  Basically, get the path from current page 
//and use it to refernce popup window html
var basePopupPath;

//First check for a ? in the path and get rid of it and everything to the right
idx = location.href.indexOf("?")
if (idx < 0) {
  basePopupPath = location.href;
} else {
  basePopupPath = location.href.substring(0,idx);
}
//Now truncate up to last slash
basePopupPath = basePopupPath.substring(0,basePopupPath.lastIndexOf("/")+1)

function enableInstructorTips()
{
  WM_setCookie ("itip", "yes", 0, "/topics", location.host, false);
}

function disableInstructorTips()
{
  WM_killCookie("itip","/topics",location.host);
}

function addInstructorTip(title,page,w,h)
{
  if (WM_readCookie("itip")=="yes")
  {
    //alert('pop');
    document.write('<a href="Javascript:popupPage(');
	document.write("'"+title+"','"+page+"',"+w+","+h+");");
	document.write('"><img border="0" src="/images/btn_instructortip.gif"></a>');
  }
}

function getPopupWindow(popupName)
{
  var i
  for (i=0; i<popupNames.length;i++)
  {
    if (popupNames[i] == popupName)
     return popupWindows[i]
  }
  return null
}

function addPopupWindow(popupName,popupWindow)
{
  var idx
  idx = popupNames.length;
  popupNames[idx] = popupName
  popupWindows[idx] = popupWindow
}


function popupPage(title,page,w, h) {
  x = (screen.availWidth - w)/2
  y = (screen.availHeight -h)/2
  if (page.charAt(0) != "/")
  {
    page = basePopupPath + page;
  }
  winPage=makePopupWindowPos(winPage, title, page,w,h,x,y)
}

function popupExploreWindowTopLeft(winName,winURL,width,height)
{
  //First lookup name in list of available windows.
  //If it already exists and is not closed then just
  //bring it to the front.  If not, then create it and
  //add it to the list.
  win = getPopupWindow(winName)
  if (win != null && ! win.closed) {
    win.focus()
  } else {
    x = 0;
    y = 0;
    newWin = window.open(winURL,winName,"resizable=no,height="+height+",width="+width+",scrollbars=no"+",left="+x+",top="+y)
    addPopupWindow(winName,newWin)
  }
}

function popupExploreWindow(winName,winURL,width,height)
{
  var win;
  //First lookup name in list of available windows.
  //If it already exists and is not closed then just
  //bring it to the front.  If not, then create it and
  //add it to the list.
  win = getPopupWindow(winName)
//  if (win != null && ! win.closed) {
// 	alert("found "+winName+"url="+win.location.pathname+" newuRL="+winURL)
//  }
  if (win != null && ! win.closed && (win.location.pathname == winURL)) {
//	alert("found "+winName+"url="+win.location.pathname+" newuRL="+winURL)
    win.focus()
  } else {
    x = (screen.availWidth - width)/2
    y = (screen.availHeight -height)/2
    newWin = window.open(winURL,winName,"resizable=no,height="+height+",width="+width+",scrollbars=no"+",left="+x+",top="+y)
    addPopupWindow(winName,newWin)
	newWin.focus();
  }
}


function explorex(pathname,w,h) {
  if (!w) {
    w = 710
  }
  if (!h) {
    h = 360
  }

  popupExploreWindow("explore","/applets/"+pathname,w,h)

}


function explore(name,w,h) {


  if (!w) {
    w = 710
  }
  if (!h) {
    h = 360
  }

  var htmlName;

  htmlName = name.substr(name.lastIndexOf("/")+1)
  

  popupExploreWindow("explore","/applets/"+name+"/"+htmlName+".html",w,h)
}


function uc() {
  popupPage('uc','/public/under_construction.htm',518,110);
}

function contactus() {
  popupPage('contact','/public/contact_us.asp',508,350);
}

function graphcalc() {
  
  var winName = 'graphcalc'
  var width = 350
  var height = 350
  var winURL = '/applets/graphcalc.html'

  win = getPopupWindow(winName)
  if (win != null && ! win.closed) {
    win.focus()
  } else {
    x = 0
    y = 0
    newWin = window.open(winURL,winName,"resizable=no,height="+height+",width="+width+",scrollbars=no"+",left="+x+",top="+y)
    addPopupWindow(winName,newWin)
  }
//  popupPage('graphcalc','/applets/graphcalc.html',350,350);
}

function grapher() {
  
  var winName = 'grapher'
  var width = 725
  var height = 445
  var winURL = '/applets/grapher.html'

  win = getPopupWindow(winName)
  if (win != null && ! win.closed) {
    win.focus()
  } else {
    x = 0
    y = 0
    newWin = window.open(winURL,winName,"resizable=no,height="+height+",width="+width+",scrollbars=no"+",left="+x+",top="+y)
    addPopupWindow(winName,newWin)
  }
//  popupPage('graphcalc','/applets/graphcalc.html',350,350);
}



//Popups up a file with no scrollbar
function popupx(winName,winURL,width,height) {
  var x,y;  
  var win;
  x = (screen.availWidth - width)/2
  y = (screen.availHeight -height)/2
  if (winURL.charAt(0) != "/")
  {
    winURL = basePopupPath + winURL;
  }

  win = getPopupWindow(winName)
  if (win != null && ! win.closed) {
    win.focus()
  } else {
    x = 0
    y = 0
    newWin = window.open(winURL,winName,"resizable=no,height="+height+",width="+width+",scrollbars=no"+",left="+x+",top="+y)
    addPopupWindow(winName,newWin)
  }
//  popupPage('graphcalc','/applets/graphcalc.html',350,350);

function mustlogin() {
  
  var winName = 'mustlogin'
  var width = 510
  var height = 90
  var winURL = '/public/mustlogin.asp'

  win = getPopupWindow(winName)
  if (win != null && ! win.closed) {
    win.focus()
  } else {
    x = 0
    y = 0
    newWin = window.open(winURL,winName,"resizable=no,height="+height+",width="+width+",scrollbars=no"+",left="+x+",top="+y)
    addPopupWindow(winName,newWin)
  }
//  popupPage('graphcalc','/applets/graphcalc.html',350,350);
}
}