/*********************************************************************************************************************************************/
//These functions are used to access thye stock table via an ajax call
//The system can then determine if the tshirt is sold out or not
// if the tshirt is sold out, the user will then be unable to add the tshirt to their basket
//the add button is hidden using div replavement


		//show/hide the add button
		function toggleBox(szDivID, iState) // 1 visible, 0 hidden
		{
			//alert("in toggle");
			if(document.layers){	   //NN4+
				document.layers[szDivID].visibility = iState ? "show" : "hide";
			}else if(document.getElementById){	  //gecko(NN6) + IE 5+
				var obj = document.getElementById(szDivID);
				obj.style.visibility = iState ? "visible" : "hidden";
			}else if(document.all){	// IE 4
				document.all[szDivID].style.visibility = iState ? "visible" : "hidden";
			}
		}
		//these functions are needed to fire multiple tasks

		function colour_combo(){//dropdown colour select
			getSelectedIndexes();
			updatePage();
		}
		function colour_combo1(num){//rollover colour select
			setIndex(num);
			updatePage();
		}

		//get the different tshirt parameters and send them to be checked against stock
		function updatePage(){
			//alert("in update");
			var sex = document.getElementById("sel_sex");
			var sexValue = sex.value;
		        var colour = document.getElementById("sel_color");
			var colourValue = colour.options[colour.selectedIndex].value;
		        var size = document.getElementById("sel_size");
			var sizeValue = size.options[size.selectedIndex].value;
			var id = document.getElementById("hid_itemid");
			var fullstring = sexValue+"#"+colourValue+"#"+sizeValue+"#"+id.value;
			//alert(fullstring);
			sendRequest(fullstring);
		    }

		function pageStarter(sexValue, colourValue, sizeValue, idValue){

			var fullstring = sexValue+"#"+colourValue+"#"+sizeValue+"#"+idValue;
			//alert(fullstring);
			sendRequest(fullstring);
		}

		    //call the php srcipt test.php to check the number of remaining tshirts
		    function sendRequest(fullstring) {
				new Ajax.Request("../test.php",
					{
					method: 'post',
					postBody: 'data='+ fullstring,
					onComplete: showResponse
					});
				}


			//show or hide the add to basket button
			function showResponse(req){
				// the response of the php script returns the number of tshirts left
				var left = req.responseText;
				//alert(left);
				//alert(left);
				if(left==0){
					var button = document.getElementById("addButton");
					button.value = "Sold out";
					button.disabled = true;
					show_sold_out(1);
				}else if(left>0){
					//alert("hello1");
					var button = document.getElementById("addButton");
					toggleBox('buttonDiv', 1);
					show_sold_out(0);
					button.value = "Add to Basket";
					button.disabled = false;
				}

			}
			function show_sold_out(flag){

				if(flag){
					document.getElementById("sold_out_img").src = "images/sticker_sold_out.gif";
					//alert("sold out");
				}
				else document.getElementById("sold_out_img").src = "images/blank.gif";
			}
/*********************************************************************************************************************************************/
