// Add the totals of the items up so that they can be sent to paypal
// as well as let the user know as they go how much the item is going to cost
function addTotals () {
	totalPrice = 125;
	for(var i=0;i<document.forms[0].length;i++) {
		var currentItem = document.forms[0].elements[i];
		if(currentItem.getAttribute('price')) {
			totalPrice += (currentItem.getAttribute('price')*currentItem.value);
		}
	}
	if(document.getElementById('totalPrice')) {
		document.getElementById('totalPrice').innerHTML = '$' + totalPrice;
		document.getElementById('formPrice').value = totalPrice;
	}
}


function validateForms(formName) {
	/* Possible validation types: (use class="" to call the validation)
		required*/
		containsErrors = false;
		
	// Loop through the form and call each item in the form
	for(var i=0;i<formName.elements.length;i++) {
		var thisElement = formName.elements[i];
		if(thisElement.className.indexOf("required") != -1 || thisElement.className.indexOf("Required") != -1) {
			checkFilled(thisElement);
		}
	}
			
	
	if(containsErrors) {
		return false;
	}
}


// Called functions from validateForms() to get different types
function checkFilled(field) {
	if(field.value.length < 1 || field.value == field.defaultValue) {
		field.style.background = '#f9fad9 url("http://www.waterworkspark.com/images/error.png") no-repeat left center';
		field.style.paddingLeft = '15px';
		containsErrors = true;
	}
	else {
		field.style.background = '#ffffff';
		field.style.paddingLeft = '0px';
	}
}
