/*
* Developed by Fusion Learning Systems, 2002
* Exception: All MM_ methods are MacroMedia.
*/


//*********************************************************************************//
//	This function analyzes the parses the query string and adds the name/value pairs
//  to an array, args.
//*********************************************************************************//
function getArgs()
{
	var args = new Object();
	var queryString = window.location.search.substring(1);
	var pairs = queryString.split("&");
	//loop through the queryString
	for(var i=0;i < pairs.length; i++)
	{
		var pos = pairs[i].indexOf('=');
		if (pos == -1) continue;
		var name = pairs[i].substring(0,pos);
		var value = pairs[i].substring(pos+1);
		args[name] = unescape(value);
	}
	return args;
}

//*********************************************************************************//
//	This function grabs a value out of the args array, from getArgs() (see above)
//*********************************************************************************//
function handleQueryString(folder)
{
	var args = getArgs();
	var file = "";
	if (args.file)
	{
		file = args.file;
		mediafile = folder+file;
		return mediafile;
	}
	else if (args.footnote)
	{
		return args.footnote;
	}
}

//*********************************************************************************//
//	This function creates a string that can be referenced in the page by document.write()
//*********************************************************************************//
function writeQuickTime(mediafile, h, w)
{
	var string = "<object classid='clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B' height='"+h+"' width='"+w+"' codebase='http://www.apple.com/qtactivex/qtplugin.cab'>";
	string += "	<param name='src' value='"+mediafile+"'>";
	string += "	<param name='autoplay' value='true'>";
	string += "	<param name='controller' value='true'>";
	string += "	<param name='pluginspace' value='htp/www.apple.com/quicktime/download/indext.html'>";
	string += "	<embed src='"+mediafile+"' height='"+h+"' width='"+w+"' autoplay='true' controller='true' pluginspace='http://www.apple.com/quicktime/download/'></embed>";
	string += "</object>";
	return string;
}

//*********************************************************************************//
// loadTool function for 2006 editions
// This function takes a selected value and loads the URL and window parameters
//*********************************************************************************//

function loadTool_2006(toolValue)
{
	switch( toolValue )
	{
		case "periodic_table":
		{
			//alert("Periodic Table");
		 	toolPopupWindow = window.open('pertab.htm','toolPopupWindow','width=640,height=490,scrollbars=yes,resizable=yes,menubar=no');
		 	//http://go.hrw.com/resources/go_sc/periodic/per_tab.htm
		 	break;
		}
		default:
		{
			loadTool(toolValue);
			break;
		}
	}
}

//*********************************************************************************//
// This function takes a selected value and loads the URL and window parameters
//*********************************************************************************//

function loadTool(toolValue1)
{
	// Was an edition value passed as the second parameter
	if( arguments.length > 1 )
	{
		// Calculate the edition specific loadTool function name
		var editionLoadToolFunc = 'loadTool_' + arguments[1];

		// Is the edition specific function defined?
		if( self[editionLoadToolFunc] )
		{
			// Call the edition specific function and exit this function
			self[editionLoadToolFunc](toolValue1);
			return;
		}
	}

	if (toolValue1 != "")
		{
			// If glossary, then parse tool Value
			// glossary paramater should be in the form glossary_bookid_isbnvalue (eg. glossary_h6x_00223423432)
			if (toolValue1.substring(0,8) == "glossary")
			{
			  toolValue = "glossary";
			} // end glossary case
			else
			{
				toolValue = toolValue1;
			} // end non glossary cases

			switch (toolValue) {
				case "grapher":
				{
				 	//alert("Grapher");
					toolPopupWindow = window.open('http://grapher.hrw.com','toolPopupWindow','width=650,height=440,resizable=yes,menubar=no,scrollbars=yes');
				  	break;
				}
				case "periodic_table":
				{
					//alert("Periodic Table");
				  	toolPopupWindow = window.open('http://go.hrw.com/resources/go_sc/periodic/per_tab.htm','toolPopupWindow','width=640,height=490,scrollbars=yes,resizable=yes,menubar=no');
				  	break;
				}
				case "notebook":
				{
					//alert("Notebook");
					toolPopupWindow = window.open('tool.html','toolPopupWindow','width=300,height=300,resizable=yes,menubar=no,scrollbars=no');
				  	break;
				}
				case "glossary":
				{
				   // alert("Glossary");
				   toolPopupWindow = window.open('http://go.hrw.com/resources/go_sc/glossary/frame.htm','toolPopupWindow','width=570,height=500,scrollbars=yes,resizable=no,menubar=no');
				   break;
				}
				case "scientific_calculator":
				{
					//alert("Scientific Calculator");
				  toolPopupWindow = window.open('/sh2/sh07_10/student/calc/Sci_Calculator.html','toolPopupWindow','width=640,height=490,scrollbars=yes,resizable=yes,menubar=no');
				  break;
				}
				case "graphing_calculator":
				{
					//alert("Graphing Calculator");
				  toolPopupWindow = window.open('/sh2/sh07_10/student/calc/graphCalc.html','toolPopupWindow','width=640,height=490,scrollbars=yes,resizable=yes,menubar=no');
				  break;
				}
				case "highlighted":  
				{ 
					parent.content.page.annotation.createAnnotation('highlight',true);
				  	break;					
				}
				case "deletehighlighted":  
				{ 
					parent.content.page.annotation.deleteHighlight();
				  	break;					
				}
				case "annotated":  
				{ 
				alert("annotated");
					parent.content.page.annotation.createAnnotation('normal',true);
				  	break;					
				}
				case "hideannotated":  
				{ 
					parent.content.page.annotation.hideAllAnnotations();
				  	break;					
				}
				case "showannotated":  
				{ 
					parent.content.page.annotation.showAllAnnotations();
				  	break;					
				}
				case "setbookmarked":  
				{ 
					top.setBookmark();
				  	break;					
				}
				case "gotobookmarked":  
				{ 
					top.gotoBookmark();
				  	break;					
				}
				case "howtouse":  
				{ 
					GP_AdvOpenWindow('../selectHelp.jsp','htuwindow','fullscreen=no,toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes',500,400,'center','ignoreLink','',0,'');
				  	break;					
				}

			}//end switch
		}//end if not empty
}

