//JavaScript

function Recalc() {
var aCode, nPrice, nExtPrice, nQty, nShip, nTotal, aPrice, aExtPrice, aShip, aTotal
aCode=document.getElementById('os0').value;  
nQty=Number(document.getElementById('Qty').value);
nShip=Number(document.getElementById('Ship').value);

//Shipping
switch(nQty){
case 1: nShip=3.75;  break;
case 2: nShip=6.50;  break;
case 3: nShip=9.25;  break;
default: nShip=9.25 + (1.10 * nQty-3);  
}

//Price
if (aCode>='1000' && aCode <='1099' ) {
	nPrice=12.95;
}
else {
	switch(aCode){
	case '5555': nPrice= 1.00; nShip=0; break;
	case '995': nPrice= 4.00;  break;
	case 'local': nPrice= 12.95; nShip=0; break;
	case '': nPrice= 13.95; break;
	default: alert ('The Discount Code is not valid. ');
	}
}

nTotal=nPrice * nQty + nShip;

aTotal=String(Math.round(nTotal*100)/100);
if (aTotal.indexOf('.') == aTotal.length - 2) {
	aTotal = aTotal + '0';	
}
if (aTotal=='10') {
	aTotal = '1.00';	
}

aPrice=String(Math.round(nPrice*100)/100);
if (aPrice.indexOf('.') == aPrice.length - 2) {
	aPrice = aPrice + '0';	
}
if (aPrice=='10') {
	aPrice = '1.00';	
}
if (aPrice=='40') {
	aPrice = '4.00';	
}
nExtPrice=nPrice * nQty;
aExtPrice=String(Math.round(nExtPrice*100)/100);
if (aTotal.indexOf('.') == aExtPrice.length - 2) {
	aExtPrice = aExtPrice + '0';	
}
if (aExtPrice=='10') {
	aExtPrice = '1.00';	
}
if (aExtPrice=='4') {
	aExtPrice = '4.00';	
}

aShip=String(Math.round(nShip*100)/100);
if (aShip.indexOf('.') == aShip.length - 2) {
	aShip = aShip + '0';	
}
if (aShip=='10') {
	aShip = '1.00';	
}

document.getElementById('Price').value=aPrice;
document.getElementById('ExtPrice').value=aExtPrice;
document.getElementById('Ship').value=aShip;
document.getElementById('oTotal').value=aTotal;
document.getElementById('amount').value=aTotal;
}
	
	
HmPg_on = new Image ( );
HmPg_off = new Image ( );
Inside_on = new Image ( );
Inside_off = new Image ( );
Comments_on = new Image ( );
Comments_off = new Image ( );
GetBook_on = new Image ( );
GetBook_off = new Image ( );
Ebooks_on = new Image ( );
Ebooks_off = new Image ( );
Resources_on = new Image ( );
Resources_off = new Image ( );

HmPg_on.src = '/images/btnHome_On.gif';
HmPg_off.src = '/images/btnHome_Off.gif';
Inside_on.src = '/images/btnInside_On.gif';
Inside_off.src = '/images/btnInside_Off.gif';
Comments_on.src = '/images/btnComments_On.gif';
Comments_off.src = '/images/btnComments_Off.gif';
GetBook_on.src = '/images/btnGetBook_On.gif';
GetBook_off.src = '/images/btnGetBook_Off.gif';
Ebooks_on.src = '/images/btnEbooks_On.gif';
Ebooks_off.src = '/images/btnEbooks_Off.gif';
Resources_on.src = '/images/btnResources_On.gif';
Resources_off.src = '/images/btnResources_Off.gif';

function button_on ( imgId )
{
imgName = new String ();
imgName=document.getElementById(imgId).name  
if ( document.images )
  {
    butOn = eval ( imgName + '_on.src' );
    document.getElementById(imgId).src = butOn;
  }
}
function Loader(){
if (document.title=='Get the Book') {
document.getElementById('mast').style.backgroundImage='url(/images/mastheadNoBug.jpg)';  }
else {
document.getElementById('mast').style.backgroundImage='url(/images/masthead.jpg)';
}
	
SetMenus();	
SetSubmenu();	
}


function SetMenus() {
document.getElementById('HmPg').src='/images/btnHome_Off.gif';  
document.getElementById('Inside').src='/images/btnInside_Off.gif';  
document.getElementById('Comments').src='/images/btnComments_Off.gif';  
document.getElementById('GetBook').src='/images/btnGetBook_Off.gif';  
document.getElementById('Ebooks').src='/images/btnEbooks_Off.gif';  
document.getElementById('Resources').src='/images/btnResources_Off.gif';  

switch(document.title){
case 'As the Oceans Rise': HmPg.src='/images/btnHome_On.gif';  break;
case 'Inside the Book': Inside.src='/images/btnInside_On.gif';  break;
case 'Commentary': Comments.src='/images/btnComments_On.gif';  break;
case 'Get the Book': GetBook.src='/images/btnGetBook_On.gif';  break;
case 'About e-Books': Ebooks.src='/images/btnEbooks_On.gif';  break;
case 'Resources': Resources.src='/images/btnResources_On.gif';  break;
}
}

