/**********************************/
/*-+-      shic ACMS beta      -+-*/
/*-+-    -- JAVA SCRIPTS --    -+-*/
/*+-       www.shicgmbh.de      -+*/
/*-  © ichier2009 www.ichier.de  -*/
/*                                */
/*  last modified 06.04.09        */
/*                                */
/*  all rights reserved!          */
/**********************************/

function iajax(url,env,type,func,ind,prot,async) {
	// url = document only e.g. /page.php
	// env = env without leading ? e.g. id=13&data_action=xml
	// type = json, xml, text
	// func = function to hand over result
	// prot = protocol GET|POST

	var ajaxhttp;

	// create object ie or moz style
	try {
		ajaxhttp = new XMLHttpRequest();
	}
	catch (e){
		try {
			ajaxhttp = new ActiveXObject("Msxml2.XMLHTTP");
		} 
		catch (e){
			try {
				ajaxhttp = new ActiveXObject("Microsoft.XMLHTTP");
			} 
			catch (failed) {
				ajaxhttp = null;
			}
		}  
	}
	
	if (ajaxhttp == null) {
		//alert("Ajax-Fehler: Konnte HTTP Request nicht ausführen.");
		eval("if(typeof(func)=='undefined' || typeof(" + func + ") == 'function') { " + func + "(false,ind,true); }");
		return;
	}

	// open connection (post in case parameters are longer than 512bytes)
	if(typeof(prot)=='undefined') { prot = 'GET'; }
	if(typeof(async)=='undefined') { async = true; }
	if(prot=='GET') {
		// get
		ajaxhttp.open("GET", url + "?" + env, async);
		// set handler
		ajaxhttp.onreadystatechange = handle_http_state; //function(){handle_http_state(ajaxhttp);};
		// send request
		ajaxhttp.send(null);
	} else {
		// post
		ajaxhttp.open("POST", url, async);
		//Send the proper header information along with the request
		ajaxhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		ajaxhttp.setRequestHeader("Content-length", env.length);
		ajaxhttp.setRequestHeader("Connection", "close");
		// set handler
		ajaxhttp.onreadystatechange = handle_http_state; //function(){handle_http_state(ajaxhttp);};
		// send request
		ajaxhttp.send(env);
	}


	// handler
	function handle_http_state() {
		if (ajaxhttp.readyState == 4) {
			if (ajaxhttp.status == 200) {
				handle_http_data();
			} else {
				//alert("Ajax-Fehler: konnte Daten nicht laden. \rstatus: \r" + ajaxhttp.status);
				eval("if(typeof(func)=='undefined' || typeof(" + func + ") == 'function') { " + func + "(false,ind,true); }");
				return;
			}
		}
	}

	// handle data
	function handle_http_data() {
		var resposestr = ajaxhttp.responseText;
		// check if session timeout and similar here! errorcodes & co
		if(resposestr=='timeout') {
			// check if warned allready!
			alert("Ihre Sitzung ist abgelaufen. Bitte loggen Sie sich neu ein.");
			eval("if(typeof(func)=='undefined' || typeof(" + func + ") == 'function') { " + func + "(false,ind,true); }");
			return;
		}

		if(type=='json') {
			eval("var result = (" + resposestr + ")");
			eval("if(typeof(func)=='undefined' || typeof(" + func + ") == 'function') { " + func + "(result,ind,true); }");
			return;
		}else if(type=='text') {
			eval("if(typeof(func)=='undefined' || typeof(" + func + ") == 'function') { " + func + "(resposestr,ind,true); }");
			return;
		} else {
			parse_xml_data();
			return;
		}
	}

	// xml to array
	function parse_xml_data() {
		// to be coded! maybe ;) cause theres json ... but if its external data...
		return '';
	}


}