var previous_tab_id = 0;
var answer_id = 0;
var voted = false;
function tabClick(id)	{
	if (previous_tab_id != id) {
		document.getElementById('tab'+id).className = 'homeTabSelected';				
		document.getElementById('tabc'+id).style.display = 'block';				
		document.getElementById('tab'+previous_tab_id).className = 'homeTab';				
		document.getElementById('tabc'+previous_tab_id).style.display = 'none';				
		previous_tab_id = id;
	}		
}function tabClickN(id)	{
	if (previous_tab_id != id) {
		document.getElementById('tab'+id).className = 'homeTabSelectedN';				
		document.getElementById('tabc'+id).style.display = 'block';				
		document.getElementById('tab'+previous_tab_id).className = 'homeTabN';				
		document.getElementById('tabc'+previous_tab_id).style.display = 'none';				
		previous_tab_id = id;
	}		
}
function vote(question_id) {
	if (answer_id != 0) {		
		xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null){
			alert ("Browser does not support HTTP Request");
			return;
		} 
	
		var url = WWW_ROOT + "/lib/vote.jsp?&";
		url=url + "questionId=" + question_id;
		url=url + "&answerId=" + answer_id;
		url=url + "&sid="+Math.random();
		xmlHttp.onreadystatechange=stateChanged;
	//	netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	}	
}
function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}
function stateChanged() { 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 			
		if (trim(xmlHttp.responseText) != 'voted') {
			document.getElementById('answers').innerHTML = xmlHttp.responseText;		
		}else{
			votedAlert();
		}	
	} 
}
function changeVote(id) {
	if (answer_id != 0) {
		document.getElementById('answer'+answer_id).checked = false;
	}
	answer_id = id;
}
function GetXmlHttpObject(){ 
	var objXMLHttp=null
	if (window.XMLHttpRequest)
	{			
		objXMLHttp=new XMLHttpRequest()
	}
	else if (window.ActiveXObject)
	{
	objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
	}
	return objXMLHttp
}
