// Clear keyword from searchfield 

//<!--
//function clearText(myform) {
//myform.elements['searchfield'].value="";
//}

//////////////////////////////////////////////////////////////////////////////////////

// Blank search alert 

function isBlank() {
value=document.forms[0].elements['query_string'].value;

if ( value == "" ){
  alert("You did not enter a search term. Please try again.");
  return false;
}
  else {
  return true;
}
}

//////////////////////////////////////////////////////////////////////////////////////

// AutoBlink
// Puts Google's Autolink on the Blink :)
// (c) 2005 Chris Ridings   http://www.searchguild.com
// Redistribute at will but leave this message intact
// -
// 5th March - Implemented speed enhancement suggested by the guy who wrote
// http://www.dougaltoolbar.com/
// -
// 5th March - Added additional elements to reduce machine load
// 5th March - Added option to not remove links but to 
// rewrite ISBN links as amazon affiliate links!
// Fill in the following
// if you wish to do this. e.g.  var amazonaffiliate="goodlookingco-20"
// Leave as is to remove links in the normal way

var amazonaffiliate="";

var linkcount;
function checklinks() {
 if (!(linkcount==document.links.length)) {
   // Something changed the links!
   // Iterate for an id of _goog
   for (i=0; i < document.links.length; i++) {
	if (document.links[i].id.substring(0,5)=="_goog") {
	// If we find an id of _goog then do something
		if (amazonaffiliate=="") { 
			// No affiliate id defined so remove the links
			var tr = document.links[i].parentTextEdit.createTextRange();
			tr.moveToElementText(document.links[i]);
			tr.execCommand("Unlink",false);
			tr.execCommand("Unselect",false);
			i--;
		} else {
			// An affiliate id defined so rewrite ISBN links
			if (document.links[i].href.indexOf("isbn")>0) {
var isbn=document.links[i].href.substring(document.links[i].href.indexOf("text")+5,document.links[i].href.length);
document.links[i].href="http://www.amazon.com/exec/obidos/external-search?search-type=ss&tag=" + amazonaffiliate + "&keyword=" + isbn + "&index=books";
			}
		}
	}
   }
  }
  linkcount = document.links.length;
  setTimeout("checklinks()",500);
}
if (document.getElementById && document.createElement) {
	linkcount=document.links.length;
	setTimeout("checklinks()",500);
}


//////////////////////////////////////////////////////////////////////////////////////

//Style sheet switcher for printer friendly format
//Change function. The selection is only applied to the current page.
//function setActiveStyleSheet(title) {
//  var i, a, main;
//  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
//    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
//      a.disabled = true;
//      if(a.getAttribute("title") == title) a.disabled = false;
//    }
//  }
//}

//////////////////////////////////////////////////////////////////////////////////////

//Style sheet switcher for font resizing
//Sourced from A List Apart - Power To The People: Relative Font Sizes, by Bojan Mihelac
//http://www.alistapart.com/articles/relafont/

function fontsizeup() {
  active = getActiveStyleSheet();
  switch (active) {
    case 'A--' : 
      setActiveStyleSheet('A-');
      break;
    case 'A-' : 
      setActiveStyleSheet('A');
      break;
    case 'A' : 
      setActiveStyleSheet('A+');
      break;
    case 'A+' : 
      setActiveStyleSheet('A++');
      break;
    case 'A++' :
      break;
    default :
      setActiveStyleSheet('A');
      break;
  }
}

function fontsizedown() {
  active = getActiveStyleSheet();
  switch (active) {
    case 'A++' : 
      setActiveStyleSheet('A+');
      break;
    case 'A+' : 
      setActiveStyleSheet('A');
      break;
    case 'A' : 
      setActiveStyleSheet('A-');
      break;
    case 'A-' : 
      setActiveStyleSheet('A--');
      break;
    case 'A--' : 
       break;
    default :
      setActiveStyleSheet('A--');
      break;
  }
}

function setActiveStyleSheet(title) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
}

function getActiveStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
  }
  return null;
}

function getPreferredStyleSheet() {
  return ('A-');
}

function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
//    var expires = "";
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}

window.onload = function(e) {
  var cookie = readCookie("style");
  var title = cookie ? cookie : getPreferredStyleSheet();
  setActiveStyleSheet(title);
}

window.onunload = function(e) {
  var title = getActiveStyleSheet();
  createCookie("style", title, 365);
}

var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
if (title == 'null') {
  title = getPreferredStyleSheet();
}

setActiveStyleSheet(title);

//////////////////////////////////////////////////////////////////////////////////////

