/************************************************
* Vorlage für die Verwendung von Ajax 		*
* -> Erstellung der Verbindung (js)		*
* C 2007 by René Lange @ mindbox        	*
************************************************/

// <--- Variablendeklaration --->
var xmlHttp
var output

// <--- Hauptfunktionen --->

function sendAjaxRequest(id, value, validationMode, mustHave) {
	this.output = output;				

	// URL zusammenstellen
	var url="http://" + location.host + "/fileadmin/scripts/formValidate.php";
	
	url=url+"?id="+id;
	url=url+"&value="+value;
	url=url+"&mode="+validationMode;
	url=url+"&mustHave="+mustHave;
	
	// Verbindung erstellen und senden
	xmlHttp = GetXmlHttpObject();
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",encodeURI(url),true);
	xmlHttp.send(null);	
}

// <--- Hilfsfunktionen --->

// Response prüfen, ob Abgeschlossen oder noch in Bearbeitung
function stateChanged() { 
	if (xmlHttp.readyState==4) { 
		vars = xmlHttp.responseText.split(';');

		var el;
		el = $(vars[0].toString());

		if(vars[2] == 'nothing') {
			el.setStyle('backgroundColor','#fff');
			el.setProperty('title','');
			return;
		}

		if(vars[2] == 'true') {
			el.setStyle('backgroundColor','#ffe8e9');
			var errorStr = "Bitte " + String.fromCharCode(252) + "berpr" + String.fromCharCode(252) + "fen Sie Ihre Angaben."

			el.setProperty('title',errorStr);
		} else {
			el.setStyle('backgroundColor','#f2ffed');
			if(el.hasClass('errField')){
				el.removeClass('errField');
			}
			el.setProperty('title','');
		}
	}
}


// Objekt für einen der Verschiedenen Browser erstellen
function GetXmlHttpObject() {
	var xmlHttp=null;
	try { // Firefox, Opera 8.0+, Safari
  		xmlHttp=new XMLHttpRequest();
  	}
	catch (e) { // Internet Explorer
		try {
    			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    		}
  		catch (e) {
    			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    		}
	}
	return xmlHttp;
}