/**
 * ES AJAX
**/
function ES_GetSync(sUrl)
{
	ES_oHttpObj.open("GET", sUrl, false);
	ES_oHttpObj.send(null);
	if (ES_oHttpObj.status == 200)
		return ES_oHttpObj.responseText;
	else
	{
		alert('Ajax Connection to [' + sUrl + '] failed: ' + ES_oHttpObj.status);
		return '';
	}
}

function ES_GetAsync(sUrl)
{
	ES_oHttpObj.open("GET", sUrl, false);
	ES_oHttpObj.onreadystatechange = function() {
		if (ES_oHttpObj.readyState == 4)
		{
			if (ES_oHttpObj.status == 200)
				return ES_oHttpObj.responseText;
			else
			{
				alert('Ajax Connection to [' + sUrl + '] failed: ' + ES_oHttpObj.status);
				return '';
			}
		}
	}

	ES_oHttpObj.send(null);
}

function ES_GetAjaxObject() {
  var xmlhttp;
  /*@cc_on
  @if (@_jscript_version >= 5)
    try {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (E) {
        xmlhttp = false;
      }
    }
  @else
  xmlhttp = false;
  @end @*/
  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    try {
      xmlhttp = new XMLHttpRequest();
    } catch (e) {
      xmlhttp = false;
    }
  }
  return xmlhttp;
}

/**
 * DEFS
**/
ES_aLoadedScripts = Array();
ES_oHttpObj = ES_GetAjaxObject();
ES_loadScripts = new Array();
ES_loadScriptsIndex = 0;

/**
 * LOAD SCRIPTS
**/

function ES_LoadJavascript(sFile, sPrependPath, sText)
{
	var refreshText = '[File '+ES_loadScriptsIndex+'/'+ES_loadScripts.length+' Load: '+sPrependPath+sFile+'] '+sText;
	document.getElementById('loading_current').innerHTML = refreshText;
	window.status = refreshText;

	var sTextRequest = ES_GetSync(sPrependPath + sFile);

	var esBody = document.body;
	if (document.getElementById("esOwnScript"))
		esBody.removeChild(document.getElementById("esOwnScript"));
	var esOwnScript = document.createElement("script");
	esOwnScript.type = "text/javascript";
	esOwnScript.id = "esOwnScript";
	esBody.appendChild(esOwnScript);
	esOwnScript.text = sTextRequest;
	ES_loadScriptsIndex++;
	window.setTimeout('ES_LoadWalk()', 250);
}

function ES_LoadWalk()
{
	if (typeof ES_loadScripts[ES_loadScriptsIndex] != 'undefined')
	{
		ES_LoadJavascript(ES_loadScripts[ES_loadScriptsIndex][0], ES_loadScripts[ES_loadScriptsIndex][1], ES_loadScripts[ES_loadScriptsIndex][2]);
	}
	else
	{
		document.getElementById('loading_current').style.color = '#00AA00';
		document.getElementById('loading_current').innerHTML = 'Done! Refresh the site baby...';

		window.setTimeout('onLoadEvents()', 500);
	}
}

function ES_setDefaultText()
{
	document.getElementById('loading_current').innerHTML = 'Oh men, please wait, only a few seconds!!';
}

function ES_Load()
{
	var esLoadingScriptCurrent = document.createElement("span");
	esLoadingScriptCurrent.id = "loading_current";
	document.getElementById('loading_innest').appendChild(esLoadingScriptCurrent);

	ES_loadScripts.push(new Array('prototype.js.php', 'javascript/', 'Prototype Javascript Library'));
	ES_loadScripts.push(new Array('scriptaculous.js.php', 'javascript/', 'Script Aculous'));
	ES_loadScripts.push(new Array('builder.js.php', 'javascript/', 'Aculous Builder'));
	ES_loadScripts.push(new Array('effects.js.php', 'javascript/', 'Aculous Effects'));
	ES_loadScripts.push(new Array('dragdrop.js.php', 'javascript/', 'Aculous Dragdrop'));
	ES_loadScripts.push(new Array('controls.js.php', 'javascript/', 'Aculous Controls'));
	ES_loadScripts.push(new Array('slider.js.php', 'javascript/', 'Aculous Slider'));
	ES_loadScripts.push(new Array('es.js.php', 'javascript/', 'ES Core Library'));

	window.setTimeout('ES_setDefaultText()', 10);
	window.setTimeout('ES_LoadWalk()', 1000);
}

