<!-- 
/****************************************************
*			    	General Routines
*             ==================
*            (c) Adrian Jones, woodsgood.ca
*****************************************************/

// returns the "name" Object
function getObject(name) {return (document.getElementById?document.getElementById(name):document.all?document.all[name]:document.layers?eval("document.layers[\"" + name + "\"]"):null); }

// "within-page" navigation; one DIV (of id "objid") is displayed while making previous element invisible.
var objPage = null;										// old (or previous) object
function doShow(objid) {
	if (objPage) objPage.style.display="none";	// blank any that are displayed
	objPage=getObject(objid);							// get referenced object
	objPage.style.display = "block";					// display it
}

function doNoShow(objid) {
	objPage=getObject(objid);							// get referenced object
	objPage.style.display = "none";					// display it
}

var objT = null;										// old (or previous) DIV
function doShowT(obj) {
	objT=getObject(obj);							// get referenced object
	if(objT.style.display=="block") {
		objT.style.display = "none";					// hide it
	} else {
		objT.style.display = "block";					// display it
	}
}

function initNews(go,time){
	if (go) {												// go if true
		objPage=getObject("newsBox");						// get referenced object
		objPage.style.display = "block";					// display it
		if(Number(time)==0) return;							// show always
		newsTime = parseInt(time,10);
		showNews();
	}
}
function doemail(name,service) {
	var em=""+name+"@"+service+"";
	document.write('<a href="mailto:'+em+'">'+em+'</a>');
}

// fades colour (rgb) of object (o) to (enl) at speed (s)
function KW_fade(r,g,b,e,n,l,s,o){ for(i=0;i<s+1;i++) setTimeout("KW_s("+KW_c(r,e,s,i)+","+KW_c(g,n,s,i)+","+KW_c(b,l,s,i)+",'"+o+"');",i*s);}
function KW_s(r, g, b, el)	{ getObject(el).style.color="rgb("+r+","+g+","+b+")";}
function KW_c(a,b,s,i) 		{ return Math.floor(a+(b-a)*(i/s));}

// doCopy places the copyright on the page
function doCopy(inc) {
	today=new Date();y0=today.getFullYear();
	var m="";
	m+='<div id="copy">Copyright &copy; 1998-'+y0+' Edstar Inc.&nbsp;&nbsp;All rights reserved.';
	if(inc) m+='&nbsp;&nbsp;Web by <a target="_blank" href="http://woodsgood.ca/fwebdesign.htm">WoodsGood</a></div>';
	document.write(m);
}





// Order form information

// Global variables

var subtotal=0;
var shipcost=0;
var totalcost=0;
var f;
var l;
var c=true;		// currency: true=US, false=CAN

function clearForm(fn,ln,cur) {
	f=Number(fn);l=Number(ln)+1;c=(cur=="true")?true:false;
//	alert(l)
	for (x=f;x<l;x++) {
		qref="q"+x+"";cref="c"+x+"";
		getObject(qref).value="";
		getObject(cref).value="";
	}
	getObject("sub").value="";
	getObject("sah").value="";
	getObject("tot").value="";
}


// totals etc. for book ordering page

function doTotal(item,cost,max) {
	var i=parseInt(item,10);
	var m=parseInt(max,10);
	var qn = "q"+i+"";cn = "c"+i+"";
	var qty=parseInt(getObject(qn).value,10);
	if (!qty && qty != 0) {
		alert('Please enter a numeric quantity');
		qty=0;
		getObject(qn).value=qty;
	}
	if (max !=0 && qty > max ) {
		alert('Maximum quantity for this book is '+max);
		qty=max;
		getObject(qn).value=qty;
	}
	var tc=qty*cost;
	getObject(cn).value=(tc ==0)?"":dollarFormat(tc);
	doTotalOrder();
}

function doTotalOrder() {
	subtotal=0;
	for (i=f;i<l;i++) {
		var cn="c"+i+"";
		var cell=getObject(cn).value;
		if(cell !== null) {
			var cost=Number(cell.substr(1));
			subtotal=Number(subtotal)+Number(cost);
		}
	}
	getObject("sub").value=dollarFormat(subtotal);
	shipcost = Number(doShip(subtotal));
	getObject("sah").value=dollarFormat(shipcost);
	totalcost = shipcost + subtotal;
//	alert(totalcost);
	getObject("tot").value=dollarFormat(totalcost);
}

function doShip(tot) {
	if(tot == 0) return 0;
	var total = (c)?total_US.split(","):total_CAN.split(",");
	var ship  = (c)?ship_US.split(","):ship_CAN.split(",");
//	alert(tot);
	for(x=0;x<total.length;x++) {
//		alert(tot+", "+total[x]);
		if (tot<=parseInt(total[x],10)) {
//			alert(ship[x])
			return (ship[x]);
		}
	}
	return 0;
}


var total_US = "10,20,30,40,50,60,70,80,90,100,125,150,175,200,225,250,275,300,400,500,100000";
var ship_US  = "5.99,6.99,8.99,9.99,10.99,11.99,12.99,13.99,14.99,15.99,17.99,18.99,20.99,22.99,24.99,26.99,28.99,30.99,34.99,44.99,44.99";

