// Sollen Alerts gemacht werden (Merkzettel)
var doAlert=true;


function reloadDocument() {
	location.reload();
}

function reloadPostitDocument() {
	if (window.parent.frames.length==2) {
		window.parent.frames[1].location.reload();
	}
}

function loadProduct(id){
    var ajaxRequest;  // The variable that makes Ajax possible!

    try{
        // Opera 8.0+, Firefox, Safari
        ajaxRequest = new XMLHttpRequest();
    } catch (e){
        // Internet Explorer Browsers
        try{
            ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try{
                ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e){
                // Something went wrong (User Probably Doesn't have JS or JS is turned off)
                alert("Your Browser Doesn't support AJAX.");
                return false;
            }
        }
    }
    // Create a function that will receive data sent from the server
    ajaxRequest.onreadystatechange = function(){
        //This if satement will check if the status of the script
        //If the readyState is not equal to 4 (The request is complete)
        //It will display text that says loading...
        if(ajaxRequest.readyState < 4){
            //AJAX in the prenthacies, is what id element in the body will be changed.
            document.getElementById('overlayDiv').style.visibility='visible';
            document.getElementById('overlayDiv').innerHTML = "Lade Daten...";
        }
        //Once the readyState is equal to four, this means that the request was sent,
        //and successfully processed.
        if(ajaxRequest.readyState == 4){
            //This is where the output of the file we called and it will be placed
            //in the div where we named the ID = AJAX
            document.getElementById('overlayDiv').style.visibility='visible';
            document.getElementById('overlayDiv').innerHTML = ajaxRequest.responseText;
			
		
			if (navigator.appName.indexOf("Explorer") != -1)
			{
				document.getElementById('overlayDiv').style.top = document.body.scrollTop;
			}
			else
			{
				document.getElementById('overlayDiv').style.position = 'fixed';
				document.getElementById('overlayDiv').style.top = '1px';
				
			}
			
			
			
        }
    }
    //This section processes the data
    ajaxRequest.open("GET", 'script/loadProduct.php?productID='+id, true);
    ajaxRequest.send(null);
}

function setPostit(id, action){
    var ajaxRequest;  // The variable that makes Ajax possible!
    try{
        // Opera 8.0+, Firefox, Safari
        ajaxRequest = new XMLHttpRequest();
    } catch (e){
        // Internet Explorer Browsers
        try{
            ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try{
                ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e){
                // Something went wrong (User Probably Doesn't have JS or JS is turned off)
                alert("Your Browser Doesn't support AJAX.");
                return false;
            }
        }
    }
    // Create a function that will receive data sent from the server
    ajaxRequest.onreadystatechange = function(){
        //This if satement will check if the status of the script
        //If the readyState is not equal to 4 (The request is complete)
        //It will display text that says loading...
        if(ajaxRequest.readyState < 4){
            //AJAX in the prenthacies, is what id element in the body will be changed.
        }
        //Once the readyState is equal to four, this means that the request was sent,
        //and successfully processed.
        if(ajaxRequest.readyState == 4){
            //This is where the output of the file we called and it will be placed
            //in the div where we named the ID = AJAX
            switch(ajaxRequest.responseText) {
				case 'added': if (doAlert) alert('Das Produkt wurde auf Ihrem Merkzettel eingetragen.'); reloadPostitDocument(); break;
				case 'deleted':  if (doAlert) alert('Das Produkt wurde aus Ihrem Merkzettel gestrichen.'); reloadDocument();  break;
				case 'clean': if (doAlert) alert('Ihr Merkzettel ist nun leer.');reloadDocument();  break;
				case 'maxCount': if (doAlert) alert('Ihr Merkzettel ist voll.'); break;		
				case 'noProduct': if (doAlert) alert('Dieses Produkt existiert nicht.'); break;					
			}
        }
    }
    //This section processes the data
    ajaxRequest.open("GET", 'script/setPostit.php?productID='+id+'&action='+action, true);
    ajaxRequest.send(null);
}

