 /*google analytics*/
function loadScript(url){ document.write('<script src="', url, '" type="text/javascript"></script>');}
loadScript("http://www.google-analytics.com/urchin.js");

//========== Error Handler ============
	window.onerror = abort;

function abort(msg){
  var msgTxt;
  if(msg){msgTxt = msg}
	else{msgTxt = 'Martini FAP 7e'}
  window.status = msgTxt;
  return true
}

var d = document;
var dt = d.title

// sets dtt = doc <title> tag (loads before doc.title)

if(d.getElementsByTagName('title')[0]) { var dtt = d.getElementsByTagName('title')[0].innerHTML;}

/* var uA = navigator.userAgent */
/* if((uA.indexOf('MSIE 5.')>-1) && (uA.indexOf('Mac_PowerPC')>-1)) */
/* 	{var isMacIE5 = true;} */
/* if(isMacIE5 && dtt=="Movies")  */
/* 		  {playMacIE5();} */
		  
/* =========================================
	   CSS
=========================================*/
var navCSS = (d.URL.indexOf('navbar')>-1)?'leftnav':'pc';
d.write("<LINK REL='Stylesheet' HREF='"+myRoot+"css/"+navCSS+".css'>");


//::::::: Style Object  ::::::::
/* cross-browser function to get an object's style object given its id */

function getStyleObject(objID) {
      if(d.getElementById && d.getElementById(objID)) {
	// W3C DOM
	  return d.getElementById(objID).style;
      } else if (d.all && d.all(objID)) {
	// MSIE 4 DOM
	  return d.all(objID).style;
      } else if (d.layers && d.layers[objID]) {
	// NN 4 DOM.. note: this won't find nested layers
	  return d.layers[objID];
      } else { return false; }
}

function doStyle(objID,prop,val) {
  var s = getStyleObject(objID);
  if(s) {s[prop]=val}
}

/* =========================================
	   GENERAL
=========================================*/

var medialibPath = cssDir.substring(0,cssDir.indexOf('_wps_stylereplacable'))
/* path to site medialib in WPS; includes trailing "/";
use "myRoot" var for the _wps_stylereplacable folder */

var fWin = null;

function openFlashcards(url) { 
  if (!fWin || fWin.closed) {
    fWin = window.open(url, 'Flashcards', 'toolbar=0,location=0,status=0,menubar=0,scrollbars=auto,resizable=1,width=580,height=500');
   } else {
     fWin.location = url;
     fWin.focus();
}}

function openHint(hinturl)
{
var hintWindow = window.open(hinturl, 'Hint', 'height=400,width=500,toolbar=no,resizable=yes,scrollbars=yes');
if(hintWindow.opener == null) hintWindow.opener = window;
hintWindow.focus();
}

/* ====== WPS REDIRECT CODE (from Christian Lee) ====== */

function resolvePath(myLink,qURL) {
        var myURL = '';
        //trim off last seven character beyond the .html
        var trimEnd = myLink.length - 7;
        //start 10 characters into the value of myLink
        //I know 10 character will get us beyond the a, href, and = sign
        for ( var i=10; i<trimEnd; i++ ) {
                myURL = myURL + myLink.charAt(i);
        }
        //use a RegExp() to get the pattern of a CURL
        var myPattern = /[01],\d*,\d+(-(\w*))?,\d*(\.utf8)?\.html/g;
        // Fix for new URL syntax:
        var urlStartIdx = myLink.indexOf('"');
        var urlEndIdx = myLink.indexOf('"', urlStartIdx + 1);
        var myNewURL = myLink.substring(urlStartIdx + 1, urlEndIdx);
        var myCURL = myPattern.exec(myURL);
        //var myLocat = myCURL[0].toString();
        myRedirect(myNewURL,qURL);
}

function myRedirect(myLocat,qURL) {self.location.href=myLocat+qURL;}

function wpsLink(myLink) {
	resolvePath(myLink); }


//=============================================
//=-=-=-=-=-= onLoad event handler =-=-=-=-=-=

window.onload = runJS;

function runJS(){

  hideExtraRows("left_nav_vspace","breadcrumb_above","breadcrumbs_below", "topnav_links_above");
	if(self==top.frames['navcont'].frames['CONTENT']){
		   doNavBar(dtt);
	}
	else if(self==top.frames['navcont'].frames['navbar'])
		{ gbLinks(); resizeSeparator();
		}
}

//LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL
//NNNNNNNNNNNNNNNN   LEFTNAV  NNNNNNNNNNNNNNNN


var ff=0;

function doNavBar(dtt){
	var nav = parent.frames['navbar']
		if(nav.d){
			nav.setNav(dtt);
			//nav.putOnHat();
		}else{ff++; if(ff<5){doNavBar(dtt);}}
}

function resizeSeparator() {
	var sepImg = d.images['Separator']
	if(sepImg){
	sepImg.className='separatorImg';
}}

var orange1 = '', orange2 = '';
var blue1 = '';


