

function roundNumber(num, dec) {
	var result = Math.round( Math.round( num * Math.pow( 10, dec + 1 ) ) / Math.pow( 10, 1 ) ) / Math.pow(10,dec);
	return result;
}

function squareFootage(n,m)
{
var boxes=Math.ceil(n/m);

document.itemForm.vwquantity.value=boxes;

if((Math.ceil(n/m))>1)
{
$("#SquareFootDescription").html("<br/>You requested <b>"+n+"</b> Square Feet.<br/>You will need <b>At least "+(Math.ceil(n/m))+" boxes</b> which totals <b>"+(boxes*m).toFixed(2)+" square feet</b> at <b>"+m+" sqft / box.</b><br/>We recommend having at least <b>10% extra</b>.");
}
else{
$("#SquareFootDescription").html("<br/>You requested <b>"+n+"</b> Square Feet.<br/>You will need <b>At least "+(Math.ceil(n/m))+" box</b> which totals <b>"+(boxes*m).toFixed(2)+" square feet</b> at <b>"+m+" sqft / box.</b><br/>We recommend having at least <b>10% extra</b>.");
}

}

function numbersonly(e, decimal) {
var key;
var keychar;

if (window.event) {
   key = window.event.keyCode;
}
else if (e) {
   key = e.which;
}
else {
   return true;
}
keychar = String.fromCharCode(key);

if ((key==null) || (key==0) || (key==8) ||  (key==9) || (key==13) || (key==27) ) {
   return true;
}
else if ((("0123456789").indexOf(keychar) > -1)) {
   return true;
}
else if (decimal && (keychar == ".")) { 
  return true;
}

else
   alert("You may only enter numbers into the square foot, length, width and price fields");
   return false;
   
}


function reset(){
document.calculationStation.width.value="";
document.calculationStation.length.value="";
document.calculationStation.sqf.value="0";
document.calculationStation.total.value="$ 0.00";
document.calculationStation.totalQuantity.value="0";
}
function calculateStation(){

if(document.calculationStation.width.value.length==0)
{
alert ("Please Enter a Width");
return;
}
if(document.calculationStation.length.value.length==0)
{
alert ("Please Enter a Length");
return;
}

var sqFT=(document.calculationStation.width.value*document.calculationStation.length.value*document.calculationStation.over.value).toFixed(2);

document.calculationStation.sqf.value=sqFT;

//document.square.squarefeet.value=sqFT;

$("#sqfts").val="";
$("#sqfts").val=Math.ceil(sqFT);

//$("input[name='squarefeet']").val("");
//$("input[name='squarefeet']").val(Math.ceil(sqFT));


document.calculationStation.total.value="$"+(sqFT*document.calculationStation.pSQF.value).toFixed(2);

document.calculationStation.totalQuantity.value=Math.ceil(document.calculationStation.sqf.value/document.calculationStation.bSQF.value);
document.itemForm.vwquantity.value=Math.ceil(document.calculationStation.sqf.value/document.calculationStation.bSQF.value);


//alert(sqFT+" "+document.calculationStation.bSQF.value);

squareFootage(sqFT,document.calculationStation.bSQF.value);
}
