// initialize global variables
var detectableWithVB = false;
var pluginFound = false;


function goURL(daURL) {
    // if the browser can do it, use replace to preserve back button
    if(javascriptVersion1_1) {
	window.location.replace(daURL);
    } else {
	window.location = daURL;
    }
    return;
}

function redirectCheck(pluginFound, redirectURL, redirectIfFound) {
    // check for redirection
    if( redirectURL && ((pluginFound && redirectIfFound) || 
	(!pluginFound && !redirectIfFound)) ) {
	// go away
	goURL(redirectURL);
	return pluginFound;
    } else {
	// stay here and return result of plugin detection
	return pluginFound;
    }	
}

function canDetectPlugins() {
    if( detectableWithVB || (navigator.plugins && navigator.plugins.length > 0) ) {
	return true;
    } else {
	return false;
    }
}

function detectAcrobat(redirectURL, redirectIfFound) {
    pluginFound = detectPlugin('application/pdf'); 
    // if not found, try to detect with VisualBasic
    if(!pluginFound && detectableWithVB) {
	pluginFound = detectActiveXControl('Pdf.PdfCtrl.1');
    }
    // check for redirection
    return redirectCheck(pluginFound, redirectURL, redirectIfFound);
}

function detectFlash(redirectURL, redirectIfFound) {
    pluginFound = detectPlugin('Shockwave','Flash'); 
    // if not found, try to detect with VisualBasic
    if(!pluginFound && detectableWithVB) {
	pluginFound = detectActiveXControl('ShockwaveFlash.ShockwaveFlash.1');
    }
    // check for redirection
    return redirectCheck(pluginFound, redirectURL, redirectIfFound);
}

function detectDirector(redirectURL, redirectIfFound) { 
    pluginFound = detectPlugin('Shockwave','Director'); 
    // if not found, try to detect with VisualBasic
    if(!pluginFound && detectableWithVB) {
	pluginFound = detectActiveXControl('SWCtl.SWCtl.1');
    }
    // check for redirection
    return redirectCheck(pluginFound, redirectURL, redirectIfFound);
}

function detectQuickTime(redirectURL, redirectIfFound) {
    pluginFound = detectPlugin('QuickTime');
    // if not found, try to detect with VisualBasic
    if(!pluginFound && detectableWithVB) {
	pluginFound = detectQuickTimeActiveXControl();
    }
    return redirectCheck(pluginFound, redirectURL, redirectIfFound);
}

function detectReal(redirectURL, redirectIfFound) {
    pluginFound = detectPlugin('RealPlayer');
    // if not found, try to detect with VisualBasic
    if(!pluginFound && detectableWithVB) {
	pluginFound = (detectActiveXControl('rmocx.RealPlayer G2 Control') ||
		       detectActiveXControl('RealPlayer.RealPlayer(tm) ActiveX Control (32-bit)') ||
		       detectActiveXControl('RealVideo.RealVideo(tm) ActiveX Control (32-bit)'));
    }	
    return redirectCheck(pluginFound, redirectURL, redirectIfFound);
}

function detectWindowsMedia(redirectURL, redirectIfFound) {
    pluginFound = detectPlugin('Windows Media Player');
    // if not found, try to detect with VisualBasic
    if(!pluginFound && detectableWithVB) {
	pluginFound = detectActiveXControl('MediaPlayer.MediaPlayer.1');
    }
    return redirectCheck(pluginFound, redirectURL, redirectIfFound);
}

function detectPlugin() {
    // allow for multiple checks in a single pass
    var daPlugins = detectPlugin.arguments;
    // consider pluginFound to be false until proven true
    var pluginFound = false;
    // if plugins array is there and not fake
    if (navigator.plugins && navigator.plugins.length > 0) {
	var pluginsArrayLength = navigator.plugins.length;
	// for each plugin...
	for (pluginsArrayCounter=0; pluginsArrayCounter < pluginsArrayLength; pluginsArrayCounter++ ) {
	    // loop through all desired names and check each against the current plugin name
	    var numFound = 0;
	    for(namesCounter=0; namesCounter < daPlugins.length; namesCounter++) {
		// if desired plugin name is found in either plugin name or description
		if( (navigator.plugins[pluginsArrayCounter].name.indexOf(daPlugins[namesCounter]) >= 0) || 
		    (navigator.plugins[pluginsArrayCounter].description.indexOf(daPlugins[namesCounter]) >= 0) ) {
		    // this name was found
		    numFound++;
		}   
	    }
	    // now that we have checked all the required names against this one plugin,
	    // if the number we found matches the total number provided then we were successful
	    if(numFound == daPlugins.length) {
		pluginFound = true;
		// if we've found the plugin, we can stop looking through at the rest of the plugins
		break;
	    }
	}
    }
    return pluginFound;
} // detectPlugin


