var ROOT_DIR;

function scan_page()	{preload(document.images.length)}
function preload(num)	{for (i = 0; i <= num-1; i++) load_img(document.images[i].name)}
function load_img(name)	{this.over=new Image(); this.over.src=ROOT_DIR+'images/button/'+name+'_o.png';}
function img(imgName, onOff, layer) {
	if (document.images) {
		if (onOff == 1)	{
			if (layer ==1) document.getElementById(imgName+'T').style.visibility = "visible";
			document[imgName].src = ROOT_DIR+'images/button/'+imgName+'_o.png';
		}
		if (onOff == 0)	{
			if (layer ==1) document.getElementById(imgName+'T').style.visibility = "hidden";
			document[imgName].src = ROOT_DIR+'images/button/'+imgName+'.png';	
		}	
	}
}
function change_bg(imgName) {
	// "hintergrund-02"
	x = document.getElementById('hauptcontainer').style.backgroundImage.src;
	alert(x);
	document.getElementById('hauptcontainer').style.backgroundImage = "url("+ROOT_DIR+"images/"+imgName+".jpg)";
}


var namen=new Array("hintergrund-02.jpg","hintergrund-03.jpg");
var bilder=new Array();
var nr=0;

function lade()
{
  window.setTimeout("naechstes()",5000);
}

function naechstes()
{
  nr=(nr+1)%2;    /* Bild hochzaehlen und mod 4 */
    /* Bild austauschen : */
 document.getElementById('hauptcontainer').style.backgroundImage = "url("+ROOT_DIR+"images/"+namen[nr]+")";
    /* Timeout auf 500 Millisekunden setzen : */
  window.setTimeout("naechstes()",5000);
}




function makeRequest(del) {
	http_request = false;

	if (del == 1) var url =  ROOT_DIR+"page/calculate.php?deckel=0&club=0";
	else var url =  ROOT_DIR+"page/calculate.php?deckel="+document.kalkulator.Menge_Bierdeckel.value+"&club="+document.kalkulator.Menge_Clubbecher.value;
	
	// alert(url);

    if (window.XMLHttpRequest) { // Mozilla, Safari, IE7...
        http_request = new XMLHttpRequest();
    } else if (window.ActiveXObject) { // IE
        http_request = new ActiveXObject("Microsoft.XMLHTTP");
    }

    if (!http_request) {
        alert('Giving up :( Cannot create an XMLHTTP instance');
        return false;
    }
    
	http_request.onreadystatechange = alertContentsKorb;

    http_request.open('GET', url, true);
    http_request.send(null);
}

function alertContentsKorb() {
    if (http_request.readyState == 4) {
        if (http_request.status == 200) {
            var xmldoc = http_request.responseXML;

            var root_node = xmldoc.getElementsByTagName('summe_club').item(0);
		    document.kalkulator.summe_club.value = root_node.firstChild.data;
		    //document.getElementById('summe_club').firstChild.data = root_node.firstChild.data;

            var root_node = xmldoc.getElementsByTagName('summe_deckel').item(0);
		    document.kalkulator.summe_deckel.value = root_node.firstChild.data;
		    //document.getElementById('summe_deckel').firstChild.data = root_node.firstChild.data;

            var root_node = xmldoc.getElementsByTagName('summe').item(0);
		    document.kalkulator.summe.value = root_node.firstChild.data;
		    //document.getElementById('summe').firstChild.data = root_node.firstChild.data;

        } else {
            alert('There was a problem with the request.');
        }
    }
}
