function createRequestObject() {
	http = false;
	try {
		http = new XMLHttpRequest();
	}
	catch (ie) {
		try {
			http = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (ieagain) {
			try {
				http = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (failed) {
				http = false;
			}
		}
	}

	if (!http) {
		alert("Error initializing.");
	}
	return http;
}

var http = createRequestObject(); 
var reqcomments = [];
function togglecomments(newsid) {
	var el = 'comments_'+newsid;
	toggle(el);
	if(reqcomments[newsid] != 'yes') {
		reqcomments[newsid] = 'yes';
		getComments(newsid);
	}
}

function toggle(obj) {
	var el = document.getElementById(obj);
	if ( el.style.display != 'none' ) {
		//alert('toggle: is visible. Hide');
		el.style.display = 'none';
	}
	else
	{
		//alert('toggle: is hiding. Show');
		el.style.display = '';
	}
}

function displaycommentloading(newsid) {
        document.getElementById('comments_load_'+newsid).innerHTML = '<img src="./img/loading.gif" alt="" />';
}
function hidecommentloading(newsid) {
	document.getElementById('comments_load_'+newsid).innerHTML = '';
}

function displayloading() {
	/*document.getElementById('loading').style.display = 'block'; */
}

function hideloading() {
	/*document.getElementById('loading').style.display = 'none'; */
}

function getComments(newsid){
	displaycommentloading(newsid);
	http.open('GET', 'index.php?m=article_internal&a=view_comments&id='+newsid);
	http.onreadystatechange = function() { handleComment(newsid); }
	http.send(null);
}

function handleComment(newsid){
	if((http.readyState == 4 || http.readyState=="complete")){ //Finished loading the response
		if(http.status == 200)
		{
			var response = http.responseText;
			hidecommentloading(newsid);
			
			document.getElementById('comments_'+newsid).style.display = 'block';
			document.getElementById('comments_'+newsid).innerHTML = response + document.getElementById('comments_'+newsid).innerHTML;
		}
		else
		{
			hideloading();
			document.getElementById('comments'+newsid).innerHTML = http.statusText;
		}
	}
}

