function GetXmlHttpObject(){
	var xmlHttp=null;
	try{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
		if (xmlHttp.overrideMimeType) {
         	// set type accordingly to anticipated content type
            //xmlHttp.overrideMimeType('text/xml');
            xmlHttp.overrideMimeType('text/html');
         }
	}
	catch (e){
    	// Internet Explorer
	    try{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e){
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
    }
	return xmlHttp;
}

function vote(comment, vote)
{
	var xhr = GetXmlHttpObject();
	xhr.open("POST", "assist.php", true);		
	xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
	xhr.onreadystatechange=function(){
		if(xhr.readyState == 4){
			tmp = document.getElementById("voteup"+comment).className;
			if(vote=="1"){
				if(document.getElementById("voteup"+comment).className.replace('selected_vote','') == tmp) {
					document.getElementById('voteup'+comment).className = "selected_vote";
					document.getElementById('votedown'+comment).className = "";
				} else {
					document.getElementById('voteup'+comment).className = "";
					document.getElementById('votedown'+comment).className = "";			
				}
			}
			tmp2 = document.getElementById("votedown"+comment).className;
			if(vote=="-1"){
				if(document.getElementById("votedown"+comment).className.replace('selected_vote','') == tmp2) {
					document.getElementById('voteup'+comment).className = "";
					document.getElementById('votedown'+comment).className = "selected_vote";
				} else {
					document.getElementById('voteup'+comment).className = "";
					document.getElementById('votedown'+comment).className = "";			
				}
			}
			document.getElementById('points'+comment).innerHTML = xhr.responseText;
		}
	}
	xhr.send("comment="+comment+"&vote="+vote); 
//	xhr.setRequestHeader('Connection', 'close');
}

function replytocomment(comment_id){
	document.getElementById('replyingto').value = comment_id;
	window.location = "#comment_box";
	document.getElementById('response').focus();
	if(comment_id!="-1"){
		document.getElementById('comment_heading').innerHTML = "Replying to comment "+comment_id+" [<a href='javascript:replytocomment(-1);'>cancel reply</a>]";
	} else {
			document.getElementById('comment_heading').innerHTML = "What is the answer to this puzzle?";
	}
}
