function stockCheck(M) {
var inStock = true
for (x in outOfStockList) {if (M == outOfStockList[x]) inStock = false};
return inStock
}

function countBasket() {
var firstCut = document.cookie.split(";")[0]
var secondCut = firstCut.split("=")[1]
basket = secondCut.split(",")
var c = basket.length - 2


if (document.getElementById) {

if (c<1) { document.getElementById("bask").innerHTML="Your Basket<br>is Empty"; }

if (c==1) { document.getElementById("bask").innerHTML="There is <big>1</big> item in your basket."; }

if (c>1) { document.getElementById("bask").innerHTML="There are <big>" + c + "</big> items in your basket."; }
}


}

function moreInfo(x) {
info = window.open("", "", "width=1000, height=700, scrollbars, top=10, left=10")
info.document.write("<html><head><title>The Ambleside Toy Shop: " + itemName[x] + "</title><link type='text/css' rel='stylesheet' href='test.css'></head><body style='background-image: none; text-align: center;'>")
info.document.write("<img src='pics/pic" + x + ".jpg'><br>")
info.document.write(itemName[x] + "<br>")
info.document.write(itemDes1[x] + "<br>")
info.document.write(itemDes2[x] + "<br>")
info.document.write(itemInfo[x] + "<br>")
info.document.write("<a href='javascript:self.close()'><div  style='cursor:pointer' class='close' id='close1' onMouseOver=id='close2' onMouseDown=id='close3' onMouseUp=id='close2' onMouseOut=id='close1'>Close</div></a>")
info.document.write("</body></html>")
}

function addToBasket(x) {

firstCut = document.cookie.split(";")[0]
var secondCut = firstCut.split("=")[1]
newSecondCut = secondCut + x + ","
document.cookie="item=" + newSecondCut +";expires=" + expireDate.toGMTString()
countBasket()
}

function checkLetters() { var xx=document.getElementById("letters").value;
if (xx=="") { alert("PLease enter the letter(s) you wish to buy.") }
else if (/[^a-zA-Z\s]/g.test(xx)) { alert("Please re-enter your letters without using any other characters or puctuation.") }
else {
var letterChoice = xx.replace(/\s/g,"")
letterChoice = letterChoice.toUpperCase()
var plural = (letterChoice.length>1)?"s":"";
var OK = confirm("You have selected the following letter" + plural + ":\r" + letterChoice + "\rCost: £" + letterChoice.length + ".00")
if (OK==true) {
firstCut = document.cookie.split(";")[0]
var secondCut = firstCut.split("=")[1]
newSecondCut = secondCut + "26_" + letterChoice.length + "_" + letterChoice + ","
document.cookie="item=" + newSecondCut +";expires=" + expireDate.toGMTString()
countBasket()
}
}
}

Words = new Array("zero","one","two","three","four","five","six","seven","eight","nine","ten","eleven","twelve","thirteen","fourteen","fifteen");
Pages = new Array("Zero","Home","Jigsaw Puzzles","Teddy Bear Clothing","Soft Toys","Wooden Toys","Meccano","Games","Things to Make","Stocking Fillers","Music and Magic","Wooden Train Sets","For Your Room","Perplexing Puzzles","For Children Under 3","Bath Time");
Addresses = new Array("zero","index","Jigsaws","TeddyBearClothing","SoftToysAll","WoodenAll","MeccanoAll","GamesAll","Make","Stocking","MusicAndMagic","Trains","Decor","Puzzles","Under3","BathTime");


function drawTree(x) {


document.write('<table cellpadding="0" cellspacing="0">');
document.write('<tr class="row2"><td width="245"></td></tr>');

for (n=1; n<=15; n++) {


document.write('<tr class="row2"><td width="245"></td></tr>');
document.write('<tr class="row"><td class="ce"><a href="' + Addresses[n] + '.html">');
if (n==x) {
document.write('<div class="' + Words[n] + '" id="four" >');
} else {
document.write('<div class="' + Words[n] + '" id="one" onMouseOver=id="two" onMouseDown=id="three" onMouseUp=id="two" onMouseOut=id="one" >');
}

document.write(Pages[n] +'</div></a></td></tr>');

}

document.write('</table>');

}

