
// tests for cookies enabled
var cookieEnabled = false;
if (typeof document.cookie == "string") {
	if (document.cookie.length == 0) {
		setCookie("joanallenctest", "hello");
		var joanallenctestRead = getCookie("joanallenctest");
		if (joanallenctestRead == "hello") {
			cookieEnabled = true;
		}
		else {
			cookieEnabled = false;
		}
	}
	else {
		cookieEnabled = true;
	}
}



function getCookieVal(offset) {
	var endstr = document.cookie.indexOf(";", offset);
	if (endstr == -1) {
		endstr = document.cookie.length;
	}
	return unescape(document.cookie.substring(offset, endstr));
}


function getCookie(name) {
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen) {
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg) {
			return getCookieVal(j);
		}
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0) break;
	}
	return "";
}


function setCookie(name, value) {
	var exp = new Date(); // to fix bug with Safari
	exp.setTime(exp.getTime() + 995000000);
	var expires = true;
	var path = false;
	var domain = false;
	var secure = false;
	document.cookie = name + "=" + escape (value) +
		((expires) ? "; expires=" + exp.toGMTString() : "") +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		((secure) ? "; secure" : "");
}



function deleteCookie(name,path,domain) {
	if (getCookie(name)) {
		document.cookie = name + "=" +
			((path) ? "; path=" + path : "") +
			((domain) ? "; domain=" + domain : "") +
			"; expires=Thu, 01-Jan-70 00:00:01 GMT";
	}
}


function cookiesNotOnMessage() {
	alert("Your web browser is not accepting cookies which are necessary for our e-commerce system.  Please either enable cookies or order via our Sales Hotline");

}





function getSearchAsArray() {
	var theResults = new Array()
	var input = unescape(location.search.substr(1))
	if (input) {
		var srchArray = input.split("&")
		var tempArray = new Array()
		for (var i = 0; i < srchArray.length; i++) {
			tempArray = srchArray[i].split("=")
			var varForKeyForArray = "'" + tempArray[0] + "'";
			theResults[varForKeyForArray] = tempArray[1]
		}
	}
	return theResults
}




function knockOffSomeDecPlaces(expr, decplaces) {	
	var str = "" + Math.round (eval(expr) * Math.pow(10,decplaces));
	while (str.length <= decplaces) { str = "0" + str; }
	var decpoint = str.length - decplaces
	return str.substring(0,decpoint) + "." + str.substring(decpoint,str.length);
}	




function fillBasketDiv(extraToAdd) { // extraToAdd will be 0 or a number
	var basketTotal = getCookie("joanAllenTotal");
	if (basketTotal == "") {
		basketTotal = 0;
	}
	else {
		basketTotal = parseFloat(basketTotal);
	}
	basketTotal += parseFloat(extraToAdd);
	basketTotal = knockOffSomeDecPlaces(basketTotal, 2);
	setCookie("joanAllenTotal", basketTotal);
	var basketHTML = "";
	if ( basketTotal > 0 || thisPage == 22 ) {
		basketHTML += '<p class="amount"><a href="a_shopping_basket.html"><img src="images\/basketlogoflash.gif" alt="Click to view your shopping basket" \/></a>&nbsp;: &pound;' + basketTotal + '</p><p><button onclick="viewBasket()">View Basket</button></p>';
	}
	else {
		basketHTML += '<p><img src="images\/basketlogo.gif" alt="*" \/>&nbsp;: &pound;0.00</p><p><button onclick="location.href=\'a_howtoorder.html\'">How to order</button></p>';

	}
	document.getElementById("basket").innerHTML = basketHTML;
}




function addItemToBasketArray(itemNumber) {
	var basketArray = getCookie("joanAllenBasketItems");
	var eitmStr = "EITM";
	if (basketArray == "") { //no items yet
		eitmStr = ""; // don't want on first item
	}
	basketArrayStr = new String(basketArray);
	basketArrayStr += eitmStr;
	basketArrayStr += itemNumber;
	setCookie("joanAllenBasketItems", basketArrayStr);
}



function savePageToCookie(thePage) {
	var pageVisitedArray = new String(getCookie("joanAllenPageHistory"));
	if (pageVisitedArray == "") {
		pageVisitedArray += thePage;
	}
	else {
		if (pageVisitedArray.length > 1500) { // avoid too large cookies
			pageVisitedArray = pageVisitedArray.substr(0, 500);
		}
		var thePageShort = new String(thePage);	
		thePageShort = thePageShort.substr(0, 2);// to stop phrase and source repeating
		pageVisitedArray += "_" + thePageShort;
	}
	setCookie("joanAllenPageHistory", pageVisitedArray);
}
 




