agt=navigator.userAgent.toLowerCase();
SF = ((agt.indexOf('safari')!=-1)&&(agt.indexOf('mac')!=-1))?true:false;
SFV = (SF)?parseFloat(agt.substring(agt.indexOf("applewebkit/")+12,agt.indexOf("applewebkit/")+15)):0;
FF = (agt.indexOf('gecko')!=-1 && !SF);
Mac = navigator.platform.indexOf("Mac") != -1;

thisInterval=0;
thisTimeout=0;

g_depth = 2;

function headerFooterInit(depth){
	uselessvar = 0;
	txt = new Array(18,16,14,12,10,9);
	if(typeof(depth)=="undefined"){depth=2;}
	g_depth = depth;
	loadButtons(g_depth);
	if (depth<=1){
		addMarketingDiv(depth);
	};
}

function addMarketingDiv(depth){
	var dive = document.createElement("div");
	dive.style.position="absolute";
	dive.style.left=(depth==1)?"498px":"530px";
	dive.style.top=(depth==1)?"160px":"220px";
	dive.style.width=(depth==1)?"246px":"211px";
//    	dive.style.background="blue";
   	dive.style.background="#e6e6e6";
//    	dive.style.background="#3993b6";
//	dive.style.border="1px solid black";
	dive.style.padding="5px";
	dive.style.fontFamily="Arial";
//	dive.style.color="#3993b6";
	dive.style.color="blue";
//	dive.style.color="#b0e0f6";
	dive.style.fontSize="13px";

//	Marketing gobblety goop.

	var s = "This trial is provided for evaluation purposes and contains roughly 15% of the content of our calculus-based textbook and Virtual Physics Labs.<br><br>";
	s += "If you are an individual and would like to purchase one of our products, you can ";
	s += "<a href='https://webstore.kineticbooks.com/index.php/cPath/22'>purchase here. <br><br></a>";
	s += "If you are an institution, you can<br>";
	s += "<a href='http://kineticbooks.com/products/prod_purchinfo.html'>view all our licenses </a>here.";

//	End marketing gobblety goop

	dive.innerHTML = s;
	document.body.appendChild(dive);
}
function findPosX(obj){
	var curleft = 0;
	if (obj.offsetParent){
		while (obj.offsetParent){
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
			}
		}
	else if (obj.x)
		curleft += obj.x;
	if(SF&&SFV<100) curleft -= 1;
	return curleft;
	}

function findPosY(obj){
	var curtop = 0;
	if (obj.offsetParent){
		while (obj.offsetParent){
			curtop += obj.offsetTop
			obj = obj.offsetParent;
			}
		}
	else if (obj.y)
		curtop += obj.y;
	if(SF&&SFV<100) curtop -= 1;
	return curtop;
	}

function popup(term){
	if(document.getElementById(term)!='undefined'){
		var place = term.substring(term.indexOf("-"),term.length);
		var e = document.getElementById("toc4"+place);
		if(document.getElementById(term).style.height==""){	document.getElementById(term).style.height=25;}
		clearInterval(thisInterval);
		clearTimeout(thisTimeout);
		if(document.getElementById(term)!=null){
			layerToPop = document.getElementById(term).style;
			layerToPop.left = findPosX(e);
			layerToPop.top = findPosY(e);
			layerToPop.visibility = "visible";
			thisInterval = setInterval("dynamicMove('"+term+"',5)",25);
			}
		}
	}
function hide(lName){
	var st = document.getElementById(lName).style;
	st.visibility = "hidden";
	st.height = 20;
	}
function hidelayer(lName){
	if(document.getElementById(lName)!='undefined'){
		clearInterval(thisInterval)
		clearTimeout(thisTimeout);
		if(!Mac){
			if(document.getElementById(lName)!=null){
				thisInterval = setInterval("dynamicMove('"+lName+"',-5)",25);
				}
			}
		else{
			thisTimeout = setTimeout("hide('"+lName+"')",500);
			}
		}
	}

