﻿

function elementExists(which) {
	if(which) {
		return true;
	}else{
		return false;
	}
}
	
	

window.addEvent('domready', function() {
	initRightNav();
	
});




function initRightNav() {
	for(i=0;i<20;i++) {
	if($('subNav'+i)){
	var rightnavFX = new Fx.Slide('subNav'+i);
	rightnavFX.hide();
	}}
}
function openNav(which){
	var rightnavFX = new Fx.Slide(which);
	rightnavFX.toggle();
}







//AJAX code
function ajaxAddToBasket(which,whichButton,linkButton){
	//var xmlhttp=null
	var linkItem=document.getElementById('addtobasketLinkText' + whichButton)
	var theSize=document.getElementById('selectSize').value;
	var theWeight = $("productWeight").get("text");
	theSize = theWeight + " . " + theSize;
	//alert(theWeight);
	
	if($("selectFlavour")) {
		var theFlavour = $("selectFlavour").get("value");
		theSize = theSize + " . " + theFlavour;
	}
	
	//var quantity=document.getElementById('quantity' + whichButton).value;
	var quantity=1;
	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);
		//document.getElementById("basketQuantity"+whichButton).style.display="none";
	}
	
	
	
	xmlhttp.open("GET","global/ajax/ajax.asp?action=add&id=" + which + "&quantity=" + quantity + "&size=" + theSize + "",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="<strong>added!</strong> go to my basket"
			ajaxUpdateFittingRoomItems()
			ajaxUpdateBasketPriceSmall()
		}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 rightnavFX = new Fx.Slide(which);
	rightnavFX.slideOut();

	/*
	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 ajaxUpdateBasketPriceSmall(){
	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 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;
					document.getElementById("labelBasketPrice2").innerHTML=xmlhttpBasketPrice.responseText;
					ajaxUpdateBasketDeliveryPrice();
				}
			}
		}
	}
	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)
}


function ajaxUpdateQuantity(which,value) {
	if (window.XMLHttpRequest){
		xmlhttpQuantity=new XMLHttpRequest()
	}else if (window.ActiveXObject){
		xmlhttpQuantity=new ActiveXObject("Microsoft.XMLHTTP")
	}
	if (xmlhttpQuantity != null){
		xmlhttpQuantity.onreadystatechange=function() {
			if (xmlhttpQuantity.readyState==4){
				if (xmlhttpQuantity.status==200){
					//document.getElementById("holderPaypalForm").innerHTML=""
					//document.getElementById("holderPaypalForm").innerHTML=xmlhttpPaypal.responseText;
					ajaxUpdateBasketPrice();
					ajaxUpdatePayPalForm();
				}
			}
		}
	}
	var ajaxURL="global/ajax/ajax.asp?ajaxAction=updatequantity&id=" + which + "&value=" + value + "";
	xmlhttpQuantity.open("GET",ajaxURL,true)
	xmlhttpQuantity.send(null)
}
