function CRequestObject ()
{
if (window.XMLHttpRequest) {this.XHRObject = new XMLHttpRequest();}
else {
if (window.ActiveXObject) {this.XHRObject = new ActiveXObject("Microsoft.XMLHTTP");}
}
}

CRequestObject.prototype.RequestFile = function (File, onLoadFunction)
{
var _this = this;
this.XHRObject.onreadystatechange = function ()
{
if(_this.XHRObject.readyState == 4)
{
if (_this.XHRObject.status == 200)
{onLoadFunction(_this.XHRObject);}
}
};
// Open and send the request for the file
this.XHRObject.open('GET',File,true);
this.XHRObject.send(null);
};


CRequestObject.prototype.RequestAndRunScript = function (ScriptFile)
{
var _this = this;

// Define an onload function that will be called after loading the script
var onLoadFunction = function(XHRObject)
{
eval( XHRObject.responseText );
if (_this.onCompletion) {
_this.onCompletion();
}
};
// Load the script file and run it
this.RequestFile(ScriptFile, onLoadFunction);
};

// funcio que carrega de forma serialitzada
// els fitxers javascript de l'aplicació
// la descarrega es assincrona: podem executar a //acces inicial//
// el codi independent del javascript, de forma immediata

async_loader_map = function(nummap)
{
// Load and initialize the scripts
var RequestObject1 = new CRequestObject();
var RequestObject2 = new CRequestObject();
var RequestObject3 = new CRequestObject();
var RequestObject4 = new CRequestObject();
var RequestObject5 = new CRequestObject();
var RequestObject6 = new CRequestObject();
var RequestObject7 = new CRequestObject();

var baseUrl = 'http://www.estatpropi.cat/js/';
/*
//amb codi newsticker
RequestObject1.onCompletion = function() { RequestObject2.RequestAndRunScript(baseUrl+'XParser.js');};
RequestObject2.onCompletion = function() { RequestObject3.RequestAndRunScript(baseUrl+'OverlayMessage.js');};
RequestObject3.onCompletion = function() { RequestObject4.RequestAndRunScript(baseUrl+'markermanager.js');};
RequestObject4.onCompletion = function() { RequestObject5.RequestAndRunScript(baseUrl+'webtoolkit.cookies.js');};
RequestObject5.onCompletion = function() { RequestObject6.RequestAndRunScript(baseUrl+'newsticker.js');};
RequestObject6.onCompletion = function() { RequestObject7.RequestAndRunScript(baseUrl+'MapUtils2.js');};
RequestObject7.onCompletion = function() { MainMap.customize(nummap);init_newsticker();};//operacions sï¿½ncrones
RequestObject1.RequestAndRunScript(baseUrl+'zxml.js');
*/
//sense MapUtils : posar al Head, a page.tpl.php //javascript_set_principal() 
RequestObject1.onCompletion = function() { RequestObject2.RequestAndRunScript(baseUrl+'markermanager.js');};
RequestObject2.onCompletion = function() { RequestObject3.RequestAndRunScript(baseUrl+'webtoolkit.cookies.js');};
RequestObject3.onCompletion = function() { RequestObject4.RequestAndRunScript(baseUrl+'newsticker.js');};
RequestObject4.onCompletion = function() { };
RequestObject6.onCompletion = function() { MainMap.customize(nummap);init_newsticker();};//operacions sï¿½ncrones
RequestObject1.RequestAndRunScript(baseUrl+'OverlayMessage.js');
/*
RequestObject1.onCompletion = function() { RequestObject2.RequestAndRunScript(baseUrl+'markermanager.js');};
RequestObject2.onCompletion = function() { RequestObject3.RequestAndRunScript(baseUrl+'webtoolkit.cookies.js');};
RequestObject3.onCompletion = function() { RequestObject4.RequestAndRunScript(baseUrl+'newsticker.js');};
RequestObject4.onCompletion = function() { RequestObject5.RequestAndRunScript(baseUrl+'MapUtils2.js');};
RequestObject5.onCompletion = function() { MainMap.onLoad(0, 'pais');};
RequestObject6.onCompletion = function() { MainMap.customize(nummap);init_newsticker();};//operacions sï¿½ncrones
RequestObject1.RequestAndRunScript(baseUrl+'OverlayMessage.js');
*/
//acces inicial
};


async_loader = function(div,geoscope)
{
// Load and initialize the scripts
var RequestObject1 = new CRequestObject();
var RequestObject2 = new CRequestObject();
var RequestObject3 = new CRequestObject();
var RequestObject4 = new CRequestObject();
var RequestObject5 = new CRequestObject();
var RequestObject6 = new CRequestObject();
var RequestObject7 = new CRequestObject();

var baseUrl = 'http://www.estatpropi.cat/js/';
/*
//amb codi newsticker
RequestObject1.onCompletion = function() { RequestObject2.RequestAndRunScript(baseUrl+'XParser.js');};
RequestObject2.onCompletion = function() { RequestObject3.RequestAndRunScript(baseUrl+'OverlayMessage.js');};
RequestObject3.onCompletion = function() { RequestObject4.RequestAndRunScript(baseUrl+'markermanager.js');};
RequestObject4.onCompletion = function() { RequestObject5.RequestAndRunScript(baseUrl+'webtoolkit.cookies.js');};
RequestObject5.onCompletion = function() { RequestObject6.RequestAndRunScript(baseUrl+'newsticker.js');};
RequestObject6.onCompletion = function() { RequestObject7.RequestAndRunScript(baseUrl+'MapUtils2.js');};
RequestObject7.onCompletion = function() { MainMap.onLoad(div, geoscope);init_newsticker();};//operacions síncrones
RequestObject1.RequestAndRunScript(baseUrl+'zxml.js');
*/
RequestObject1.onCompletion = function() { RequestObject2.RequestAndRunScript(baseUrl+'markermanager.js');};
RequestObject2.onCompletion = function() { RequestObject3.RequestAndRunScript(baseUrl+'webtoolkit.cookies.js');};
RequestObject3.onCompletion = function() { RequestObject4.RequestAndRunScript(baseUrl+'newsticker.js');};
RequestObject4.onCompletion = function() { RequestObject5.RequestAndRunScript(baseUrl+'MapUtils2.js');};
RequestObject5.onCompletion = function() { MainMap.onLoad(div, geoscope);init_newsticker();};//operacions síncrones
RequestObject1.RequestAndRunScript(baseUrl+'OverlayMessage.js');
//acces inicial
};
