var thevoteid = 0;
var submitremaining = 4000;

function voteup(id)
{
	thevoteid = id;
	var VoteUp_ajReq;  // The variable that makes Ajax possible!
	
	try
	{
		// Opera 8.0+, Firefox, Safari
		VoteUp_ajReq = new XMLHttpRequest();
	}
	catch (e)
	{
		// Internet Explorer Browsers
		try
		{
			VoteUp_ajReq = new ActiveXObject("Msxml2.XMLHTTP");
		}	
		catch (e) 
		{
			try
			{
				VoteUp_ajReq = new ActiveXObject("Microsoft.XMLHTTP");
			}	 
			catch (e)
			{
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}
	// Create a function that will receive data sent from the server
	VoteUp_ajReq.onreadystatechange = function()
	{
		if(VoteUp_ajReq.readyState == 4)
		{
			
			if (VoteUp_ajReq.responseText.substr(0,6)=="succes")
			{
				document.getElementById('votes' + thevoteid).innerHTML = "<em>" + VoteUp_ajReq.responseText.substr(7) +"";
			}
			else
			{
				alert(VoteUp_ajReq.responseText);
			}	
			//VoteUp_ajReq.responseText;
		}
		
	}
	var theurl = "voteajax.php?action=voteup&id=" +  thevoteid;
	VoteUp_ajReq.open("GET", theurl, true);
	VoteUp_ajReq.send(null); 
}


function votedown(id)
{
	thevoteid = id;
	var VoteDown_ajReq;  // The variable that makes Ajax possible!
	
	try
	{
		// Opera 8.0+, Firefox, Safari
		VoteDown_ajReq = new XMLHttpRequest();
	}
	catch (e)
	{
		// Internet Explorer Browsers
		try
		{
			VoteDown_ajReq = new ActiveXObject("Msxml2.XMLHTTP");
		}	
		catch (e)
		{
			try
			{
				VoteDown_ajReq = new ActiveXObject("Microsoft.XMLHTTP");
			}	 
			catch (e)
			{
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}
	// Create a function that will receive data sent from the server
	VoteDown_ajReq.onreadystatechange = function()
	{
		if(VoteDown_ajReq.readyState == 4)
		{
			
			if (VoteDown_ajReq.responseText.substr(0,6)=="succes")
			{
				document.getElementById('votes' + thevoteid).innerHTML = VoteDown_ajReq.responseText.substr(7);
			}
			else
			{
				alert(VoteDown_ajReq.responseText);
			}	
			//VoteDown_ajReq.responseText;
		}
		
	}
	var theurl = "voteajax.php?action=votedown&id=" +  thevoteid;
	VoteDown_ajReq.open("GET", theurl, true);
	VoteDown_ajReq.send(null); 
}

function remaining()
{
	//max characters = 1000;
	submitremaining = (4000-document.submitquote.chatlog.value.length);
	if (submitremaining>-1)
	{
		document.getElementById('remaining').innerHTML = submitremaining + " characters remaining";
	}
	else
	{
		document.getElementById('remaining').innerHTML =  "<span style=\"color: #FF0000;\">" + submitremaining + "</span> characters remaining. Any text exceeding the limit will be cut off.";
	}
	var a = setTimeout('remaining()', 200);
}	
function clearbox()
{
	if (confirm("Are you sure you want to clear the input field?"))
	{
		document.submitquote.chatlog.value = "";
	}
}