// Here we write out the VBScript block for MSIE Windows
if ((navigator.userAgent.indexOf('MSIE') != -1) && (navigator.userAgent.indexOf('Win') != -1)) {
    document.writeln('<script language="VBscript">');

    document.writeln('\'do a one-time test for a version of VBScript that can handle this code');
    document.writeln('detectableWithVB = False');
    document.writeln('If ScriptEngineMajorVersion >= 2 then');
    document.writeln('  detectableWithVB = True');
    document.writeln('End If');

    document.writeln('\'this next function will detect most plugins');
    document.writeln('Function detectActiveXControl(activeXControlName)');
    document.writeln('  on error resume next');
    document.writeln('  detectActiveXControl = False');
    document.writeln('  If detectableWithVB Then');
    document.writeln('     detectActiveXControl = IsObject(CreateObject(activeXControlName))');
    document.writeln('  End If');
    document.writeln('End Function');

    document.writeln('\'and the following function handles QuickTime');
    document.writeln('Function detectQuickTimeActiveXControl()');
    document.writeln('  on error resume next');
    document.writeln('  detectQuickTimeActiveXControl = False');
    document.writeln('  If detectableWithVB Then');
    document.writeln('    detectQuickTimeActiveXControl = False');
    document.writeln('    hasQuickTimeChecker = false');
    document.writeln('    Set hasQuickTimeChecker = CreateObject("QuickTimeCheckObject.QuickTimeCheck.1")');
    document.writeln('    If IsObject(hasQuickTimeChecker) Then');
    document.writeln('      If hasQuickTimeChecker.IsQuickTimeAvailable(0) Then ');
    document.writeln('        detectQuickTimeActiveXControl = True');
    document.writeln('      End If');
    document.writeln('    End If');
    document.writeln('  End If');
    document.writeln('End Function');

    document.writeln('</scr' + 'ipt>');
}

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();
}


function setStyleSheet() {
var whichBrowser = (navigator.appName);
if (whichBrowser == "Netscape")
document.write("<link rel='stylesheet'"," href=http://www.nextext.com/nextext_2001_netscape.css"," type='text/css'>");
else
document.write("<link rel='stylesheet'"," href=http://www.nextext.com/nextext_2001.css"," type='text/css'>");
}


// This function controls the global pulldown menu

function CK_MenuItemRedirectPage(){
var myChoice, mySelection;
myChoice = document.masterform.quickfindmenu.selectedIndex;

/* This line of code assigns the highlighted item in the list menu to a variable.
Make sure you refer to the right form name and to the right List/Menu name. */

mySelection=document.masterform.quickfindmenu.options[myChoice].value;

/* This line of code assigns the dynamically choosen option to a variable. */

location=mySelection;

/* This line of code replaces the current page with the selected item. */

/* If you want to open the page in a new or different frame window instead of
opening the page in the current window, you can replace the above line of 
code with below.

window.open(mySelection,"myWindow");
*/

}
//This function writes the global lower nav text
function writeLowNav() {
document.write("<a href='http://www.nextext.com'>","Home","</a>"," | ","<a href='languagearts.cfm'>","Language Arts","</a>"," | ","<a href='socialstudies.cfm'>", "Social Studies","</a>", " | ", "<a href='worldlanguages.cfm'>","World Languages","</a>", " | ","<a href='previewnextext.cfm'>"," Preview Nextext","</a>", " | ", "<a href='contactus.cfm'>","Contact Us","</a>","<br>","<a href='http://www.hmco.com/hmco/Copyright.html'>","&copy; 1995-2001 Nextext","</a>",",an imprint of","<a href='http://www.mcdougallittell.com'>","McDougal Littell","</a>");
}

//This function dynamically assigns a link to a book's Introduction page
function goIntro() {
//srcUrl is the URL of the current page
var srcUrl =location.href;
// targetPage is the page you want to go to
var targetPage;
// this finds the text after the _ , such as, myfile_ovr.html which would be "ovr.html"
srcFile = srcUrl.substring(srcUrl.indexOf("_")+1,srcUrl.length);
// this replace the part of the current page's srcUrl with the one for the intro"int.html"
targetpage= srcUrl.replace(srcFile,'int.cfm');
// this redirects the browser to the requested URL
location.href = targetpage;
}

//This function dynamically assigns a link to a book's Overview page
function goOverview() {
//srcUrl is the URL of the current page
var srcUrl =location.href;
// targetPage is the page you want to go to
var targetPage;
// this finds the text after the _ , such as, myfile_ovr.html which would be "ovr.html"
srcFile = srcUrl.substring(srcUrl.indexOf("_")+1,srcUrl.length);
// this replace the part of the current page's srcUrl with the one for the intro"int.html"
targetpage= srcUrl.replace(srcFile,'ovr.cfm');
// this redirects the browser to the requested URL
location.href = targetpage;
}

//This function dynamically assigns a link to a book's Table of Contents page
function goToc() {
//srcUrl is the URL of the current page
var srcUrl =location.href;
// targetPage is the page you want to go to
var targetPage;
// this finds the text after the _ , such as, myfile_ovr.html which would be "ovr.html"
srcFile = srcUrl.substring(srcUrl.indexOf("_")+1,srcUrl.length);
// this replace the part of the current page's srcUrl with the one for the intro"int.html"
targetpage= srcUrl.replace(srcFile,'toc.cfm');
// this redirects the browser to the requested URL
location.href = targetpage;
}

// This function is currently not being used but it takes the browser to the previous page
function breadcrumb() {
var prevPage = history.back();
document.write(PrevPage);
}

//This fuction dynamically assigns the last breadcrumb, which is simply the page title of the current page
function breadcrumbPage() {
var curPage;
curPage = document.title;
document.write(curPage);
}

//These functions control the rollover images
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_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_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_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 controls the homepages rotating content, the book montages
function bookDisplay() {
var how_many_displays = 4;
var now = new Date()
var sec = now.getSeconds()
var display = sec % how_many_displays;
var width ="550"
var height ="153"
display +=1;
if (display==1) {
srcImage="images/home_bookdisplay1.gif";
}
if (display==2) {
srcImage="images/home_bookdisplay2.gif";
}
if (display==3) {
srcImage="images/home_bookdisplay3.gif";
}
if (display==4) {
srcImage="images/home_bookdisplay4.gif";
}
document.write('<img src=\"' + srcImage + '\" width=')
document.write(width + ' height=' + height + '>');
}

function submit_search(){
document.masterform.submit();
}
