// JavaScript Document
function clearDefault(el) {
  if (el.defaultValue==el.value) el.value = ""
}
//SUBMIT FX
function submitForm(elem){
  while (elem.parentNode && elem.parentNode.tagName != "FORM"){
       elem = elem.parentNode;
  }
  var oForm = elem.parentNode;
  oForm.submit();
}
//CALCULATOR SCRIPTS
var numb = '0123456789';
var lwr = 'abcdefghijklmnopqrstuvwxyz';
var upr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
 
function isValid(parm,val) {
  if (parm == "") return false;
  for (i=0; i<parm.length; i++) {
    if (val.indexOf(parm.charAt(i),0) == -1) return false;
  }
  return true;
}
 
function isNum(parm) {return isValid(parm,numb);}

function calculate()
{
  var total = 0;
  var carsTotal = 0;
  var treesTotal = 0;
  var coalTotal = 0;
  
  if (document.ofrm.qtyA.value != ""){
     if (isNum(document.ofrm.qtyA.value)){
     	  total += (document.ofrm.qtyA.value * 692);
	}
   }  
  if (document.ofrm.qtyB.value != ""){
     if (isNum(document.ofrm.qtyB.value)){
     	  total += (document.ofrm.qtyB.value * 658);
	}
   }
  if (document.ofrm.qtyC.value != ""){
     if (isNum(document.ofrm.qtyC.value)){
     	  total += (document.ofrm.qtyC.value * 636);
	}
   }
  if (document.ofrm.qtyD.value != ""){
     if (isNum(document.ofrm.qtyD.value)){
     	  total += (document.ofrm.qtyD.value * 566);
	}
   } 
  if (document.ofrm.qtyE.value != ""){
     if (isNum(document.ofrm.qtyE.value)){
     	  total += (document.ofrm.qtyE.value * 622);
	}
   }
  
  treeTotal = Math.floor(eval(total*.160068462));
  coalTotal = Math.floor(eval(total*0.8));
  carsTotal = Math.floor(eval(total*.000211075));
  total = "$" + eval(total);


    if (document.getElementById){
        document.getElementById("savings").innerHTML = total;
        document.getElementById("coal").innerHTML = coalTotal;
        document.getElementById("trees").innerHTML = treeTotal;
        document.getElementById("cars").innerHTML = carsTotal;
    }else if (document.all){
        document.all("savings").innerHTML = total;
        document.all("coal").innerHTML = coalTotal;
        document.all("trees").innerHTML = treeTotal;
        document.all("cars").innerHTML = carsTotal;
    }else if (document.layers){
        document.layers("savings").innerHTML = total; 
        document.layers("coal").innerHTML = coalTotal;
        document.layers("trees").innerHTML = treeTotal;
        document.layers("cars").innerHTML = carsTotal;
     }
} 
//TIMELINE SCRIPTS
