
function setCookie(name, value)
         {
         //If name is the empty string, it places a ; at the beginning
         //of document.cookie, causing clearCookies() to malfunction.
         if(name != '')
            document.cookie = name + '=' + value;
         }

function ReadCookie(cookieName) {
 var theCookie=""+document.cookie;
 var ind=theCookie.indexOf(cookieName);
 if (ind==-1 || cookieName=="") return ""; 
 var ind1=theCookie.indexOf(';',ind);
 if (ind1==-1) ind1=theCookie.length; 
 return unescape(theCookie.substring(ind+cookieName.length+1,ind1));
}



//----------------------------------------------------------
function show_iframe(w,h,src){
	//alert("aaaaaaaa")
	LeftPosition = (screen.width) ? (screen.width - w)/2 : 200;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 500;
	w = w + 16;
/*	if(h == 600) h = h/2;*/
//	w = 200;
//	h = 0;
	window.open(src,'','width='+w+',height='+h+',resizable=no, scrollbars=no, status=no,titlebar=no');
	//window.open(ventana,'','width=440, height=650, resizable=no, scrollbars=yes, status=no, left=' + posL +',top=' + posR +" ' " );
}
//----------------------------------------------------------
function ischecked() {
	//alert("bbbbbbbb")
 	opc = document.forms.encuesta.opcion;
	val = 0;

	for (var i = 0 ; i < opc.length ; i++) {
		if (opc[i].checked) {val = opc[i].value;}
    }
	
	
	return val;
}
//----------------------------------------------------------
/*function validarVoto(id_encuesta){
	alert("cccccc")
	var voto = fetchNamedCookie("encuesta_"+id_encuesta);
	
	if(voto != "voto"){/*El tipo no voto todav?a*/
	/*	var oDiv = document.getElementById("votar");

		oDiv.style.display = "block";
	}
	else{/*El tipo ya voto*/
	/*	var oMsjEncuesta = document.getElementById("mensaje");
				
		oMsjEncuesta.style.display = "block";
		oMsjEncuesta.innerHTML = "Usted ya vot&oacute;.";
	}
}*/
//----------------------------------------------------------

function votar(id_encuesta,acc){
	
	
	
	/*var voto = fetchNamedCookie("encuesta_"+id_encuesta);*/
	//alert(id_encuesta);
	/*if(validarEleccion(id_encuesta)){	alert('111111111111111111');
	if(acc == "voto" ){alert('2222222222222222');
		var oMsjEncuesta = document.getElementById("mensaje"+id_encuesta);
		oMsjEncuesta.style.display = "block";
		oMsjEncuesta.innerHTML = "Usted ya vot&oacute;.";
		
		document.getElementById("votar"+id_encuesta).style.display = "none";
	}*/
		
	if(validarEleccion(id_encuesta)>0){//alert('33333333333333333333');
		
			if(acc != "noVoto") {//alert('4444444444444444444444444');
				//if(value > 0){alert('555555555555555555555555555');
					//show_iframe(440,490,"/encuestas/ver_resultados.php?id=" + id_encuesta + "&idopcion=" + value + "&ver=1");
				   	  	
				
					
				cargarvoto("/encuestas/votar.php?v1=" + id_encuesta + "&voto=1"+ "&v2="+validarEleccion(id_encuesta),id_encuesta);
				setCookie( "encuesta_"+id_encuesta, "voto");
					//show_iframe(0,0,"/encuestas/ver_resultados.php2?id=" + id_encuesta + "&voto=1"+ "&opcion="+value);
				//}
				var oMsjEncuesta = document.getElementById("mensaje"+id_encuesta);
		oMsjEncuesta.style.display = "block";
		oMsjEncuesta.innerHTML = "Usted ya vot&oacute;.";
		
		document.getElementById("votar"+id_encuesta).style.display = "none";
				// show_iframe(440,490,"/encuestas/ver_resultados.php?id=" + id_encuesta + "&voto=1");
			}
			else show_iframe(440,490,"/encuestas/ver_resultados.php?id=" + id_encuesta + "&voto=1");
	}
	else{//alert('6666666666666666666666666');
		if(acc == "noVoto"){//alert('77777777777777777777777');
			show_iframe(440,490,"/encuestas/ver_resultados.php?id=" + id_encuesta + "&voto=1"+ "&opcion="+value);
		}
		else{
			//alert('888888888888888888888888888888');
			var oMsjEncuesta = document.getElementById("mensaje"+id_encuesta);
			oMsjEncuesta.style.display = "block";
			oMsjEncuesta.innerHTML = "Seleccione opci&oacute;n";
			return false;
		}
	//alert("Para votar primero debe seleccionar una opci?n de la encuesta.");
	}
}


//----------------------------------------------------------
function validarEleccion(id){//retorna la opcion a la cual se voto en la encuesta TIENE QUE SER ID MAYOR A 0

	var encu='encuesta'+id;
	
	opc = document.getElementById(encu).opcion;
	//alert(opc);
	val = 0;

	for (var i = 0 ; i < opc.length ; i++) {
		
		if (opc[i].checked) val = opc[i].value;
    }

		return val;
	
}

/*Limpiar msj correspondientes a la encuesta*/
function limpiarMsj(id){	
	//alert("ggggggg")
	if(document.getElementById("votar"+id).style.display == "block"){
		var oMsjEncuesta = document.getElementById("mensaje"+id);
		oMsjEncuesta.style.display = "none";
	}
}

function crearObjetoAjax(){
	var obj;
	if(window.XMLHttpRequest){ // no es IE
		obj = new XMLHttpRequest();
	}
	else{ // Es IE o no tiene el objeto
		try {
			obj = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch (e) {
			alert('El navegador utilizado no está soportado');
		}
	}
	return obj;
}

//--------------------------------------------------
function cargarvoto(url,id)
{	//alert("hhhhhhhhhh")
	 
	//$('logoAjaxLoad').show();
	
	oXML = crearObjetoAjax();
	oXML.open("GET",url);
	
	oXML.onreadystatechange = function(){
		
		if (oXML.readyState == 4 ){			
			var resp = oXML.responseText;
			
			document.getElementById("enc_ver"+id).innerHTML=resp;
		}						
	}
	
	oXML.send(null);
	
	
}

