// # Dynamic Data Loading # //

// This script is part of Zetaneon.

// Returns a XMLHttpRequest which is compatible with the clients browser

// Examples
//# var XMLHttpRequest = createRequest();


	function createRequest() {
	
		if (window.XMLHttpRequest) {
			request = new XMLHttpRequest(); // Mozilla, Safari, Opera
		}
		else if (window.ActiveXObject) {
			try {
				request = new ActiveXObject('Msxml2.XMLHTTP'); // IE 5
			} catch (e) {
				try {
					request = new ActiveXObject('Microsoft.XMLHTTP'); // IE 6
				} catch (e) {}
			}
		}
		
		// Return the request
		return request;
		
	}

// Allows you to load data from the server without complete site refresh

// Examples:
//# dynLoad("GET", "answer.php", "question=is the earth a plate", "", "", "", "", "alert(obj_req.responseText)") 

// Parameters

	// str_method: Method of request, GET or POST
	// str_target: Target File
	// str_data:   Data to submit as Query String
	// str_func0:  Function to call at State 0
	// str_func1:  Function to call at State 1
	// str_func2:  Function to call at State 2
	// str_func3:  Function to call at State 3
	// str_func4:  Function to call at State 4


	function dynLoad(str_method, str_target, str_data, str_func0, str_func1, str_func2, str_func3, str_func4) {
	
		// Create a XMLHttpRequest valid for all Browsers (IE5+, Mozilla, Co.)
		var obj_req = createRequest();
		
		// Call the Users functions at each State
		obj_req.onreadystatechange = function() {
		
			switch(obj_req.readyState) {
			
				case 0:
					eval(str_func0);
					break;
				case 1:
					eval(str_func1);
					break;
				case 2:
					eval(str_func2);
					break;
				case 3:
					eval(str_func3);
					break;
				case 4:
					eval(str_func4);
					break;
					
			}
			
		}
		
		// Internet Explorer Cache Fix
		if (checkBrowserName("MSIE")) {
			var obj_time = new Date();
			var int_unix = obj_time.getTime() + Math.random().toString();
			
			if (str_method == "GET") str_data += "&" + int_unix;
			if (str_method == "POST") str_target += "?" + int_unix;
		}
		
		// Transmit via GET or POST
		
			// GET Method
			if (str_method == "GET") {
			
				obj_req.open("GET", str_target + "?" + str_data, true);
				obj_req.send(null);
				
			}
			
			// POST Method
			if (str_method == "POST") {
			
				obj_req.open("POST", str_target, true);
				obj_req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
				obj_req.setRequestHeader("Content-length", str_data.length);
				obj_req.setRequestHeader("Connection", "close");
				obj_req.send(str_data);
				
			}
		
	}


// Shorter form which just needs State 4

// Examples:
//# dynLoad("GET", "answer.php", "question=is the earth a plate", "alert(obj_req.responseText)") 

// Parameters

	// str_method: Method of request, GET or POST
	// str_target: Target File
	// str_data:   Data to submit as Query String
	// str_func4:  Function to call at State 4


	function dynLoad4(str_method, str_target, str_data, str_func4) {
	
		// Call dynLoad
		dynLoad(str_method, str_target, str_data, "", "", "", "", str_func4);
		
	}

	
// A call to the direct-mini-engine to enable Avantgarde features for this request

// Exampes:
//# dynDirect("GET", "module/page/answer.php", "question=is the earth a plate", "function() {...}", "function() {...}", "function() {...}", "alert(obj_req.responseText)", "AskQuestion");

	// str_method: Method of request, GET or POST
	// str_data:  Data to submit as Query String
	// str_code:   User defined code with rules defined in the direct.xml.php
	// str_func0:  Function to call at State 0
	// str_func1:  Function to call at State 1
	// str_func2:  Function to call at State 2
	// str_func3:  Function to call at State 3
	// str_func4:  Function to call at State 4
	

	function dynDirect(str_method, str_data, str_code, str_func0, str_func1, str_func2, str_func3, str_func4) {
		dynLoad(str_method, 'kernel/engine.php', 'directcall=' + str_code + '&directcallpath=' + modul_path + '&' + str_data, str_func0, str_func1, str_func2, str_func3, str_func4);
	}


// Shorter form which just needs State 4

// Examples:
//# dynDirect("GET", "question=is the earth a plate", "AnswerQuestion", "alert(obj_req.responseText)") 

// Parameters

	// str_method: Method of request, GET or POST
	// str_data:   Data to submit as a Query String
	// str_code:   User defined code with rules defined in the direct.xml.php
	// str_func4:  Function to call at State 4


	function dynDirect4(str_method, str_data, str_code, str_func4) {
	
		// Call dynLoad
		dynDirect(str_method, str_data, str_code, "", "", "", "", str_func4);
		
	}