// convert leftnav gradebook buttons to text links
function gbLinks(){
	var n = ["cm","ci","gb","rr","jac"];
	var nTxt = ["Class Manager","Class Info","Gradebook","Results Reporter","Join a Class"]
	for(i=0;i<n.length; i++){
		if(d.images[n[i]]){
			var img = d.images[n[i]];
				img.style.display = "none"
			var txt = nTxt[i];
			} else {continue}
		if(img && txt){
		var tn = d.createTextNode(txt);
		var gbLink = img.parentNode;
				gbLink.className='gbLink';
			var gbID = 'gbLink'+i; gbLink.setAttribute('id',gbID);
				gbLink.onmouseover='javascript:doNavStyle("'+gbID+'",1.1)'
				gbLink.onmouseout='javascript:doNavStyle("'+gbID+'",0.1)'
		gbLink.insertBefore(tn,img);
			} else {continue}
	}
}


//=-=-=-=-=-= Set leftnav selected button =-=-=-=-=-=

function setNav(mod) {
	var navDoc = parent.frames['navbar'].document
	if(navDoc){		  
	  for(i=0;i<navDoc.links.length;i++) {
		  var dl = navDoc.links[i];
		  var nodeTxt = dl.firstChild.nodeValue;
		  	if(nodeTxt=='Calculator') {
			  dl.href = 'javascript:openCalc();';
			  dl.removeAttribute('target')
			}
		   if(dl.id.indexOf('gbLink') > -1){continue}
		  var newID = 'navLink'+i;
			  dl.setAttribute('id',newID);
		  doNavStyle(newID,0);
			  dl.setAttribute('onmouseover','javascript:doNavStyle("'+newID+'",1)')
			  dl.setAttribute('onmouseout','javascript:doNavStyle("'+newID+'",0)')
		  if(nodeTxt==mod){ 	  //compare navlink with CONTENT title
			  doNavStyle(newID,1);
			  dl.setAttribute('onmouseover','')
			  dl.setAttribute('onmouseout','')
		  } else {continue}
	  }}
}

function doNavStyle(id,swch){
	if(swch==1){doStyle(id,'backgroundColor',blue1);}
	else if(swch==0){
		doStyle(id,'backgroundColor','');}
	else if(swch==0.1){
		doStyle(id,'backgroundColor','');
		doStyle(id,'color',orange1);}
	else if(swch==1.1){     // highlight for navbar gradebook links
		doStyle(id,'backgroundColor',orange1);
		doStyle(id,'color','#fff');} 
}


function openCalc(){		window.open("http://media.pearsoncmg.com/bc/bc_hewitt_conceptual_9/medialib/calculator/index.html","Calculator","toolbar=no,location=no,status=no,menubar=no,scrollbars=no,width=200,height=280,resizable=no");
}

function reloadNavBar() {return true}

//=-=-=-=-=-= hide extra breadcrumbs rows =-=-=-=-=-=

var tds = d.getElementsByTagName("TD")

function hideExtraRows(classNames){
if(tds){
var args = hideExtraRows.arguments
for (i=0;i<tds.length;i++){
	var tc = (tds[i].className)?(tds[i].className):null;
	for(j=0;j<args.length;j++){
		if(tc==args[j]){tds[i].parentNode.style.display = 'none';}}
}}}


//OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO
//=-=-=-=-=-= OVERVIEW GRIDS =-=-=-=-=-=

function tweakGrid(){
var tdTags = d.getElementsByTagName("TD")
for (i=0;i<tdTags.length;i++){
	if(tdTags[i].parentNode.className=="rowHead"){
		tdTags[i].setAttribute("id","gridCorner");
		var gc = tdTags[i];
		break;}}
var t3 = d.getElementsByTagName('table').item(2)
t3.parentNode.insertBefore(d.createElement('br'),t3)
}



/* 
=========================================
GENERAL functions
=========================================
*/

var fWin = null;
function openFlashcards(url) { 
  if (!fWin || fWin.closed) {
    fWin = window.open(url, 'Flashcards', 'toolbar=0,location=0,status=0,menubar=0,scrollbars=auto,resizable=1,width=580,height=500');
   } else {
     fWin.location = url;
     fWin.focus();
}}

function openHint(hinturl){ 
	var hintWindow = window.open(hinturl, 'Hint', 'height=400,width=500,toolbar=no,resizable=yes,scrollbars=yes');
	if(hintWindow.opener == null) hintWindow.opener = window;
	hintWindow.focus();}

// bullet
var nv7,nu=navigator.userAgent,b1='&#8227;',b2='<span class=dingBullet>4<\/span>';
if ((nu.indexOf("Netscape/7") != -1) && (nu.indexOf("Macintosh") == -1)) {nv7=true}
else {nv7=false}
var bullet=nv7?b1:b2

//  for Web Links
//for labeling activities

function openTutorial(tUrl) {
window.open(tUrl,'tut_window','toolbar=1,location=1,status=1,menubar=1,scrollbars=1,resizable=1,width=800,height=600');
}

function opentutorial(tUrl) {
window.open(tUrl,'tut_window','toolbar=1,location=1,status=1,menubar=1,scrollbars=1,resizable=1,width=800,height=600');
}


//***************************  


