// JavaScript Document

//AJAX code
function ajaxAddToBasket(which,whichButton,linkButton){
	//var xmlhttp=null
	var linkItem=document.getElementById('addtobasketLinkText' + whichButton)
	var quantity=document.getElementById('quantity' + whichButton).value;
	
	if($('selectSize')) {
		theSize="Size:" + document.getElementById("selectSize").value;
	}else{
		theSize="";
	}
	if($('selectWeight')) {
		theWeight=", Weight:" + document.getElementById("selectWeight").value;
	}else{
		theWeight="";
	}
	if($('selectHand')) {
		theHand=", Hand:" + document.getElementById("selectHand").value;
	}else{
		theHand="";
	}
	var productOptions=theSize + theWeight + theHand;
	
	linkItem.innerHTML='<strong>adding</strong> to basket...';
	linkButton.onclick=function() {
	
	}
	
	// code for Mozilla, etc.
	if (window.XMLHttpRequest){
	xmlhttp=new XMLHttpRequest()
	}
	// code for IE
	else if (window.ActiveXObject){
	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
	}
	if (xmlhttp!=null){
	//xmlhttp.onreadystatechange=ajaxAddToFittingRoomAction linkItem
	xmlhttp.onreadystatechange=function() {
		ajaxAddToBasketAction(linkButton)
		$("basketQuantity"+whichButton).fade(0);
		$("basketSize").fade(0);
		if($("basketWeight")) {
			$("basketWeight").fade(0);
		}
		if($("basketHand")) {
			$("basketHand").fade(0);
		}
		//document.getElementById("basketQuantity"+whichButton).style.display="none";
	}
	
	
	xmlhttp.open("GET","global/ajax/ajax.asp?action=add&id=" + which + "&quantity=" + quantity + "&options=" + productOptions + "",true)
	xmlhttp.send(null)
	}
}
function ajaxAddToBasketAction(which){
	// if xmlhttp shows "loaded"
	var linkItem=document.getElementById('addtobasketLinkText' + which)
	
	if (xmlhttp.readyState==4){
		// if "OK"
		if (xmlhttp.status==200){
			which.href="index.asp?action=showbasket"
			which.innerHTML="go to <strong>basket</strong>"
			ajaxUpdateFittingRoomItems()
			//alert(which.href);
		}else{
			//alert("Problem retrieving XML data:" + xmlhttp.statusText)
		}
	}
}



//AJAX code
function ajaxUpdateFittingRoomItems(){
	//var xmlhttp=null
	// code for Mozilla, etc.
	if (window.XMLHttpRequest){
	xmlhttp=new XMLHttpRequest()
	}
	// code for IE
	else if (window.ActiveXObject){
	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
	}
	if (xmlhttp!=null){
	//xmlhttp.onreadystatechange=ajaxAddToFittingRoomAction linkItem
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4){
			// if "OK"
			if (xmlhttp.status==200){
				document.getElementById("labalBasketItems").innerHTML=xmlhttp.responseText;
			}else{
				//alert("Problem retrieving XML data:" + xmlhttp.statusText)
			}
		}
	}
	
	
	
	xmlhttp.open("GET","global/ajax/ajax.asp?ajaxAction=showbasketitems",true)
	xmlhttp.send(null)
	}
}





function removeFromBasket(id,which) {
	ajaxRemoveFromBasket(id)
	var myFx = new Fx.Tween(which);
	myFx.start('height', '0');
	$(which).fade('out');
	myFx.onComplete=function() {
		$(which).setStyle('display','none');
	}
}


function ajaxRemoveFromBasket(id){
	if (window.XMLHttpRequest){
		xmlhttp=new XMLHttpRequest()
	}else if (window.ActiveXObject){
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
	}
	if (xmlhttp != null){
		xmlhttp.onreadystatechange=function() {
			if (xmlhttp.readyState==4){
				if (xmlhttp.status==200){
					document.getElementById("labalBasketItems").innerHTML=xmlhttp.responseText;
					ajaxUpdateBasketPrice();
					ajaxUpdateBasketDeliveryPrice();
					ajaxUpdatePayPalForm();
				}
			}
		}
	}
	xmlhttp.open("GET","global/ajax/ajax.asp?ajaxAction=removefrombasket&id=" + id + "",true)
	xmlhttp.send(null)
}
function ajaxUpdateBasketPrice(){
	if (window.XMLHttpRequest){
		xmlhttpBasketPrice=new XMLHttpRequest()
	}else if (window.ActiveXObject){
		xmlhttpBasketPrice=new ActiveXObject("Microsoft.XMLHTTP")
	}
	if (xmlhttpBasketPrice != null){
		xmlhttpBasketPrice.onreadystatechange=function() {
			if (xmlhttpBasketPrice.readyState==4){
				if (xmlhttpBasketPrice.status==200){
					document.getElementById("labelBasketPrice").innerHTML=xmlhttpBasketPrice.responseText;
				}
			}
		}
	}
	xmlhttpBasketPrice.open("GET","global/ajax/ajax.asp?ajaxAction=updatebasketprice",true)
	xmlhttpBasketPrice.send(null)
}
function ajaxUpdateBasketDeliveryPrice(){
	if (window.XMLHttpRequest){
		xmlhttpDelPrice=new XMLHttpRequest()
	}else if (window.ActiveXObject){
		xmlhttpDelPrice=new ActiveXObject("Microsoft.XMLHTTP")
	}
	if (xmlhttpDelPrice != null){
		xmlhttpDelPrice.onreadystatechange=function() {
			if (xmlhttpDelPrice.readyState==4){
				if (xmlhttpDelPrice.status==200){
					document.getElementById("labelBasketDeliveryPrice").innerHTML=xmlhttpDelPrice.responseText;
				}
			}
		}
	}
	xmlhttpDelPrice.open("GET","global/ajax/ajax.asp?ajaxAction=updatebasketdeliveryprice",true)
	xmlhttpDelPrice.send(null)
}
function ajaxUpdatePayPalForm(){
	if (window.XMLHttpRequest){
		xmlhttpPaypal=new XMLHttpRequest()
	}else if (window.ActiveXObject){
		xmlhttpPaypal=new ActiveXObject("Microsoft.XMLHTTP")
	}
	if (xmlhttpPaypal != null){
		xmlhttpPaypal.onreadystatechange=function() {
			if (xmlhttpPaypal.readyState==4){
				if (xmlhttpPaypal.status==200){
					document.getElementById("holderPaypalForm").innerHTML=""
					document.getElementById("holderPaypalForm").innerHTML=xmlhttpPaypal.responseText;
				}
			}
		}
	}
	xmlhttpPaypal.open("GET","global/ajax/ajax.asp?ajaxAction=updatepaypalform",true)
	xmlhttpPaypal.send(null)
}

