var BiaspherePoll={
query:function(url, data, out) {
	var ajaxRequest;
	try{
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				alert("Javascript Error");
				return "";
			}
		}
	}
	ajaxRequest.open('POST', url, false);
	ajaxRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	ajaxRequest.send(typeof(data)=="string" ? data : "");
	if(typeof(data)!=="string" && typeof(out)!=="string") {
		return ajaxRequest.status;
	}
	switch(typeof(out)=="string" && out.length>0 ? out.toLowerCase() : "default") {
	case "obj":
		return ajaxRequest;
	case "xml":
		return ajaxRequest.responseXML;
	default:
		return ajaxRequest.responseText;
	}
},
load:function(id, act) {
	document.getElementById('biasphere_poll_' + id).innerHTML=BiaspherePoll.query('/library/poll?id=' + id + (typeof(act)=="string" ? '&do=' + act : ''), '');
	return false;
},
init:function(id) {
	document.write("<div id=\"biasphere_poll_" + id + "\" class=\"poll\"></div>");
	BiaspherePoll.load(id);
},
vote:function(id, val) {
	var out="";
	if(typeof(val)=="string") {
		out=val;
	} else {
		var i=0;
		while(document.getElementById('poll' + id + 'option' + i)!==null) {
			if(document.getElementById('poll' + id + 'option' + i).checked) {
				out+=document.getElementById('poll' + id + 'option' + i).value + ';';
			}
			i++;
		}
	}
	document.getElementById('biasphere_poll_' + id).innerHTML=BiaspherePoll.query('/library/poll?id=' + id, 'submit=' + out);
	return false;
}
};
