// JavaScript Document
	
	function marcarTodos (opcion) {
		switch (opcion) {
			case 0:
				var tabla = document.getElementById("resultadosObtenidos"); 
				var checkboxes = tabla.getElementsByTagName("input"); 
				for (var i = 0; i < checkboxes.length; i++) { 
					tipo = checkboxes[i].getAttribute("type"); 
					if ( tipo == "checkbox") { 
						checkboxes[i].checked=true;
					}
				}
				break;
			case 1:
				var tabla = document.getElementById("resultadosObtenidos"); 
				var checkboxes = tabla.getElementsByTagName("input"); 
				for (var i = 0; i < checkboxes.length; i++) { 
					tipo = checkboxes[i].getAttribute("type"); 
					if ( tipo == "checkbox") { 
						checkboxes[i].checked=false;
					}
				}
				break;
		}
	}
	
	function ponerdato(valor,elemento,imagen,total,puntuacionTotal)
	{			
		$(total).value = $(total).value - $(elemento).value;
		$ (puntuacionTotal).value = $ (puntuacionTotal).value -$ (elemento).value;
		
		if (imagen!='null')		
    		$(imagen).style.visibility = ($(imagen).style.visibility == 'hidden') ? 'visible' : 'visible'; //damos un atributo display:none que oculta el div
    		
	  	$(elemento).value = valor;
	  	
	  	if (!$(total).value)
	  		$(total).value = valor;
	  	else	
	  		$(total).value = parseInt($(total).value) + parseInt(valor); //parseInt -> convierte a entero	  
	  		
	  	if(!$(puntuacionTotal).value)
	  			$(puntuacionTotal).value = valor;
	  	else
	  		 $(puntuacionTotal).value = parseInt($(puntuacionTotal).value)+parseInt(valor);			  		
	}
		
	function calcular(total,pond,base,ps,ncrit,ponderadaTotal)
	{
		var puntMax = ncrit*9;
		var Pp = $(total).value * (ps/puntMax);
	  	//$(pond).value = Math.round(Pp); //redondea el entero sin decimales
		$(pond).value = Pp.toFixed(2);
	  	$ (ponderadaTotal).value = Pp;
	  	var puntMin = ncrit*1;
	  	var min = puntMin * (ps/puntMax) ;
	  	var max = puntMax * (ps/puntMax) ;
	  	var Pb = ((Pp-min)/(max-min))*100;
	  	if (Pb<0)
	  		$(base).value = 0
	  	else	
	  		//$(base).value = Math.round(Pb);
			$(base).value = Pb.toFixed(2);
	}
	
	
	function calcularPonderada(total,pond,ponderadaTotal,ncrit,base100Total){
    var tot = 0;
    for(var i=0; i<ncrit;i++){
     var nombre = 'ponderadahidden'+i;
      if($(nombre).value)
        tot = parseFloat(tot)+parseFloat($(nombre).value);
    }
   $(ponderadaTotal).value= Math.round(tot);
   
   var min = 11.11;
   var max = 100;
   
   var Pb = ((tot-min)/(max-min))*100;
   if(Pb<0)
   		$(base100Total).value = 0;
   else
   		$(base100Total).value = Math.round(Pb);
   
  }
	
  function validarForm(id,idioma) {	
		var error = false;
		var error = false;
		var radio = false;	
        $$('form#'+id+' .required').each(function(node){
		   if (node.value == "") {
                error = true;
				radio = true;
            }
        });
        $$('form#'+id+' .file').each(function(node){
		   if (node.value == "") {
				error = true;
                radio = false;
            }
        });
        if (error == true) {
			if(radio == true){	
				if(idioma=='es')
				  alert("No ha seleccionado todos los registros");
				else
					alert("You havenīt selected all of the fields"); 
				return false;
			}else{
				if(idioma=='es')
					alert("debe seleccionar un archivo");
				else
					alert("must select a file");
				return false;
			}
        } else {
			$(id).submit();
        }
    }
    
   function validarCheck(idioma){
		selected = $$('.validate-one-required').any(function (e) {												    
			if(e.checked)
				return true;
		});
		if (selected) {
				if(idioma=='es'){
				if (confirm(String.fromCharCode(191)+'Seguro que desea estos registros?')){
		      		return true;
				} else {
					return false;
				}
			}else{
			  if (confirm(String.fromCharCode(191)+'Sure wish these records?')){
		      		return true;
				} else {
					return false;
				}
			}
		} else {
				if(idioma=='es')
			   alert('No ha seleccionado ningun registro.');
			else
				 alert('Have not selected register');
			return false;
		}
	}   
	

