// Ergonet JavaScript Document :: Conducta : Shout Box
function shoutSubmit() {
	var obj = document.getElementById('shoutBoxInput');
	var obj1 = document.getElementById('pid');
	if (obj != null && obj1 != null) {
		var shout=obj.value;
		obj.value='';
		var pid = obj1.value;
		var path = "/lib/conducta/app/shoutBox.php";
		if (shout && pid) {
			var params="shoutBoxInput="+shout+"&pid="+pid;
			shoutXHR(path,params);
		} else {
			populate('shoutBoxDisplayOnShowPage','Please Shout something!');
		}
		return false;
	}
}
function shoutXHR(path,params) {
	loading('1','Loading');
	div='evaluate';
	xmlhttp = false;
	createXMLHttpObject();
	xmlhttp.open("POST",path,true);
	xmlhttp.onreadystatechange = setAnyInnerHtml;
	xmlhttp.initialise;
	xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
	xmlhttp.send(params);
}
function runShout() {
	var shoutBox = document.getElementById('shoutBox');
	if (shoutBox) {
		shoutBox.innerHTML="<div id='shoutSleeve' style='left:0px'>" + "Shout Box initialising" + "</div>";
		shoutTimeout = window.setTimeout('shoutGet()',1000);
	}
}
var shoutTimeout=null;
var shoutGetStringTimeoutInterval=30000;
var shoutAnimateTimeout=null;
var maxLetters=400;
var shoutString='';
var shoutStringCurrent='';
var currentSleeveLeft=0;
var showPagePid=0;
function shoutGet() {
	//window.clearTimeout(shoutGetStringTimeoutInterval);
	var path = "/lib/conducta/app/shoutBox.php";
	var params = "func=getString";
	if (showPagePid) {
		params += "&showPagePid="+showPagePid;
	}
	shoutXHR(path,params);
	shoutTimeout = window.setTimeout('shoutGet()',shoutGetStringTimeoutInterval);
}
function shoutDisplay(str) {
	if (shoutString != str && str!='') {
		shoutString = str;
		shoutStringCurrent = "<div id='shoutSleeve' style='left:0px'>" + shoutString + "</div>";
		var shoutBox = document.getElementById('shoutBox');
		if (shoutBox) {
			shoutBox.innerHTML = shoutStringCurrent;
		}
		currentSleeveLeft = 500;
		shoutAnimate();
	}
}
function shoutAnimate() {
	var shoutBox = document.getElementById('shoutBox');
	if (shoutBox) {
		window.clearTimeout(shoutAnimateTimeout);
		/*
		var ltr = shoutStringCurrent.substr(0,1);
		shoutStringCurrent = shoutStringCurrent.substr(1)+ltr;
		shoutBox.innerHTML = shoutStringCurrent;
		*/
		var shoutSleeve = document.getElementById('shoutSleeve');
		if (shoutSleeve != null) {
			var width=shoutSleeve.offsetWidth;
			//if (width<1000) { width=1000; }
			currentSleeveLeft--;
			if ( currentSleeveLeft < ((width-500)*-1)) { currentSleeveLeft=918; }
			shoutSleeve.style.left=currentSleeveLeft+'px';
			shoutAnimateTimeout = window.setTimeout('shoutAnimate()',10);
		}
	}
}