var total_CAN = "10,20,30,40,50,60,70,80,90,100,125,150,175,200,225,250,275,300,400,500,100000";
var ship_CAN  = "5.99,6.99,8.99,9.99,10.99,11.99,12.99,13.99,14.99,15.99,17.99,18.99,20.99,22.99,24.99,26.99,28.99,30.99,34.99,44.99,44.99";

function printWindow(){
   bV = parseInt(navigator.appVersion,10);
   if (bV >= 4) window.print();
}

function dollarFormat(anynum) {

   //-- Returns passed number as string in $xxx,xxx.xx format.
   anynum=eval(anynum);
   workNum=Math.abs((Math.round(anynum*100)/100));workStr=""+workNum;
   if (workStr.indexOf(".")==-1){workStr+=".00";}
   dStr=workStr.substr(0,workStr.indexOf("."));dNum=dStr-0;
   pStr=workStr.substr(workStr.indexOf("."));
   while (pStr.length<3){pStr+="0";}

   //--- Adds comma in thousands place.
//   if (dNum>=1000) {
//      dLen=dStr.length;
//      dStr=parseInt(""+(dNum/1000))+","+dStr.substring(dLen-3,dLen);
//   }

   //-- Adds comma in millions place.
//   if (dNum>=1000000) {
//      dLen=dStr.length;
//      dStr=parseInt(""+(dNum/1000000))+","+dStr.substring(dLen-7,dLen);
//   }
   retval = dStr + pStr ;
   //-- Put numbers in parentheses if negative.
//   if (anynum<0) {retval="("+retval+")"};
   return "$"+retval;
}

/*******************************************************
* showNews() makes the box visible for (adTime) seconds
* A seconds countdown (object "count") is shown in the box
********************************************************/

var newsTime;  // number of seconds ad box is shown
var newsCount=0;

function showNews(time) {
	if(newsCount<newsTime) {
		newsCount+=1;
     	obj = getObject("newsCount");
		obj.innerHTML="<small>Hide in "+(newsTime-newsCount+1)+" secs</small>";
		setTimeout("showNews()",1000);}
	else closeNews();
}

function closeNews() {
	objPage=getObject("newsBox");							// get referenced object
	objPage.style.display = "none";					// display it
}
//***************************


