// JavaScript Document
MM_preloadImages('img/comunes/menu_opcion_3b.gif','img/comunes/menu_opcion_1b.gif','img/comunes/menu_opcion_2b.gif','img/comunes/menu_opcion_4b.gif','img/comunes/menu_opcion_5b.gif','img/comunes/menu_opcion_6b.gif','img/comunes/menu_opcion_7b.gif','img/comunes/menu_opcion_8b.gif','img/comunes/menu_opcion_9b.gif');


function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}


function checkLogin() {
    var formu = window.document.formlogin;
    if ( formu.email.value == "" ) {
        alert( "No has introducido ningún e-mail" );
        formu.email.focus();
    } else if ( formu.password.value == "" ) {
        alert( "No has introducido ningún password" );
        formu.password.focus();
    } else {
        formu.submit();
    }
}

function desplegarSegunda()
{
	var capa = document.getElementById("segundapregunta");
	var capa2 = document.getElementById("estadisticas");
	
	capa.style.display = "block";
	capa2.style.display = "block";
}

function desplegarEnviar()
{
	if (getCheckedValue(document.formencuesta.voto2) != "" && document.getElementById("comunidad").value != 0 && document.getElementById("edad").value != 0 && getCheckedValue(document.formencuesta.sexo) != "")
	{
		var capa = document.getElementById("botEnviarEncuesta");
		var capa2 = document.getElementById("botEnviarEncuestaDisabled");
		
		capa2.style.display = "none";
		capa.style.display = "block";
	}
}

function plegar()
{
	var capa1 = document.getElementById("botEnviarEncuesta");
	capa1.style.display = "none";
	var capa2 = document.getElementById("botVerResultados");
	capa2.style.display = "none";
	var capa3 = document.getElementById("botEnviarEncuestaDisabled");
	capa3.style.display = "none";
}

/////// AJAX
function createRequestObject(){
	  var peticion;
	  var browser = navigator.appName;
			if(browser == "Microsoft Internet Explorer"){
				  peticion = new ActiveXObject("Microsoft.XMLHTTP");
			}else{
				  peticion = new XMLHttpRequest();
}
return peticion;
}

var http = new Array();
function ObtDatos(url)
{
	var act = new Date();
	http[act] = createRequestObject();
	http[act].open('get', url);
	http[act].onreadystatechange = function() 
	{
		if (http[act].readyState == 4) 
		{
			if (http[act].status == 200 || http[act].status == 304) 
			{
				var texto;
				texto = http[act].responseText;
				var DivDestino = document.getElementById("encuesta");
				if (texto != "Error")
					DivDestino.innerHTML = '<div>'+texto+'</div>';
			}
		}
	}
	http[act].send(null);
}
 
function encuesta(accion) {
	
	  var voto1 = getCheckedValue(document.formencuesta.voto1);
	  var voto2 = getCheckedValue(document.formencuesta.voto2);
	  var comunidad = document.formencuesta.comunidad.value;
	  var edad = document.formencuesta.edad.value;
	  var sexo = getCheckedValue(document.formencuesta.sexo);
	  
	  var DivDestino = document.getElementById("encuesta");
	  
	  DivDestino.innerHTML = "<div></div>";
	  if (accion) 
	  {
		  plegar();
		  if (accion == "votar2" || accion == "resultados2")
		  {
		  	ObtDatos("ajax_encuesta2.php?accion="+accion+"&voto1="+voto1+"&voto2="+voto2+"&comunidad="+comunidad+"&sexo="+sexo+"&edad="+edad);  
		  }
		  else
		  {
		  	ObtDatos("ajax_encuesta.php?accion="+accion+"&voto1="+voto1+"&voto2="+voto2+"&comunidad="+comunidad+"&sexo="+sexo+"&edad="+edad);
		  }
	  } 
}

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 obtenerExtension(nombre)
{
	var extension = nombre.substr(nombre.lastIndexOf('.')+1);
	return extension.toLowerCase();
}

/*
	function cargardiscipulos() {	  
	  var DivDestino = document.getElementById("discipulos");
	  DivDestino.innerHTML = "<div></div>";
	  ObtDatos("ajax_discipulos.php?ID_registro=<?php echo $ID_registro?>");
}
*/