function drawSign(x) {
document.write("<table borders='0' cellpadding='0' cellspacing='0' width='150' align='left' vAlign='top'>")
document.write("<tr height='200'><td width='150'></td></tr>")
document.write("<tr style='height: 170px;'><td style='width: 150px; vertical-align: middle;'><div class='sign'><table borders='0' cellpadding='0' cellspacing='0'><tr style='height: 19px;'><td style='width: 19px;'></td><td style='width: 112px;'></td><td style='width: 19px;'></td></tr><tr style='height: 132px;'><td></td><td>" + x + "</td><td></td></tr></table></div></td></tr>")
document.write("<tr height='30'><td><div class='ExtraEnd' id='ExtraThis'></div></td></tr>")
document.write("</table>")



}

function drawExtra(n,a,A,b,B,c,C,d,D,e,E) {

document.write("<table borders='0' cellpadding='0' cellspacing='0' width='150' align='left' vAlign='top'>")
document.write("<tr height='200'><td width='150'></td</tr>")

if (a!="") {

document.write("<tr height='30'><td class='cE'><a href='" + A + ".html'>")

if (n==1) { document.write("<div class='ExtraOne' id='ExtraThis'>" + a + "</div></a></td</tr>") }
else { document.write("<div class='ExtraOne' id='Extra' onMouseOver=id='ExtraOver' onMouseDown=id='ExtraDown' onMouseUp=id='ExtraOver' onMouseOut=id='Extra'>" + a + "</div></a></td</tr>") }

document.write("<tr height='5'><td width='150'><div class='ExtraBit1' id='ExtraBit'></div></td</tr>")
} else { document.write("<tr height='35'><td></td></tr>") }

if (b!="") {

document.write("<tr height='30'><td class='cE'><a href='" + B + ".html'>")

if (n==2) { document.write("<div class='ExtraTwo' id='ExtraThis'>" + b + "</div></a></td</tr>") }
else { document.write("<div class='ExtraTwo' id='Extra' onMouseOver=id='ExtraOver' onMouseDown=id='ExtraDown' onMouseUp=id='ExtraOver' onMouseOut=id='Extra'>" + b + "</div></a></td</tr>") }

document.write("<tr height='5'><td width='150'><div class='ExtraBit2' id='ExtraBit'></div></td</tr>")
} else { document.write("<tr height='30'><td width='150'><div class='ExtraBit10' id='ExtraBit'></div></td</tr>")
	document.write("<tr height='5'><td width='150'><div class='ExtraBit2' id='ExtraBit'></div></td</tr>") }


if (c!="") {

document.write("<tr height='30'><td class='cE'><a href='" + C + ".html'>")

if (n==3) { document.write("<div class='ExtraThree' id='ExtraThis'>" + c + "</div></a></td</tr>") }
else { document.write("<div class='ExtraThree' id='Extra' onMouseOver=id='ExtraOver' onMouseDown=id='ExtraDown' onMouseUp=id='ExtraOver' onMouseOut=id='Extra'>" + c + "</div></a></td</tr>") }

document.write("<tr height='5'><td width='150'><div class='ExtraBit3' id='ExtraBit'></div></td</tr>")
} else { document.write("<tr height='30'><td width='150'><div class='ExtraBit20' id='ExtraBit'></div></td</tr>")
	document.write("<tr height='5'><td width='150'><div class='ExtraBit3' id='ExtraBit'></div></td</tr>") }

if (d!="") {

document.write("<tr height='30'><td class='cE'><a href='" + D + ".html'>")

if (n==4) { document.write("<div class='ExtraFour' id='ExtraThis'>" + d + "</div></a></td</tr>") }
else { document.write("<div class='ExtraFour' id='Extra' onMouseOver=id='ExtraOver' onMouseDown=id='ExtraDown' onMouseUp=id='ExtraOver' onMouseOut=id='Extra'>" + d + "</div></a></td</tr>") }

document.write("<tr height='5'><td width='150'><div class='ExtraBit4' id='ExtraBit'></div></td</tr>")
} else { document.write("<tr height='30'><td width='150'><div class='ExtraBit30' id='ExtraBit'></div></td</tr>")
	document.write("<tr height='5'><td width='150'><div class='ExtraBit4' id='ExtraBit'></div></td</tr>") }

if (e!="") {

document.write("<tr height='30'><td class='cE'><a href='" + E + ".html'>")

if (n==5) { document.write("<div class='ExtraFive' id='ExtraThis'>" + e + "</div></a></td</tr>") }
else { document.write("<div class='ExtraFive' id='Extra' onMouseOver=id='ExtraOver' onMouseDown=id='ExtraDown' onMouseUp=id='ExtraOver' onMouseOut=id='Extra'>" + e + "</div></a></td</tr>") }

document.write("<tr height='5'><td width='150'><div class='ExtraBit5' id='ExtraBit'></div></td</tr>")
} else { document.write("<tr height='30'><td width='150'><div class='ExtraBit40' id='ExtraBit'></div></td</tr>")
	document.write("<tr height='5'><td width='150'><div class='ExtraBit5' id='ExtraBit'></div></td</tr>") }

document.write("<tr height='30'><td><div class='ExtraEnd' id='ExtraThis'></div></td></tr>")
document.write("</table>")


}

