//Preloads images for the dock
dockpic1 = new Image;
dockpic1.src='images/nowai/nowai_black_on.png';

dockpic2 = new Image;
dockpic2.src='images/nowai/nowai_blue_on.png';

dockpic3 = new Image;
dockpic3.src='images/nowai/nowai_green_on.png';

dockpic4 = new Image;
dockpic4.src='images/nowai/nowai_orange_on.png';

dockpic5 = new Image;
dockpic5.src='images/nowai/nowai_pink_on.png';

dockpic6 = new Image;
dockpic6.src='images/nowai/nowai_red_on.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.nowaipillows.nowbl.value == "no" && document.nowaipillows.nowaib.value == "no" && document.nowaipillows.nowaig.value == "no" && document.nowaipillows.nowaio.value == "no" && document.nowaipillows.nowaip.value == "no" && document.nowaipillows.nowair.value == "no") {
		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 (dockname == "fd012") {
			document[dockname].src= 'images/nowai/nowai_black_on.png';
		}
		
		if (dockname == "db012") {
			document[dockname].src='images/nowai/nowai_blue_on.png';
		}
		
		if (dockname == "it012") {
			document[dockname].src='images/nowai/nowai_green_on.png';
		}
		
		if (dockname == "ip012") {
			document[dockname].src='images/nowai/nowai_orange_on.png';
		}
		
		if (dockname == "ic012") {
			document[dockname].src='images/nowai/nowai_pink_on.png';
		}
		
		if (dockname == "pb012") {
			document[dockname].src='images/nowai/nowai_red_on.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.nowaipillows.nowbl.value == "yes" || document.nowaipillows.nowaib.value == "yes" || document.nowaipillows.nowaig.value == "yes" || document.nowaipillows.nowaio.value == "yes" || document.nowaipillows.nowaip.value == "yes" || document.nowaipillows.nowair.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 (dockname == "fd012") {
				document[dockname].src= 'images/nowai/nowai_black_off.png';
			}
			
			if (dockname == "db012") {
				document[dockname].src='images/nowai/nowai_blue_off.png';
			}
			
			if (dockname == "it012") {
				document[dockname].src='images/nowai/nowai_green_off.png';
			}
			
			if (dockname == "ip012") {
				document[dockname].src='images/nowai/nowai_orange_off.png';
			}
			
			if (dockname == "ic012") {
				document[dockname].src='images/nowai/nowai_pink_off.png';
			}
			
			if (dockname == "pb012") {
				document[dockname].src='images/nowai/nowai_red_off.png';
			}
			
			
			//sets hidden input box to no
			txt = "no";
			tbox.value = txt;
			
			//returns the add to cart button to normal
			if (document.nowaipillows.nowbl.value == "no" && document.nowaipillows.nowaib.value == "no" && document.nowaipillows.nowaig.value == "no" && document.nowaipillows.nowaio.value == "no" && document.nowaipillows.nowaip.value == "no" && document.nowaipillows.nowair.value == "no") {
				var imagebutton = document.getElementById("addtocartbutton");
				imagebutton.src = "images/addtocart.png";
			}
		}
	}
}

function LoadItemsInCart() {
	itemsAdded = false;
	
	if 	(document.nowaipillows.nowbl.value == "yes") {
		document['nowbladd'].src='images/remove.png';
		itemsAdded = true;
	}
	
	if 	(document.nowaipillows.nowaib.value == "yes") {
		document['nowaibadd'].src='images/remove.png';
		itemsAdded = true;
	}
	
	if 	(document.nowaipillows.nowaig.value == "yes") {
		document['nowaigadd'].src='images/remove.png';
		itemsAdded = true;
	}
	
	if 	(document.nowaipillows.nowaio.value == "yes") {
		document['nowaioadd'].src='images/remove.png';
		itemsAdded = true;
	}
	
	if 	(document.nowaipillows.nowaip.value == "yes") {
		document['nowaipadd'].src='images/remove.png';
		itemsAdded = true;
	}
	
	if 	(document.nowaipillows.nowair.value == "yes") {
		document['nowairadd'].src='images/remove.png';
		itemsAdded = true;		
	}
	
	if (itemsAdded) {
		var imagebutton = document.getElementById("addtocartbutton");
		imagebutton.src ="images/addtocart_checked.png";
	}
	
}
