
/* - jsformhandlers.js - */
function update_form()
{
 //alert('update_form')

var price;

var mylist=document.getElementById("numOfItems")
if (mylist.value<5 && mylist.value>=1)
    price_val = document.getElementById("1").value
else if (mylist.value<10 && mylist.value>=5)
    price_val = document.getElementById("2").value
else if (mylist.value<25 && mylist.value>=10)
    price_val = document.getElementById("3").value
else if (mylist.value<50 && mylist.value>=25)
    price_val = document.getElementById("4").value
else if (mylist.value<100 && mylist.value>=50)
    price_val = document.getElementById("5").value
else if (mylist.value>=100)
    price_val = document.getElementById("6").value

//alert(price_val)
price = parseFloat(price_val)

document.getElementById("label2").firstChild.nodeValue = price.formatMoney()
document.getElementById("einzelpreis").firstChild.nodeValue = price.formatMoney()

update_anzahl();

}

function update_anzahl()
{
// update_form();

//alert('onUpdate')

//update tag in order_stats
var mylist=document.getElementById("numOfItems")
document.getElementById("anzahl").firstChild.nodeValue = mylist.value

//zwischensumme update
var preis = document.getElementById("einzelpreis").firstChild.nodeValue
//alert('preis:'+preis)
var amount = parseFloat(mylist.value)*parseFloat(preis)
//document.getElementById("amount").value = amount.formatMoney() 
//alert('amount:'+amount)

if (document.getElementById ('amount').firstChild )
    document.getElementById ('amount').firstChild.nodeValue = amount.formatMoney();

var versand =  document.getElementById("versandkosten").firstChild.nodeValue
//alert('versand:'+versand)

var total = parseFloat(amount) + parseFloat(versand)
//var mwst = total - (total*100/119)
var mwst_prozent = 19.00
var mwst = total * (mwst_prozent/100)
total = total + mwst

document.getElementById("mwst").firstChild.nodeValue = mwst.formatMoney()

//alert('total:'+total)
if (document.getElementById ('total').firstChild )
    document.getElementById ('total').firstChild.nodeValue = total.formatMoney();


};

function UpdateDelivery(browser)
{
  //alert("function UpdateDelivery"); 
  var versandkosten = parseFloat(browser)
  if (document.getElementById ('versandkosten').firstChild )
    document.getElementById ('versandkosten').firstChild.nodeValue = versandkosten.formatMoney();
  
  onUpdateDelivery();
};

function onUpdateDelivery()
{
  //alert('onUpdateDelivery')
 
//hier das Element in der Statusanzeige referenzieren
var mylist=parseInt(document.getElementById("anzahl").firstChild.nodeValue)
var price_val = parseFloat(document.getElementById("einzelpreis").firstChild.nodeValue)

var amount = parseFloat(mylist) * parseFloat(price_val) 
//var amount = document.getElementById("amount").firstChild.nodeValue // Parse-Fehler wegen der Währungsformatierung mit formatMoney()
//alert(parseFloat(amount))

var versand = document.getElementById("versandkosten").firstChild.nodeValue
var total = parseFloat(amount) + parseFloat(versand)
//var mwst = total - (total*100/119)
var mwst_prozent = 19.00
var mwst = total * (mwst_prozent/100)
total = total + mwst

if (document.getElementById ('mwst').firstChild)
    document.getElementById ('mwst').firstChild.nodeValue = mwst.formatMoney();

if (document.getElementById ('total').firstChild)
    document.getElementById ('total').firstChild.nodeValue = total.formatMoney();
    
};




//+ Jonas Raoni Soares Silva
//@ http://jsfromhell.com/number/fmt-money [v1.0]

Number.prototype.formatMoney = function(c, d, t){
	var n = this, c = isNaN(c = Math.abs(c)) ? 2 : c, d = d == undefined ? "," : d, t = t == undefined ? "." : t,
	i = parseInt(n = (+n || 0).toFixed(c)) + "", j = (j = i.length) > 3 ? j % 3 : 0;
	return (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t)
	+ (c ? d + (n - i).toFixed(c).slice(2) : "");
};


function toggleLayer( whichLayer )
{
  var elem, vis;
  if( document.getElementById ) // this is the way the standards work
    elem = document.getElementById( whichLayer );
  else if( document.all ) // this is the way old msie versions work
      elem = document.all[whichLayer];
  else if( document.layers ) // this is the way nn4 works
    elem = document.layers[whichLayer];
  vis = elem.style;
  // if the style.display value is blank we try to figure it out here
  if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
    vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';
  vis.display = (vis.display==''||vis.display=='block')?'none':'block';
};

