<!--Sod Calculator -->

/******* Sod Guy Editable Pricing Items *********/

var kyBlueGrassPrice = 0.29;

var fescuePrice = 0.15;

var cTaxRate = .039;

var sodInstallPrice = .17;

var sodAmendPrice = .30;

var sodTearOutPrice = 1.00;

/****** WARNING ******** DO NOT EDIT ANYTHING BELOW HERE */



/******* Other Variables ******/
/*  DO NOT EDIT ANYTHING BELOW HERE */

var sodPrice = 0;

var isNN = 1;

var totalFtSq = 0;

var pCharge = 0;

var sCharge = 0;

var cTax = 0;

var deliveryCharge = 0;

var sodInstallCharge = 0;

var sodAmendCharge = 0;

var sodTearOutCharge = 0;



function fmt(val){

  if(val+""=="NaN")

    return "0";

  else

    return Math.round(val*100)/100;

}


function calcPriceFromTotal(){

	with(document.calcForm){

		areaSqV = totalArea.value

		if(!checkStr(areaSqV, "0123456789."))	areaSqV = 0
		
		/*if(sodType[0].checked) { */
			sodPrice = kyBlueGrassPrice;
		/*} else {
			sodPrice = fescuePrice;
		} */		  

		totalArea2.value = fmt(areaSqV);
		
		totalFtSq = fmt(areaSqV);

		sodQC = Math.ceil(fmt(areaSqV/10));

		Quantity.value = sodQC;
		
		sCharge = sodQC*sodPrice*10;
		
		sodCharge.value = dollarize(sCharge);	
		
		pallets.value = Math.ceil(fmt(Quantity.value/64));
		
		pCharge = pallets.value*10;
		
		palletCharge.value = dollarize(pCharge);
		
		cTax = (sCharge) * cTaxRate;
		
		coTax.value = dollarize(cTax);
		
		deliveryCharge = fmt(delivery.value);
		
		checkdelivery.value = dollarize(delivery.value);
		
		if( installation.checked) {		
			sodInstallCharge = Math.ceil(fmt(areaSqV/10))* 10 * sodInstallPrice;
			installCharge.value = dollarize(sodInstallCharge);
			palletCharge.value = dollarize(0);
			pCharge = 0;
			checkdelivery.value = dollarize(150);
			deliveryCharge = 150;
		} else {
			sodInstallCharge = 0;
			installCharge.value = dollarize(sodInstallCharge);	
		}
		
		if( soil_amend.checked) {		
			sodAmendCharge = Math.ceil(fmt(areaSqV/10))* 10 * sodAmendPrice;
			amendCharge.value = dollarize(sodAmendCharge);		
		} else {
			sodAmendCharge = 0;
			amendCharge.value = dollarize(sodAmendCharge);	
		}

		if( tear_out.checked) {		
			sodTearOutCharge = Math.ceil(fmt(areaSqV/10))* 10 * sodTearOutPrice;
			tearOutCharge.value = dollarize(sodTearOutCharge);		
		} else {
			sodTearOutCharge = 0;
			tearOutCharge.value = dollarize(sodTearOutCharge);	
		}




		cost.value = dollarize(sCharge + pCharge + cTax + deliveryCharge + sodInstallCharge + sodAmendCharge + sodTearOutCharge);

	}

}



function checkStr(test, goodvals){

	test = test.toString();

	goodvals = goodvals.toString();

	breaker = false;

	for(counter=0; counter < test.length && breaker == false; counter++){

		if(goodvals.indexOf(test.charAt(counter)) == -1){

			breaker = true;

		}

	}

	return (!breaker);

}


function dollarizeORIGINAL(q){
var tot=q.toString().replace(/^\$|,/g, ''), count=0
if (!/^\d*\.?\d+$/.test(tot)){
alert('Valid Numbers or Valid Dollar Values only Please')
return q;
}
tot=tot.indexOf('.')==-1? tot+='.0' : tot.length-tot.indexOf('.')==1? tot+='0' : tot
tot=tot.split('.')
tot[1]=Math.round(Math.abs('.'+tot[1])*100).toString()
if(tot[1].length>2){
tot[0]=tot[0]==''? '1' : (parseInt(tot[0], 10)+1).toString()
tot[1]=tot[1].charAt(1).toString()+tot[1].charAt(2)
}
tot[2]=''
tot[0]=tot[0]==''? '0' : parseInt(tot[0], 10).toString()
for (var i_tem = tot[0].length-1 ; i_tem > -1 ; i_tem--){
if (count&&count%3==0)
tot[2]+=','
tot[2]+=tot[0].charAt(i_tem)
count++
}
tot='$'+tot[2].split('').reverse().join('')+'.'+tot[1]
tot=tot.length-tot.indexOf('.')==2? tot+='0' : tot
return tot;
}



function dollarizeCURRENT(q){
var tot=q.toString().replace(/^\$|,/g, ''), count=0
if (!/^\d*\.?\d+$/.test(tot)){
alert('Valid Numbers or Valid Dollar Values only Please')
return q;
}

tot=Math.round(tot*100)/100
alert(tot)
tot=tot.toString()
alert(tot)
tot='$'+tot
alert(tot)
return tot;
}


function dollarize(n)
{
 pennies = n * 100;

 pennies = Math.round(pennies);

 strPennies = "" + pennies;
 len = strPennies.length;

 return '$' + strPennies.substring(0, len - 2) + "." + strPennies.substring(len - 2, len);
}

/*autocheck install */
function checkInstall(){

	with(document.calcForm){


/*		totalArea2.value = fmt(areaSqV);
		
		totalFtSq = fmt(areaSqV);

		sodQC = Math.ceil(fmt(areaSqV/10));

		Quantity.value = sodQC;
		
		sCharge = sodQC*sodPrice*10;
		
		pallets.value = Math.ceil(fmt(Quantity.value/64));
		
		pCharge = pallets.value*10;
		
		palletCharge.value = dollarize(pCharge);
		
		cTax = (sCharge) * cTaxRate;
		
		coTax.value = dollarize(cTax);
		
		deliveryCharge = fmt(delivery.value);
		
		checkdelivery.value = dollarize(delivery.value); */
		
/*		if( installation.checked) {		
			sodInstallCharge = Math.ceil(fmt(areaSqV/10))* 10 * sodInstallPrice;
			installCharge.value = dollarize(sodInstallCharge);
			palletCharge.value = dollarize(0);
			pCharge = 0;
			checkdelivery.value = dollarize(150);
			deliveryCharge = 150;
		} else {
			sodInstallCharge = 0;
			installCharge.value = dollarize(sodInstallCharge);	
		}*/
		
		if( soil_amend.checked) {	
			installation.checked=true;
			installation.disabled=true;
			
		
		
/*			sodAmendCharge = Math.ceil(fmt(areaSqV/10))* 10 * sodAmendPrice;
			amendCharge.value = dollarize(sodAmendCharge);	*/
			
			
			
		} else {
			installation.disabled=false;
		}





/*		cost.value = dollarize(sCharge + pCharge + cTax + deliveryCharge + sodInstallCharge + sodAmendCharge + sodTearOutCharge); */

	}

}

