/*
### desenvolvido por Aurelio de Morais - Aurl Informática ###

requer as funções: jquery-1.4.2.min.js

*** exemplo de parametro 'enquetes' - em JSON ***
	var enquetes=[
			{'idE':'1','pergunta':'O que você acha?','data':'21/10/2000','resposta':[
				{'id':1,'text':'bom','contador':1},
				{'id':2,'text':'médio','contador':12},
				{'id':3,'text':'ruim','contador':9}
			]},
			{'idE':'2','pergunta':'Você gostou?','data':'21/10/2000','resposta':[
				{'id':1,'text':'sim','contador':11},
				{'id':2,'text':'não','contador':44}
			]},
		]
*/
function loadEnquete(enquetes){
	var rand=function(n){return parseInt(Math.random()*n);}
	var I=rand(enquetes.length);
	
	var html='';
	var idE =  enquetes[I].idE;
	var resp = enquetes[I].resposta;
	var i=0;

	html+="<form name='formEnquete_"+idE+"' id='formEnquete_"+idE+"' class='forms bxEnquete'>";
	
	html+='<h4>'+ enquetes[I].pergunta +'</h4>';
		for(i=0;i<resp.length;i++){
			html+="<label><input type='radio' name='idResp' id='resp_"+idE+"_"+resp[i].id+"' value='"+resp[i].id+"'/>"+resp[i].text+"</label>";
		}
	html+="<input type='submit' name='bt' value='Votar' class='bte color' />";//<input type='button' name='bt' class='bte res' id='bt' value='Resultado Parcial'/>";
	html+="<a href='#' id='bt'>Resultado Parcial</a>";
	
	html+="<input type='hidden' name='idE' value='"+idE+"'/>";
	html+="</form>";

	document.write(html);
	
	$('form#formEnquete_'+idE).bind('submit',function(){
		var f=$(this)
		if(f.find('input[checked=true]').val()==undefined){
			alert('Selecione uma opção.');return false;
		}else{
			var woenq = window.open('','woenq','scrollbars=1,width=622, height=360, top=10, left=10');
			if(window.focus){woenq.focus();}
			f.attr({'target':'woenq','method':'post','action':siteUrl+'/enquete/script.asp?id='+idE });
		};
		
	})
	.find('a#bt').bind('click',function(){
		var woenq = window.open(siteUrl+'/enquete/script.asp?idE='+idE+'&view=1','woenq','scrollbars=1,width=622, height=360, top=10, left=10');
		if(window.focus){woenq.focus();}
	});
};