function SetSubmenu()   {
 	loc=document.location.href;
	pgnm=loc.split('/');

//	document.getElementById('menuBook').style.display='block'; 
	if (pgnm[3]=='inside') {    
	switch(pgnm[4]) {
	case "index.htm": document.getElementById('submenu0').style.color='#660000';	break;  
	case "toc.htm": document.getElementById('submenu1').style.color='#660000'; break;  
	case "chap1.htm": document.getElementById('submenu2').style.color='#660000';  break;
	case "interviews.htm": document.getElementById('submenu3').style.color='#660000';  break;
	case "author.htm": document.getElementById('submenu4').style.color='#660000';  break;
	}	
	}
	if (pgnm[3].toLowerCase()=="ebooks") {    
	switch(pgnm[4]) {
//	 purchase will probably need to be php  
	case "index.htm": document.getElementById('submenu0').style.color='#660000'; break;  
	case "formats.htm": document.getElementById('submenu1').style.color='#660000'; break;  
	case "switch.htm": document.getElementById('submenu2').style.color='#660000';  break;
	case "stores.htm": document.getElementById('submenu3').style.color='#660000';  break;
	}	
	}
}

	function ShowLong(sID) {
		var oID=document.getElementById(sID);
		oID.style.display='inline';
			}
	function HideLong(sID) {
		var oID=document.getElementById(sID);
		oID.style.display='none';
			}
	function OpenWin(url) {
   		 open(url);
		   } 
	function ChgURL(url) {
		window.location=url;
		  }
	function URLattrib(Att)  {
		var strURL="index1.php?aid=" + Att;
		window.location=strURL; 
		}	 
	
function CheckForm(f) {
	var  fn, ft, chkOK
	chkOK=0;
	var ftObj=document.getElementsByName("FTpicker"); 
	
	for (var i=0; i < ftObj.length; i++) {
		if (ftObj[i].checked) {
			chkOK = 1;
		}
	}
	if (chkOK==1) {
		return true;
		} 
		else {
		alert ("Please select a file format and then press Submit again");
		return false;
		}
}

function SetFN(ftype) {

	 switch (ftype) {
	 case 'lit': fn='AsTheOceansRise.lit'; fe='.lit'; break; 
	 case 'mobi': fn='AsTheOceansRise.mobi'; fe='.mobi'; break; 
	 case 'sony': fn='AsTheOceansRise-Sony.pdf'; fe='.sony'; break; 
	 case 'pdf': fn='AsTheOceansRise.pdf'; fe='.pdf'; break; 
	 case 'epub': fn='AsTheOceansRise.epub'; fe='.epub'; break; 
	 case 'mp3': fn='AsTheOceansRiseAudiobook.zip'; fe='.mp3'; break; 
	 default: fn='NoPick';
	 }
	 document.getElementById('FT').value=fn;
	 document.getElementById('FE').value=fe;
}

function SetFNchap(ftype) {
	 switch (ftype) {
	 case 'lit': fn='AsTheOceansRiseChap1.lit'; fe='.lit'; break; 
	 case 'mobi': fn='AsTheOceansRiseChap1.mobi'; fe='.mobi'; break; 
	 case 'sony': fn='AsTheOceansRise-SonyChap1.pdf'; fe='.sony'; break; 
	 case 'pdf': fn='AsTheOceansRiseChap1.pdf'; fe='.pdf'; break; 
	 case 'epub': fn='AsTheOceansRiseChap1.epub'; fe='.epub'; break; 
	 case 'mp3': fn='AsTheOceansRiseChap1.mp3'; fe='.mp3'; break; 
	 default: fn='NoPick';
	 }
	 document.getElementById('FT').value=fn;
	 document.getElementById('FE').value=fe;
}

		 
		 
		 




					   
 function testX()
 {
 CallURL=String(document.referrer).substring(0,30)  
CallURL=document.referrer  
 alert (document.referrer);
alert (String(document.referrer).substring(0,30) );

if (CallURL == "http://www.astheoceansrise.com") {
	document.body.style.backgroundImage="url(images/water_rising.jpg)";
}
}

function SetBG() {
alert (chkHome)
if (chkHome == 'home') {
	document.body.style.backgroundImage="url(images/water_rising.gif)";
}
}



