function inventoryCheckValidate(invObj)
{
	// if checked
	if (invObj.checked)
	{
		// add price to the order total price
		adjustOrderTotal("InventoryFeedManagementPrice","add");
	}
	else // if unchecked
	{
		// subtract price from the order total price
		adjustOrderTotal("InventoryFeedManagementPrice","minus");
		
		var costObj = document.getElementById("Cost");
		if (costObj.checked)
		{
			// uncheck the cost price if it is check
			costObj.checked = false;
			// subtract cost price from the order total if cost was checked	
			adjustOrderTotal("CostManagementPrice","minus");	
		}
	}
}

function costCheckValidate(costObj)
{
	// if checked
	if (costObj.checked)
	{
		var invObj = document.getElementById("InventoryAndFeed");
		if (!invObj.checked) // check if inventory checked
		{
			// if not give an alert
			alert("Cost Management is only available as an addon to Inventory & Feed Management.\nPlease check Inventory & Feed Management to proceed.");
			costObj.checked = false;
		}
		else
			adjustOrderTotal("CostManagementPrice","add");
	}
	else // if unchecked
	{
		// subtract price from order total
		adjustOrderTotal("CostManagementPrice","minus");
	}
}

function taggedFishValidate(tagObj)
{
	// if checked
	if (tagObj.checked)
	{
		adjustOrderTotal("taggedFishTrackingPrice","add");
	}
	else // if unchecked
	{
		// subtract price from order total
		adjustOrderTotal("taggedFishTrackingPrice","minus");
	}
}

function adjustOrderTotal(field,operation)
{
	var totalObj = document.getElementById("orderTotalPrice");
	var fieldObj = document.getElementById(field);
	
	var totalValue = parseFloat(totalObj.innerText.toString());
	var fieldValue = parseFloat(fieldObj.innerText.toString());
	
	if (operation == 'add')
	{
		var newValue = totalValue + fieldValue;
		newValue = newValue.toFixed(2);
		totalObj.innerText = newValue.toString();
	}
	else
	{
		var newValue = totalValue - fieldValue;
		
		if (newValue != 0)
		{
			newValue = newValue.toFixed(2);
			totalObj.innerText = newValue.toString();
		}
		else
			totalObj.innerText = "0.00";
	}
}

function validateMonthly(termsObj)
{
	var InventoryFeedManagementPrice = document.getElementById("InventoryFeedManagementPrice");
	var CostManagementPrice = document.getElementById("CostManagementPrice");
	var taggedFishTrackingPrice = document.getElementById("taggedFishTrackingPrice");
	
	if (termsObj.value == "monthly" && termsObj.checked)
	{
		// this means that monthly was clicked and that monthly is checked
		// first make all prices be monthly
		InventoryFeedManagementPrice.innerText = "39.99";
		CostManagementPrice.innerText = "19.99";
		taggedFishTrackingPrice.innerText = "19.99";
	}
	else if (termsObj.value == "annually" && termsObj.checked)
	{
		// this mean that annually was clicked and that annually is checked
		// make all prices annually
		InventoryFeedManagementPrice.innerText = "399.99";
		CostManagementPrice.innerText = "199.99";
		taggedFishTrackingPrice.innerText = "199.99";
	}
	
	// now make order total 0.00
	var totalObj = document.getElementById("orderTotalPrice");
	totalObj.innerText = "0.00";
	
	// now go thru each check box, if it's check, add to the total
	var InventoryAndFeed = document.getElementById("InventoryAndFeed");
	var Cost = document.getElementById("Cost");
	var TaggedFish = document.getElementById("TaggedFish");
	
	if (InventoryAndFeed.checked)
		adjustOrderTotal("InventoryFeedManagementPrice","add");
		
	if (Cost.checked)
		adjustOrderTotal("CostManagementPrice","add");
		
	if (TaggedFish.checked)
		adjustOrderTotal("taggedFishTrackingPrice","add");
	
}

function validateAccountSignup()
{
	var businessname 		= document.getElementById("businessname");
	var firstname 			= document.getElementById("firstname");
	var lastname 			= document.getElementById("lastname");
	var addressline1 		= document.getElementById("addressline1");
	var city 				= document.getElementById("city");
	var state 				= document.getElementById("state");
	var zip 				= document.getElementById("zip");
	var country 			= document.getElementById("country");
	var phone 				= document.getElementById("phone");
	var emailaddress 		= document.getElementById("emailaddress");
	var pword 				= document.getElementById("pword");
	var pword2 				= document.getElementById("pword2");
	var InventoryAndFeed	= document.getElementById("InventoryAndFeed");
	var Cost				= document.getElementById("Cost");
	var TaggedFish			= document.getElementById("TaggedFish");
	var termsMonthly		= document.getElementById("termsMonthly");
	var termsAnnually		= document.getElementById("termsAnnually");
	var aquaFarm			= document.getElementById("aquaFarm");
	
	
	if (businessname.value.toString() == "")
	{
		alert("Please enter your business name.  \nIf you are not a business, enter your own name.  Thank you!");
		return false;
	}
	
	if (firstname.value.toString() == "")
	{
		alert("Please enter your first name.  Thank you!");
		return false;
	}
	
	if (lastname.value.toString() == "")
	{
		alert("Please enter your last name.  Thank you!");
		return false;
	}
	
	if (addressline1.value.toString() == "")
	{
		alert("Please enter your address information.  Thank you!");
		return false;
	}
	
	if (city.value.toString() == "")
	{
		alert("Please enter your city.  Thank you!");
		return false;
	}
	
	if (state.value.toString() == "")
	{
		alert("Please enter your state.  If you country has no states, please enter N/A.  Thank you!");
		return false;
	}
	
	if (country.value.toString() == "")
	{
		alert("Please enter your country.  Thank you!");
		return false;
	}
	
	if (zip.value.toString() == "")
	{
		alert("Please enter your zip code.  Thank you!");
		return false;
	}
	
	if (phone.value.toString() == "")
	{
		alert("Please enter your phone number.  Thank you!");
		return false;
	}
	
	if (emailaddress.value.toString() == "")
	{
		alert("Please enter your email address.  Thank you!");
		return false;
	}
	
	if (aquaFarm.value.toString() == "1")
	{
		return true;
	}
	
	if (pword.value.toString() == "")
	{
		alert("Please enter your password.  Thank you!");
		return false;
	}
	
	if (pword2.value.toString() == "")
	{
		alert("Please re enter your password.  Thank you!");
		return false;
	}
	
	if (pword.value != pword2.value)
	{
		alert("Your passwords do not match.  Please re-enter.");
		pword.value = "";
		pword2.value = "";
		return false;
	}
	
	if (!InventoryAndFeed.checked && !Cost.checked && !TaggedFish.checked)
	{
		alert("Please select a service plan.  Thank you!");
		return false;
	}
	
	if (!termsMonthly.checked && !termsAnnually.checked)
	{
		alert("Please selet a billing cycle.  Thank you!");
		return false;
	}
	
	return true;	
}
