window.onload=function(){
linkEmail();
externalLinks();
startCalc();
}

function externalLinks() {
	if (!document.getElementsByTagName) 
		return; 
	var anchors = document.getElementsByTagName("a"); 
	for (var i=0; i<anchors.length; i++) {
		var anchor = anchors[i]; 
		if (anchor.getAttribute("href") &&  anchor.getAttribute("rel") == "external") anchor.target = "_blank";
		if (anchor.getAttribute("href") &&  anchor.getAttribute("rel") == "external") anchor.rel = "nofollow";
	}
}

function linkEmail() {
  if(!document.getElementsByTagName) return;
  var allElts = document.getElementsByTagName("*");
  if(allElts.length == 0 && document.all) 
    allElts = document.all; //hack for IE5
  for(var i=0; i<allElts.length; i++) {
    var elt = allElts[i];
    var className = elt.className || elt.getAttribute("class") 
      || elt.getAttribute("className");
    if(className && className.match(/\bemail\b/)
        && elt.firstChild.nodeType == 3) {
      var addr = elt.firstChild.nodeValue;
      addr = addr.replace(/[ \[\{\(\|\/\\]at[ \]\}\)\|\/\\]/i, "@")
        .replace(/[ \[\{\(\|\/\\](dot|period)[ \]\}\)\|\/\\]/gi, ".");
      var lnk = document.createElement("a");
      lnk.setAttribute("href","mailto:"+addr);
      lnk.appendChild(document.createTextNode(addr));
      elt.replaceChild(lnk, elt.firstChild);
    }
  }
}

function toggle( targetId ){
if (document.getElementById){
  		target = document.getElementById( targetId );
  			if (target.style.display == "none"){
  				target.style.display = "";
  			} else {
  				target.style.display = "none";
  			}
  	}
}

function cent(amount) {
    amount -= 0;
    return (amount == Math.floor(amount)) ? amount + '.00' : (  (amount*10 == Math.floor(amount*10)) ? amount + '0' : amount);
}
function startCalc(){
  interval = setInterval("calc()",1);
}
function calc(){
  var priceone
  var pricetwo
  var pricethree
  var pricefour
  var pricefive
  var shipone
  var shiptwo
  var shipthree
  var shipfour
  var shipfive
  
  priceone = (document.orderform.quantity1.value * 17);
  pricetwo = (document.orderform.quantity2.value * 11);
  pricethree = (document.orderform.quantity3.value * 4);
  pricefour = (document.orderform.quantity4.value * 3);
  pricefive = (document.orderform.quantity5.value * 1.5);
  
  shipone = (document.orderform.quantity1.value * 1);
  shiptwo = (document.orderform.quantity2.value * 0.5);
  shipthree = (document.orderform.quantity3.value * 0.1);
  shipfour = (document.orderform.quantity4.value * 0.07);
  shipfive = (document.orderform.quantity5.value * 0.03);
  
   if ((shipone * 1)+(shiptwo * 1)+(shipthree * 1)+(shipfour * 1)+(shipfive * 1) == ""){
  	document.orderform.ship.value = cent(0);
  }
  
  else if ((shipone * 1)+(shiptwo * 1)+(shipthree * 1)+(shipfour * 1)+(shipfive * 1) <= "0.4"){
  	document.orderform.ship.value = cent(2);
  }
  
  else if ((shipone * 1)+(shiptwo * 1)+(shipthree * 1)+(shipfour * 1)+(shipfive * 1) <= "0.9"){
  	document.orderform.ship.value = cent(5);
  }

  else if ((shipone * 1)+(shiptwo * 1)+(shipthree * 1)+(shipfour * 1)+(shipfive * 1) <= "1"){
  	document.orderform.ship.value = cent(15);
  }
  else if ((shipone * 1)+(shiptwo * 1)+(shipthree * 1)+(shipfour * 1)+(shipfive * 1) <= "2"){
  	document.orderform.ship.value = cent(20);
  }
  else if ((shipone * 1)+(shiptwo * 1)+(shipthree * 1)+(shipfour * 1)+(shipfive * 1) <= "3"){
  	document.orderform.ship.value = cent(25);
  }
  else if ((shipone * 1)+(shiptwo * 1)+(shipthree * 1)+(shipfour * 1)+(shipfive * 1) <= "4"){
  	document.orderform.ship.value = cent(30);
  }
  else if ((shipone * 1)+(shiptwo * 1)+(shipthree * 1)+(shipfour * 1)+(shipfive * 1) <= "5"){
  	document.orderform.ship.value = cent(35);
  }
  else if ((shipone * 1)+(shiptwo * 1)+(shipthree * 1)+(shipfour * 1)+(shipfive * 1) <= "6"){
  	document.orderform.ship.value = cent(40);
  }
  else if ((shipone * 1)+(shiptwo * 1)+(shipthree * 1)+(shipfour * 1)+(shipfive * 1) <= "7"){
  	document.orderform.ship.value = cent(45);
  }
  else if ((shipone * 1)+(shiptwo * 1)+(shipthree * 1)+(shipfour * 1)+(shipfive * 1) <= "8"){
  	document.orderform.ship.value = cent(50);
  }
  else if ((shipone * 1)+(shiptwo * 1)+(shipthree * 1)+(shipfour * 1)+(shipfive * 1) <= "9"){
  	document.orderform.ship.value = cent(55);
  }
  
  document.orderform.subtotal.value = cent((priceone * 1)+(pricetwo * 1)+(pricethree * 1)+(pricefour * 1)+(pricefive * 1));
  document.orderform.total.value = cent((document.orderform.ship.value * 1) + (document.orderform.subtotal.value * 1));
}
function stopCalc(){
  clearInterval(interval);
}

