// Javascript to manipulate colour and size selections
function DoMeFirst() {
theSessionSize='';
if (SizeType == "NA") {theSessionSize=""; }
if (SizeType == "Bra") {theSessionSize="<?php echo $_SESSION[VisitorBraSize] ?>"; }
if (SizeType == "UKBust") {theSessionSize="<?php echo $_SESSION[UKBust] ?>"; }
if (SizeType == "UKWaist") {theSessionSize="<?php echo $_SESSION[UKWaist] ?>"; }
if (SizeType == "UKHips") {theSessionSize="<?php echo $_SESSION[UKHips] ?>"; }
if (SizeType == "Bust") {theSessionSize=Math.round("<?php echo $_SESSION[Bust] ?>");}
if (SizeType == "Waist") {theSessionSize=Math.round("<?php echo $_SESSION[Waist] ?>");}
if (SizeType == "Hips") {theSessionSize=Math.round("<?php echo $_SESSION[Hips] ?>");}
if (SizeType == "Corset") {theSessionSize=Math.round("<?php echo $_SESSION[Waist] ?>");}
if (SizeType == "WKD") {theSessionSize=2 + Number("<?php echo $_SESSION[UKWaist] ?>");}
Hips = Number("<?php echo $_SESSION[UKHips] ?>");
Waist = Number("<?php echo $_SESSION[UKWaist] ?>");
TotSize = Hips + Waist;
AvgSize = Number("<?php echo $_SESSION[UKHips] ?>");
DoMeNext();
}
function DoMeNext() {
	if (theColour != "") {JW_LoadColourSearchKeys(theColour, theFabric, newImage, 'SEL1', '1');	}
	if (theSize != "") {ShowKey(theSize, 'SIZ1', '1');} 
	if (SizeType == "S-M-L") {
		 if (AvgSize > 13) {theSessionSize="XL"; }
		 if (AvgSize > 11) {theSessionSize="L"; }	
		 if (AvgSize > 9) {theSessionSize="M"; }		 	 
		 if (AvgSize > 7) {theSessionSize="S"; }
	}
	if (SizeType == "XX/XX") {
		 if (AvgSize >= 18) {theSessionSize="16/18"; }
		 if (AvgSize >= 16) {theSessionSize="14/16"; }	
		 if (AvgSize >= 14) {theSessionSize="12/14"; }		 	 
		 if (AvgSize >= 12) {theSessionSize="10/12"; }
		 if (AvgSize >= 10) {theSessionSize="8/10"; }
	}
	if (SizeType == "S/S") {
		 if (AvgSize >= 18) {theSessionSize="M/L"; }
		 if (AvgSize >= 14) {theSessionSize="S/M"; }	
	}	
	if (SizeType == "WKDS-M-L") {
		 if (AvgSize > 16) {theSessionSize="L"; }	
		 if (AvgSize = 14) {theSessionSize="M"; }		 	 
		 if (AvgSize >= 12) {theSessionSize="S"; }
	}
	if (SizeType == "WKDXX/XX") {
		 if (AvgSize >= 18) {theSessionSize="16/18"; }
		 if (AvgSize >= 16) {theSessionSize="14/16"; }	
		 if (AvgSize >= 14) {theSessionSize="12/14"; }		 	 
		 if (AvgSize >= 12) {theSessionSize="10/12"; }
		 if (AvgSize >= 10) {theSessionSize="8/10"; }
	}
	if (SizeType == "WKDS/S") {
		 if (AvgSize >= 18) {theSessionSize="M/L"; }
		 if (AvgSize >= 12) {theSessionSize="S/M"; }	
	}
	if (theSessionSize != "") {
  		ArraySearch = theSessionSize;
  		for (i = Asize.length-1; i > -1; i--) 
		{
		if(ArraySearch == Asize[i]) break;
		}
		if (i >= 0) {
			DefSize = "SIZ" + (i + 1);
			var currTabElem = document.getElementById(DefSize); 
			currTabElem.setAttribute("class", "LinkTable2"); 
			currTabElem.setAttribute("className", "LinkTable2"); 
			ShowKey(theSessionSize, DefSize, Asize.length);
			theSize = theSessionSize;}	
		}
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}

}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function resetcells(totcells) { 
 for (i = totcells; i > 0; i--) {
    cellid = "SEL" + i;
 	var currTabElem = document.getElementById(cellid); 
	currTabElem.setAttribute("class", "LinkTable1"); 
	currTabElem.setAttribute("className", "LinkTable1"); 
	}
return; 
} 
function resetscells(totscells) { 
 for (i = totscells; i > 0; i--) {
    cellsid = "SIZ" + i;
 	var currTabElem = document.getElementById(cellsid); 
	currTabElem.setAttribute("class", "LinkTable1"); 
	currTabElem.setAttribute("className", "LinkTable1"); 
	}
return; 
} 
function JW_LoadColourSearchKeys(colour, fabric, newImage, OnlySize, SizeCode, selcol, totcells) { //Invigoration
  theColour = colour;
  theFabric = fabric;
  thepreText = " in size ";
  theText = "";
  if (SizeCode == "Corset"){	          
	  theText = " inch waist"; 
  	  thepreText = " in a ";
							}
  	resetcells(totcells);
  	var currTabElem = document.getElementById(selcol); 
	currTabElem.setAttribute("class", "LinkTable2"); 
	currTabElem.setAttribute("className", "LinkTable2");
	if (OnlySize == "Various") {  ArraySearch = theColour + " " + theFabric + " " + theSize; }
	else { ArraySearch = theColour + " " + theFabric + " " + OnlySize; 
	theSize = OnlySize; }
  for (i = SEL.length-1; i > -1; i--) {
	if(ArraySearch == SEL[i]) break;
	}
if (theSize != "") { 
	if (LEADTIME[i] == "Out of Stock ") {
	document.getElementById("MyPrice").innerHTML="Unfortunately the " + theColour + " " + theFabric + thepreText + theSize + theText + " is out of stock";
	document.ADD_TO_CART.eCart4_1_ATC.disabled=true;
	document.ADD_TO_CART.eCart4_1_Quantity_Add.disabled=true;
	return;
	}
	else {
		if (theFabric == "Gift Voucher") {
			document.getElementById("MyPrice").innerHTML="You've selected the £" + PRICE[i] + " Gift Voucher, usual dispatch " + LEADTIME[i];
			document.ADD_TO_CART.eCart4_1_ID_Add.value = PRODUCTID[i];
			document.ADD_TO_CART.eCart4_1_ATC.disabled=false;
			document.ADD_TO_CART.eCart4_1_Quantity_Add.disabled=false;
			return;}
		else {	
			document.getElementById("MyPrice").innerHTML="You've selected " + theColour + " " + theFabric + thepreText + theSize + theText + ". Price £" + PRICE[i] + ", usual dispatch " + LEADTIME[i];
			document.ADD_TO_CART.eCart4_1_ID_Add.value = PRODUCTID[i];
			document.ADD_TO_CART.eCart4_1_ATC.disabled=false;
			document.ADD_TO_CART.eCart4_1_Quantity_Add.disabled=false;
			return;}
	}
}
	if (theSize == ""){
		if (theFabric == "Gift Voucher") { 
			document.getElementById("MyPrice").innerHTML="You've selected the Gift Voucher, please select value";}
		else {
			document.getElementById("MyPrice").innerHTML="You've selected " + theColour + " " + theFabric + ", 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(size, selscol, OnlySizex, SizeCodex, totscells) { //Invigoration
  theSize = size;
  thepreText = " in size ";
  theText = "";
  if (SizeCodex == "Corset"){theText = " inch waist"; 
  							thepreText = " in a ";
							}				
  	resetscells(totscells);
  	var currTabElem = document.getElementById(selscol); 
	currTabElem.setAttribute("class", "LinkTable2"); 
	currTabElem.setAttribute("className", "LinkTable2"); 
	if (OnlySizex == "Various") {  ArraySearch = theColour + " " + theFabric + " " + theSize; }
	else {  ArraySearch = theColour + " " + theFabric + " " + OnlySizex; 
	theSize = OnlySizex; }
  for (i = SEL.length-1; i > -1; i--) {
	if(ArraySearch == SEL[i]) break;
	}
if (theColour != "") { 
	if (LEADTIME[i] == "Out of Stock ") {
	document.getElementById("MyPrice").innerHTML="Unfortunately the " + theColour + " " + theFabric + thepreText + theSize + theText + " is out of stock.";
	document.ADD_TO_CART.eCart4_1_ATC.disabled=true;
	document.ADD_TO_CART.eCart4_1_Quantity_Add.disabled=true;
	return;
	}
	else { 
		if (theFabric == "Gift Voucher") {
			document.getElementById("MyPrice").innerHTML="You've selected the £" + PRICE[i] + " Gift Voucher, usual dispatch " + LEADTIME[i];
			document.ADD_TO_CART.eCart4_1_ID_Add.value = PRODUCTID[i];
			document.ADD_TO_CART.eCart4_1_ATC.disabled=false;
			document.ADD_TO_CART.eCart4_1_Quantity_Add.disabled=false;
			return;}
		else {	
			document.getElementById("MyPrice").innerHTML="You've selected " + theColour + " " + theFabric + thepreText + theSize + theText + ". Price £" + PRICE[i] + ", usual dispatch " + LEADTIME[i];
			document.ADD_TO_CART.eCart4_1_ID_Add.value = PRODUCTID[i];
			document.ADD_TO_CART.eCart4_1_ATC.disabled=false;
			document.ADD_TO_CART.eCart4_1_Quantity_Add.disabled=false;
			return;}	
		}
}
	if (theColour == ""){
		if (theFabric == "Gift Voucher") { 
			document.getElementById("MyPrice").innerHTML="You've selected the Gift Voucher, please select style";}
		else {
			document.getElementById("MyPrice").innerHTML="You've selected " + theColour + " " + theFabric + ", please select your size";}
	}
	var currTabElem = document.getElementById("MyPrice"); 
	return;
}