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;

function goDictionary(linkObj) {
	var definition="";
	if (typeof(linkObj)=="string")
	{
		definition=linkObj;
	}
	else
	{
		definition=linkObj.innerText;
	}

	popupPage("define","/public/define.asp?define=" + definition,490, 250)
}

//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 enableQuantSkills()
{
  WM_setCookie ("qskills", "yes", 0, "/topics", location.host, false);
}

function disableQuantSkills()
{
  WM_killCookie("qskills","/topics",location.host);
}

function isEven (n) {
  return n % 2 == 0;
}
function isOdd (n) {
  return n % 2 != 0;
}

function addAnswer(idx,w,h)
{
  if ((WM_readCookie ("itip")=="yes") || ((isOdd(idx) && (WM_readCookie("amode")=="1" || WM_readCookie("amode")=="3")) || (isEven(idx) && (WM_readCookie("amode")=="2" || WM_readCookie("amode")=="3"))) ) {
    document.write('<a onClick="window.status=\'\'; return true;" onMouseOut="window.status=\'\'; return true;" onMouseOver="window.status=\'Answer\'; return true;" href="Javascript:popupPage(');
    document.write("'answer','answer"+idx+".htm',"+w+","+h+");");
    document.write('"><img border="0" src="/images/btn_answer.gif"></a>');
  }
}

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 addQuantSkills(title,page,w,h)
{
  if (WM_readCookie("qskills")=="yes")
  {
    //alert('pop');
    document.write('<a href="Javascript:popupPage(');
	document.write("'"+title+"','"+page+"',"+w+","+h+");");
	document.write('"><img border="0" src="/images/btn_quanskills.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) {
  var purl = new String(page);
  
  x = (screen.availWidth - w)/2
  y = (screen.availHeight -h)/2
  if (purl.charAt(0) != "/" && purl.indexOf("http://")!=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 sketchx(pathname,w,h) {
  if (!w) {
    w = 725
  }
  if (!h) {
    h = 445
  }

  popupExploreWindow("sketch","/applets/"+pathname,w,h)

}


function sketchx_waldman(pathname,w,h) {
  if (!w) {
    w = 725
  }
  if (!h) {
    h = 445
  }

  popupPage("sketch","/applets/waldmanmicro/swf_frame.asp?theswf="+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,454);
}

function contactus_support() {
  popupPage('support','/public/contact_us.asp?support=yes',508,454);
}

function graphcalc(myurl,myw, myh) {
  
  var winName = 'graphcalc'
  var width = myw
  var height = myh
  var winURL = myurl

  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'
  var winURL = '/applets/grapher_only_standalone.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 graphSolveit(srcFile) {
  
  var winName = 'graphersolveit'
  var width = 725
  var height = 445
  var winURL = '/applets/graphsolveit.asp?src='+escape(srcFile);

  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);
}

//Popups up a file with scrollbar
function popup_scroll(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=yes"+",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);
}

function popupJavaWindow(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 = (screen.availWidth - width)/2
    y = (screen.availHeight -height)/2
    newWin = window.open(winURL,winName,"resizable=yes,height="+height+",width="+width+",scrollbars=yes"+",left="+x+",top="+y)
    addPopupWindow(winName,newWin)
  }
}

function addAnswer_finance(idx,w,h)
{
  if ((WM_readCookie ("itip")=="yes") || ((isOdd(idx) && (WM_readCookie("amode")=="1" || WM_readCookie("amode")=="3")) || (isEven(idx) && (WM_readCookie("amode")=="2" || WM_readCookie("amode")=="3"))) ) {
    document.write('<a onClick="window.status=\'\'; return true;" onMouseOut="window.status=\'\'; return true;" onMouseOver="window.status=\'Answer\'; return true;" href="Javascript:popupPage(');
    document.write("'answer','answer"+idx+".htm',"+w+","+h+");");
    document.write('"><img border="0" src="/images/btn_answer_red.gif"></a>');
  }
}

function toGoldLink(classId, roleId) {
    loc = "/protected/student/goldlink.asp?classId="+classId+"&role="+roleId;
    popupPage('goldlink',loc,900,600);
}
  
function hideStudentResource()
{

  if ((WM_readCookie ("hideResource")=="1") || (WM_readCookie ("approved")=="no"))  {
	var headID = document.getElementsByTagName("head")[0];         
	var cssNode = document.createElement('link');
	cssNode.type = 'text/css';
	cssNode.rel = 'stylesheet';
	cssNode.href = '/common/hiddenclass_hide.css';
	headID.appendChild(cssNode);  

  } else {
	var headID = document.getElementsByTagName("head")[0];         
	var cssNode = document.createElement('link');
	cssNode.type = 'text/css';
	cssNode.rel = 'stylesheet';
	cssNode.href = '/common/hiddenclass_show.css';
	headID.appendChild(cssNode);  
  }
}