function dynamicMove(layerToMove, pxInterval){
//moves the tab layers 10 px at a time, starting and stopping at certain points.
	layerMove = document.getElementById(layerToMove);
	var yBeg = layerMove.style.height;
	var y = parseFloat(yBeg);

	y += pxInterval;
	var big = (pxInterval>0)?(SF)?90:95:20;
	var tester = (pxInterval>0)?(y<big):(y>big);
	if(tester) {
		layerMove.style.height = y;
		}
	else{
		clearInterval(thisInterval);
		layerMove.style.height = (pxInterval>0)?(SF)?85:90:25;
		if(pxInterval<0) hide(layerToMove);
		}
	}
function colorup(cll,clr){
	if(document.getElementById(cll)){
		document.getElementById(cll).style.backgroundColor=clr;
		}
	}
function getChapterToc(){
	var loc = document.location.toString()
	if(loc.indexOf("quizboard")>0){
	var path = loc.substring(loc.indexOf("?")+6,loc.indexOf("&"));
	document.location.href = "../../"+path+"/toc.html";
	}
	else{
		// ha ha
	}
}

function openpa(){
	var paloc = "../../media/uw/widget.html";
	var loc = document.location.toString();
	if (loc.indexOf("problems")>0) paloc = "../"+paloc;
	wide = 700;
	tall = 540;
	var vert = (screen.height - tall) / 2;
	var horiz = (screen.width - wide) / 2;
	var extras = 'height='+tall+',width='+wide+',top='+vert+',left='+horiz+',scrollbars=no,toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=yes';
	var name = "PhysicsFactbook";

	win = window.open(paloc, name, extras)
	if (parseInt(navigator.appVersion) >= 4) { win.focus(); }
	}

function pa(){
	var backup = "";
	for (var i=0;i<g_depth;i++){backup += "../";}
	wide = 700;
	tall = 600;
	var vert = (screen.height - tall) / 2;
	var horiz = (screen.width - wide) / 2;
	var extras = 'height='+tall+',width='+wide+',top='+vert+',left='+horiz+',scrollbars=no,toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=yes';
	var paloc = backup+"media/uw/widget.html";
	var name = "PhysicsFactbook";

	win = window.open(paloc, name, extras)
	if (parseInt(navigator.appVersion) >= 4) { win.focus(); }
	}


function feedbackButton(sec,ch,depth){
	if(typeof(depth)=="undefined"){depth=2;}

	var backup = "";
	for (var i=0;i<depth;i++){backup += "../";}

/*
	window.onunload=function(){	var thecookie = "";
	thecookie+= "fs="+((typeof(fs)!='undefined')?fs:"2")+"; ";
	thecookie+= "nt="+((typeof(nt)!='undefined')?nt:"true")+"; ";
	thecookie+= "ns="+((typeof(ns)!='undefined')?ns:"true")+"; ";
	thecookie+= "hl="+((typeof(hl)!='undefined')?hl:"false")+"; ";
	thecookie+= "he="+((typeof(he)!='undefined')?he:"true")+"; ";
	thecookie+=	"narr="+((typeof(narr)!='undefined')?narr:"false")+"; settxt(); ";
		var loc = document.location.toString();
		if (loc.substr(0,16)=='http://localhost'){post("localprefs",thecookie);}
	}
*/
	document.write('<img src="'+backup+'media/prefs/footer_issues1.gif" id="issues" onClick="feedback(\'Textbook&ChId='+ch+'&SecId='+sec+'\',this);">')
}

function feedback(type,obj){
	if (typeof(issuesbtn)=="undefined"){
		loadButtons(g_depth);
	}
	if (typeof(issuesbtn)=="undefined") return false;
	document.getElementById("issues").src=issuesbtn[2].src;
	var base = "http://www.kineticbooks.com/forms/feedback.php";
	var extras = "scrollbars=yes,toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,resizable=yes";
	var name = "fb";
	type += "&ver="+version+"&loc=web&pid="+prodID;
	var html = base+"?product="+type;
	var nwin = window.open(html,name,extras);
	if (parseInt(navigator.appVersion) >= 4) { nwin.focus(); }

	}