//*********************************************************************************//
//This function loads a popup in the Parent Window to be used for calling audio media
//*********************************************************************************//

function loadAudio(gotoPage) {
	audioPopupWindow = window.open(gotoPage,'audiowindow','width=325,height=120,resizable=yes,menubar=no,scrollbars=no');
	if (window.focus) {audioPopupWindow.focus()}
}

function downloadAudio(gotoPage) {
	//audioPopupWindow = window.open(gotoPage,'audiowindow','width=325,height=120,resizable=yes,menubar=no,scrollbars=no');
	//if (window.focus) {audioPopupWindow.focus()}
	location.href = gotoPage;
}

//*********************************************************************************//
//This function loads a URL in the Parent Window
//*********************************************************************************//

function loadURL(url) {
	window.parent.location=url;
}

//*********************************************************************************//
//This function loads a redirected URL in the Parent Window
//*********************************************************************************//

function redirect(url) {
	//setTimeout(redirect(),10000);
	window.location.replace(url);
}

//*********************************************************************************//
// This function lauches the popup window
// Browser detect opens different size window to accomodate Netscape
// Netscape window: 788 X 525
// IE window: 788 X 494
// May have to adjust size for MAC
//*********************************************************************************//

function loadPopup(gotoPage) {
 var bName=navigator.appName;
var bVer=parseInt(navigator.appVersion);
var platform=navigator.platform.substr(0,3);

// If user OS is Windows
if (platform=="Win") {
	//Netscape
	if ((bName=="Netscape") && (bVer<=4)) {
		popupWindow = window.open(gotoPage,'popupwindow','width=788,height=525,resizable=yes,menubar=yes');
		if (window.focus) {popupWindow.focus()}
	}
	//MSIE4
	else {
		popupWindow = window.open(gotoPage,'popupwindow','width=788,height=494,resizable=yes,menubar=yes');
		if (window.focus) {popupWindow.focus()}
	}

// If user OS is Mac
} else if (platform=="Mac") {
	//Netscape
	if ((bName=="Netscape") && (bVer>=4)) {
		popupWindow = window.open(gotoPage,'popupwindow','width=788,height=525,resizable=yes,menubar=yes');
		if (window.focus) {popupWindow.focus()}
	}
	//MSIE
	else {
		popupWindow = window.open(gotoPage,'popupwindow','width=788,height=494,resizable=yes,menubar=yes');
		if (window.focus) {popupWindow.focus()}
		}
	}
}

//*********************************************************************************//
// This function lauches the popup window
// Browser detect opens different size window to accomodate Netscape
// Netscape window: 830 X 630
// IE window: 830 X 630
// May have to adjust size for MAC
//*********************************************************************************//

//*********************************************************************************//
// This function for Virtual Investigations
//*********************************************************************************//

