function closegrid() {
	document.getElementById("shoecatalogueouter").style.display='none';
	document.getElementById("Master2").style.visibility='hidden';
}

function showgrid() {
	document.getElementById("Master2").style.visibility='visible';
	document.getElementById("shoecatalogueouter").style.display='block';
}

function ss(shoeid) {
	result=shoeid.split("@@"); //name, pic, price, sale price, reason
	if (result[4]=='0') {
		var priceline = "<span class='priceticket'>&pound;"+result[2];
	}
	else
	{ 
		if (result[4]=='1') {
			var priceline = "<span class='discount'>&pound;"+result[2]+"</span><span class='priceticket'>Now &pound;"+result[3]+"</span>";
		}
		else
		{
			var priceline = "<img src='/SiteImages/tamemberprice.png' /><span class='priceticket'> &pound;"+result[3]+"</span>";
		}
	}
	
	var chosensupportlevel = 4-Math.floor((result[6]-1)/5); //0-4
    var chosencushionlevel = (result[6]-1)%5; //1-5
	var targetsupportlevel = 4-Math.floor((result[7]-1)/5);
	var targetcushionlevel = (result[7]-1)%5;
	//17chosen and 18target(/5 =3 17/5=3
	//alert("chosensupp:"+chosensupportlevel+" chosencush:"+chosencushionlevel+" targetsupp:"+targetsupportlevel+" targetcush:"+targetcushionlevel);
	
	var cushion = (chosencushionlevel-targetcushionlevel);
	var support = (chosensupportlevel-targetsupportlevel);
	if (cushion>2) { cushion=2; }
	if (cushion<-2){ cushion=-2;}
	if (support>2) { support=2; }
	if (support<-2){ support=-2;}
	cushion = (cushion*18)+54+"px";
	support = (support*18)+54+"px";
	
	document.getElementById("shoegridsummary").innerHTML="<div id='sspic' style='background-image:url(/ApexProductImages/TN/TN"+result[1]+");'></div><div id='ssname'>"+result[0]+"<br/>"+priceline+"<br/><div id='sscompcush' style='background-position:0px "+cushion+"'></div><div id='sscompsupp' style='background-position:50px "+support+"'></div></div>";

	oElement = document.getElementById('t'+result[5]);
	var x = 0;
	var y = 0;
	while( oElement != null ) {
		y += oElement.offsetTop;
		x += oElement.offsetLeft;
		oElement = oElement.offsetParent;
	}
	
	//position the summary box to the right of the mouseover target
	document.getElementById("shoegridsummary").style.left = x+25+"px";
	document.getElementById("shoegridsummary").style.top = y+"px";
	document.getElementById("shoegridsummary").style.display='block';
	document.getElementById("shoegridsummary").style.backgroundPosition="0px 0px";
	
}

function hs() {
	document.getElementById("shoegridsummary").style.display='none';
}

function switchimg(sourcecol, sourcerow) {
	if (document.getElementById("imgtable").rows[sourcerow].cells[sourcecol].innerHTML.search("TNblankthumbnail.jpg") == -1) {
		slicestart = document.getElementById("imgtable").rows[sourcerow].cells[sourcecol].innerHTML.search("/TN/TN")+6;
		slicestop = document.getElementById("imgtable").rows[sourcerow].cells[sourcecol].innerHTML.search(".jpg")+4;
		imgurl = document.getElementById("imgtable").rows[sourcerow].cells[sourcecol].innerHTML.slice(slicestart, slicestop);
		
		document.getElementById("largepic").innerHTML = "<img src='ApexProductImages/"+imgurl+"'/></img>";
	} else {
		document.getElementById("largepic").innerHTML = "<img src='ApexProductImages/blankthumbnail.jpg'/></img>";
	}
}

function addtocart(prodID) {
	var http=getXMLHTTPRequest();
	if (document.getElementById('sizeselector')!=null) {
		if(document.getElementById('sizeselector').options[document.getElementById('sizeselector').selectedIndex].text=="size.."){
			alert("Please choose the size you would like to order");
			return;
		}
	}
	
	//send new product details via xmlHTTP then go the cart with window.location to avoid parameters in the URL
	if (document.getElementById('sizeselector')===null) {
		modurl = "http://www.apex-sports.co.uk/ajaxbasket.php?p="+prodID+"&a=add&s=n/a&display=N";}
	else {
		modurl = "http://www.apex-sports.co.uk/ajaxbasket.php?p="+prodID+"&a=add&display=N&s="+encodeURIComponent(document.getElementById('sizeselector').options[document.getElementById('sizeselector').selectedIndex].text);
	}
	
	http.open("GET", modurl, false);
	http.send(null);
	window.location="http://www.apex-sports.co.uk/shoppingcart.php";
}

function loadimage(sourcefile) {
	document.getElementById("largeimg").src = sourcefile;
}