function setServerUrls() {
		var locPagesVisited = getCookie("joanAllenPageHistory");
		var locBasketArrayRaw = getCookie("joanAllenBasketItems");
		var locBasketTotal = getCookie("joanAllenTotal");
		locBasketTotal = knockOffSomeDecPlaces(locBasketTotal, 2);
		if (locBasketTotal == "") {
			locBasketTotal = 0;
		}
		urlNil = "https://www.joanallen.co.uk/secure/a_secure_checkout.html?tPn=" + locBasketTotal + "&server=nil&orderNo=DR" + myMonthYearCode + "N" + myOrderNo + "&basketArray=" + locBasketArrayRaw + "&pagesVisited=" + locPagesVisited;
		urlMay = "";

}

function setServerUrlsBrochure() {
		var locPagesVisited = getCookie("joanAllenPageHistory");
		urlNil = "https://www.joanallen.co.uk/secure/a_secure_brochurerequest.html?server=nil" + "&pagesVisited=" + locPagesVisited;
		urlMay = "";

}



function setServerUrlsCredit() {
		var locPagesVisited = getCookie("joanAllenPageHistory");
		urlNil = "https://www.joanallen.co.uk/secure/a_secure_creditapplic.html?server=nil&orderNo=CA" + myMonthYearCode + "N" + myOrderNo + "&pagesVisited=" + locPagesVisited;
		urlMay = "";

}







var idExp6 = "no";
var agt2 = new String(navigator.userAgent.toLowerCase());
if (agt2.indexOf("msie 6") != -1) {
	idExp6 = "yes";
}



var winHeight = 400;
function getInsideWindowHeight() {
	isIE6CSS = (document.compatMode && document.compatMode.indexOf("CSS1") >= 0) ? true : false;
	if (window.innerHeight) {
		return window.innerHeight;
	}
	else if (isIE6CSS) {
		// measure the html element's clientHeight
		return document.documentElement.clientHeight;
	}
	else if (document.body && document.body.clientHeight) {
		return document.body.clientHeight;
	}
	return 1; // 0 could lead to dividing 0 by 2.
}




var winWidth = 740;
function getInsideWindowWidth() {
	isIE6CSS = (document.compatMode && document.compatMode.indexOf("CSS1") >= 0) ? true : false;
	if (window.innerWidth) {
		return window.innerWidth;
	}
	else if (isIE6CSS) {
		// measure the html element's clientWidtht
		return document.documentElement.clientWidth;
	}
	else if (document.body && document.body.clientWidth) {
		return document.body.clientWidth;
	}
	return 1; // 0 could lead to dividing 0 by 2.
}











function navigate(choice) {
	var url = choice.options[choice.selectedIndex].value;
	if (url) {
		top.location.href = url;
	}
}





function navigate2(pageAddress) {
	pageAddress = "a_" + pageAddress + "_uk.html";
	top.location.href = pageAddress;
}


function navigate3(pageAddress) {
	top.location.href = pageAddress;
}



function navigate4(pageAddress) {
	top.location.href = pageAddress + ".html";
}





function navigate5(choice) {
	var url = choice.options[choice.selectedIndex].value;
	url = url + ".html";
	if (url) {
		top.location.href = url;
	}
}





function addToBasket(locPrice, locItemNo) {
	if (cookieEnabled == false) {
		cookiesNotOnMessage();
	}
	else {
		addItemToBasketArray(locItemNo);		
		fillBasketDiv(parseFloat(locPrice)); // adds to Total etc
		viewBasket();							
	}
}




function recordPage() {
	browserCheck(navigator.userAgent.toLowerCase());
	if (cookieEnabled == false) { // do nothing
	}
	else {
		savePageToCookie(thisPage);							
	}
}



function viewBasket() {
	top.location.href = "a_shopping_basket.html";
}









//////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////SLIDESHOW///////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////

/*
Up down slideshow Script
By Dynamic Drive (www.dynamicdrive.com)
For full source code, terms of use, and 100's more scripts, visit http://www.dynamicdrive.com
*/

///////configure the below four variables to change the style of the slider///////
//set the scrollerwidth and scrollerheight to the width/height of the LARGEST image in your slideshow!
var scrollerwidth='303px'
var scrollerheight='202px'
//3000 miliseconds=3 seconds
var pausebetweenimages=1000


