// JavaScript Document

/* This script and many more are available free online at
The JavaScript Source!! http://javascript.internet.com
Created by: Jim Stiles | www.jdstiles.com */
function startCalc(){
  interval = setInterval("calc()",1);
}
function calc(){
  one = document.pay1.itemprice.value;
  two = document.pay1.shippingcost.value; 
  three = document.pay1.videoprice.value;
  four = document.pay1.customprice.value;
  five = document.pay1.dreamprice.value;
  total = (one * 1) + (two * 1) + (three * 1) + (four * 1) + (five * 1); /* This calculates total items correctly */
  
  t = CurrencyFormatted(total * 0.0825);
  tax = (total * 0.0825); 
  grand = CurrencyFormatted(total + tax);
  
  f = CurrencyFormatted(grand * 0.015);  
  fee = (grand * 0.015);
  gt = CurrencyFormatted((fee)+(grand * 1));
  
  document.pay1.total.value = total + ".00";
  document.pay1.tax.value = t;
  document.pay1.fee.value = f;  
  document.pay1.grand.value = gt;

}
function stopCalc(){
  clearInterval(interval);
}

function CurrencyFormatted(amount)
{
	var i = parseFloat(amount);
	if(isNaN(i)) { i = 0.00; }
	var minus = '';
	if(i < 0) { minus = '-'; }
	i = Math.abs(i);
	i = parseInt((i + .005) * 100);
	i = i / 100;
	s = new String(i);
	if(s.indexOf('.') < 0) { s += '.00'; }
	if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
	s = minus + s;
	return s;
}

var global_tooshort='';

function fieldlength(obj) {
  if (global_tooshort) {
   global_tooshort.focus();
   global_tooshort='';
   return;
  }
  if (obj && obj.value.length && obj.value.length > 200){
    alert("Max 200 Characters Allowed. Please re-enter your comments");
    obj.value="";
    global_tooshort=obj;
  }
}

function clearDefault(el) {
  if (el.defaultValue==el.value) el.value = ""
}