var count = 0;
function addchoice(val)
{
	count +=1;
	document.getElementById("choices").innerHTML =  	document.getElementById("choices").innerHTML+'<div id="choice'+count +'"><div class="form-item"> <label for="choice-'+count +'-chtext">Choice '+count +': </label> <input maxlength="128" name="chtext['+count +']" id="choice-'+count +'-chtext" size="60" value="'+val+'" class="form-text error" type="text"></div><div class="form-item"> <label for="choice-'+count +'-chvotes">Votes for choice '+count +': </label> <input maxlength="7" name="chvotes['+count +']" id="choice-'+count +'-chvotes" size="5" value="0" class="form-text" type="text"></div></div>';
}
function deletechoice()
{

	document.getElementById("choice"+count ).innerHTML='';
	document.getElementById("choice"+count ).id='delete';
	count -=1;
}
function sendNewPoll(url)
{
	if(getCheckedValue(document.forms['form1'].elements['checkbox']) =="")
	{
		document.getElementById('error').innerHTML='<font color="#FF0000">الرجاء اختيار  الإجابة  </font>';
	}
	else
	{
		url += "&";
		url += "id="+document.getElementById('pollid').value;
		url += "&count="+document.getElementById('count').value;
		url += "&uid="+document.getElementById('uid').value;
		url += "&check="+getCheckedValue(document.forms['form1'].elements['checkbox']);
		url += "&chvotes="+getValues(document.forms['form1'].elements['chvotes']);
		url += "&title="+document.getElementById('polltitle').value;
		
		sndReq(url);
	}
	
}

function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}
function getValues(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	var values = "";
	
	for(var i = 0; i < radioLength; i++) {
		values += radioObj[i].value+",";
	}
	return values;
}

function sndReq(url) {
	
   AJAXGet(url,pollResponse,false,false);
}
function pollResponse(sText)
{
	if(sText)
	{
       document.getElementById('Pollcontents').innerHTML = sText;
       document.getElementById("voteButton").style.display = 'none';
	}
	else
	{
		alert(sText)
	}
}