/*

 * $Source: /web/cvs/olc/webapp/styles/shared/v2_catalyst_dhtml.js,v $
 * $Revision: 1.3 $
 * $Author: daniel $
 * $Date: 2004/12/28 17:54:22 $
 *
 * Copyright 2002 The McGraw-Hill Companies. All Rights Reserved
 * Revision history omitted from client-side files.

*/

/* 
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
   Default values
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
*/

var toolOrigin = 135;
var toolTop = 135;
var navOffset = 20;
var scrolledBy = 0;
var winWidth = 0;
var curTool="";
var curScript = "";
var nextScript = "";
var intervalID = 0;
var navIsOpen = 1;
var isLocked = 0;
var isDynamic = 0;			// so Notes can tell when it's working with dynamic content
var needPrefsUpdate = 0;	// triggers refresh of cookie data after prefs change

// These are defaults; may be overridden by cookies:
var loggedIn = 0;
var teachersEdition=0;
var curNav="nav";
var glideSpeed="3";
var oldSitemapPage="";

/* 
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
   Init and Page monitor
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
*/

function PageLoad() {
	// use this for functions that should be run exactly once per page.

	loadOlcCookie(document.forms.dataContainer.isbn.value);
	
	updateForms();
	
	InitLayers();
	
	// show the proper sitemap page, if that's the current page:
	if (window.document.forms.hiddenSitemapData) {
		oldSitemapPage = window.document.forms.hiddenSitemapData.firstResourceLayer.value;
		startSiteMap();
	}

	// open the login drawer, if the user got here sneakily:
	/* No longer needed... SMS
	if ((isLocked == 1) && (loggedIn == 0)) {
		stopTool(); // just in case
		startTool("toolLoginForced");
	}
	*/
	
	// open the login drawer if we got here via a failed login attempt:
	if (getQueryVal('LOGIN_ERR_CODE') == 1) {
		stopTool(); 
		startTool("toolLogin");
		alert("The username and password you entered were not correct. Please try again.");
	}
	if (getQueryVal('LOGIN_ERR_CODE') == 2) {
		stopTool(); 
		startTool("toolLogin");
		alert("Your account does not yet have access to this website. Please follow the \"Purchase Access\" link.");
	}
	
	// show the instructor navbar, if relevant:
	if (teachersEdition == 1) {
		showLayer('navTE');
	}

	// start the page monitor...
	if (intervalID == 0) {
		intervalID = setInterval("CatMonitor()",10);
	}
	pageHasLoaded = 1;
}


function CatMonitor() {
	// This script runs continuously
	// and handling the drawer animations.
	
	// Originally had the drawers using their own setIntervals, but Opera on Windows
	// doesn't handle that very well. (memory problems, I think.)
	
	// run any ongoing scripts:
	if (curScript) {
		eval(curScript);
	}
	return true;
}


function InitLayers() {
	// This function is called often; for functions that should be called
	// only on the initial page load, use PageLoad() instead.
	showCatToolbar();

	// not needed for catalyst (yet) ;-) CS
	/*
	if (teachersEdition == 1) {
		if (curNav == "nav") {curNav = "navTE"};
	} else {
		if (curNav == "navTE") {curNav = "nav"};
	}
	*/
	
}


/*
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
   DHTML scripts
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
*/


function showCatToolbar() {	
	if (loggedIn == 1) {
		showLayer("toolbarLoginDiv")
	}
	else {
		hideLayer("toolbarLoginDiv")
	}
}


//there's actually a shared logout function in v2_functions.js, but this style
//doesn't use layers for nav, and I needed to remove some stuff from the function
//hence, the version here...
function doCatalystLogout() {
	// clear the cookie, and reset any prefs
	deleteCookie("OLC" + window.document.forms.dataContainer.isbn.value);
	deleteCookie("OLCGroup");
	if (getCookie("OLC" + window.document.forms.dataContainer.isbn.value) || getCookie("olcGroup")) {
		alert("We're sorry, but the web browser you are using does not clear your user data on logout. Quit the program to log out.");
	}
	loggedIn = 0;
	teachersEdition = 0;
	InitLayers();
	stopTool();
}


function SetLogin(isTE) {
	// FOR TESTING PURPOSES ONLY
	
	loggedIn = 1;
	teachersEdition = isTE;
	
	setSessionCookie("PWISBN",document.dataContainer.isbn.value);

	// normal login will need to set this as well.
	setSessionCookie("olcuser","fakeusername");
	document.forms.dataContainer.user_id.value = "fakeusername";
	
	// temporary cookie
	setSessionCookie("tmpolcInstructor",teachersEdition);

	// close any open drawers:
	stopTool();
	
	// need to reset navbars etc in case the float state has changed.
	InitLayers();
	
}