function setCookie(c_name,value,expiredays) {
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

function getCookie(c_name) {
	if (document.cookie.length>0) {
		c_start=document.cookie.indexOf(c_name + "=");
		if (c_start!=-1) {
			c_start=c_start + c_name.length+1; 
			c_end=document.cookie.indexOf(";",c_start);
			if (c_end==-1) c_end=document.cookie.length;
			return unescape(document.cookie.substring(c_start,c_end));
		} 
	}
	return "";
}

function checkCookie() {
	username=getCookie('username');
	if (username!=null && username!="") {
		alert('Welcome again '+username+'!');
	} else {
	username=prompt('Please enter your name:',"");
	if (username!=null && username!="") {
		setCookie('username',username,365);
		} 
	}
}


function doOther() {
  var m='<div class="blBox">';
  m+='<a href="books.html?0"><img src="images/book-Pig.jpg" class="blImg" alt="Pig"></a>';
  m+='<a href="books.html?6"><img src="images/book-Bug.jpg" class="blImg" alt="Bug"></a>';
  m+='<a href="books.html?5"><img src="images/book-Goof.jpg" class="blImg" alt="Goof"></a>';
  m+='<a href="books.html?4"><img src="images/book-Cole.jpg" class="blImg" alt="Cole"></a>';
  m+='<a href="books.html?3"><img src="images/book-Dont.jpg" class="blImg" alt="Dont"></a><br>';
  m+='<a href="books.html?2"><img src="images/book-Put.jpg" class="blImg" alt="Put"></a>';
  m+='<a href="books.html?1"><img src="images/book-If.jpg" class="blImg" alt="If"></a>';
  m+='<a href="books.html?7"><img src="images/book-Get.jpg" class="blImg" alt="Get"></a>';
  m+='<a href="books.html?8"><img src="images/book-Poems.jpg" class="blImg" alt="Pig"></a>';
  m+='</div>';
  getObject("cc").innerHTML=m;
}


/***********************************************
* Carousel Slideshow II- By Harry Armadillo (http://www.codingforums.com/showthread.php?t=58814)
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
* Please keep this notice intact
***********************************************/

function carousel(params){
  if(!(params.width>0 && isFinite(params.width)))params.width=100;
  if(!(params.height>0 && isFinite(params.height)))params.height=100;
  if(!(params.sides>2 && isFinite(params.sides)))params.sides=4;
  if(!(params.steps>0 && params.steps<100 && isFinite(params.steps)))params.steps=20;
  if(!(params.speed>0 && isFinite(params.speed)))params.speed=8;
  if(!(params.image_border_width>=0 && isFinite(params.image_border_width)))params.image_border_width=0;
  if(isFinite(params.id)||!params.id)params.id='bad_id_given_'+Math.random();

  document.write("<div class='caroselItself' style=\"z-index:100;\" id='"+params.id.replace(/[^a-zA-Z0-9]+/g,'_')+"'></div>");
  var cdiv=document.getElementById(params.id.replace(/[^a-zA-Z0-9]+/g,'_'));
  cdiv.style.width=params.width+'px';
  cdiv.style.height=params.height+'px';
  cdiv.style.border=params.border;
  cdiv.style.position='relative';
  cdiv.style.overflow='hidden';
  cdiv.title=params.id;

  var counter=0,spinning=true,interval=Math.floor(60000/params.sides/params.steps/params.speed)-5;
  interval=isNaN(interval)?200:interval;
  var img_position=[],images=[],img_dimension=[];
  var img_index=params.images.length+1,img_index_cap=2*params.images.length;
  var faces=Math.ceil(params.sides/2), dimension, direction, targ, attr, faraway;

  function init(){
    if(params.direction=="left" || params.direction=="right"){
      direction=params.direction;
      dimension="width";
      }
    else if(params.direction=="top" || params.direction=="bottom"){
      direction=params.direction;
      dimension="height";
      }
    else {
      direction="left";
      dimension="width";
      }
    faraway=(direction=="left"||direction=="top")?'-20000px':'20000px';
    cdiv.style[dimension]=params[dimension]/(params.size_mode=='image'?Math.sin(Math.PI/params.sides):1)+'px';
    var img=new Image();
    img.style.position='absolute';
    img.style[direction]=faraway;
    img.style.width=params.width-2*params.image_border_width+'px';
    img.style.height=params.height-2*params.image_border_width+'px';
    img.style.border=(params.image_border_width||0)+'px solid '+params.image_border_color;

    for(var i=0;i<params.images.length;i++){
      images[i]=img.cloneNode(true);
      images[i].src=params.images[i];
      if(params.links && params.links[i] && params.links[i]!=''){
			images[i].onclick=new Function("location='" + params.links[i] + "'");  // Adrian's edit
		}
//      if(params.links && params.links[i] && params.links[i]!=''){
//        targ=params.lnk_targets && params.lnk_targets[i]||params.lnk_base||'new';
//        if(targ=="_blank"){
//          attr=(params.lnk_attr && params.lnk_attr[i])?",'"+params.lnk_attr[i]+"'":"";
//          images[i].onclick=new Function("window.open('"+params.links[i]+"','"+targ+"'"+attr+")");
//          }
//        else if(targ.substr(0,1)=="_"){
//          images[i].onclick=new Function(targ.substr(1)+".location='"+params.links[i]+"'");
//          }
//        else{
//          attr=(params.lnk_attr && params.lnk_attr[i])?",'"+params.lnk_attr[i]+"'":"";
//          images[i].onclick=new Function("var t='"+targ+"';if(window[t]){try{window[t].close()}catch(z){}}window[t]=window.open('"+params.links[i]+"',t"+attr+");window[t].focus()");
//          }
//        images[i].style.cursor=document.all?'hand':'pointer';
//        }

      if(params.titles && params.titles[i] && params.titles[i]!='')
        images[i].title=params.titles[i];
      if(document.all)
        images[i].alt=images[i].title;
      images[i+params.images.length]=images[i];
      if(params.images.length==faces)
        images[i+2*params.images.length]=images[i];
      cdiv.appendChild(images[i]);
      }

    var face_size=params.size_mode=='image'?params[dimension]:params[dimension]*Math.sin(Math.PI/params.sides);
    var face_offset=params[dimension]*Math.cos(Math.PI/params.sides)/(params.size_mode=='image'?Math.sin(Math.PI/params.sides):1)/2-0.5;
    var pi_piece=2*Math.PI/params.steps/params.sides;
    for(i=0;i<=params.steps*faces;i++){
      img_dimension[i]=face_size*Math.sin(pi_piece*i);
      img_position[i]=(i<params.steps*params.sides/2)?Math.floor(params[dimension]/2/(params.size_mode=='image'?Math.sin(Math.PI/params.sides):1)-face_offset*Math.cos(pi_piece*i)-img_dimension[i]/2)+'px':faraway;
      img_dimension[i]=img_dimension[i]-2*params.image_border_width>1?Math.ceil(img_dimension[i])-2*params.image_border_width+'px':'1px';
      }
    }
  init();

  cdiv.rotate = function(){
    setTimeout('document.getElementById("'+cdiv.id+'").rotate()',interval);
    if(!spinning) return;
    if(++counter>=params.steps){
      counter=0;
      if(++img_index>=img_index_cap)
        img_index=params.images.length;
      }
    images[img_index-faces].style[direction]=faraway;
    for(var i=faces-1;i>=0;i--){
      images[img_index-i].style[direction]=img_position[counter+i*params.steps];
      images[img_index-i].style[dimension]=img_dimension[counter+i*params.steps];
      }
    }
  cdiv.onmouseover=function(){
    spinning=false;
    }
  cdiv.onmouseout=function(){
    spinning=true;
    }
  setTimeout('document.getElementById("'+cdiv.id+'").rotate()',100);
  }

  
-->
