// Open Popup
/*
 * PARAMETERS
 * - url (URL of the popup)
 * - name (Name of the popup)
 * - w (Width)
 * - h (Height)
 * - scrolling (no = 0 / yes = 1)
 */
function openPopup(url,name,w,h,scrolling) {
	leftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	topPosition = (screen.height) ? (screen.height-h)/2 : 0;
	settings = "height="+h+",width="+w+",top="+topPosition+",left="+leftPosition+",scrollbars="+scrolling+",resizable=0";
	window.open(url,name,settings);
}

// Post poll
//$(".mod-poll form").submit(function() {
//	openPopup($(this).attr("action"),"popupPoll","264","349",0);
//	return false;
//});


$(document).ready(function(){
	// Post poll
	$("#frm-poll").submit(function() {
		var voto = '';
		var id;
		var nivel;
		for (i=0;i<document.getElementsByTagName('input').length;i++)
		{
			if (document.getElementsByTagName('input')[i].getAttribute('type') == 'hidden' &&
				document.getElementsByTagName('input')[i].getAttribute('name') == 'n'){
				nivel = document.getElementsByTagName('input')[i].value;}
			if (document.getElementsByTagName('input')[i].getAttribute('type') == 'hidden' &&
				document.getElementsByTagName('input')[i].getAttribute('name') == 'id'){
				id = document.getElementsByTagName('input')[i].value;}
			if (document.getElementsByTagName('input')[i].getAttribute('type') == 'hidden' &&
			document.getElementsByTagName('input')[i].getAttribute('name') == 'url'){
			url = document.getElementsByTagName('input')[i].value;}
		//	if (document.getElementsByTagName('input')[i].getAttribute('type') == 'hidden' &&
		//		document.getElementsByTagName('input')[i].getAttribute('name') == 'pregunta'){
		//		pregunta = document.getElementsByTagName('input')[i].value;}
			if (document.getElementsByTagName('input')[i].getAttribute('type') == 'radio' &&
				document.getElementsByTagName('input')[i].getAttribute('name') == 'rdo-poll' &&
				document.getElementsByTagName('input')[i].checked == true){
				voto = document.getElementsByTagName('input')[i].value;}
		} 
										 
		openPopup($(this).attr("action")+'?id='+id+'&rdo-poll='+voto+'&n='+nivel+'&url='+url,"popupPoll", "264", "349" , "0");
		return false;
	});

	// Add in <a> event onclick 
	$("#frm-poll a.btn-general").click(function(){
		$("#frm-poll").submit();
		return false;
	});
});


