
// globale Instanz von XMLHttpRequest
var xmlHttp = false;

// XMLHttpRequest-Instanz erstellen
// ... für Internet Explorer
try {
	xmlHttp  = new ActiveXObject("Msxml2.XMLHTTP");
} catch(e) {
	try {
		xmlHttp  = new ActiveXObject("Microsoft.XMLHTTP");
	} catch(e) {
		xmlHttp  = false;
	}
}
// ... für Mozilla, Opera und Safari
if (!xmlHttp  && typeof XMLHttpRequest != 'undefined') {
	xmlHttp = new XMLHttpRequest();
}

function saveMerkzettel(obj){
	if (xmlHttp) {
		xmlHttp.open('POST', 'http://www.zimmerboerse-prerow.de/merkzettel.php');
		xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		 
		xmlHttp.send('mzobj='+obj);
		xmlHttp.onreadystatechange = function () {
			if (xmlHttp.readyState == 4) {
				var suchstring = /(bereits)/g;
				var suchergebnis = suchstring.test( xmlHttp.responseText );
				if (suchergebnis == false) {
					var anzAlt = $("#mz_input").val();
					var anzNeu = parseInt(anzAlt) + 1;
					document.getElementById("mz_anzahl").innerHTML = anzNeu;
					$("#mz_input").val(anzNeu);
				}
				document.getElementById("mz-meldung").innerHTML = xmlHttp.responseText;
			}
		}
	}
}

function deleteMerkzettel(){
	if (xmlHttp) {
		xmlHttp.open('POST', 'http://www.zimmerboerse-prerow.de/merkzettel.php');
		xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		 
		xmlHttp.send('loescheAlles=1');
		xmlHttp.onreadystatechange = function () {
			if (xmlHttp.readyState == 4) {
				document.getElementById("mz-meldung").innerHTML = xmlHttp.responseText;
			}
		}
	}
}

function deleteObjMerkzettel(obj){
	if (xmlHttp) {
		xmlHttp.open('POST', 'http://www.zimmerboerse-prerow.de/merkzettel.php');
		xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		 
		xmlHttp.send('loeschen='+obj);
		xmlHttp.onreadystatechange = function () {
			if (xmlHttp.readyState == 4) {
				$('#'+obj).remove();
				var anzAlt = $("#mz_input").val();
				var anzNeu = parseInt(anzAlt) - 1;
				document.getElementById("mz_anzahl").innerHTML = anzNeu;
				$("#mz_input").val(anzNeu);
				if (anzNeu == 0) {$('#mz_tabelle').remove();$('.mz-meldung').show(); }
				document.getElementById("mz-meldung").innerHTML = xmlHttp.responseText;
			}
		}
	}
}
