function calculateTotal(){
	var lvdblCasePrice = 120;
	var lvdblHalfCasePrice = 70;
	var lvdblTotalCost = 0;
	var lvstrItemsPurchased = "";
	with (document.main){
		//lvdblTotalCost += qty_2007chardonnay12.options[qty_2007chardonnay12.selectedIndex].value * lvdblCasePrice
		//lvdblTotalCost += qty_2007chardonnay6.options[qty_2007chardonnay6.selectedIndex].value * lvdblHalfCasePrice
		//lvdblTotalCost += qty_2007Dolcetto12.options[qty_2007Dolcetto12.selectedIndex].value * lvdblCasePrice
		//lvdblTotalCost += qty_2007Dolcetto6.options[qty_2007Dolcetto6.selectedIndex].value * lvdblHalfCasePrice
lvdblTotalCost += qty_2009Pinotage12.options[qty_2009Pinotage12.selectedIndex].value * lvdblCasePrice
lvdblTotalCost += qty_2009Pinotage6.options[qty_2009Pinotage6.selectedIndex].value * lvdblHalfCasePrice
		lvdblTotalCost += qty_2009UnwoodedChardonnay12.options[qty_2009UnwoodedChardonnay12.selectedIndex].value * lvdblCasePrice
		lvdblTotalCost += qty_2009UnwoodedChardonnay6.options[qty_2009UnwoodedChardonnay6.selectedIndex].value * lvdblHalfCasePrice
		lvdblTotalCost += qty_2009Rose12.options[qty_2009Rose12.selectedIndex].value * lvdblCasePrice
		lvdblTotalCost += qty_2009Rose6.options[qty_2009Rose6.selectedIndex].value * lvdblHalfCasePrice
		lvdblTotalCost += qty_2008Dolcetto12.options[qty_2008Dolcetto12.selectedIndex].value * lvdblCasePrice
		lvdblTotalCost += qty_2008Dolcetto6.options[qty_2008Dolcetto6.selectedIndex].value * lvdblHalfCasePrice

		lvdblTotalCost += qty_2009BarrelFermentedChardonnay12.options[qty_2009BarrelFermentedChardonnay12.selectedIndex].value * lvdblCasePrice
		lvdblTotalCost += qty_2009BarrelFermentedChardonnay6.options[qty_2009BarrelFermentedChardonnay6.selectedIndex].value * lvdblHalfCasePrice
		//lvdblTotalCost += qty_2006Dolcetto12.options[qty_2006Dolcetto12.selectedIndex].value * lvdblCasePrice
		//lvdblTotalCost += qty_2006Dolcetto6.options[qty_2006Dolcetto6.selectedIndex].value * lvdblHalfCasePrice
		lvdblTotalCost += qty_mixedcase12.options[qty_mixedcase12.selectedIndex].value * lvdblCasePrice
		
		if(lvdblTotalCost > 0){ //Add freight if qty greater than 1 (ie. total > 0)
			if (delivery[0].checked){
				lvdblTotalCost += 6
			}
			if (delivery[1].checked){
				lvdblTotalCost += 6
			}
			if (delivery[2].checked){
				lvdblTotalCost += 12
			}
			if (delivery[3].checked){
				lvdblTotalCost += 20
			}
			if (rural_delivery.checked){
				lvdblTotalCost+=8
			}
		}
		//alert(lvdblTotalCost);		
	}	
	displayTotalCost(lvdblTotalCost);
}

function displayTotalCost(paramTotalCost){
	
	document.getElementById("orderTotal").innerHTML = "" + toDollarsAndCents(paramTotalCost).toString();
	document.main.scAmount.value = toDollarsAndCents(paramTotalCost).toString();
	//alert("Total cost: $" + document.main.totalAmount.value);
}

function validateOrder(){
	var problem = 0;
	var message = "";
	with (document.main){
		if (name.value.length == 0) {
			problem++;
			message=message + "\nName is required.";
		}
		if (address.value.length == 0) {
			problem++;
			message=message + "\nAddress is required.";
		}
		if (!verifyEmail(email.value)) {
			problem++;
			message=message + "\nYour valid email address is required.";
		}
		if (scAmount.value == "0.00"){
			problem++;
			message=message + "\nSelect at least one wine option to proceed.";
		}
	}	
	
	if (problem > 0){
		alert(message);
		return false;
	}
	else {
		return true;
	}
}

function containsInvalidChars(paramInput){
	if (paramInput.indexOf(".")>-1 || paramInput.indexOf("\/")>-1) {
		return true;
	}
	else {
		return false;
	}
}

function verifyEmail(addr) { 
    var atPos = addr.indexOf('@'); 
    var dotPos = addr.lastIndexOf('.') 
    if (atPos>0 && dotPos>atPos+1) return true; 
    else
    	return false;
}

function toDollarsAndCents(n) {
  var s = "" + Math.round(n * 100) / 100
  var i = s.indexOf('.')
  if (i < 0) return s + ".00"
  var t = s.substring(0, i + 1) + s.substring(i + 1, i + 3)
  if (i + 2 == s.length) t += "0"
  return t
}

function futureDate(){
	var aMonth = new Array("January","February","March","April","May","June","July","August","September","October","November","December");
	var selectedMonth;
	for (i=0;i<12;i++){
		if (aMonth[i] == document.Main.Month07.options[document.Main.Month07.options.selectedIndex].value){
			selectedMonth = i + 1;
		}
	}		
	var lvSelectedDate = selectedMonth + "/" + document.Main.Date06.options[document.Main.Date06.options.selectedIndex].value+ "/" + document.Main.Year08.options[document.Main.Year08.options.selectedIndex].value;
	var lvConvertedDate = new Date(lvSelectedDate);
	var now = new Date();
	var myDate = now.getDate()+"/"+(now.getMonth()+1)+"/"+now.getYear();
	var lvintDateDiff = lvConvertedDate - now
	if (lvintDateDiff<0){
		return false;
	}
	else{
		return true;
	}
}