function listProducts() {


var L = List.length
if (screen.width>1025) {

for (n=1; n<=L; n++) {
if (n==3||n==5||n==7||n==9) { document.write("</tr><tr height='111'>") }
if ((n>=12) && (n%3==0)) { document.write("</tr><tr height='111'><td width='64'></td>") }
m=List[n-1]
document.write("<td rowspan='2' width='192' class='tablenorm'>")
document.write("<table borders='0' cellpadding='0' cellspacing='0'>")
document.write("<tr height='3'><td colspan=2></td></tr>")
document.write("<tr height='100'><td colspan=2><a href='javascript:moreInfo(" + m + ")'><img src='thumbs/thumb" + m + ".gif' border='0'></A><b>£" + itemPric[m] + "</b></td></tr><tr height='20'><td colspan=2>" + itemName[m] + "</td></tr><tr height='20'><td colspan=2>")
document.write(itemDes1[m] + "</td></tr><tr height='20'><td colspan=2>")
document.write(itemDes2[m] + "</td></tr><tr height='20'><td width='14'></td><td>")

if (m!=26) {
if (stockCheck(m)) {document.write("<div style='cursor:pointer'class='close' id='close1' onMouseOver=id='close2' onMouseDown=id='close3' onMouseUp=id='close2' onMouseOut=id='close1' onClick='addToBasket(" + m + ")'>Add to Basket</div></td></tr>")}
else {document.write("OUT OF STOCK</td></tr>")}
	} else {
if (stockCheck(m)) {document.write("<div style='cursor:pointer'class='close' id='close1' onMouseOver=id='close2' onMouseDown=id='close3' onMouseUp=id='close2' onMouseOut=id='close1' onClick='checkLetters()'>Add to Basket</div></td></tr>")}
else {document.write("OUT OF STOCK</td></tr>")}
	}




document.write("</table>")
document.write("</td>")
}

if (L<9) { 
if (L==8) {
	document.write("</tr><tr height='111'><td rowspan='2' width='192'></td><td rowspan='2' width='192'></td><td rowspan='2' width='192'></td>") } else
if (L==7) {
	document.write("<td rowspan='2' width='192'></td>")
	document.write("</tr><tr height='111'><td rowspan='2' width='192'></td><td rowspan='2' width='192'></td><td rowspan='2' width='192'></td>") } else
if (L==6) {
	document.write("</tr><tr height='111'><td rowspan='2' width='192'></td><td rowspan='2' width='192'></td>")
	document.write("</tr><tr height='111'><td rowspan='2' width='192'></td><td rowspan='2' width='192'></td><td rowspan='2' width='192'></td>") } else
if (L==5) {
	document.write("<td rowspan='2' width='192'></td>")
	document.write("</tr><tr height='111'><td rowspan='2' width='192'></td><td rowspan='2' width='192'></td>")
	document.write("</tr><tr height='111'><td rowspan='2' width='192'></td><td rowspan='2' width='192'></td><td rowspan='2' width='192'></td>") } else
if (L==4) {
	document.write("</tr><tr height='111'><td rowspan='2' width='192'></td><td rowspan='2' width='192'></td>")
	document.write("</tr><tr height='111'><td rowspan='2' width='192'></td><td rowspan='2' width='192'></td>")
	document.write("</tr><tr height='111'><td rowspan='2' width='192'></td><td rowspan='2' width='192'></td><td rowspan='2' width='192'></td>") } else
if (L==3) {
	document.write("<td rowspan='2' width='192'></td>")
	document.write("</tr><tr height='111'><td rowspan='2' width='192'></td><td rowspan='2' width='192'></td>")
	document.write("</tr><tr height='111'><td rowspan='2' width='192'></td><td rowspan='2' width='192'></td>")
	document.write("</tr><tr height='111'><td rowspan='2' width='192'></td><td rowspan='2' width='192'></td><td rowspan='2' width='192'></td>") } else
if (L==2) {
	document.write("</tr><tr height='111'><td rowspan='2' width='192'></td><td rowspan='2' width='192'></td>")
	document.write("</tr><tr height='111'><td rowspan='2' width='192'></td><td rowspan='2' width='192'></td>")
	document.write("</tr><tr height='111'><td rowspan='2' width='192'></td><td rowspan='2' width='192'></td>")
	document.write("</tr><tr height='111'><td rowspan='2' width='192'></td><td rowspan='2' width='192'></td><td rowspan='2' width='192'></td>") }
}
if ((L>=9) && (L%3==1)) { document.write("<td rowspan='2' width='192'></td>") }
if ((L>=9) && (L%3==0)) { document.write("<td rowspan='2' width='192'></td><td rowspan='2' width='192'></td>") }

} else {

for (n=1; n<=L; n++) {
if (n==2||n==5) { document.write("<td rowspan='2' width='192' class='tablenorm'></td></tr><tr height='111'>") }
if (n==4||n==7) { document.write("</tr><tr height='111'>") }
if ((n>=9) && (n%5==4)) { document.write("<td rowspan='2' width='192' class='tablenorm'></td></tr><tr height='111'><td width='64'></td>") }
if ((n>=9) && (n%5==2)) { document.write("</tr><tr height='111'><td width='64'></td>") }
m=List[n-1]
document.write("<td rowspan='2' width='192' class='tablenorm'>")
document.write("<table borders='0' cellpadding='0' cellspacing='0'>")
document.write("<tr height='3'><td colspan=2></td></tr>")
document.write("<tr height='100'><td colspan=2><a href='javascript:moreInfo(" + m + ")'><img src='thumbs/thumb" + m + ".gif' border='0'></A><b>£" + itemPric[m] + "</b></td></tr><tr height='20'><td colspan=2>" + itemName[m] + "</td></tr><tr height='20'><td colspan=2>")
document.write(itemDes1[m] + "</td></tr><tr height='20'><td colspan=2>")
document.write(itemDes2[m] + "</td></tr><tr height='20'><td width='14'></td><td>")

if (m!=26) {
if (stockCheck(m)) {document.write("<div style='cursor:pointer'class='close' id='close1' onMouseOver=id='close2' onMouseDown=id='close3' onMouseUp=id='close2' onMouseOut=id='close1' onClick='addToBasket(" + m + ")'>Add to Basket</div></td></tr>")}
else {document.write("OUT OF STOCK</td></tr>")}
	} else {
if (stockCheck(m)) {document.write("<div style='cursor:pointer'class='close' id='close1' onMouseOver=id='close2' onMouseDown=id='close3' onMouseUp=id='close2' onMouseOut=id='close1' onClick='checkLetters()'>Add to Basket</div></td></tr>")}
else {document.write("OUT OF STOCK</td></tr>")}
	}




document.write("</table>")
document.write("</td>")
}

if (L<7) {
if (L==6) { document.write("</tr><tr height='111'><td rowspan='2' width='192' class='tablenorm'></td><td rowspan='2' width='192' class='tablenorm'></td><td rowspan='2' width='192' class='tablenorm'></td>") } else
if (L==5) { document.write("<td rowspan='2' width='192' class='tablenorm'></td>")
	document.write("</tr><tr height='111'><td rowspan='2' width='192' class='tablenorm'></td><td rowspan='2' width='192' class='tablenorm'></td><td rowspan='2' width='192' class='tablenorm'></td>") } else
if (L==4) { document.write("<td rowspan='2' width='192' class='tablenorm'></td>")
	document.write("</tr><tr height='111'><td rowspan='2' width='192' class='tablenorm'></td><td rowspan='2' width='192' class='tablenorm'></td>")
	document.write("</tr><tr height='111'><td rowspan='2' width='192' class='tablenorm'></td><td rowspan='2' width='192' class='tablenorm'></td><td rowspan='2' width='192' class='tablenorm'></td>") }
if (L==3) { document.write("</tr><tr height='111'><td rowspan='2' width='192' class='tablenorm'></td><td rowspan='2' width='192' class='tablenorm'></td>")
	document.write("</tr><tr height='111'><td rowspan='2' width='192' class='tablenorm'></td><td rowspan='2' width='192' class='tablenorm'></td>")
	document.write("</tr><tr height='111'><td rowspan='2' width='192' class='tablenorm'></td><td rowspan='2' width='192' class='tablenorm'></td><td rowspan='2' width='192' class='tablenorm'></td>") } else
if (L==2) { document.write("<td rowspan='2' width='192' class='tablenorm'></td>")
	document.write("</tr><tr height='111'><td rowspan='2' width='192' class='tablenorm'></td><td rowspan='2' width='192' class='tablenorm'></td>")
	document.write("</tr><tr height='111'><td rowspan='2' width='192' class='tablenorm'></td><td rowspan='2' width='192' class='tablenorm'></td>")
	document.write("</tr><tr height='111'><td rowspan='2' width='192' class='tablenorm'></td><td rowspan='2' width='192' class='tablenorm'></td><td rowspan='2' width='192' class='tablenorm'></td>") } else
if (L==1) { document.write("<td rowspan='2' width='192' class='tablenorm'></td>")
	document.write("</tr><tr height='111'><td rowspan='2' width='192' class='tablenorm'></td><td rowspan='2' width='192' class='tablenorm'></td>")
	document.write("</tr><tr height='111'><td rowspan='2' width='192' class='tablenorm'></td><td rowspan='2' width='192' class='tablenorm'></td>")
	document.write("</tr><tr height='111'><td rowspan='2' width='192' class='tablenorm'></td><td rowspan='2' width='192' class='tablenorm'></td>")
	document.write("</tr><tr height='111'><td rowspan='2' width='192' class='tablenorm'></td><td rowspan='2' width='192' class='tablenorm'></td><td rowspan='2' width='192' class='tablenorm'></td>") }

}

if ((L>=7) && ((L%5==2)||(L%5==4))) { document.write("<td rowspan='2' width='192' class='tablenorm'></td><td rowspan='2' width='192' class='tablenorm'></td>") }
if ((L>=7) && ((L%5==0)||(L%5==3))) { document.write("<td rowspan='2' width='192' class='tablenorm'></td>") }

}

}