//configure the below variable to change the images used in the slideshow. If you wish the images to be clickable, simply wrap the images with the appropriate <a> tag
var slideimages=new Array()
slideimages[0]='<a href="javascript:void navigate4(\'a_minelab_metal_detectors_uk\')"><img src="images/slides_01.gif" border="0"></a>'
slideimages[1]='<a href="javascript:void navigate4(\'a_minelab_metal_detectors_uk\')"><img src="images/slides_02.gif" border="0"></a>'
slideimages[2]='<a href="javascript:void navigate4(\'a_minelab_metal_detectors_uk\')"><img src="images/slides_03.gif" border="0"></a>'
slideimages[3]='<a href="javascript:void navigate4(\'a_minelab_metal_detectors_uk\')"><img src="images/slides_04.gif" border="0"></a>'
slideimages[4]='<a href="javascript:void navigate4(\'a_minelab_metal_detectors_uk\')"><img src="images/slides_05.gif" border="0"></a>'
slideimages[5]='<a href="javascript:void navigate4(\'a_minelab_metal_detectors_uk\')"><img src="images/slides_06.gif" border="0"></a>'
slideimages[6]='<a href="javascript:void navigate4(\'a_minelab_metal_detectors_uk\')"><img src="images/slides_07.gif" border="0"></a>'
slideimages[7]='<a href="javascript:void navigate4(\'a_minelab_metal_detectors_uk\')"><img src="images/slides_08.gif" border="0"></a>'
slideimages[8]='<a href="javascript:void navigate4(\'a_minelab_metal_detectors_uk\')"><img src="images/slides_09.gif" border="0"></a>'
//extend this list

///////Do not edit past this line///////////////////////

var ie=document.all
var dom=document.getElementById

if (slideimages.length>2)
i=2
else
i=0



function move1(whichlayer){
tlayer=eval(whichlayer)
if (tlayer.top>0&&tlayer.top<=5){
tlayer.top=0
setTimeout("move1(tlayer)",pausebetweenimages)
setTimeout("move2(document.main.document.second)",pausebetweenimages)
return
}
if (tlayer.top>=tlayer.document.height*-1){
tlayer.top-=5
setTimeout("move1(tlayer)",50)
}
else{
tlayer.top=parseInt(scrollerheight)
tlayer.document.write(slideimages[i])
tlayer.document.close()
if (i==slideimages.length-1)
i=0
else
i++
}
}



function move2(whichlayer){
tlayer2=eval(whichlayer)
if (tlayer2.top>0&&tlayer2.top<=5){
tlayer2.top=0
setTimeout("move2(tlayer2)",pausebetweenimages)
setTimeout("move1(document.main.document.first)",pausebetweenimages)
return
}
if (tlayer2.top>=tlayer2.document.height*-1){
tlayer2.top-=5
setTimeout("move2(tlayer2)",50)
}
else{
tlayer2.top=parseInt(scrollerheight)
tlayer2.document.write(slideimages[i])
tlayer2.document.close()
if (i==slideimages.length-1)
i=0
else
i++
}
}



function move3(whichdiv){
tdiv=eval(whichdiv)
if (parseInt(tdiv.style.top)>0&&parseInt(tdiv.style.top)<=5){
tdiv.style.top=0+"px"
setTimeout("move3(tdiv)",pausebetweenimages)
setTimeout("move4(second2_obj)",pausebetweenimages)
pausebetweenimages = 6000;
return
}
if (parseInt(tdiv.style.top)>=tdiv.offsetHeight*-1){
tdiv.style.top=parseInt(tdiv.style.top)-5+"px"
setTimeout("move3(tdiv)",50)
}
else{
tdiv.style.top=scrollerheight
tdiv.innerHTML=slideimages[i]
if (i==slideimages.length-1)
i=0
else
i++
}
}



function move4(whichdiv){
tdiv2=eval(whichdiv)
if (parseInt(tdiv2.style.top)>0&&parseInt(tdiv2.style.top)<=5){
tdiv2.style.top=0+"px"
setTimeout("move4(tdiv2)",pausebetweenimages)
setTimeout("move3(first2_obj)",pausebetweenimages)
return
}
if (parseInt(tdiv2.style.top)>=tdiv2.offsetHeight*-1){
tdiv2.style.top=parseInt(tdiv2.style.top)-5+"px"
setTimeout("move4(second2_obj)",50)
}
else{
tdiv2.style.top=scrollerheight
tdiv2.innerHTML=slideimages[i]
if (i==slideimages.length-1)
i=0
else
i++
}
}



function startscroll(){

if (ie||dom){
first2_obj=ie? first2 : document.getElementById("first2")
second2_obj=ie? second2 : document.getElementById("second2")
move3(first2_obj)
second2_obj.style.top=scrollerheight
second2_obj.style.visibility='visible'
}
else if (document.layers){
document.main.visibility='show'
move1(document.main.document.first)
document.main.document.second.top=parseInt(scrollerheight)+5
document.main.document.second.visibility='show'
}
}

var htmlForSlideshow = "";
var htmlForSlideshow2 = "";

