// JavaScript Document

function upd() {

	 var cont = document.getElementById("cont").value;
	var idx = document.getElementById("idx").value;
	var lang = document.getElementById("lang").value;
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
		  xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
		  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	
	xmlhttp.onreadystatechange=function()
	{
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
			document.getElementById("result").innerHTML=xmlhttp.responseText;
			
		}
	 }
	
	xmlhttp.open("GET","/ajax/update_content.php?idx=" + idx + "&lang=" + lang + "&cont=" + escape(cont) ,true);
	xmlhttp.send();
}


function additem(artnr) {
	var qty = document.getElementById('qty'+artnr).value;
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
		  xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
		  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	
	xmlhttp.onreadystatechange=function()
	{
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
			document.getElementById('basket').innerHTML=xmlhttp.responseText;
			window.location.href = "basket.php";
			//alert("Artikel wurde in den Warenkorb gelegt.")
		}
	 }		
	xmlhttp.open("GET","ajax/addbasket.php?artnr=" + artnr + "&qty=" + qty ,true);
	xmlhttp.send();
}

function updateitem(artnr) {
	var qty = document.getElementById('qty'+artnr).value;
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
		  xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
		  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	
	xmlhttp.onreadystatechange=function()
	{
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
			document.getElementById('basket').innerHTML=xmlhttp.responseText;
			location.reload();
		}
	 }		
	xmlhttp.open("GET","ajax/updatebasket.php?artnr=" + artnr + "&qty=" + qty ,true);
	xmlhttp.send();
}

function deleteitem(artnr) {
	var qty = 0;
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
		  xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
		  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	
	xmlhttp.onreadystatechange=function()
	{
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
			document.getElementById('basket').innerHTML=xmlhttp.responseText;
			location.reload();
		}
	 }		
	xmlhttp.open("GET","ajax/updatebasket.php?artnr=" + artnr + "&qty=" + qty ,true);
	xmlhttp.send();
}

function runden(zahl,stellen) {
	var p = Math.round(zahl * Math.pow(10,stellen))/Math.pow(10,stellen);
	return p;
}

function bmicalc() {
	color = new Array();
		color[0] = '#66F';
		color[1] = '#36F';
		color[2] = '#0CF';
		color[3] = '#0C6';
		color[4] = '#990';
		color[5] = '#C60';
		color[6] = '#F36';
		color[7] = '#C30';
		if (document.getElementById('groesse').value != '' && document.getElementById('gewicht').value != '') {
			var groesse = document.getElementById('groesse').value / 100 ;
			var gewicht = document.getElementById('gewicht').value;
			var BMI = gewicht / Math.pow(groesse,2);
			BMI = runden(BMI,1);
			if (BMI < 16) { text = "Sie haben starkes Untergewicht";cindex= 0; }
			if (BMI >= 16 && BMI <= 17) { text = "Sie haben m&auml;ssiges Untergewicht";cindex= 1; }
			if (BMI > 17 && BMI <= 18.5) { text = "Sie haben leichtes Untergewicht";cindex= 2; }
			if (BMI > 18.5 && BMI <= 25) { text = "Sie haben Normalgewicht";cindex= 3; }
			if (BMI > 25 && BMI <= 30) { text = "Sie haben leichtes &Uuml;bergewicht (Pr&auml;adipositas)";cindex= 4; }
			if (BMI > 30 && BMI <= 35) { text = "Sie haben m&auml;ssiges &Uuml;bergewicht (Adipositas Grad I)";cindex= 5; }
			if (BMI > 35 && BMI <= 40) { text = "Sie haben starkes &Uuml;bergewicht (Adipositas Grad II)";cindex= 6; }
			if (BMI > 40) { text = "Sie haben extremes &Uuml;bergewicht (Adipositas Grad III)";cindex= 7; }
			document.getElementById('resultat').innerHTML = 'Ihr BMI ist: ' + BMI + '<br>' + text;
			document.getElementById('resultat').style.backgroundColor = color[cindex];
		}
}

function ajaxfilemanager(field_name, url, type, win) {
			var ajaxfilemanagerurl = "/editor/jscripts/tiny_mce/plugins/ajaxfilemanager/ajaxfilemanager.php";
			var view = 'detail';
			switch (type) {
				case "image":
				view = 'thumbnail';
					break;
				case "media":
					break;
				case "flash": 
					break;
				case "file":
					break;
				default:
					return false;
			}
            tinyMCE.activeEditor.windowManager.open({
                url: "/editor/jscripts/tiny_mce/plugins/ajaxfilemanager/ajaxfilemanager.php?view=" + view,
                width: 782,
                height: 440,
                inline : "yes",
                close_previous : "no"
            },{
                window : win,
                input : field_name
            });
            
		}
