function GetXmlHttpObject()
{
	var xmlHttp=null;		
	try
    {
    	// Firefox, Opera 8.0+, Safari
    	xmlHttp=new XMLHttpRequest();
    }
  	catch (e)
    {
    	// Internet Explorer
    	try
     	{
      		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      	}
    	catch (e)
      	{
      		xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      	}
    }
  	return xmlHttp;
}
	
function showHint(str)
{
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
  	{
  		alert ("Your browser does not support AJAX!");
  		return;
  	} 
	var url="inc/getschools.php";
	url=url+"?s="+str;
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=function()
  	{
  		if(xmlHttp.readyState==4)
    	{
    		if(xmlHttp.responseText == -1) {
    			document.getElementById("schoolscroll").innerHTML='<div style="margin: 5px;">Sorry, your school doesn\'t have a board yet. Request a board in the box to the right!</div>';
    			document.getElementById("new_school").value=str;
    		}
    		else {
    			document.getElementById("schoolscroll").innerHTML=xmlHttp.responseText;
    			document.getElementById("new_school").value='';
    		}
	    }
  	}
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function report(post_id, type) {
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
  	{
  		alert ("Your browser does not support AJAX!");
  		return;
  	} 
  	document.getElementById("report_"+type+post_id).innerHTML='reported';
	var url="inc/report.php";
	url=url+"?id="+post_id;
	url=url+"&type="+type;
	url=url+"&sid="+Math.random();

	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function vote(post_id, type, dir, factor) {
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
  	{
  		alert ("Your browser does not support AJAX!");
  		return;
  	} 
  	
  	numvotes = parseInt(document.getElementById('numvotes_'+type+'_'+post_id).innerHTML);
	
	if(dir=='up') {
		numvotes++;
	}
	else if(dir=='down') {
		numvotes--;
	}

  	document.getElementById('numvotes_'+type+'_'+post_id).innerHTML = numvotes;
  	
  	if(numvotes == 1) {
  		document.getElementById('votetext_'+type+'_'+post_id).innerHTML = 'vote';
  	}
  	else {
  		document.getElementById('votetext_'+type+'_'+post_id).innerHTML = 'votes';
  	}

	var url="inc/vote.php";
	url=url+"?id="+post_id;
	url=url+"&type="+type;
	url=url+"&dir="+dir;
	url=url+"&factor="+factor;
	url=url+"&sid="+Math.random();

	xmlHttp.open("GET",url,true);
	
	xmlHttp.send(null);
}