function loadPopupVI(gotoPage) {
 var bName=navigator.appName;
var bVer=parseInt(navigator.appVersion);
var platform=navigator.platform.substr(0,3);

// If user OS is Windows
if (platform=="Win") {
	//Netscape
	if ((bName=="Netscape") && (bVer<=4)) {
		popupWindow = window.open(gotoPage,'popupwindow','width=830,height=630,resizable=yes,scrollbars=yes');
		if (window.focus) {popupWindow.focus()}
	}
	//MSIE4
	else {
		popupWindow = window.open(gotoPage,'popupwindow','width=830,height=630,resizable=yes,scrollbars=yes');
		if (window.focus) {popupWindow.focus()}
	}

// If user OS is Mac
} else if (platform=="Mac") {
	//Netscape
	if ((bName=="Netscape") && (bVer>=4)) {
		popupWindow = window.open(gotoPage,'popupwindow','width=830,height=630,resizable=yes,scrollbars=yes');
		if (window.focus) {popupWindow.focus()}
	}
	//MSIE
	else {
		popupWindow = window.open(gotoPage,'popupwindow','width=830,height=630,resizable=yes,scrollbars=yes');
		if (window.focus) {popupWindow.focus()}
		}
	}
}


//*********************************************************************************//
// This function loads the Help Window
//*********************************************************************************//

function loadHelp(gotoPage) {
	popupWindow = window.open(gotoPage,'helpwindow','width=550,height=450,resizable=yes,menubar=yes,scrollbars=yes');
}

//*********************************************************************************//

function loadTour(gotoPage) {
	popupWindow = window.open(gotoPage,'tourwindow','width=789,height=541,resizable=no,toolbar=no,menubar=no,scrollbars=no');
}
//Netscape 4: 788x541 window size produces 800x572 window in NS 4. Windows 2000 gray task bar is 28 high.
//Netscape 4: 789x542 window size produces 801x573 window in NS 4. Windows 2000 gray task bar is 28 high.
//IE 5: 788x541 window size produces 798x570 window in IE 5. Windows 2000 gray task bar is 28 high.
//IE 5: 789x542 window size produces 799x571 window in IE 5. Windows 2000 gray task bar is 28 high.
//WinXP blue interface: 789x542 window will extend about 10px under task bar. Blue task bar is 34 high.
//WinXP blue interface: 541 height would have to be changed to 530 to accommodate thicker WinXP blue browser interface and task bar.

//*********************************************************************************//

function loadTutor(gotoPage) {
	//SCITUTOR LINKS
	//popupWindow = window.open(gotoPage,'tutorwindow','width=775,height=550,resizable=yes,menubar=yes,scrollbars=no');
	popupWindow = window.open(gotoPage,'tutorwindow','menubar=no,toolbar=no,resizable=yes,scrollbars=yes,dependent=yes,status=0,alwaysRaised=yes,width=790,height=544');
	//popupWindow = window.open(gotoPage,'tutorwindow','menubar=no,toolbar=no,resizable=no,scrollbars=no,dependent=yes,status=0,alwaysRaised=yes,width=800,height=600');
}

//*********************************************************************************//

function loadCpyrghtLinks(gotoPage) {
	popupWindow = window.open(gotoPage,'cpyrghtlinkswindow','width=575,height=450,resizable=yes,scrollbars=yes');
}

//*********************************************************************************//

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

//*********************************************************************************//
function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

//*********************************************************************************//
function MM_nbGroup(event, grpName) { //v3.0
  var i,img,nbArr,args=MM_nbGroup.arguments;
  if (event == "init" && args.length > 2) {
    if ((img = MM_findObj(args[2])) != null && !img.MM_init) {
      img.MM_init = true; img.MM_up = args[3]; img.MM_dn = img.src;
      if ((nbArr = document[grpName]) == null) nbArr = document[grpName] = new Array();
      nbArr[nbArr.length] = img;
      for (i=4; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
        if (!img.MM_up) img.MM_up = img.src;
        img.src = img.MM_dn = args[i+1];
        nbArr[nbArr.length] = img;
    } }
  } else if (event == "over") {
    document.MM_nbOver = nbArr = new Array();
    for (i=1; i < args.length-1; i+=3) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = (img.MM_dn && args[i+2]) ? args[i+2] : args[i+1];
      nbArr[nbArr.length] = img;
    }
  } else if (event == "out" ) {
    for (i=0; i < document.MM_nbOver.length; i++) {
      img = document.MM_nbOver[i]; img.src = (img.MM_dn) ? img.MM_dn : img.MM_up; }
  } else if (event == "down") {
    if ((nbArr = document[grpName]) != null)
      for (i=0; i < nbArr.length; i++) { img=nbArr[i]; img.src = img.MM_up; img.MM_dn = 0; }
    document[grpName] = nbArr = new Array();
    for (i=2; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = img.MM_dn = args[i+1];
      nbArr[nbArr.length] = img;
  } }
}

