
sfHover = function() {
	var sfEls = document.getElementById("topnav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);

function buyUK($isbn){
 //buy from Amazon UK using 10 or 13 digit ISBNs
	$tag='beverlnaidooshom'
	$url='http://www.amazon.co.uk';
	gotoAmazon($tag, $url, $isbn)	
}

function buyUS($isbn){
 //buy from Amazon UK using 10 or 13 digit ISBNs
	$tag='beverlnaidooshom'
	$url='http://www.amazon.com';
	gotoAmazon($tag, $url, $isbn)	
}

function gotoAmazon($tag, $url, $isbn){
	isbn10=convert($isbn)
	$amazonlink= $url  + "/exec/obidos/ASIN/" + isbn10 + "/" + $tag ;
	window.location.href=$amazonlink;
}


function convert($isbn){
	$re=/[- ]/g;  //the regular expression to remove hyphens and spaces
	$isbnraw=$isbn.replace($re,"");
	
	if ($isbnraw.length==10){//traditional
		return $isbnraw;
	}
	
	else  {//13 digit means work out the 10 digit equivalent
		$isbncore=$isbnraw.substr(3,9);
		mult=10;
		totsum=0
		//alert($isbncore);
		for(c=0; c<9; c++){
			totsum += mult * $isbncore.substr(c,1)
			mult--
		}
		rem=totsum%11
		if(rem==0) addon="0";	else addon=String(11-rem)
		
		if(addon=="10"){addon="X"}
		return $isbncore + addon			
	}

}


function email(a,b){
	document.location = "mailto:" + a + "\x40" + b;
}

function email2(addr){
	//addr is the address with a @ sign replaced by an image
	//find the first <
	str=addr.innerHTML
	//alert (str)
	bit=str.split(/[<>]/)
	a=bit[0]
	b=bit[2]
	document.location = "mailto:" + a + "\x40" + b;
}

function trim(inputString) {
   // Removes leading and trailing spaces from the passed string. Also removes
   // consecutive spaces and replaces it with one space. If something besides
   // a string is passed in (null, custom object, etc.) then return the input.
   if (typeof inputString != "string") { return inputString; }
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
   while (ch == " ") { // Check for spaces at the beginning of the string
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ") { // Check for spaces at the end of the string
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
   while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
   }
   return retValue; // Return the trimmed string back to the user
} // Ends the "trim" function







