// JavaScript Document
function estaVacio (texto){
	if (texto == null || texto == ""){ 
		return true;
	}
	return false;
}

function INIchequear(form,op,preg,rs,id,sesion){
 miopcion = -1;
 for (i=op.length - 1; i > -1; i--) {
  if (op[i].checked) {
   miopcion = i
   i = -1
  }
 }
 if (miopcion == -1) {
  alert("Es necesario seleccionar una de las opciones");
 }else{
  if (rs == 1){
	 form.action = "./encuestas/" + sesion + ".asp?opp=acceso&pregunta=" + preg + "&rs="+rs + "&id=" + id + "&subencuesta=" + miopcion  
  }else{
	if (window.showModalDialog) {
		op = window.showModalDialog("./encuestas/subencuesta.asp","Perfil del votante","dialogWidth:260px;dialogHeight:260px;center:yes;resizable:no;scroll:no;status:no;unadorned:no;edge:Raised;");		
		if (op ){			
			form.action = "./encuestas/realizarVotacion.asp?pregunta=" + preg + "&rs="+rs + "&id=" + id + "&subencuesta=" + op 
		}
	}
	
  }
  form.submit()
 }

}



function chequear(form,op,preg,rs,id,sesion){

 miopcion = -1;
 for (i=op.length - 1; i > -1; i--) {
  if (op[i].checked) {
   miopcion = i
   i = -1
  }
 }
 
 if (miopcion == -1) {
  alert("Es necesario seleccionar una de las opciones");
 }else{
  if (rs == 1){	
	 form.action = "./" + sesion + ".asp?opp=acceso&pregunta=" + preg + "&rs="+rs + "&id=" + id + "&subencuesta=" + miopcion  
  }else{
	if (window.showModalDialog) {
		op = window.showModalDialog("./subencuesta.asp","Perfil del votante","dialogWidth:260px;dialogHeight:260px;center:yes;resizable:no;scroll:no;status:no;unadorned:no;edge:Raised;");			
		if (op ){			
			form.action = sesion + ".asp?opp=realizarVotacion&pregunta=" + preg + "&rs="+rs + "&id=" + id + "&subencuesta=" + op   
		}
	}
	
  }
  form.submit()
 }

}

function selectAll(selectBox) {
	for (var i = 0; i < selectBox.options.length; i++) {		
		selectBox.options[i].selected = true;
	}
	
}

function removeOption(theSel){
  var selIndex = theSel.selectedIndex;
  if (selIndex != -1) {
    for(i=theSel.length-1; i>=0; i--)
    {
      if(theSel.options[i].selected)
      {
        theSel.options[i] = null;
      }
    }
    if (theSel.length > 0) {
      theSel.selectedIndex = selIndex == 0 ? 0 : selIndex - 1;
    }
  }

}


function addItem(){    

	var newLength = document.getElementById("lista").length;
	var pref = newLength + 1
	var texto = document.getElementById("respuesta").value
	if (texto != ""){
     document.getElementById("lista")[newLength] = document.createElement("option");
     document.getElementById("lista")[newLength].text=pref +".   " + texto;
	 document.getElementById("respuesta").value = "";
	}
     return false;
}


function uno(src,color_entrada) { 
    src.bgColor=color_entrada; src.style.cursor="hand"; 
} 
function dos(src,color_default) { 
    src.bgColor=color_default; src.style.cursor="default"; 
} 



function finalizarAñadirEncuestas(form){
	if(estaVacio(form.pregunta.value)){
		alert('Introducir la pregunta para la encuesta')
		form.pregunta.focus()
	}else if(document.getElementById("lista").length < 2){
		alert('Introducir las posibles respuestas')
		form.respuesta.focus()
	}else{
		selectAll(form.lista)		
		form.submit()
	}
}

function validarDatosAcceso(form){
	if(estaVacio(form.login.value)){
		alert('Introducir el usuario actual')
		form.login.focus()
	}else if(estaVacio(form.pass.value)){
		alert('Introducir la contraseña actual')
		form.pass.focus()
	}else if(estaVacio(form.newlogin.value) && estaVacio(form.newpass.value) ){
		alert('Introducir los datos que desea registrar')
		form.newlogin.focus()
	}else if(!estaVacio(form.newpass.value) && (form.newpass.value != form.repnewpass.value) ){
		alert('La nueva contraseña no coincide con su repetición')
		form.newpass.focus()
	}else{
		form.submit()
	}
}

function validarDatosAcceso2(form){
	if(estaVacio(form.login.value)){
		alert('Introducir el usuario actual')
		form.login.focus()
	}else if(estaVacio(form.pass.value)){
		alert('Introducir la contraseña actual')
		form.pass.focus()	
	}else{
		form.submit()
	}
}

function seleccionarTodo(form){  
   if (form.fila.name != undefined ){
	   form.fila.checked = true
   }else{
	for(i=0;i<form.fila.length;i++){
        form.fila[i].checked = true	}
   }
}

function deseleccionarTodo(form){  
   if (form.fila.name != undefined ){
	   form.fila.checked = false
   }else{
	for(i=0;i<form.fila.length;i++){
        form.fila[i].checked = false }  
   }
}

function cuentaActivas(form){
	var cont
	cont = 0	
    if (form.fila.name != undefined ){
		if(form.fila.checked == true ){
		 cont++
		}		
	}else{
	 for(i=0;i<form.fila.length;i++){
        if (form.fila[i].checked == true )
		 cont++
	 }
	}
	
	if (cont > 0){
	 formulario.action='generarInforme.asp';
	 formulario.target='_blank';
	 formulario.submit()
	}else{
	 alert('Selecciona las encuestas a listar')
	}
}


function mostrarOpcion(form){
	form.soloEliminados.disabled = (form.conEliminados.checked == 1)
	form.conEliminados.disabled = (form.soloEliminados.checked == 1)
	return true
}