//*********************************************************************************//
function MM_reloadPage(init) {
//reloads the window if Nav4 resized
	if (init==true) with (navigator) {
		if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
			document.MM_pgW=innerWidth;
			document.MM_pgH=innerHeight;
			onresize=MM_reloadPage;
		}
	}
	else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH){
	location.reload();
	}
}

MM_reloadPage(true);

//*********************************************************************************//
// sets visibility of <div> object taking into account IE/NS differences in DOM.
function showHideObject(obj, visible) {
    v = visible
    if (obj.style) {
	  obj=obj.style;
	  v=(v=='show')?'visible':(v='hide')?'hidden':v;
    }
    obj.visibility=v;
}


//*********************************************************************************//
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr;
  for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++)
  x.src=x.oSrc;
}

//*********************************************************************************//
function MM_swapImage() { //v3.0
  var i,
  j=0,x,a=MM_swapImage.arguments;
  document.MM_sr=new Array;
  for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null)
   	{
		document.MM_sr[j++]=x;
			if(!x.oSrc) x.oSrc=x.src;
			x.src=a[i+2];
	}
}


//*********************************************************************************//
// This function loads the AuthorSpace Window
// Developed by CodeWest
//*********************************************************************************//

function GP_AdvOpenWindow(theURL,winName,features,popWidth,popHeight,winAlign,ignorelink,alwaysOnTop,autoCloseTime,borderless) { //v2.0
  var leftPos=0,topPos=0,autoCloseTimeoutHandle, ontopIntervalHandle, w = 480, h = 340;  
  if (popWidth > 0) features += (features.length > 0 ? ',' : '') + 'width=' + popWidth;
  if (popHeight > 0) features += (features.length > 0 ? ',' : '') + 'height=' + popHeight;
  if (winAlign && winAlign != "" && popWidth > 0 && popHeight > 0) {
    if (document.all || document.layers || document.getElementById) {w = screen.availWidth; h = screen.availHeight;}
		if (winAlign.indexOf("center") != -1) {topPos = (h-popHeight)/2;leftPos = (w-popWidth)/2;}
		if (winAlign.indexOf("bottom") != -1) topPos = h-popHeight; 
		if (winAlign.indexOf("right") != -1) leftPos = w-popWidth; 
		if (winAlign.indexOf("left") != -1) leftPos = 0; 
		if (winAlign.indexOf("top") != -1) topPos = 0; 						
    features += (features.length > 0 ? ',' : '') + 'top=' + topPos+',left='+leftPos;}
  if (document.all && borderless && borderless != "" && features.indexOf("fullscreen") != -1) features+=",fullscreen=1";
  if (window["popupWindow"] == null) window["popupWindow"] = new Array();
  var wp = popupWindow.length;
  popupWindow[wp] = window.open(theURL,winName,features);
  if (popupWindow[wp].opener == null) popupWindow[wp].opener = self;  
  if (document.all || document.layers || document.getElementById) {
    if (borderless && borderless != "") {popupWindow[wp].resizeTo(popWidth,popHeight); popupWindow[wp].moveTo(leftPos, topPos);}
    if (alwaysOnTop && alwaysOnTop != "") {
    	ontopIntervalHandle = popupWindow[wp].setInterval("window.focus();", 50);
    	popupWindow[wp].document.body.onload = function() {window.setInterval("window.focus();", 50);}; }
    if (autoCloseTime && autoCloseTime > 0) {
    	popupWindow[wp].document.body.onbeforeunload = function() {
  			if (autoCloseTimeoutHandle) window.clearInterval(autoCloseTimeoutHandle);
    		window.onbeforeunload = null;	}  
   		autoCloseTimeoutHandle = window.setTimeout("popupWindow["+wp+"].close()", autoCloseTime * 1000); }
  	window.onbeforeunload = function() {for (var i=0;i<popupWindow.length;i++) popupWindow[i].close();}; }   
  document.MM_returnValue = (ignorelink && ignorelink != "") ? false : true;
}

//*********************************************************************************//
// added on 10 January 2007 for DPS
//*********************************************************************************//

function loadcopyPopup(gotoPage) {
       popupWindow = window.open(gotoPage,'','width=640,height=475,resizable=yes,menubar=no,scrollbars=yes');
} 