var lang={
	en : {
		noAnn : 'Announcements',
		name : 'name',
		ann : 'announcement',
		submit : 'submit',
		noHTTPReq : 'The browser does not support HTTP Request.',
		noName : 'You need to fill in both name and announcement!'
	},
	bg : {
		noAnn : 'Съобщения',
		name : 'име',
		ann : 'съобщениe',
		submit : 'изпрати',
		noHTTPReq : 'Браузърът не поддържа HTTP Request.',
		noName : 'Попълнете име и съобщение.'
	}
}

//user-set variables
var messageLen=200;//message content length
var str=lang.en;//default language
var recheck=1;//recheck or not
var recheckIn=60000;//recheck interval
var mySQLdead=new RegExp('Connection Error');//mySQL not accessible - test message

//initial values
var mySQLerr=0;//shown message for Connection Error
var inte;

if (parent.language) {if (parent.language=='bg') str=lang.bg}
function ajaxFunction() {
	var ajaxRequest;
	try {
		ajaxRequest = new XMLHttpRequest();
	} catch (e) {
		try {ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {
				alert("Your browser broke!");
				return false;
			}
		}
	}
	return ajaxRequest;
}
function showData(noHTTPReq) {
	htmlRequest2 = ajaxFunction();
	if (htmlRequest2==null) {
		alert (noHTTPReq);
		return;
	}
	var str="outputinfo.php?last="+document.getElementById('last').innerHTML;
	htmlRequest2.open("GET", str, true);
	htmlRequest2.onreadystatechange = function() {
		if (htmlRequest2.readyState == 4) {
			if (htmlRequest2.status == 200) {
				var area=document.getElementById("shoutarea");
				if (mySQLdead.test(htmlRequest2.responseText)) {
					if (mySQLerr==0) {
						mySQLerr=1;
						var str='<p id="alrt">Connection Error</p>'+area.innerHTML;
						area.innerHTML=str
					}
				return false
				}
				mySQLerr=0;
				if (htmlRequest2.responseText != '') area.innerHTML = htmlRequest2.responseText;
			} else {
				var str='<p id="alrt">ERROR: request status is: ' + htmlRequest2.status + '</p>'+area.innerHTML;
				area.innerHTML=str
			}
		}
	}
	htmlRequest2.send(null)
}
function saveData(messageLen, noHTTPReq, noName) {
	htmlRequest = ajaxFunction();
	if (htmlRequest==null) {
		alert (noHTTPReq);
		return;
	}
	if (document.shoutbox.shouter.value == "" || document.shoutbox.shouter.value == "NULL" || document.shoutbox.shouter_comment.value == "" || document.shoutbox.shouter_comment.value == "NULL") {
		alert(noName);
		return;
	}
	htmlRequest.open('POST', 'sendshout.php');
	htmlRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	htmlRequest.send('name='+document.shoutbox.shouter.value+'&message='+document.shoutbox.shouter_comment.value.slice(0,messageLen)); 

	document.shoutbox.shouter_comment.value = ''; // Updates the shout boxs text area to NULL.
	document.shoutbox.shouter_comment.focus(); // Focuses the text area.
	
	if (inte) {
		clearInterval(inte);
		inte=setInterval('showData(str.noHTTPReq)',recheckIn);
	};
	setTimeout('showData(str.noHTTPReq)',500);
}