function pound(x) {
pence=Math.round(100*x)
pence=pence + "p"
len=pence.length
if (len==3) { pounds = "0." + pence.charAt(0) + pence.charAt(1) } else if (len==2) { pounds = "0.0" + pence.charAt(0) } else {
newPence=""
for (l=0; l<len-3; l++) { newPence=newPence + pence.charAt(l) }
pounds = newPence + "." + pence.charAt(len-3) + pence.charAt(len-2)
}
return(pounds)
}

function removeFromBasket(N) {
newBasket = new Array(c)
for (m=1; m<N; m++) { newBasket[m] = basket[m] }
for (m=N; m<c; m++) { newBasket[m] = basket[m+1] }
basket = new Array(c)
for (m=1; m<c; m++) { basket[m] = newBasket[m] }
c -= 1
prev = 'item=,'
for (p=1; p<=c; p++) {
prev = prev + basket[p] + ','
}
document.cookie=prev + ";expires=" + expireDate.toGMTString()
window.location="basket.html"
}



function clearBasket() {
document.cookie="item=,;expires=" + expireDate.toGMTString()
window.location="basket.html"
}

var xpost = new Array("AB","IV","KW","PA","PH","HS","ZE","GY","JE","IM")


function formCheck() {
var bad=/[^A-Za-z\d\s\r,.\-_]/
if (document.forms.order.name.value==null || document.forms.order.name.value=="" || /[^A-Za-z\d\s\r,.\-]/.test(document.forms.order.name.value) == true)
{ alert("Please enter your name \rusing only letters, digits, and the following characters:\rcomma, full stop, hyphen"); return false; }
 
if (document.forms.order.address.value==null || document.forms.order.address.value=="" || /[^A-Za-z\d\s\r,.\-]/.test(document.forms.order.address.value) == true)
{ alert("Please enter your address \rusing only letters, digits, and the following characters:\rcomma, full stop, hyphen"); return false; }
 
if (document.forms.order.postcode.value==null || document.forms.order.postcode.value=="" || /[^A-Za-z\d\s]/.test(document.forms.order.postcode.value) == true)
{ alert("Please enter your postcode \rusing only letters, digits and spaces"); return false; }
 else { document.forms.order.postcode.value = document.forms.order.postcode.value.toUpperCase() }
 
var p = document.forms.order.postcode.value.replace(/\s/g,"")
 
if (/^[A-Z]{1,2}[0-9][A-Z0-9]{0,1}[0-9][A-Z]{2}$/.test(p) != true) {alert("Please enter a valid postcode"); return false;}
 
var xx = p.split("")
var xxx = xx[0] + xx[1]
for (x in xpost) {if (xpost[x] == xxx) {alert ("Delivery to this postcode may cost more. \rPlease phone or email us to check"); return false;} }
 
if (document.forms.order.email.value==null || document.forms.order.email.value=="" || /[^A-Za-z\d\s\r,.\-_\@]/.test(document.forms.order.email.value) == true)
{ alert("Please enter your email \rusing only letters, digits, and the following characters:\rcomma, full stop, hyphen, underscore and @"); return false; }
 
var a = document.forms.order.email.value.indexOf("@");
var aa = document.forms.order.email.value.lastIndexOf("@");
 
var b = document.forms.order.email.value.lastIndexOf(".");
if (a!=aa||a<1||a+2>b||b+2>document.forms.order.email.value.length) { alert("Please enter a valid email address"); return false; }
 
if (/[^\d\s]/.test(document.forms.order.tel.value) == true)
{ alert("Please enter your telephone number \rusing only digits and spaces"); return false; }
 
if (/[^\d\s]/.test(document.forms.order.mob.value) == true)
{ alert("Please enter your mobile number \rusing only letters, digits, and the following characters:\rcomma, full stop, hyphen, underscore"); return false; }
 
if (/[^A-Za-z\d\s\r,.\-]/.test(document.forms.order.additionalInfo.value) == true)
{ alert("Please enter any additional information \rusing only letters, digits, and the following characters:\rcomma, full stop, hyphen, underscore"); return false; }
 
 
}
var TermsText = "<dl><dt>Prices and Payment</dt><dd>All prices are inclusive of VAT. Prices exclude delivery. For orders less than £20 we add £4 for delivery. For orders of £20 or more but less than £100 we add £7 delivery. For orders of £100 or more we do not charge for delivery. The above charges apply to most of mainland Britain. Delivery to the Highlands and Islands of Scotland may be more. We will contact you before dispatching your order if this is the case. </dd><dt>Delivery</dt><dd>We will either use a private parcel delivery service or the Royal Mail depending on the size of the order. We aim to dispatch all orders as quickly as possible. You will normally receive your order within 3 working days but this is not a guarantee. If we are out of stock of any of the items on your order we will contact you by phone or e-mail to let you know. We will agree with you whether to send part of your order or wait until we have the full order to send. </dd><dt>Returns</dt><dd>If for any reason you change your mind and wish to cancel all or part of your order you may do so within seven days of receiving your order. You can do this by phoning 015394 33780 or by e-mailing sales@theamblesidetoyshop.co.uk We will either ask you to post the item(s) or we may arrange a collection. We will refund your payment including any delivery charge. You may have to pay the cost of returning the goods. All item(s) returned must be in the same condition in which you received them, including any packaging and labels.</dd><dt>Order Confirmation and Acceptance</dt><dd>When we receive your order you will see a confirmation page which you may wish to print. This confirms that we have received your order. It does not mean that we have accepted your order. There is always the possibility that we might have made a mistake with the prices or other details. If there are any problems we will let you know as soon as possible.</dd></dl>";

function showTerms() {

if (document.getElementById("terms").innerHTML=="") { document.getElementById("terms").innerHTML=TermsText; } else {document.getElementById("terms").innerHTML=""}
}


