var xmlHttp
var admi_gid 
function createpoll(id)
{
admi_gid =id;
 var oForm = document.groupfrm;

 if(trim(oForm.pollquestion.value)=='' ||trim(oForm.pollquestion.value)=='Title' )
	{
 alert('Please enter poll question.');
 return false;
 }

 	var objElements = oForm.elements;
	var retObjFound = null;
	var y=1;
	var cnt=0;
	document.groupfrm.task.value ='savepolls';

	for(iCtr = 0; iCtr < objElements.length; iCtr ++)
	{ 
		if(objElements[iCtr].name.indexOf('polloption') > -1)
		{ 
			if(objElements[iCtr].value!='' && objElements[iCtr].value!= 'option'+y )
			{cnt++;}
			y++
		}
	}

 if(oForm.toicoption.value==0 && oForm.newtopic.checked==false )
	{
 alert('Please select a topic or check option for create a new topic.');
 return false;
 }
 if(cnt<2)
	 	{
 alert('Please enter at least two options to create a poll.');
 return false;
 }

	for(iCtr = 0; iCtr < objElements.length; iCtr ++)
	{ 
		if(objElements[iCtr].name.indexOf('polloption') > -1)
		{ 
			if(objElements[iCtr].value== objElements[iCtr].title )
			{objElements[iCtr].value='';}
		}
	}

 var sBody = getRequestBody(oForm);

	if(window.XMLHttpRequest)
	{

		req = new XMLHttpRequest();
	} 
	else if(window.ActiveXObject)
	{

		req = new ActiveXObject("Microsoft.XMLHTTP");
	}

			req.open("post", "index2.php?no_html=1&option=com_group", true);
            req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

	req.onreadystatechange = statechanged1;
	req.send(sBody);
}

function statechanged1() 
{
	if(req.readyState == 4)
	{
		if(req.status == 200) 
			{
					ajaxpage('index2.php?no_html=1&option=com_group&task=polls&group_id='+admi_gid, 'displaypan');
			} 
	}
}

    function getRequestBody(oForm) {
            var aParams = new Array();
            
            for (var i=0 ; i < oForm.elements.length; i++) {
                var sParam = encodeURIComponent(oForm.elements[i].name);
                sParam += "=";
                sParam += encodeURIComponent(oForm.elements[i].value);
                aParams.push(sParam);
            } 
            
            return aParams.join("&");        
        }