/* 
   JavaScript Document - JS
   A4M - 04.03.2010
   Malte Beckers
   Javascript Functions
*/


/* Main Navigation Layer Functions */
function showMenu(li) {
	var childNodes = li.childNodes;
	for(var i in childNodes) {
		if(childNodes[i].nodeName == "A") {
			if(childNodes[i].className != "act"){
			    childNodes[i].className = "cur";
		    }
		}
		else if(childNodes[i].nodeName == "UL") {
			childNodes[i].style.display = "block";
		}
	}
}

function hideMenu(li) {
	var childNodes = li.childNodes;
	for(var i in childNodes) {
		if(childNodes[i].nodeName == "A") {
		if(childNodes[i].className != "act"){
			    childNodes[i].className = "";
		    }
		}
		else if(childNodes[i].nodeName == "UL") {
			childNodes[i].style.display = "none";
		}
	}
}


/* Onload */
onload = function(){
	/* Set Radiobutton to checked (Art.-Nr. on Product Detail Pages) */
	if(document.orderform){
		if(document.orderform.product_artnr) {document.orderform.product_artnr.checked = true;}
		if (document.orderform.product_artnr[0]) {document.orderform.product_artnr[0].checked = true;}
	}
	/* Start Change Price */
	if(document.getElementById('product_artnr')){changePrice();}
}

function changePrice() {
	if(document.getElementById('product_artnr').value == "") {window.location.href = "http://www.attractive4mini.com/showroom.html";}
	
	var singlePrice = document.getElementById('singlePrice').value; /* Price */
	var units = document.getElementById('article').value;  /* Units/Charge */
	document.getElementById('totalArticle').innerHTML = (units*singlePrice).toFixed(2);
	
	/* Weight */
	var totalWeight = parseFloat(document.getElementById('product_totalweight').value);
	document.getElementById('sumWeight').innerHTML = totalWeight*units + " Gramm";
	
	/*Shipping */
	var shippingPrice = 0;
	if(document.getElementById('Expressversand').checked == false && 
	   document.getElementById('Expressversand_12').checked == false && 
	   document.getElementById('Expressversand_10').checked == false && 
	   document.getElementById('Expressversand_9').checked == false) { /* "Standardversand" */
		/*
		if(units*totalWeight <= 2000) {shippingPrice = 4.90;}
		else if(units*totalWeight <= 10000) {shippingPrice = 6.90;}
		else if(units*totalWeight <= 20000) {shippingPrice = 11.90;}
		else if(units*totalWeight <= 31500) {shippingPrice = 13.90;}
		*/
		if(units*totalWeight <= 1000) {shippingPrice = 2.50;}                 /* Briefe pauschal 2,50 EUR */
		else if(units*totalWeight > 1000 && units*totalWeight <= 31500) {shippingPrice = 9.90;} /* Pakete pauschal 9,90 EUR */
		else { 
		    document.getElementById('shippingNote').style.display = "block";
			document.getElementById('shippingNoteExpress').style.display = "none";
		}
		/* Hide Suboptions Expressversand */
		document.getElementById('suboption1').style.display = "none";
		document.getElementById('suboption2').style.display = "none";
		document.getElementById('suboption3').style.display = "none";

	} else {/* "Expressversand" */
		if(units*totalWeight <= 2000) {var shippingPrice = 12.90;}
		else if(units*totalWeight <= 10000) {shippingPrice = 19.90;}
		else if(units*totalWeight <= 20000) {shippingPrice = 23.90;}
		else if(units*totalWeight <= 31500) {shippingPrice = 34.90;}
		else {
		    document.getElementById('shippingNoteExpress').style.display = "block";
			document.getElementById('shippingNote').style.display = "none";
		}
		/* Suboptions Expressversand */
		if(document.getElementById('Expressversand_12').checked == true){shippingPrice += 4.90;}
		if(document.getElementById('Expressversand_10').checked == true){shippingPrice += 12.90;}
		if(document.getElementById('Expressversand_9').checked == true){shippingPrice += 24.90;}
		document.getElementById('suboption1').style.display = "block";
		document.getElementById('suboption2').style.display = "block";
		document.getElementById('suboption3').style.display = "block";
	}
	if(units*totalWeight >= 31501){ /* Warning to email */
		document.getElementById('product_warning').value = "Versandhinweis:\nDie Bestellung ueberschreitet das zulaessige Gewicht des Paketversands!\nNach erfolgreicher Bestellung werden wir uns mit Ihnen in Verbindung setzen,\num die fuer Sie beste Versandart zu waehlen.";
	} else {document.getElementById('product_warning').value = "";}
	
	/* Option "Nachnahme" */
	if(document.getElementById('Nachnahme').checked == true) {shippingPrice += 7.00;} 
	
	/* Show Shipping Price */
	document.getElementById('totalShipping').innerHTML = shippingPrice.toFixed(2);
	/* Shipping to large */
	if(document.getElementById('shippingNote').style.display == "block" || document.getElementById('shippingNoteExpress').style.display == "block"){
		document.getElementById('totalShipping').innerHTML = 0;
	}
	
	totalPrice(shippingPrice);
}
function totalPrice(tS) {
	if(document.getElementById('totalPrice')){
		sP = Number(document.getElementById('singlePrice').value);
		tP = Number(document.getElementById('totalArticle').innerHTML) + Number(document.getElementById('totalShipping').innerHTML);
		document.getElementById('shippingPrice').value = tS.toFixed(2);
		document.getElementById('totalPrice').innerHTML = tP.toFixed(2);
		document.getElementById('totalprice').value = tP.toFixed(2);
		document.getElementById('totalShipping').innerHTML += " &euro";
		document.getElementById('shippingPrice').value = tS.toFixed(2) + " EUR";
		/* Shipping to large */
		if(document.getElementById('shippingNote').style.display == "block" || document.getElementById('shippingNoteExpress').style.display == "block"){
			document.getElementById('totalShipping').innerHTML = "Paketgewicht &uuml;berschritten<br />(siehe Versandhinweis)";
		}
	}
}
