// JavaScript Document

//Using
/*

loadUrl(url, target)
-- loads url(string) in the target(string), where the target is the name of the id of some element in the html

reloadUrl(url, target, time, id)
-- the same but reloads the file in miliseconds wich is time
	the id is to separate the diferent reload values and to...
	
stopReloadUrl(id)
-- id is the id given to start it

loopArray(url, target, time, id)
-- here the url is Array and in time seconds function loops the diferent urls in the array
-- if you have string wit separator use javascript function split (ask google for help)

*/

//Do not tuch the code from here
var req = null;
var times = new Array();
var arrays = new Array();
var counts = new Array();

function processReqChange(target) {
    if (req.readyState == 4 && req.status == 200 ) {
//if (req.readyState == 4 ) {  
	var dobj = document.getElementById(target);
    dobj.innerHTML = req.responseText;
  }
}

function loadUrl( url, target ) {
  if(window.XMLHttpRequest) {
    try { req = new XMLHttpRequest();
    } catch(e) { req = false; }
  } else if(window.ActiveXObject) {
    try { req = new ActiveXObject('Msxml2.XMLHTTP');
    } catch(e) {
    try { req = new ActiveXObject('Microsoft.XMLHTTP');
    } catch(e) { req = false; }
  } }
  if(req) {
	document.getElementById(target).innerHTML="Моля изчакайте...";
	req.onreadystatechange = function () {processReqChange(target);};
	req.open('POST', url, true);
    req.send(null);
  } else {
	var dobj = document.getElementById( target );
	dobj.innerHTML="Error loading!";
  }
}

function reloadUrl(url, target, time, id) {
	times[id] = setInterval("loadUrl('"+url+"', '"+target+"')", time);
}

function stopReloadUrl(id) {
	clearInterval(times[id]);
}

function loopArray(url, target, time, id) {
	arrays[id] = new Array();
	arrays[id] = url;
	counts[id] = 0;
	times[id] = setInterval("loop('"+target+"', '"+id+"')", time);
}

function loop(target, id) {
	loadUrl(arrays[id][counts[id]], target);
	if (counts[id]>=arrays[id].length-1) {counts[id]=0;} else {counts[id]++;}
}


