function validate(){
	var d=document.f1;
	var valid;
	var submitOK="True";
	var chk=0;
	var dist=0;
	var dep=0;
	var cases=0;
	var ttl=0;
	var shipcharge=0;
	var botdep=0;

	
	if (d.qty1.value > 120 ) { alert("For orders of 10 cases or more, please contact Noble Ridge Vineyard & Winery directly.")}
	if (d.qty2.value > 120 ) { alert("For orders of 10 cases or more, please contact Noble Ridge Vineyard & Winery directly.")}
	if (d.qty3.value > 120 ) { alert("For orders of 10 cases or more, please contact Noble Ridge Vineyard & Winery directly.")}
	if (d.qty4.value > 120 ) { alert("For orders of 10 cases or more, please contact Noble Ridge Vineyard & Winery directly.")}
	if (d.qty5.value > 120 ) { alert("For orders of 10 cases or more, please contact Noble Ridge Vineyard & Winery directly.")}
	
	amt= new Array();
	amt[0]=parseInt(d.qty1.value,10);
	amt[1]=parseInt(d.qty2.value,10);
	amt[2]=parseInt(d.qty3.value,10);
	amt[3]=parseInt(d.qty4.value,10);
	amt[4]=parseInt(d.qty5.value,10);
	  

	chk=amt[0]+amt[1]+amt[2]+amt[3]+amt[4];
	

	if (chk > 0)  {
		
		if (chk > 120 ) { 
		alert("For orders of 10 cases or more, please contact Noble Ridge Vineyard & Winery directly.")
		return false;
		}

		if (chk > 0 && chk%12 != 0 ) {
		alert("Please order wine in cases of 12.")
		return false;
		}	
		
		if (submitOK == "True") {
		cases=chk/12; 
		botdep=cases*1.2;
//		grandtot=ttl+botdep+(del[dist]* cases);
		}
	}

	prc = new Array;
	prc[0]=27.90;  //Pinot Noir
	prc[1]=19.90;  //Meritage
	prc[2]=23.90;  //Chardonnay
	prc[3]=18.90;  //Pinot Gris
	prc[4]=17.90;  //Mingle

	
	if(d.fullname.value == '') 	{
		alert("Please provide your name.");
		d.fullname.focus();
		return false;
	} 
		if(d.street.value == '') 	{
		alert("Please provide your address.");
		d.street.focus();
		return false;
	} 
		if(d.city.value == '') 	{
		alert("Please provide the name of your city.");
		d.city.focus();
		return false;
	} 
		if(d.prov.value == '') 	{
		alert("Please provide the name of your province.");
		d.prov.focus();
		return false;
	} 
		if(d.pcode.value == '') 	{
		alert("Please provide your postal code.");
		d.pcode.focus();
		return false;
	} 
	

	
	if (submitOK=="False" ) {return false;	}
	if (submitOK=="True" ) {
	
		ttl=(amt[0]*prc[0])+(amt[1]*prc[1])+(amt[2]*prc[2])+(amt[3]*prc[3])+(amt[4]*prc[4]);
					
//		d.schg.value = round_decimals (del[dist]* cases, 2); // Shipping charges
		d.wchg.value = round_decimals (ttl,2); 		// total wine charges
		d.botdeposit.value = round_decimals (botdep,2);  //bottle deposit
//		d.grtot.value = round_decimals (grandtot,2);  //grand total
		return true;
	}	
	
}
	
function calc() {
	var d=document.f1;
	
	
	amt1= new Array();
	amt1[0]=parseInt(d.qty1.value,10);
	amt1[1]=parseInt(d.qty2.value,10);
	amt1[2]=parseInt(d.qty3.value,10);
	amt1[3]=parseInt(d.qty4.value,10);
	amt1[4]=parseInt(d.qty5.value,10);

	
	numbots=amt1[0]+amt1[1]+amt1[2]+amt1[3]+amt1[4];
	
	d.Quantity006.value=numbots/12; // number of cases for calculating bottle deposit

	d.Quantity001.value=amt1[0];  //Pinot Noir +GST+PST  
	d.Quantity002.value=amt1[1];  //Meritage +GST+PST  
	d.Quantity003.value=amt1[2];  //Chardonnay +GST+PST  
	d.Quantity004.value=amt1[3];  //Pinot Grigio +GST+PST  
	d.Quantity005.value=amt1[4];  //Mingle +GST+PST  	
	d.ShippingName.value = d.fullname.value;
	d.ShippingAddress.value = d.street.value;
	d.ShippingCity.value = d.city.value;
	d.ShippingProvince.value = d.prov.value;
	d.ShippingPostal.value = d.pcode.value;

	
	d.submit();
}

function round_decimals(original_number, decimals) {
    var result1 = original_number * Math.pow(10, decimals)
    var result2 = Math.round(result1)
    var result3 = result2 / Math.pow(10, decimals)
    return pad_with_zeros(result3, decimals)
}

function pad_with_zeros(rounded_value, decimal_places) {
    // Convert the number to a string
    var value_string = rounded_value.toString()
    // Locate the decimal point
    var decimal_location = value_string.indexOf(".")
    // Is there a decimal point?
    if (decimal_location == -1) {       
        // If no, then all decimal places will be padded with 0s
        decimal_part_length = 0      
        // If decimal_places is greater than zero, tack on a decimal point
        value_string += decimal_places > 0 ? "." : ""
    }
    else {
        // If yes, then only the extra decimal places will be padded with 0s
        decimal_part_length = value_string.length - decimal_location - 1
    }
    // Calculate the number of decimal places that need to be padded with 0s
    var pad_total = decimal_places - decimal_part_length   
    if (pad_total > 0) {       
        // Pad the string with 0s
        for (var counter = 1; counter <= pad_total; counter++) 
            value_string += "0"
        }
    return value_string
}

