//ajax v 0.10
// Zarz 啊


var ajax_debug_mode = false;
//var ajax_debug_mode = true;
var ajax_request_type = "GET";
function ajax_debug(text) {
	if (ajax_debug_mode)
		alert("RSD: " + text)
}
function ajax_init_object() {
    ajax_debug("ajax_init_object() called..")
	
    var A;
	try {
		A=new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		try {
			A=new ActiveXObject("Microsoft.XMLHTTP");
		} catch (oc) {
			A=null;
		}
	}
	if(!A && typeof XMLHttpRequest != "undefined")
		A = new XMLHttpRequest();
	if (!A)
		ajax_debug("Could not create connection object.");
	return A;
}
function ajax_do_call(uri, func_name, args) {
	var i, x, n;
	//var uri;
	var post_data;
	
	//uri = "<?php echo $zajaxremote_uri; ?>";
	if (ajax_request_type == "GET") {
		if (uri.indexOf("?") == -1) 
			uri = uri + "?rs=" + escape(func_name);
		else
			uri = uri + "&rs=" + escape(func_name);
		for (i = 0; i < args.length-1; i++) 
			uri = uri + "&rsargs[]=" + escape(args[i]);
		uri = uri + "&rsrnd=" + new Date().getTime();
		post_data = null;
	} else {
		post_data = "rs=" + escape(func_name);
		for (i = 0; i < args.length-1; i++) 
			post_data = post_data + "&rsargs[]=" + escape(args[i]);
	}
	
	x = ajax_init_object();
	x.open(ajax_request_type, uri, true);
	if (ajax_request_type == "POST") {
		x.setRequestHeader("Method", "POST " + uri + " HTTP/1.1");
		x.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	}
	x.onreadystatechange = function() {
		if (x.readyState != 4) 
			return;
		ajax_debug("received " + x.responseText);
		
		var status;
		var data;
		status = x.responseText.charAt(0);
		data = x.responseText.substring(2);
		if (status == "-") 
			alert("Error: " + data);
		else  
			args[args.length-1](data);
	}
	x.send(post_data);
	ajax_debug(func_name + " uri = " + uri + "/post = " + post_data);
	ajax_debug(func_name + " waiting..");
	delete x;
}


function explode(inputstring, separators, includeEmpties) {
	inputstring = new String(inputstring);
	separators = new String(separators);
	
	if(separators == "undefined") {
		separators = "|";
	}
	
	fixedExplode = new Array(1);
	currentElement = "";
	count = 0;
	
	for(x=0; x < inputstring.length; x++) {
		str = inputstring.charAt(x);
		if(separators.indexOf(str) != -1) {
		    if ( ( (includeEmpties <= 0) || (includeEmpties == false)) && (currentElement == "")) { }
		    else {
				fixedExplode[count] = currentElement;
				count++;
				currentElement = ""; 
				} 
			}
		    else { currentElement += str; }
	}
	
	if (( ! (includeEmpties <= 0) && (includeEmpties != false)) || (currentElement != "")) {
	    fixedExplode[count] = currentElement; 
	}
	return fixedExplode;
}

function explodeStr(str) {
    str_r = new Array();
	var separators = "|";
	var includeEmpties = 1;
    str_r = explode(str, separators, includeEmpties);
    return str_r;
}
