var mInterval;
var mInterval2;

function removeSpaces(string) {
	var tstring = "";
	string = '' + string;
	splitstring = string.split(" ");
	for(i = 0; i < splitstring.length; i++)
	tstring += splitstring[i];
	tstring = escape(tstring);
	return tstring;
}

if (window.XMLHttpRequest) {
    xmlHttp = new XMLHttpRequest();
} else if (window.ActiveXObject) {
    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
function callServer(url) {
  xmlHttp.open("GET", url , true);
  xmlHttp.onreadystatechange = updatePage;
  xmlHttp.send(null);
}
//function updatePage() {
//  if (xmlHttp.readyState == 4) {
//    var response = xmlHttp.responseText;
//    document.getElementById("visitor_online").innerHTML = response;
//    url="rtoc.php?q=" + removeSpaces(document.title);
//   setTimeout("callServer(url)",8000);
//  }
//}


function startProgressBar(tot) {
	reset();
  mInterval = setInterval("doProgress(" + tot + ")",1800/tot);

}

function reset() {
	document.getElementById("mask").style.left = "0px";
	document.getElementById("mask").style.width = document.getElementById("mContainer").offsetWidth + "px";
	document.getElementById("progressIndicator").style.zIndex  = 10;
	document.getElementById("mask").style.display = "block";
	document.getElementById("progressIndicator").innerHTML = "0%";
}

function doProgress(tot) {
	curWidth = parseInt(document.getElementById("mask").offsetWidth);
	curLeft = parseInt(document.getElementById("mask").offsetLeft);

	curWidth --;
	curLeft ++;

	if(curLeft ==201) {
		clearInterval(mInterval);
		document.getElementById("mask").style.display = "none";
		return;
	}


	document.getElementById("mask").style.left = curLeft + "px";
	if(parseInt(document.getElementById("mask").offsetWidth)>10)document.getElementById("mask").style.width = curWidth + "px";
	document.getElementById("progressIndicator").innerHTML = Math.floor((curLeft / parseInt(document.getElementById("gradient").offsetWidth))*100) + ".00% (" + (100 - Math.floor((curLeft / parseInt(document.getElementById("gradient").offsetWidth))*100)) * 200 + "MB left)";	
  if (Math.floor((curLeft / parseInt(document.getElementById("gradient").offsetWidth))*100) == Math.round(tot)) {
  document.getElementById("progressIndicator").innerHTML = tot + "% (" + Math.round(((100 - tot) * 200) )  + "MB left)";
  clearInterval(mInterval);

   }
}



function startProgressBar2(tot) {
	reset2();
	mInterval2 = setInterval("doProgress2(" + tot + ")",1800/tot);
}

function reset2() {
	document.getElementById("Bmask").style.left = "0px";
	document.getElementById("Bmask").style.width = document.getElementById("BmContainer").offsetWidth + "px";
	document.getElementById("BprogressIndicator").style.zIndex  = 10;
	document.getElementById("Bmask").style.display = "block";
	document.getElementById("BprogressIndicator").innerHTML = "0%";
}

function doProgress2(tot2) {

  curWidth2 = parseInt(document.getElementById("Bmask").offsetWidth);
	curLeft2 = parseInt(document.getElementById("Bmask").offsetLeft);

	curWidth2 --;
	curLeft2 ++;

	if(curLeft2 ==201) {
		clearInterval(mInterval2);
		document.getElementById("Bmask").style.display = "none";
		return;
	}


	document.getElementById("Bmask").style.left = curLeft2 + "px";
	if(parseInt(document.getElementById("Bmask").offsetWidth)>20)document.getElementById("Bmask").style.width = curWidth2 + "px";
	document.getElementById("BprogressIndicator").innerHTML = Math.floor((curLeft2 / parseInt(document.getElementById("Bgradient").offsetWidth))*100) + ".00% (" + (100 - Math.floor((curLeft2 / parseInt(document.getElementById("Bgradient").offsetWidth))*100)) * 2000 + "MB left)";
  if (Math.floor((curLeft2 / parseInt(document.getElementById("Bgradient").offsetWidth))*100) == Math.round(tot2)) {
  document.getElementById("BprogressIndicator").innerHTML = tot2 + "% (" + Math.round((100 - tot2) * 3000,2) + "MB left)";
  clearInterval(mInterval2);
  return; }
  
}
  function changeContent()
    {
    var x=document.getElementById('usersonline').rows[0].cells;
    x[0].innerHTML="NEW CONTENT";
    }
    
  function confirmSubmit()
  {
  var agree=confirm("This is NOT the searchbox, press Cancel if you wasn't trying to shout something we need to know.");
  if (agree)
  	return true ;
  else
  	return false ;
  }
