var debug_mode = false;var response = new Object;
function debug(s){if (debug_mode) alert(s);}
function init_ajax() {
	debug("init_ajax() called..");
	var o;
	try {o=new ActiveXObject("Msxml2.XMLHTTP");} catch (e){try {o=new ActiveXObject("Microsoft.XMLHTTP");} catch (oc){o=null;}}
	if(!o && typeof(XMLHttpRequest) != "undefined") o = new XMLHttpRequest();
	if (!o)	debug("Could not create connection object.");
  return o;
}

function ajax_call(args) {
	var uri;var func;var params;var post_data='';
	var delete_afteruse = false;
	debug("in ajax_call()..");
	for (var arg in args) {if (arg == 'uri'||arg=='func'||arg=='params'||arg=='obj') continue;post_data += "&" + arg + "=" + escape(args[arg]);}
	post_data = post_data.substr(1);
	uri = args["uri"];func = args["func"];params=args["params"];
	
	if(typeof(params)=="object")response.return_type=params.returnType||"text";else response.return_type="text";
	
	response.xmlHTTP = init_ajax();
	response.xmlHTTP.onreadystatechange = Ajax_ReadyStateChanged;
	
	switch (response.return_type.toLowerCase()) {
		case "xml" :
			response.request_type = "GET";
			uri+="?"+post_data;
			post_data=null;
		break;
		default :
			response.request_type = "POST";
		break;
	}
	response.xmlHTTP.open(response.request_type, uri, true);
	response.xmlHTTP.setRequestHeader("User-Agent", "Mozilla/5.0 (Windows; Chabad_Ajax) COAjax/1.0");
	if (response.request_type=="POST") {
		response.xmlHTTP.setRequestHeader("Method", "POST " + uri + " HTTP/1.1");
		response.xmlHTTP.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	}
	response.xmlHTTP.send(post_data);
	
	if (typeof(response.func)=='function'&&typeof(func)=='function') response.donot_clear=true;
	debug(uri);if (func) response.func = func; if (params) response.params = params;if(args.obj)response.obj=args.obj;
	
	debug(post_data);
	
//	delete x;
	return true;
}

function Ajax_ReadyStateChanged() {
	if (response.xmlHTTP.readyState != 4) 
		return;

	var status;var data;var txt = response.xmlHTTP.responseText;
	status = txt.charAt(0);
	data =txt.substring(2) //.Replace('\n','|||');
	var return_type="text";
	
	if (response.return_type=="xml") data=response.data=response.xmlHTTP.responseXML;else response.data=response.xmlHTTP.responseText;
	if (status == "0") { alert("Error: " + data); } else { 
		debug(data);
	  if (response.func) {
			if (response.params) {
				if (typeof(response.params)=='string') 
					eval(response.func + '("'+ response.params + '","' + data + '")'); 
				else if (typeof(response.func)=='string') {eval(response.func + '("'+ response.params + '","' + data + '")');}
				else response.func(response.params,data);
			} 
			else if (typeof(response.func)=='string') eval(response.func + '("'+ data + '")');
			else {response.func.call(response.obj, data);}
		}
	}
	if (!response.donot_clear) {response.func=null; response.params=null;}
	response.donot_clear=false;
}

String.prototype.Replace = function(o,n) {return this.split(o).join(n);}

function activate_javascript_ie(Container_Elm) {
	if (!document.all) return;
	var script_tags=Container_Elm.getElementsByTagName("script");
	for (var i=0;script_tags.length>i;i++) {
		if (script_tags[i].getAttribute("src")) {script_tags[i].src = script_tags[i].getAttribute("src");}
		else {script_tags[i].text=script_tags[i].innerHTML;}
	}
}
