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);
	amt[5]=parseInt(d.qty7.value,10);
	amt[6]=parseInt(d.qty8.value,10);
	amt[7]=parseInt(d.qty9.value,10);
	amt[8]=parseInt(d.qty10.value,10);
	amt[9]=parseInt(d.qty11.value,10);
	amt[10]=parseInt(d.qty12.value,10);
	amt[11]=parseInt(d.qty13.value,10);
	amt[12]=parseInt(d.qty14.value,10);
	amt[13]=parseInt(d.qty15.value,10);
	amt[14]=parseInt(d.qty16.value,10);
	amt[15]=parseInt(d.qty17.value,10);

	  

	chk=amt[0]+amt[1]+amt[2]+amt[3]+amt[4];
	
	giftchk=amt[5]+amt[6]+amt[7]+amt[8]+amt[9]+amt[10]+amt[11]+amt[12]+amt[13]+amt[14]+amt[15];
	

	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]=25.99;  //Pinot Noir
	prc[1]=29.99;  //Meritage
	prc[2]=20.99;  //Chardonnay
	prc[3]=18.99;  //Pinot Gris
	prc[4]=65.00;  //King's Ransom 
	prc[5]=34.99;  //BottleBag - Grigio 
	prc[6]=49.99;  //BottleBag - Noir
	prc[7]=49.99;  //BottleBag - Meritage
	prc[8]=59.99;  //Sip - Grigio
	prc[9]=74.99;  //Sip - Noir
	prc[10]=74.99; //Sip - Meritage
	prc[11]=149.99;   //Vertical - Noir 
	prc[12]=199.99;   //Vertical - Meritage 
	prc[13]=174.99;   //Gourmet - Grigio
	prc[14]=209.99;  //Gourmet - Noir
	prc[15]=209.99;  //Gourmet - Meritage
	
	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])+(amt[5]*prc[5])+(amt[6]*prc[6])+(amt[7]*prc[7])+(amt[8]*prc[8])+(amt[9]*prc[9])+(amt[10]*prc[10])+(amt[11]*prc[11])+(amt[12]*prc[12])+(amt[13]*prc[13])+(amt[14]*prc[14])+(amt[15]*prc[15]);
			
//		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=d.qty1.value;  //Pinot Noir +GST+PST  
	d.Quantity002.value=d.qty2.value;  //Meritage +GST+PST  
	d.Quantity003.value=d.qty3.value;  //Chardonnay +GST+PST  
	d.Quantity004.value=d.qty4.value;  //Pinot Grigio +GST+PST  
	d.Quantity005.value=d.qty5.value;  //King's Ransom +GST+PST  
	
	d.Quantity007.value=d.qty7.value;  //BottleBag - Grigio
	d.Quantity008.value=d.qty8.value;  //BottleBag - Noir  
	d.Quantity009.value=d.qty9.value;  ;  //BottleBag - Meritage  
	d.Quantity010.value=d.qty10.value;  //Sip - Grigio
	d.Quantity011.value=d.qty11.value;  //Sip - Noir
	d.Quantity012.value=d.qty12.value; //Sip - Meritge
	d.Quantity013.value=d.qty13.value; //Vertical - Noir  
	d.Quantity014.value=d.qty14.value;  //Vertical - Meritage  
	d.Quantity015.value=d.qty15.value;  //Gourmet - Grigio  
	d.Quantity016.value=d.qty16.value;  //Gourmet - Noir  
	d.Quantity017.value=d.qty17.value;  //Gourmet - Meritage  
	
	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.GiftPackageTo.value = d.to.value;
	d.GiftPackageMessage.value = d.message.value;
	d.GiftPackageFrom.value = d.from.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
}
