/**
* Shoutbox's Ajax Processing Interface
*
* @author: shiek wei
* @date created: 01 nov 2006
* @last modified: 03 nov 2006
*
* @change log
* YYYY/MM/DD	description
*/

var reqObj1;
var reqObj2;

function initRequestObj() { 
	var objXMLHttp = null
	if (window.XMLHttpRequest) { objXMLHttp = new XMLHttpRequest() } 
	else if (window.ActiveXObject) { objXMLHttp = new ActiveXObject("Microsoft.XMLHTTP") }
	return objXMLHttp
}

function getShoutData(q){
	var quantity = q
	reqObj1 = initRequestObj();
	if (reqObj1 != null){
	 	reqObj1.open("GET", "index.php?tpl=blog_shoutprocess&quantity="+quantity, true);
	  	reqObj1.onreadystatechange = showShoutData;	
		reqObj1.send(null);
		setTimeout("getShoutData("+quantity+")", 10000);	
	}
}

function showShoutData()  { 
	if (reqObj1.readyState == 4 && reqObj1.status == 200) { 
		document.getElementById("contents").innerHTML = reqObj1.responseText;
	}
}

function submitShoutData() {

	var poststr = "tpl=blog_shoutprocess&postshout=1" +				  
	              "&message=" + encodeURI( document.getElementById("message").value );
	              
	reqObj2 = initRequestObj();
	if (reqObj2 != null){		
		reqObj2.open("POST", 'index.php', true);
		reqObj2.onreadystatechange = showChangedData;
		reqObj2.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		reqObj2.setRequestHeader("Content-length", poststr.length);
		reqObj2.setRequestHeader("Connection", "close");
		reqObj2.send(poststr);
	} 	
}

function showChangedData()  { 
	if (reqObj2.readyState == 4 && reqObj2.status == 200) { 
		document.getElementById("contents").innerHTML = reqObj2.responseText;
	}
}

function refreshContent(id) {
	window.location.replace(id);
}