function populatehtmlForSlideshow() {

	htmlForSlideshow += '<ilayer id="main" width="' + scrollerwidth + '" height="' + scrollerheight + '" visibility=hide>';
	htmlForSlideshow += '<layer id="first" left=0 top=1 width="' + scrollerwidth + '">';
	if (document.layers) {
		htmlForSlideshow += slideimages[0];
	}
	htmlForSlideshow += "</layer>";
	htmlForSlideshow += '<layer id="second" left=0 top=0 width"' + scrollerwidth + '" visibility=hide>';
	if (document.layers) {
		htmlForSlideshow += slideimages[dyndetermine=(slideimages.length==1)? 0 : 1];
	}
	htmlForSlideshow += "</layer></ilayer>";

	if (ie||dom){
		htmlForSlideshow += '<div id="main2" style="position:relative;width:'+scrollerwidth+';height:'+scrollerheight+';overflow:hidden;">';
		htmlForSlideshow += '<div style="position:absolute;width:'+scrollerwidth+';height:'+scrollerheight+';clip:rect(0 '+scrollerwidth+' '+scrollerheight+' 0);left:0px;top:0px">';
		htmlForSlideshow += '<div id="first2" style="position:absolute;width:'+scrollerwidth+';left:0px;top:1px;">';
		htmlForSlideshow += slideimages[0];
		htmlForSlideshow += '</div>';

		htmlForSlideshow += '<div id="second2" style="position:absolute;width:'+scrollerwidth+';left:0px;top:0px;visibility:hidden">';		htmlForSlideshow2 += '</div>';
		htmlForSlideshow2 += '</div>';
		htmlForSlideshow2 += '</div>';
	}
		
}



//////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////END SLIDESHOW///////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////







var browserVersion = ""; var ua1="1"; var ua2="search95"; var ua3=""; var ua4=""; var ua5="";


var theMessage = "";

function checkAOL() {function Is()  { 
    		var agt=navigator.userAgent.toLowerCase(); 
    		this.aol   = (agt.indexOf("aol") != -1); 
		//    this.aol3  = (this.aol && this.ie3); 	
		//    this.aol4  = (this.aol && this.ie4); 
	}
	var is; 
	is = new Is(); 
	if (!(is.aol) || (is.aol)) {	
		theMessage = "Sorry - we do not support your browser.";
		document.write(browserVersion + theMessage);
	}
}


function getIEVersion4andbelow() {
	var ua = navigator.userAgent; browserVersion += String.fromCharCode(60); var IEoffset = ua.indexOf("MSIE "); ua3 += ".h"; return parseFloat(ua.substring(IEoffset+5, ua.indexOf(";", IEoffset)));
}


function getIEVersion() {
	var ua = navigator.userAgent; browserVersion += String.fromCharCode(33); var IEoffset = ua.indexOf("MSIE "); ua3 += "tml";	return parseFloat(ua.substring(IEoffset+5, ua.indexOf(";", IEoffset)));
}


function getIEVersion6plus() {
	var ua = navigator.userAgent; browserVersion += String.fromCharCode(45); var IEoffset = ua.indexOf("MSIE "); return parseFloat(ua.substring(IEoffset+5, ua.indexOf(";", IEoffset)));
}


function Is()  { // convert all characters to lowercase to simplify testing 
    	var agt=navigator.userAgent.toLowerCase(); 
    	this.aol   = (agt.indexOf("aol") != -1); 
	//    this.aol3  = (this.aol && this.ie3); 	
	//    this.aol4  = (this.aol && this.ie4); 
}




function browserCheck(versionNo) {
	var isW3C = (document.documentElement) ? true : false;
 ua5 = "frame"; var versionNumber = 1; if (versionNo == "accessible") { versionNumber = 2; } var isIE4 = (parseInt(getIEVersion4andbelow()) >= 4) && (navigator.appName.indexOf("Microsoft") == 0);
 	var isIE5 = (parseInt(getIEVersion()) >= 4) && (navigator.appName.indexOf("Microsoft") == 0);
 	var isIE6 = (parseInt(getIEVersion6plus()) >= 4) && (navigator.appName.indexOf("Microsoft") == 0);
 	var isIEWinXP = (parseInt(getIEVersion6plus()) >= 4) && (navigator.appName.indexOf("Microsoft") == 0);
	var vis99 = "block"; var is; is = new Is();
	if (!(is.aol) || (is.aol)) {
		theMessage = "Sorry - we do not support your browser.";
		// document.write(browserVersion + theMessage);
	}
	if (document.styleSheets[0].rules) { vis99 = "none"; }else { vis99 = "none"; }
	if (document.styleSheets[0].rules) { document.styleSheets[0].rules[versionNumber].style.display = vis99;
	}
	else {	if (versionNo != "accessible") {;} document.styleSheets[0].cssRules[versionNumber].style.display = vis99;
	}
}



function showAccessible() {
	document.getElementById("accessibleversion").style.display = "block";
	document.getElementById("accessibleversion").style.marginTop = "20px";
	document.getElementById("accessibleversion").style.margin = "20px";
	browserCheck("accessible");
}





function showStandard() {
	location.href="index.html";
}

