function fRequest(method, action, param, async, func)
{
	var xhr;

	if(window.XMLHttpRequest)
	{
		xhr = new XMLHttpRequest();
	}
	else if(window.ActiveXObject)
	{
		xhr = new ActiveXObject("Microsoft.XMLHTTP");
	}

	if(method=="get")
	{
		xhr.open("GET", action+"?"+param, async);
		if(async == true) xhr.onreadystatechange = function(){func(xhr);};
		xhr.send(null);
		if(async == false) func(xhr);
	}
	else if(method=="post")
	{
		xhr.open("POST", action, async);
		xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		if(async == true) xhr.onreadystatechange = function(){func(xhr);};
		xhr.send(param);
		if(async == false) func(xhr);
	}
}


function fShowHide(id)
{
	id = document.getElementById(id);
	(id.style.display == 'block') ? (id.style.display = 'none') : (id.style.display = 'block');
}

function fNewWordAdd()
{
	word = document.getElementById('lnew_word');
	words = document.getElementById('lwords');
	fRequest('post', 'ajax_words.php', 'word_add=1&word='+encodeURIComponent(word.value), true,
		function(xhr)
		{
			if(xhr.readyState==4 && xhr.status==200)
			{
				document.getElementById('lwords').innerHTML = xhr.responseText;
				document.getElementById('lnew_word').value = '';
			}
		});
}

function fWordDel(id)
{
	fRequest('post', 'ajax_words.php', 'word_del=1&id='+id, true,
		function(xhr)
		{
			if(xhr.readyState==4 && xhr.status==200)
			{
				document.getElementById('lwords').innerHTML = xhr.responseText;
			}
		});
}

function fRating(id, value)
{
	fRequest('post', 'ajax_rating.php', 'id='+id+'&value='+value, true,
		function(xhr)
		{
			if(xhr.readyState==4 && xhr.status==200)
			{
				document.getElementById('ldefinition_rating_'+id).innerHTML = xhr.responseText;
			}
		});
}

function fAbuse(id)
{
	definition_abuse = document.getElementById('definition_abuse_'+id);
	fRequest('post', 'ajax_abuse.php', 'id='+id+'&abuse='+definition_abuse.value, true,
		function(xhr)
		{
			if(xhr.readyState==4 && xhr.status==200)
			{
				document.getElementById('ldefinition_abuse_'+id).innerHTML = xhr.responseText;
			}
		});
}
