// JavaScript Document

function startCalc(){
  interval = setInterval("calc()",1);
  
  
}

function r2(n) { 

  ans = n * 1000 
  ans = Math.round(ans /10) + "" 
  while (ans.length < 3) {ans = "0" + ans} 
  len = ans.length 
  ans = ans.substring(0,len-2) + "." + ans.substring(len-2,len)
  return ans 
} 
function calc(){
  fc = document.periodicTableForm.firstCopy.value;
  fcadd = document.periodicTableForm.firstCopyAdd.value; 
  fcTA = document.periodicTableForm.firstCopyTA.value; 
  fcTAadd = document.periodicTableForm.firstCopyTAAdd.value; 
  fcTAposter = document.periodicTableForm.firstCopyTAposter.value; 
  fcTAposteradd = document.periodicTableForm.firstCopyTAposterAdd.value; 
  fc3D = document.periodicTableForm.firstCopy3D.value; 
  fc3Dadd = document.periodicTableForm.firstCopy3DAdd.value; 
  fcCV = document.periodicTableForm.firstCopyCV.value; 
  fcCVadd = document.periodicTableForm.firstCopyCVAdd.value; 
  //totals
  document.periodicTableForm.firstCopyTotal.value = r2(fc * 2); 
  document.periodicTableForm.firstCopyAddTotal.value = r2(fcadd * 1) ;
  
  document.periodicTableForm.firstCopyTATotal.value = r2(fcTA * 2) ;
  document.periodicTableForm.firstCopyTAAddTotal.value = r2(fcTAadd * 1) ;
  
  document.periodicTableForm.firstCopyTAposterTotal.value = r2(fcTAposter * 15) ;
  document.periodicTableForm.firstCopyTAposterAddTotal.value = r2(fcTAposteradd * 10) ;
  
  document.periodicTableForm.firstCopy3DTotal.value = r2(fc3D * 2) ;
  document.periodicTableForm.firstCopy3DAddTotal.value = r2(fc3Dadd * 0.75) ;
  
  document.periodicTableForm.firstCopyCVTotal.value = r2(fcCV * 15) ;
  document.periodicTableForm.firstCopyCVAddTotal.value = r2(fcCVadd * 10) ;
  
  document.periodicTableForm.qtyTotal.value = (fc*1+fcadd*1+fcTA*1+ fcTAadd*1+fcTAposter*1+fcTAposteradd*1+fc3D*1+ 
  fc3Dadd*1+fcCV*1+fcCVadd*1);
  
  document.periodicTableForm.amountTotal.value = r2(fc*2+fcadd*1+fcTA*2+ fcTAadd*1+fcTAposter*15+fcTAposteradd*10+fc3D*2+ 
  fc3Dadd*0.75+fcCV*15+fcCVadd*10);
  
  
  
}
function stopCalc(){
  clearInterval(interval);
}


function validate_form() {
	
	 var valid = true;
	 
	 	if (document.periodicTableForm.Name.value == "" ) {
			alert ( "Please fill in 'Your Name'." );
			valid = false;
			}
		if (document.periodicTableForm.Email.value == "") {
			alert ( "Please fill in 'Your Email'." );
			valid = false;
			}
		if (document.periodicTableForm.Phone.value == "") {
			alert ( "Please fill in 'Your Phone'." );
			valid = false;
			}
		if (document.periodicTableForm.Affiliation.value == "") {
			alert ( "Please fill in 'Your Affiliation'." );
			valid = false;
			}
		if (document.periodicTableForm.Address.value == "") {
			alert ( "Please fill in 'Your Address'." );
			valid = false;
			}
		if (document.periodicTableForm.City.value == "") {
			alert ( "Please fill in 'Your City'." );
			valid = false;
			}
		if (document.periodicTableForm.State.value == "") {
			alert ( "Please fill in 'Your State'." );
			valid = false;
			}
		if (document.periodicTableForm.PostCode.value == "") {
			alert ( "Please fill in 'Your Zip'." );
			valid = false;
			}
	 
	 return valid;
}
