// Javascript to manipulate colour and size selections

function resetcells(totcells, firstcell) { 
 stopcell = Math.floor(totcells) + Math.floor(firstcell) - 1;
 for (i = stopcell; i >= firstcell; i--) {
    cellid = "SEL" + i;
 	var currTabElem = document.getElementById(cellid); 
	currTabElem.setAttribute("class", "LinkTable1"); 
	currTabElem.setAttribute("className", "LinkTable1"); 
	}
return; 
} 
function resetscells(totscells, firstscell) { 
 stopscell = Math.floor(totscells) + Math.floor(firstscell) - 1;
 for (i = stopscell; i >= firstscell; i--) {
	 
	 cellsid = "SIZ" + i;
 	var currTabElem = document.getElementById(cellsid); 
	currTabElem.setAttribute("class", "LinkTable1"); 
	currTabElem.setAttribute("className", "LinkTable1"); 
	}
return; 
} 
function JW_LoadColourSearchKeys(ProductCode, colour, fabric, newImage, selcol, totcells, firstcell, ProductNo) { //Invigoration
  theColour[ProductNo] = colour;
  theFabric[ProductNo] = fabric;
  theProduct[ProductNo] = ProductCode;
  thepreText = " in size ";
  theText = "";
  MyPrice = "MyPrice" + ProductNo;
  CartAdd = "eCart4_1_ID" + ProductNo + "_Add";
  CartQuantity = "eCart4_1_Quantity" + ProductNo + "_Add";
  CartATC = "eCart4_1_ATC" + ProductNo;
  	resetcells(totcells, firstcell);
	var currTabElem = document.getElementById(selcol); 
	currTabElem.setAttribute("class", "LinkTable2"); 
	currTabElem.setAttribute("className", "LinkTable2"); 
  	ArraySearch = theProduct[ProductNo] + " " + theColour[ProductNo] + " " + theFabric[ProductNo] + " " + theSize[ProductNo];
  for (i = SEL.length-1; i > -1; i--) {
	if(ArraySearch == SEL[i]) break;
	}
if (theSize[ProductNo] != "") { 
	if (LEADTIME[i] == "Out of Stock ") {
	document.getElementById(MyPrice).innerHTML="Unfortunately the " + theColour[ProductNo] + " " + theFabric[ProductNo] + thepreText + theSize[ProductNo] + theText + " is out of stock";
		document.getElementById(CartATC).disabled=true;
		document.getElementById(CartQuantity).disabled=true;
	return;
	}
	else 
	{document.getElementById(MyPrice).innerHTML="You've selected " + theColour[ProductNo] + " " + theFabric[ProductNo] + thepreText + theSize[ProductNo] + theText + ". Price £" + PRICE[i] + ", usual dispatch " + LEADTIME[i];
		document.getElementById(CartAdd).value = PRODUCTID[i];
		document.getElementById(CartATC).disabled=false;
		document.getElementById(CartQuantity).disabled=false;
		return;
	}
}
	if (theSize[ProductNo] == ""){document.getElementById(MyPrice).innerHTML="You've selected " + theColour[ProductNo] + " " + theFabric[ProductNo] + ", please select your size"};
	var currTabElem = document.getElementById(MyPrice); 

	return;
}
function JW_LoadSizeSearchKey(size) { //Invigoration
	document.getElementById("MySize").innerHTML=size;
	return;
}
function popawindow() { //Invigoration
  	document.button.CARTBUTTON.disabled=false;
	return;
}
Array_index = -1
function ShowKey(ProductCode, size, selscol, totscells, firstscell, ProductNo) { //Invigoration
  theSize[ProductNo] = size;
  theProduct[ProductNo] = ProductCode;
  thepreText = " in size ";
  theText = "";
  MyPrice = "MyPrice" + ProductNo;
  CartAdd = "eCart4_1_ID" + ProductNo + "_Add";
  CartQuantity = "eCart4_1_Quantity" + ProductNo + "_Add";
  CartATC = "eCart4_1_ATC" + ProductNo;
  	resetscells(totscells, firstscell);
  	var currTabElem = document.getElementById(selscol); 
	currTabElem.setAttribute("class", "LinkTable2"); 
	currTabElem.setAttribute("className", "LinkTable2"); 
  ArraySearch = theProduct[ProductNo] + " " + theColour[ProductNo] + " " + theFabric[ProductNo] + " " + theSize[ProductNo]
  for (i = SEL.length-1; i > -1; i--) {
	if(ArraySearch == SEL[i]) break;
	}
if (theColour[ProductNo] != "") { 
	if (LEADTIME[i] == "Out of Stock ") {
	document.getElementById(MyPrice).innerHTML="Unfortunately the " + theColour[ProductNo] + " " + theFabric[ProductNo] + thepreText + theSize[ProductNo] + theText + " is out of stock.";
		document.getElementById(CartATC).disabled=true;
		document.getElementById(CartQuantity).disabled=true;
	return;
	}
	else 
	{document.getElementById(MyPrice).innerHTML="You've selected " + theColour[ProductNo] + " " + theFabric[ProductNo] + thepreText + theSize[ProductNo] + theText + ". Price £" + PRICE[i] + ", usual dispatch " + LEADTIME[i];
		document.getElementById(CartAdd).value = PRODUCTID[i];
		document.getElementById(CartATC).disabled=false;
		document.getElementById(CartQuantity).disabled=false;
		return;
	}	
}
	if (theColour[ProductNo] == ""){document.getElementById(MyPrice).innerHTML="You've selected size " + theSize[ProductNo] + theText + ", please select a colour"};
	var currTabElem = document.getElementById(MyPrice); 

	return;
}


