var xmlHttp;
function ajax(method, url, vars, callback) {
	try {
		// Firefox, Opera 8.0+, Safari
		xmlHttp = new XMLHttpRequest();
	} catch (e) {
		// Internet Explorer
		try {
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}

	// fighting with cache
	var d = new Date();
	ts = d.getTime();
	tsparam = url.indexOf('?') > -1 ? "&nocache=" + ts : "?nocache=" + ts;

	xmlHttp.open(method, url + tsparam, true);
	xmlHttp.onreadystatechange = callback;

	if (method=="POST"){
		//alert(vars);
		xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	}

	xmlHttp.send(vars);

}

function ajax_params2str(f) {
	var getstr = "&";
	//alert(f.length);
	for (i=0; i<f.length; i++){
		if (f[i].type=="text" || f[i].type=="textarea"){
			getstr += f[i].name + "=" + encodeURIComponent(f[i].value) + "&";
		}else if (f[i].type=="select-one"){
			getstr += f[i].name + "=" + f[i].options[f[i].selectedIndex].value + "&";
		}else if (f[i].type=="radio"){
			getstr += f[i].name + "=" + f[i].value + "&";
		}else if (f[i].type=="checkbox"){
			getstr += f[i].name + "=" + (f[i].checked?"on":"") + "&";
		}
	}
	//alert(getstr);
	return getstr;
}