function ajax_request(site_url,callback) {
	var http_request = false;

	if (window.XMLHttpRequest) { // Mozilla, Safari, ...
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) {
			http_request.overrideMimeType('text/html');
		}
	} else if (window.ActiveXObject) { // IE
		try {
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}
	if (!http_request) {
		alert('You are probably using the last version of Internet Explorer for the Mac which has been discontinued.');
		return false;
	}
	http_request.onreadystatechange = function() { ajax_process_response(http_request, site_url, callback); };
	http_request.open('GET', site_url, true);
	http_request.send(null);
}

function ajax_process_response(http_request, site_url, callback) {
	if (http_request.readyState == 4) {
		if (http_request.status == 200) {
			if(http_request.responseText == 'done'){
				 window.location.href = unescape(window.location.pathname);
			} else {
				eval(callback);
			}
		} else {
			alert('There is a problem ('+http_request.status+')');
			return false;
		}
	}
}

function ajax_fill_data(fill_id,returned){
	document.getElementById(fill_id).innerHTML = returned;
}

//Custom MyEvents Ajax functionality
function ajax_fill_select_box(fill_id,returned){
	var returnedarray = returned.split("||");
	
	var select_obj = document.getElementById(fill_id);
	if(select_obj){
		select_obj.length = 0;
		//Process each of the elements 	
		for ( var i=0; i<returnedarray.length; i++ ){
			var valueLabelPair = returnedarray[i].split("|")
			select_obj.options[i] = new Option(valueLabelPair[1], valueLabelPair[0]);
			if(valueLabelPair[2] == 1) select_obj.options[i].selected = true;
		}
	}else{
		alert("Couldn't find the select box '"+fill_id+"'.");
	}
}

//Dynamic map search 
function ajax_complete_search(fill_id,jsonstring){
	//ajax_fill_data(fill_id,returned);
	var map = loadMap();
	var venue_icon = custom_icon('small');
	
	//Clear overlays
	map.clearOverlays();	
	
	var jsonarray = eval(jsonstring+";");
	
	//alert(jsonarray.length);	
	for(var x=0;x<jsonarray.length;x++){
		var jsonobj = jsonarray[x]
		var p = new GLatLng(jsonobj.Latitude, jsonobj.Longitude);
		map.addOverlay(createMarker(p,venue_icon,jsonobj.Scheme,jsonobj.Description,jsonobj.Call,jsonobj.Link));
	}
	
	toggle_loading_overlay(0);
}

// ----------------------------------------- make a URL param string from a list of values passed as a JSON object -------------------------------
// BC 2008:
//  call like this:
//    s = make_url_params({ac:'show_house',id:23,title:'The pretty house'},1);
//  returns
//      ?ac=show_house&id=23&title=The%20pretty%20house

function make_url_params(params_obj,first){
	var s='';
	for (p in params_obj){
		var sep = (first || first == null)?'?':'&';
		first=0;
		s += sep + p+ '=' + escape(params_obj[p]);
	};
	return s;
}