
function dataDespatcher() {
};
dataDespatcher.prototype.initialize = function() {
	try {
		// Mozilla / Safari
		this._xh = new XMLHttpRequest();
	} catch (e) {
		// Explorer
		var _xml_HTTP_OPTIONS = new Array(							  
		'MSXML2.XMLHTTP.5.0',
		'MSXML2.XMLHTTP.4.0',
		'MSXML2.XMLHTTP.3.0',
		'MSXML2.XMLHTTP',
		'Microsoft.XMLHTTP'
		);
		var success = false;
		var componentindex;
		for (var i=0;i < _xml_HTTP_OPTIONS.length && !success; i++) {
			try {
				
				this._xh = new ActiveXObject(_xml_HTTP_OPTIONS[i]);
				componentindex = i;
				success = true;
				
			} catch (e) {
				
			}
		}
		if ( !success ) {
			
			return false;
		}
		//alert('componentName:..... ' + _xml_HTTP_OPTIONS[componentindex]);
	}
	
	return true;
}

dataDespatcher.prototype.isBusy = function() {
	estadoActual = this._xh.readyState;
	return (estadoActual && (estadoActual < 4));
}

dataDespatcher.prototype.procesa = function() {
	if (this._xh.readyState == 4 && this._xh.status == 200) {
		this.procesado = true;
	}
}

dataDespatcher.prototype.despatch = function(url,datos) {
	
	if (!this._xh) {
		if(!this.initialize()){
			return "Unable to initialize Ajax despatcher";
		}
		//this._xh.Response.Cache.SetCacheability(HttpCacheability.NoCache);
	}
	
	if (!this.isBusy()) {
		
		
		this._xh.open("POST",url,false);
		
		this._xh.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		this._xh.setRequestHeader('cache-control','no-store');
		this._xh.send(datos);
		if (this._xh.readyState == 4 && this._xh.status == 200) {
			return this._xh.responseText;
		}
		else{
			return "Unable to save :-(";
		}
	}
	return false;
}

function updateCragBlurb(cragId,blurb){
	despatcher = new dataDespatcher;		
	response = despatcher.despatch("updateCragBlurb.php","blurb="  + escape(blurb) + "&cragId=" + cragId + "");
	return response;
}
function updateAreaBlurb(areaId,blurb){
	despatcher = new dataDespatcher;		
	response = despatcher.despatch("updateAreaBlurb.php","blurb="  + escape(blurb) + "&areaId=" + areaId + "");
	return response;
}
function updateRegionBlurb(regionId,blurb){
	despatcher = new dataDespatcher;		
	response = despatcher.despatch("updateRegionBlurb.php","blurb="  + escape(blurb) + "&regionId=" + regionId + "");
	return response;
}
function updateGmapData(gMapData,tempFileName){
	var today       = new Date();
	var time = today.getTime();
	
	despatcher = new dataDespatcher;		
	
	response = despatcher.despatch("updateGMap.php","gMapData="  + escape(gMapData) + "&tempFile=" + tempFileName + "&time=" + time);
	return response;
}
function updateStuff(url){
	response = despatcher.despatch(url);
	return response;
}