/***********************************************
* AnyLink Drop Down Menu- © Dynamic Drive (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/

//Contents for menu 1
var menu1=new Array()
menu1[0]='<a href="/inside/toc.htm">&nbsp;TABLE OF CONTENTS</a>'
menu1[1]='<a href="/inside/chap1.htm">&nbsp;SAMPLE CHAPTER</a>'
menu1[2]='<a href="/inside/interviews.htm">&nbsp;INTERVIEWS</a>'
menu1[3]='<a href="/inside/author.htm">&nbsp;AUTHOR</a>'

var menu2=new Array()
menu2[0]='<a href="/ebooks/formats.htm">&nbsp;E-BOOK FORMATS</a>'
menu2[1]='<a href="/ebooks/switch.htm">&nbsp;MAKING THE SWITCH</a>'
menu2[2]='<a href="/ebooks/stores.htm">&nbsp;E-BOOK STORES</a>'

		
var menuwidth='130px' //default menu width
var menuwidth2='133px' //default menu width
var menubgcolor='url(/images/submenu.jpg)'  //menu image (could use bgcolor and change background-image below)
var disappeardelay=120  //menu disappear speed onMouseout (in miliseconds)
var hidemenu_onclick="yes" //hide menu when user clicks within menu?

/////No further editting needed

var ie4=document.all
var ns6=document.getElementById&&!document.all

if (ie4||ns6)
document.write('<div id="dropmenudiv" style="visibility:hidden;width:'+menuwidth+';background-image:'+menubgcolor+'" onMouseover="clearhidemenu()" onMouseout="dynamichide(event)"></div>')

function getposOffset(what, offsettype){
var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
var parentEl=what.offsetParent;
while (parentEl!=null){
totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
parentEl=parentEl.offsetParent;
}
return totaloffset;
}


function showhide(obj, e, visible, hidden, menuwidth){
if (ie4||ns6)
dropmenuobj.style.left=dropmenuobj.style.top="-500px"
if (menuwidth!=""){
dropmenuobj.widthobj=dropmenuobj.style
dropmenuobj.widthobj.width=menuwidth
}
if (e.type=="click" && obj.visibility==hidden || e.type=="mouseover")
obj.visibility=visible
else if (e.type=="click")
obj.visibility=hidden
}

function iecompattest(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function clearbrowseredge(obj, whichedge){
var edgeoffset=0
if (whichedge=="rightedge"){
var windowedge=ie4 && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-15 : window.pageXOffset+window.innerWidth-15
dropmenuobj.contentmeasure=dropmenuobj.offsetWidth
if (windowedge-dropmenuobj.x < dropmenuobj.contentmeasure)
edgeoffset=dropmenuobj.contentmeasure-obj.offsetWidth
}
else{
var topedge=ie4 && !window.opera? iecompattest().scrollTop : window.pageYOffset
var windowedge=ie4 && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18
dropmenuobj.contentmeasure=dropmenuobj.offsetHeight
if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure){ //move up?
edgeoffset=dropmenuobj.contentmeasure+obj.offsetHeight
if ((dropmenuobj.y-topedge)<dropmenuobj.contentmeasure) //up no good either?
edgeoffset=dropmenuobj.y+obj.offsetHeight-topedge
}
}
return edgeoffset
}

function populatemenu(what){
if (ie4||ns6)
dropmenuobj.innerHTML=what.join("")
}


function dropdownmenu(obj, e, menucontents, menuwidth){
if (window.event) event.cancelBubble=true
else if (e.stopPropagation) e.stopPropagation()
clearhidemenu()
dropmenuobj=document.getElementById? document.getElementById("dropmenudiv") : dropmenudiv
populatemenu(menucontents)

if (ie4||ns6){
showhide(dropmenuobj.style, e, "visible", "hidden", menuwidth)

dropmenuobj.x=getposOffset(obj, "left")
dropmenuobj.y=getposOffset(obj, "top")
dropmenuobj.style.left=dropmenuobj.x-clearbrowseredge(obj, "rightedge")+"px"
dropmenuobj.style.top=dropmenuobj.y-clearbrowseredge(obj, "bottomedge")+obj.offsetHeight+"px"
}

return clickreturnvalue()
}

function clickreturnvalue(){
if (ie4||ns6) return false
else return true
}

function contains_ns6(a, b) {
while (b.parentNode)
if ((b = b.parentNode) == a)
return true;
return false;
}

function dynamichide(e){
if (ie4&&!dropmenuobj.contains(e.toElement))
delayhidemenu()
else if (ns6&&e.currentTarget!= e.relatedTarget&& !contains_ns6(e.currentTarget, e.relatedTarget))
delayhidemenu()
}

function hidemenu(e){
if (typeof dropmenuobj!="undefined"){
if (ie4||ns6)
dropmenuobj.style.visibility="hidden"
}
}

function delayhidemenu(){
if (ie4||ns6)
delayhide=setTimeout("hidemenu()",disappeardelay)
}

function clearhidemenu(){
if (typeof delayhide!="undefined")
clearTimeout(delayhide)
}

if (hidemenu_onclick=="yes")
document.onclick=hidemenu
