var aLoad = new Array();

function Loader(lock) {
	this.locked=lock;
	this.load_buf;
}

function SysLoad(load_nm, buf) {
	//Load either the javascript or css file before wee continue with th ehtml page
	var pos = -1;
	// search the array for an unlocked object
	for (var i=0; i<aLoad.length; i++) {
		if (aLoad[i].locked == 1) {
			pos = i;
			break;
		}
	}
	// if we couldnt find a spare one
	if (pos == -1) {
		// create a new one, passing in the unlock code = 1
		pos = aLoad.length;
		aLoad[pos] = new Loader(1);
	}
//alert(aLoad.length);
	if (aLoad[pos].locked) {
		// set the lock
		aLoad[pos].locked = 0;
		aLoad[pos].load_buf = buf;
		h = document.getElementsByTagName("head")[0];
		aLoad[pos].s = document.createElement("script");
	   	aLoad[pos].s.onreadystatechange = function () {
   			if ((aLoad[pos].s.readyState == 'complete') || (aLoad[pos].s.readyState == 'loaded')){
				continue_rsp(aLoad[pos].load_buf);
				aLoad[pos].locked = 1;
       		}
		}
		aLoad[pos].s.onload = function () {
			continue_rsp(aLoad[pos].load_buf);
			aLoad[pos].locked = 1;
	    }
		//We need to create a new holder for the load module (CSS or JS)
		aLoad[pos].s.setAttribute("src", load_nm);
		aLoad[pos].s.setAttribute("type", "text/javascript");
		h.appendChild(aLoad[pos].s);
	} else {
		alert("Error creating Load request!.");
	}
}