function loadButtons(depth){
	if(typeof(depth)=="undefined"){depth=2;}
	var backup = "";
	for (var i=0;i<depth;i++){backup += "../";}

	issuesbtn = new Array();
	issuesbtn[1] = new Image();
	issuesbtn[1].src = backup+"media/prefs/footer_issues1.gif";
	issuesbtn[2] = new Image();
	issuesbtn[2].src = backup+"media/prefs/footer_issues2.gif";

	if(document.getElementById("issues")){
		document.getElementById("issues").onmouseover = function(){document.getElementById("issues").src=issuesbtn[2].src;};
		document.getElementById("issues").onmouseout = function(){document.getElementById("issues").src=issuesbtn[1].src;};
		}
}

function prefpage(e){
	var backup = "";
	for (var i=0;i<g_depth;i++){backup += "../";}
	var loc = document.location.href;
	var title = document.title;
	var url = backup+"prefs/prefs.html?loc="+loc+"&title="+title;
	document.location = url;
	}

function numberparas(){

	tds = document.getElementsByTagName("TD");
	idnum = 1;
	lng = 0;
	for(var nm = 0; nm < tds.length; nm++){
		if(tds[nm].className=="SectionTableCol1"){
			tds[nm].onmousedown = sthighlight;
			tds[nm].onmouseup = dohighlight;
			tds[nm].id="st"+idnum++;
			for(var ch = 0; ch<tds[nm].getElementsByTagName("P").length;ch++){
				elm = tds[nm].getElementsByTagName("P")[ch];

				elm.id = "p"+(lng+ch);
				}
				lng += ch;
			}
		}
	}


function setcookie(){
if(location.hostname!='localhost'&&location.hostname!='127.0.0.1') return;
	if(chk > 0) clearTimeout(chk);
	var thecookie = "";
	thecookie+= "fs="+((typeof(fs)!='undefined')?fs:"2")+"; ";
	thecookie+= "nt="+((typeof(nt)!='undefined')?nt:"true")+"; ";
	thecookie+= "ns="+((typeof(ns)!='undefined')?ns:"true")+"; ";
	thecookie+= "hl="+((typeof(hl)!='undefined')?hl:"false")+"; ";
	thecookie+= "he="+((typeof(he)!='undefined')?he:"true")+"; ";
	thecookie+=	"narr="+((typeof(narr)!='undefined')?narr:"false")+"; settxt(); ";
	chk = setTimeout("post(\"localprefs\",\""+thecookie+"\");",500);
	}

function post(loc,newVar) {

var vars =  document.location + "&" + newVar
var xmlhttp = getReq();
 xmlhttp.open("POST", "http://localhost:26300/Physics_for_Scientists_and_Engineers/cgi-bin/"+loc,true);
 xmlhttp.onreadystatechange=function() {
  if (xmlhttp.readyState==4) {
  }
 }
 try {
   xmlhttp.send(vars)
 } catch (E) {
   xmlhttp.open("POST", "http://localhost:26300/Physics_for_Scientists_and_Engineers/cgi-bin/"+loc,true);
   xmlhttp.send(vars)
 }
}

function getReq(){
 var xmlhttp;
  /*@cc_on
  @if (@_jscript_version >= 5)
    try {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (E) {
        xmlhttp = false;
      }
    }
  @else
  xmlhttp = false;
  @end @*/
  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    try {
      xmlhttp = new XMLHttpRequest();
    } catch (e) {
      xmlhttp = false;
    }
  }
	return xmlhttp;
}

function wSWFt(swfObject) {
	document.write("<object type=\"application/x-shockwave-flash\" " + swfObject + "</object>");
}

function wQTid(qtObject) {
	document.write("<object classid=\"clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B\" " + qtObject + "</object>");
}
