//Preloads images for the dock
dockpic1 = new Image;
dockpic1.src='images/dock/glow/fd01_glow.png';

dockpic2 = new Image;
dockpic2.src='images/dock/glow/db01_glow.png';

dockpic3 = new Image;
dockpic3.src='images/dock/glow/it01_glow.png';

dockpic4 = new Image;
dockpic4.src='images/dock/glow/ip01_glow.png';

dockpic5 = new Image;
dockpic5.src='images/dock/glow/ic01_glow.png';

dockpic6 = new Image;
dockpic6.src='images/dock/glow/pb01_glow.png';

addtocart5 = new Image;
addtocart5.src='images/remove.png';

addtocart6 = new Image;
addtocart6.src='images/addtocart_checked.png';

//Checks the form to make sure the user checked a box
function checkform (){
	valid = true;
	
	if (document.iconpillows.fd01.value!="yes" && document.iconpillows.db01.value!="yes" && document.iconpillows.it01.value!="yes" && document.iconpillows.ip01.value!="yes" && document.iconpillows.pb01.value!="yes" && document.iconpillows.ic01.value!="yes") {
		alert("Please check the boxes for the items you want to add to your cart.");
		valid = false;
	}
	if (valid == true) {
	    showSpinner();
	}
	
	return valid;
}

//If the user checks a box switch images of dock and checkbox
function addtocart(name, dockname, object) {
	var txt;
	var tbox = document.getElementById(object);
	
	//If the are adding to the cart (the value is already zero)
	if (tbox.value == "no") {
		document[name].src='images/remove.png';
		if (object == "fd011") {
			document[dockname].src='images/dock/glow/fd01_glow.png';
		}
		
		if (object == "db011") {
			document[dockname].src='images/dock/glow/db01_glow.png';
		}
		
		if (object == "it011") {
			document[dockname].src='images/dock/glow/it01_glow.png';
		}
		
		if (object == "ip011") {
			document[dockname].src='images/dock/glow/ip01_glow.png';
		}
		
		if (object == "ic011") {
			document[dockname].src='images/dock/glow/ic01_glow.png';
		}
		
		if (object == "pb011") {
			document[dockname].src='images/dock/glow/pb01_glow.png';
		}
		
		 //sets the value of the hidden input box to yes
		txt = "yes";
		tbox.value = txt;
		
		//changes the add to cart button to bright color
		if (document.iconpillows.fd01.value == "yes" || document.iconpillows.db01.value == "yes" || document.iconpillows.it01.value == "yes" || document.iconpillows.ip01.value == "yes" || document.iconpillows.pb01.value == "yes" || document.iconpillows.ic01.value == "yes") {
			var imagebutton = document.getElementById("addtocartbutton");
			imagebutton.src = "images/addtocart_checked.png";
		}
	} else {
		
		//if the user is removeing item from cart
		if (tbox.value = "yes") {
			document[name].src='images/button.png';
			
			//resets the way the checkboxes look
			if (object == "fd011") {
				document[dockname].src='images/dock/plain/fd01_no.png';
			}
			 
			if (object == "db011") {
				document[dockname].src='images/dock/plain/db01_no.png';
			}
			
			if (object == "it011") {
				document[dockname].src='images/dock/plain/it01_no.png';
			}
			
			if (object == "ip011") {
				document[dockname].src='images/dock/plain/ip01_no.png';
			}
			
			if (object == "ic011") {
				document[dockname].src='images/dock/plain/ic01_no.png';
			}
			
			if (object == "pb011") {
				document[dockname].src='images/dock/plain/pb01_no.png';
			}
			
			//sets hidden input box to no
			txt = "no";
			tbox.value = txt;
			
			//returns the add to cart button to normal
			if (document.iconpillows.fd01.value == "no" && document.iconpillows.db01.value == "no" && document.iconpillows.it01.value == "no" && document.iconpillows.ip01.value == "no" && document.iconpillows.pb01.value == "no" && document.iconpillows.ic01.value == "no") {
				var imagebutton = document.getElementById("addtocartbutton");
				imagebutton.src = "images/addtocart.png";
			}
		}
	}
}

function LoadItemsInCart() {
	var tbox = document.getElementById('fd011');
	
	if (tbox.value == "yes") {
		document['fd01add'].src='images/remove.png';
		document['fd012'].src='images/dock/glow/fd01_glow.png';
	}
		
	tbox = document.getElementById('db011');
	
	if (tbox.value == "yes") {
		document['db01add'].src='images/remove.png';
		document['db012'].src='images/dock/glow/db01_glow.png';
	}
	
	tbox = document.getElementById('it011');
	
	if (tbox.value == "yes") {
		document['it01add'].src='images/remove.png';
		document['it012'].src='images/dock/glow/it01_glow.png';
	}
	
	tbox = document.getElementById('ip011');
	
	if (tbox.value == "yes") {
		document['ip01add'].src='images/remove.png';
		document['ip012'].src='images/dock/glow/ip01_glow.png';
	}

	tbox = document.getElementById('ic011');
	
	if (tbox.value == "yes") {
		document['ic01add'].src='images/remove.png';
		document['ic012'].src='images/dock/glow/ic01_glow.png';
	}		

	tbox = document.getElementById('pb011');
	
	if (tbox.value == "yes") {
		document['pb01add'].src='images/remove.png';
		document['pb012'].src='images/dock/glow/pb01_glow.png';
	}
	
	if (document.iconpillows.fd01.value == "yes" || document.iconpillows.db01.value == "yes" || document.iconpillows.it01.value == "yes" || document.iconpillows.ip01.value == "yes" || document.iconpillows.pb01.value == "yes" || document.iconpillows.ic01.value == "yes") {
		var imagebutton = document.getElementById("addtocartbutton");
		imagebutton.src = "images/addtocart_checked.png";
	}
		
}
	
