//Add event Handler
function addBasketHandler(){
	//Javascript Degradation
	if( degradeByScript() ) return false;
  
  var anchorTags = document.getElementsByTagName("a");
  
  if(anchorTags){
  	for (var i=0; i<anchorTags.length; i++) {
  		//If the anchor has class attribute
  		if(anchorTags[i].getAttribute("id")){
  			if(anchorTags[i].getAttribute("id").substring(0,4) == "hide"){
  				var anchorID = anchorTags[i].getAttribute("id").substring(4);
  				
  				//This is a hide & show link, attach function to it
  				anchorTags[i].onclick = function(){
  					if(this.getAttribute("class") == "upArrow"){
  						this.setAttribute("class","downArrow");
  					}else if(this.getAttribute("class") == "downArrow"){
  						this.setAttribute("class","upArrow");
  					}
  					hideShowSec(this.getAttribute("id").substring(4));
  					this.blur();
  					return false;
  				}
				 }
  		}
  	}
  }
}
//Toggle between hide and show option section
function hideShowSec(eleID){
	//Change the anchor text
	var hideAnchor = document.getElementById("hide"+eleID);

	//Option Table
	var sec = document.getElementById("sec"+eleID);
	
	if(sec.className == "hideSection"){
		sec.className = "displaySection";
		if(hideAnchor.firstChild.nodeType == 3){
			hideAnchor.firstChild.nodeValue = "Hide product breakdown";
		}
	}else if(sec.className == "displaySection"){
		sec.className = "hideSection";
		if(hideAnchor.firstChild.nodeType == 3){
			hideAnchor.firstChild.nodeValue = "Show product breakdown";
		}
	}
	
	//Pricing Table
	var pri = document.getElementById("pri"+eleID);
	
	if(pri.className  == "hideSection"){
		pri.className = "displaySection";
	}else if(pri.className == "displaySection"){
		pri.className = "hideSection";
	}
}
//function hideShowSec(eleID){
//	//Change the anchor text
//	var hideAnchor = document.getElementById("hide"+eleID);
//
//	//Option Table
//	var sec = document.getElementById("sec"+eleID);
//	
//	if(sec.getAttribute("class") == "hideSection"){
//		sec.setAttribute("class", "displaySection");
//		if(hideAnchor.firstChild.nodeType == 3){
//			hideAnchor.firstChild.nodeValue = "Hide product breakdown";
//		}
//	}else if(sec.getAttribute("class") == "displaySection"){
//		sec.setAttribute("class", "hideSection");
//		if(hideAnchor.firstChild.nodeType == 3){
//			hideAnchor.firstChild.nodeValue = "Show product breakdown";
//		}
//	}
//	
//	//Pricing Table
//	var pri = document.getElementById("pri"+eleID);
//	
//	if(pri.getAttribute("class") == "hideSection"){
//		pri.setAttribute("class", "displaySection");
//	}else if(pri.getAttribute("class") == "displaySection"){
//		pri.setAttribute("class", "hideSection");
//	}
//}

function checkProceedtoCheckOut(urlLink){
	var checkOutLink = document.getElementById("proceedToCheckoutLink");
	if(checkOutLink){
		var display = document.getElementById("deliveryCostDisplay");
		if(display.firstChild.nodeValue == "\u00A3"){
			alert("Please select a delivery option.");
			return false;
		}else{
			this.submit();
			return true;
		}
	}
}

addLoadEvent(addBasketHandler);