// JavaScript Document
function limpiarZonaGeografica(){
    moveAllOptions(document.getElementById('regiones'),document.getElementById('regiones1'));
    tx_herramientaanalisis_pi1cargarProvincias(xajax.getFormValues('xajax_form'));
    validaZona();

if ( document.getElementById('checkNacional2').checked == true ) {

    enableButtonBySelector('buttonNingunaReg','regiones');
    enableButtonBySelector('buttonMenosReg','regiones');
    enableButtonBySelector('buttonTodasReg','regiones1');
    enableButtonBySelector('buttonMasReg','regiones1');
}


}


function apareceCargando(div){
	document.getElementById(div).innerHTML ="<br><img src=\'typo3conf/ext/herramienta_analisis/img/loader.gif\'/>";
}

function doit(){
	if (!window.print){
		alert("You need NS4.x to use this print button!")
		return
	}
	window.print()
}
function ayuda(Pid,id){
    iamwiner=window.open('index.php?id='+Pid+'&l='+id,'popuphelp');
//,'menubar=no, location=no, resizable=no, scrollbars=yes, status=no, toolbar=no, minimizable=no, left=10, top=10, height=425, width=640');
    iamwiner.focus();
    return false;
}

function goLite(BTN)
{
   document.getElementById(BTN).style.color = "#0033FF";
   document.getElementById(BTN).style.borderStyle = "solid";
   document.getElementById(BTN).style.borderColor = "#00CCFF";
}

function goDim(BTN)
{
   document.getElementById(BTN).style.color = "#0B333C";
   document.getElementById(BTN).style.borderStyle = "";
   document.getElementById(BTN).style.borderColor = "#bcd2e6";
}


function goLite2(BTN)
{
   document.getElementById(BTN).style.color = "#BB0000";
   document.getElementById(BTN).style.borderStyle = "solid";
   document.getElementById(BTN).style.borderColor = "#000000";
   document.getElementById(BTN).style.background = "#FFFFFF";
}

function goDim2(BTN)
{
   document.getElementById(BTN).style.color = "#FFFFFF";
   document.getElementById(BTN).style.borderStyle = "";
   document.getElementById(BTN).style.borderColor = "#000000";
   document.getElementById(BTN).style.background = "#AA0000";
}




function validaFormGraficar(){


return true;
}

function limpiarSeccionCursoAnioSubsector(){

removeAllOptions(document.getElementById('anios'));
removeAllOptions(document.getElementById('anios1'));
removeAllOptions(document.getElementById('subsectores'));
removeAllOptions(document.getElementById('subsectores1'));
document.getElementById('cuarto').checked=false;
document.getElementById('octavo').checked=false;
document.getElementById('segundo').checked=false;
return;
}

function validaZona(){

	var seccion3Valida=false;

/*
	seccion3Valida=hasOptions(document.getElementById('regiones'));

	if (seccion3Valida){
		document.getElementById('tituloSec3').innerHTML ='<b>Zona Geográfica</b>';
		return true;
	}
	else{
		document.getElementById('tituloSec3').innerHTML ='<font class="tituloInvalido">Zona Geográfica (Requerido)</font>';
		return false;
	}
	*/
	return true;
}


function validaCurAniSub(){

	var seccion2Valida=false;

	seccion2Valida=document.getElementById('cuarto').checked ||document.getElementById('octavo').checked ||document.getElementById('segundo').checked;

	if (hasOptions(document.getElementById('anios')) && seccion2Valida&&document.getElementById('anios').options.length>=1 && hasOptions(document.getElementById('subsectores')) &&document.getElementById('subsectores').options.length>=1){

		for (var i=0;i<document.getElementById('anios').options.length;i++) {
			document.getElementById('anios').options[i].selected = true;
		}
		for (var i=0;i<document.getElementById('subsectores').options.length;i++) {
			document.getElementById('subsectores').options[i].selected = true;
		}
		document.getElementById('tituloSec2').innerHTML ='<b>Curso, Año y Subsector * </b>';
		return true;
	}
	else{
		document.getElementById('tituloSec2').innerHTML ='<font class="tituloInvalido">Curso, Año y Subsector * (Requerido)</font>';
		return false;
	}

}

function validaVariables(){

	var seccion1Valida=false;

	if(document.getElementById('promedio').checked ){
		seccion1Valida=true;
	}
	if(document.getElementById('desviacion').checked ){
		seccion1Valida=true;
	}
	if(document.getElementById('minMax').checked ){
		seccion1Valida=true;
	}
	if(document.getElementById('desviacion').checked ){
		seccion1Valida=true;
	}
	if(document.getElementById('variacion').checked ){
		seccion1Valida=true;
	}

	/*
	if(seccion1Valida==false){
		document.getElementById('tituloSec1').innerHTML ='<font class="tituloInvalido">Variables de Resultado y Estadísticos * (Requerido)</font>';
		return false;
	}
    else{
		document.getElementById('tituloSec1').innerHTML ='<b>Variables de Resultado y Estadísticos * </b>';
		return true;
	}*/
	return seccion1Valida;
}

function enableButtonBySelector(but,sel){
	document.getElementById(but).disabled=!hasOptions(document.getElementById(sel));
}

/*
function disableButton(but,sel){

	document.getElementById(but).disabled=true;

}
*/


function validaForm(){

	var formValido;
	var msgAlerta='';
	var seccion1Valida;
	var seccion2Valida;
	var seccion3Valida;
	seccionGeografica = true;

	seccion2Valida=validaCurAniSub();
	if(!seccion2Valida){
		msgAlerta+='\nCampo Requerido: Curso, Año y Subsector';
	}

	seccion3Valida=validaVariables();
	if(!seccion3Valida){
		msgAlerta+='\nCampo Requerido: Variables de Resultado y Estadísticos ';
	}

	if(document.getElementById("checkNacional2").checked == true){
		if(document.getElementById("regiones").length>0){

			seccionGeografica = true;
		}
		else {
		msgAlerta+='\nCampo Requerido: Zona Geografica - Establecimiento ';
			seccionGeografica = false;
		}
	}



	formValido=seccion3Valida&&seccion2Valida&&seccionGeografica;

	if(formValido){

		apareceCargando('loading');
		return true;

	}
	else{
		alert(msgAlerta);
		return false;

	}


}

