function email(){document.location = "mailto:" + "brian" + "\x40" + "briankeaney.co.uk";}
function ready(o){if(o.tagName=="SPAN") {o.style.color="#ffc"} else {o.style.backgroundColor="#ffc"}}
function norm(o){if(o.tagName=="SPAN") {o.style.color="#c00"} else {o.style.backgroundColor="#ccc"}}

function buy($isbn){ //buy from Amazon using 10 or 13 digit ISBNs
	if (arguments[1]=="US"){
		$tag='www.briankeanc-21';
		$url='http://www.amazon.com';
	}
	else{
		$tag='www.briankeanc-20';
		$url='http://www.amazon.co.uk';
	}
	//debugger
	$re=/[- ]/g;  //the regular expression to remove hyphens and spaces
	$isbnraw=$isbn.replace($re,"");
			
	$amazonlink="";
	if ($isbnraw.length==10){//traditional
		$amazonlink= $url  + "/exec/obidos/ASIN/" + $isbnraw + "/" + $tag ;
		}
	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"}
		$isbn10=$isbncore + addon
		$amazonlink=$url  + "/exec/obidos/ASIN/" + $isbn10 + "/" + $tag ;
		//alert($amazonlink)
					
	}
	window.location.href=$amazonlink;
}
