// JavaScript Document
function add_a_poll(id){
	if(id.checked){
		document.getElementById('poll').style.display = 'block';
		var dom_polls = document.getElementById('dom_poll').getAttribute('value');
		document.getElementById('inc_poll').setAttribute('value',dom_polls);
	}else{
		document.getElementById('poll').style.display = 'none';
		document.getElementById('inc_poll').setAttribute('value',0);
	}
}
function add_question(id){
	last_p = id.parentNode;
	next_answer = parseInt(last_p.getAttribute('name'));
	this_poll = parseInt(last_p.parentNode.getAttribute('name'));
	
	new_p = document.createElement('p');
	new_text = document.createTextNode('Answer '+next_answer+': ');
	new_p.appendChild(new_text);
	new_input = document.createElement('input');
	new_input.setAttribute('type','text');
	new_input.setAttribute('name','poll_'+this_poll+'_'+next_answer);
	new_input.setAttribute('size',50);
	new_input.setAttribute('value','');
	new_p.appendChild(new_input);
	last_p.parentNode.insertBefore(new_p,last_p);
	last_p.setAttribute('name',next_answer+1);
}
function add_poll(id){
	var dom_polls = parseInt(document.getElementById('dom_poll').getAttribute('value'));
	document.getElementById('dom_poll').setAttribute('value',dom_polls+1);
	var this_poll_number = parseInt(id.parentNode.getAttribute('name'));
	id.parentNode.setAttribute('name',this_poll_number+1);
	last_p = id.parentNode;
	new_div = document.createElement('div');
	new_blockquote = document.createElement('blockquote');
	new_p_1 = document.createElement('p');
	new_p_2 = document.createElement('p');
	new_p_3 = document.createElement('p');
	new_p_4 = document.createElement('p');
	new_p_4.setAttribute('name','3');
	new_input_1 = document.createElement('input');
	new_input_2 = document.createElement('input');
	new_input_3 = document.createElement('input');
	new_input_4 = document.createElement('input');
	new_input_1.setAttribute('type','text');
	new_input_2.setAttribute('type','text');
	new_input_3.setAttribute('type','text');
	new_input_1.setAttribute('size','50');
	new_input_2.setAttribute('size','50');
	new_input_3.setAttribute('size','50');
	new_input_4.setAttribute('type','button');
	new_blockquote.setAttribute('name',this_poll_number);
	new_input_1.setAttribute('name','poll_'+this_poll_number);
	new_input_2.setAttribute('name','poll_'+this_poll_number+'_1');
	new_input_3.setAttribute('name','poll_'+this_poll_number+'_2');
	new_input_4.setAttribute('name','add_answer');
	new_input_4.setAttribute('value','Add another answer');
	new_input_4.setAttribute('onclick','add_question(this)');
	new_text_1 = document.createTextNode('Question: ');
	new_text_2 = document.createTextNode('Answer 1: ');
	new_text_3 = document.createTextNode('Answer 2: ');
	
	new_p_1.appendChild(new_text_1);
	new_p_2.appendChild(new_text_2);
	new_p_3.appendChild(new_text_3);
	new_p_1.appendChild(new_input_1);
	new_p_2.appendChild(new_input_2);
	new_p_3.appendChild(new_input_3);
	
	new_p_4.appendChild(new_input_4);
	
	new_blockquote.appendChild(new_p_2);
	new_blockquote.appendChild(new_p_3);
	new_blockquote.appendChild(new_p_4);
	
	new_div.appendChild(new_p_1);
	new_div.appendChild(new_blockquote);
	
	last_p.parentNode.insertBefore(new_div,last_p);
}
function vote_poll(id){
	var inputs = id.parentNode.getElementsByTagName('input');
	var target_ul = id.parentNode;
	var poll_id = id.parentNode.getAttribute('name');
	for(i=0;i<inputs.length;i++){
		if(inputs[i].getAttribute('type') == 'radio'){
			if(inputs[i].checked == true){
				vote_value = inputs[i].value;
			}
		}
	}
	request=GetXmlHttpObject();
		if (request==null){
		  alert ("Your browser does not support AJAX!");
		  return;
		  } 
	var url="http://www.euroherp.com/forum.php";
    request.open("POST",url,true);
	request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
	myData = "ajax=TRUE";
	myData += "&vote_poll=TRUE";
	myData += "&vote="+ vote_value;
	myData += "&poll="+ poll_id;
	request.send(myData);
	request.onreadystatechange=function (){
		if (request.readyState==4){ 
			target_ul.innerHTML=request.responseText;
		}
	};
}
