function getSection(id)
{
	var http = ajaxInitial();
	var url = "getSections.php?id=" + id;
	http.open("GET", url, true);
	
	http.onreadystatechange = function(){
		if(http.readyState == 4 && http.status == 200) {
			document.getElementById("section").innerHTML = http.responseText;
		}
	}
	http.send(null);
}
function getArticles(section_id, category_id)
{
	var http = ajaxInitial();
	var url = "getArticles.php?s="  + section_id + '&c=' + category_id;
	http.open("GET", url, true);
	
	http.onreadystatechange = function(){
		if(http.readyState == 4 && http.status == 200) {
			document.getElementById("articles").innerHTML = http.responseText;
		}
	}
	http.send(null);
}

function ajaxInitial()
{
	try {
	  request = new XMLHttpRequest();
	} catch (trymicrosoft) {
	  try {
		request = new ActiveXObject("Msxml2.XMLHTTP");
	  } catch (othermicrosoft) {
		try {
		  request = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (failed) {
		  request = false;
		}
	  }
	}
	
	if (!request)
		alert("Error initializing XMLHttpRequest!");
	return request;
}

function refreshCount()
{

}

function searchArticle()
{
	var section_id = document.getElementById('section').value;
	var category_id = document.getElementById('category').value;
	getArticles(section_id, category_id);
}

function searchArticleByTerm()
{
	var term = document.getElementById('search_term').value;

	if(!term)
	{
		alert('Please type in search term');
		document.getElementById('search_term').focus();
	}else{
		getArticlesByTerm(term);
	}

	return false;
}

function clearResult()
{
	document.getElementById("articles").innerHTML = "";
}

function getArticlesByTerm(term)
{
	var http = ajaxInitial();
	var url = "getArticlesByTerm.php?t="  + term;
	http.open("GET", url, true);
	
	http.onreadystatechange = function(){
		if(http.readyState == 4 && http.status == 200) {
			document.getElementById("articles").innerHTML = http.responseText;
		}
	}
	http.send(null);
}