// variables globales
var gMaxSolicitudes = 10;

function fNext(page) {

	var mypage = "http://localhost:8080/sede-electronica-web/vistas/formNOTA/"+page+".jsf";
	alert("mypage:"+mypage);
	window.location.href=mypage;
	}//fNext

function soloNumeros(event){
	var keynum;
	var keychar;
	var numcheck;

	if(window.event) // IE
		{
		keynum = event.keyCode;
		}
	else if(event.which) // Netscape/Firefox/Opera
		{
		keynum = event.which;
		}
	if (keynum==8)return true; //backspace
	if (keynum==9)return true; //suprimir
	if (keynum==37)return true; //tabulador
	if (keynum==39)return true; //izquierda
	if (keynum==46)return true; //derecha

	//Pasamos los valores del teclado nï¿½merico extendido a ASCII
	if(keynum >= 96){
		if(keynum >! 106){
			keynum = keynum - 48;
		}
	}
	
	keychar = String.fromCharCode(keynum);
	numcheck = /\d/;
	return numcheck.test(keychar);
}





/* 
**************************************** 
JAVASCRIPT PARA la nt22Supresion 
**************************************** 
*/
var arrayChecksModif = [];
var arrayChecksSupr  = [];

var inizializadosModif = 0;
var inizializadosSupr = 0;

function inicializaArrayChecksModif(){
 	var myform = document.getElementById('formularioNOTA');
	var inputTags = myform.getElementsByTagName('input');
	var checkboxCount = 0;
	for (var i=0, length = inputTags.length; i<length; i++) {
     	if (inputTags[i].type == 'checkbox') {
         checkboxCount++;
     }
	}
    for (var j=0; j < checkboxCount; j++)
  		arrayChecksModif[j]=0;
	
	inizializadosModif = 1;
}


function inicializaArrayChecksSupr(){
 	var myform = document.getElementById('formularioNOTA');
	var inputTags = myform.getElementsByTagName('input');
	var checkboxCount = 0;
	for (var i=0, length = inputTags.length; i<length; i++) {
     	if (inputTags[i].type == 'checkbox') {
         checkboxCount++;
     }
	}
    for (var j=0; j < checkboxCount; j++)
  		arrayChecksSupr[j]=0;
	
	inizializadosSupr = 1;
}


function onChangeSelectSupr(checkbox) {

	if (inizializadosSupr==0)
		inicializaArrayChecksSupr();
		
		
  if (document.getElementById("formularioNOTA:txtIdxCheckBoxesSupr").value!=""){
	  var arrayActual = document.getElementById("formularioNOTA:txtIdxCheckBoxesSupr").value;
	arrayChecksSupr = arrayActual.split(",");
  }

	
	var _name = checkbox.name;
	var res = _name.replace("formularioNOTA:tablaInscritosSupr:", "");
	var idx = res.replace(":chk", "");


    var _numInscritos = parseInt(document.getElementById("formularioNOTA:numInscritos").value);
  	var _totSolicitudes =  parseInt(document.getElementById("formularioNOTA:totSol").innerHTML);
	var _numDiff = parseInt(document.getElementById("formularioNOTA:numDiff").innerHTML);

	
	if (checkbox.checked==true){
		_numInscritos =  _numInscritos+1;
	}
	else{
		_numInscritos =  _numInscritos-1;
	}


 	if (_totSolicitudes+_numDiff+_numInscritos > gMaxSolicitudes) {
		checkbox.checked=false;		
		alert("Lo sentimos, no puede añadir más solicitudes. La AEPD ha establecido un máximo de "+gMaxSolicitudes+" solicitudes por cada notificación.");
	}
  	else{
		
		if (checkbox.checked==true){
			arrayChecksSupr[idx]="1";	
		}
		else{
			arrayChecksSupr[idx]="0";
		}
			  
	  	if (_totSolicitudes+_numDiff+_numInscritos == gMaxSolicitudes) {
			document.getElementById("formularioNOTA:addFileGris").style.display="inline";	
			document.getElementById("formularioNOTA:addFile").style.display="none";
		}
		else{			
			document.getElementById("formularioNOTA:addFileGris").style.display="none";	
			document.getElementById("formularioNOTA:addFile").style.display="inline";	
		}
		

		document.getElementById("formularioNOTA:txtIdxCheckBoxesSupr").value=arrayChecksSupr;
		document.getElementById("formularioNOTA:numInscritos").value= _numInscritos;
		
		var _numDiff = parseInt(document.getElementById("formularioNOTA:numDiff").innerHTML);
		document.getElementById("formularioNOTA:numFicheros").innerHTML= _numDiff + _numInscritos;
		verificarNumFicheros();
		
  }






}//onChangeSelectSupr



function onChangeSelectModif(checkbox) {
  if (inizializadosModif==0)
	inicializaArrayChecksModif();
	
  if (document.getElementById("formularioNOTA:txtIdxCheckBoxesModif").value!=""){
	  var arrayActual = document.getElementById("formularioNOTA:txtIdxCheckBoxesModif").value;
	arrayChecksModif = arrayActual.split(",");
  }


  var _name = checkbox.name;
  var res = _name.replace("formularioNOTA:tablaInscritosModif:", "");
  var idx = res.replace(":chk", "");
  var _numInscritos = parseInt(document.getElementById("formularioNOTA:numInscritos").value);
  
  
  	var _totSolicitudes =  parseInt(document.getElementById("formularioNOTA:totSol").innerHTML);
	var _numDiff = parseInt(document.getElementById("formularioNOTA:numDiff").innerHTML);
	
  
  

  if (checkbox.checked==true){
	_numInscritos =  _numInscritos+1;
  }
  else{
	_numInscritos =  _numInscritos-1;
  }
  
  
  if (_totSolicitudes+_numDiff+_numInscritos > gMaxSolicitudes) {
		checkbox.checked=false;		
		alert("Lo sentimos, no puede añadir más solicitudes. La AEPD ha establecido un máximo de "+gMaxSolicitudes+" solicitudes por cada notificación.");
	}
  else{
	  
		if (checkbox.checked==true){
			arrayChecksModif[idx]="1";
		}
		else{
			arrayChecksModif[idx]="0";		
		}

	  
	  	if (_totSolicitudes+_numDiff+_numInscritos == gMaxSolicitudes) {
			document.getElementById("formularioNOTA:addFileGris").style.display="inline";	
			document.getElementById("formularioNOTA:addFile").style.display="none";
		}
		else{			
			document.getElementById("formularioNOTA:addFileGris").style.display="none";	
			document.getElementById("formularioNOTA:addFile").style.display="inline";	
		}
		

		document.getElementById("formularioNOTA:txtIdxCheckBoxesModif").value=arrayChecksModif;
		document.getElementById("formularioNOTA:numInscritos").value= _numInscritos;
		
		var _numDiff = parseInt(document.getElementById("formularioNOTA:numDiff").innerHTML);
		document.getElementById("formularioNOTA:numFicheros").innerHTML= _numDiff + _numInscritos;
		verificarNumFicheros();
  }
  
}


/* 
**************************************** 
JAVASCRIPT PARA NOTA - la nt03 medionotificacion
**************************************** 
*/
function medioNotifChange(selectBox){

	var _CORREO_POSTAL = "0";
	var _DEH_SNE = "1";
	var _COMPARECENCIA_SEDE = "5";
	
	if (document.getElementById('formularioNOTA:msgErrorDEH'))
		document.getElementById('formularioNOTA:msgErrorDEH').innerHTML="";
	
	
	if(selectBox.value == _DEH_SNE){
		var $mensaje = "Para la notificación mediante el Servicio de Notificaciones Electrónicas es imprescindible disponer de una Dirección Electrónica Habilitada (DEH) y haberse suscrito previamente al servicio implementado por la AEPD";
		$mensaje += "\n\r";
		$mensaje += "Se tomará del certificado digital el dato relativo al CIF/NIF de la persona jurídica/física para la comprobación de su suscripción en el servicio.";
		$mensaje += "\n\r";
		//$mensaje += "ï¿½Dispone de Direcciï¿½n Electrï¿½nica Habilitada y se encuentra suscrito al servicio que la AEPD ha desarrollado para el Servicio de Notificaciones Electrï¿½nicas?";
		//Nuevo texto 21/01/2015 - sad
		$mensaje += "Si dispone de Dirección Electrónica Habilitada y se encuentra suscrito al servicio que la AEPD ha desarrollado para el Servicio de Notificaciones Electrónicas, pulse sobre el botón 'ACEPTAR'.";
		$mensaje += "\n\r";
		$mensaje += "Si no dispone de dicha dirección, pulse 'CANCELAR' y el envío de la notificación le será efectuado por correo ordinario.";
	

		if(!confirm($mensaje)){
			selectBox.value= _CORREO_POSTAL;
		}
		else{ //Confirma que usa DEH .. debo comprobarlo en la tabla de censo
			document.getElementById('formularioNOTA:btnVerificarDEH').click();
			}
	}
	
	// COMPARECENCIA EN SEDE
	else if(selectBox.value == _COMPARECENCIA_SEDE){
		// COMPARECENCIA EN SEDE
		var $mensajeCS = "Para la notificación mediante el Servicio de Comparecencia en Sede Electrónica de la AEPD (sedeagpd.gob.es), será imprescindible disponer de una dirección de correo electrónico validada por la propia AEPD.";
		$mensajeCS += "\n\r";
		$mensajeCS += "Si la cuenta de correo electrónico indicada en el campo 'Correo Electrónico' de la sección 'Dirección a efectos de notificación' no se encuentra previamente validada, al finalizar el proceso de envío de ésta solicitud se le enviará una e-mail de verificación a dicha cuenta.";
		$mensajeCS += "\n\r";
		$mensajeCS += "Por favor, revise que el correo electrónico indicado en ese campo es el correcto antes de continuar con el proceso.";
		
		
		if(!confirm($mensajeCS)){
			selectBox.value= _CORREO_POSTAL;
		}
		else{
			  document.getElementById('formularioNOTA:correoElectronicoObligatorio').value="S";
			  document.getElementById('formularioNOTA:cif_nifDeclaranteObligatorio').value="S";
			  //document.getElementById("formularioNOTA:correoElectronicoDeclarante").style.backgroundColor="#fffb9b";
			  if(document.getElementById('formularioNOTA:cif_nifDeclarante'))
			  {
				  document.getElementById('formularioNOTA:cif_nifDeclarante').focus();
			  }
			  if(document.getElementById('formularioNOTA:cif_nifDeclarante'))
			  {
				  document.getElementById("formularioNOTA:correoElectronicoDeclarante").focus();
			  }
			}
	}
	else {
		document.getElementById('formularioNOTA:correoElectronicoObligatorio').value="N";
		document.getElementById('formularioNOTA:cif_nifDeclaranteObligatorio').value="N";
		//document.getElementById("formularioNOTA:correoElectronicoDeclarante").style.backgroundColor="#fff";
		}
		
	// reflejo este valor en un input
	document.getElementById('formularioNOTA:inputCdMedioNotificacion').value= selectBox.value;
	
		
}


/* 
**************************************** 
JAVASCRIPT PARA CC - la formCC.jsf
**************************************** 
*/
function medioNotifChangeCC(selectBox){
	
	var _CORREO_POSTAL = "0";
	var _DEH_SNE = "1";
	var _COMPARECENCIA_SEDE = "5";
	
	
	// COMPARECENCIA EN SEDE
	if(selectBox.value == _COMPARECENCIA_SEDE){
		
			// COMPARECENCIA EN SEDE
		var $mensajeCS = "Para la notificación mediante el Servicio de Comparecencia en Sede de la AEPD, será imprescindible disponer de una dirección de correo electrónico validada por la propia AEPD.";
		$mensajeCS += "\n\r";
		$mensajeCS += "Al finalizar el proceso de envío de ésta notificación, se le enviará un e-Mail de verificación a la cuenta de correo que haya indicado en el campo 'Correo Electrónico' de la sección 'Dirección a efectos de notificación'.";
		$mensajeCS += "\n\r";
		$mensajeCS += "Por favor, revise que el correo electrónico indicado en ese campo es el correcto antes de continuar con el proceso.";
		
		
		if(!confirm($mensajeCS)){
			selectBox.value= _CORREO_POSTAL;
		}
		else{
			  document.getElementById('formularioCC:correoElectronicoObligatorio').value="S";
			  document.getElementById("formularioCC:correoElectronico").focus();
			}
	}
	else {
		document.getElementById('formularioCC:correoElectronicoObligatorio').value="N";
		}
		
		
}
/* 
**************************************** 
JAVASCRIPT PARA la nt03 aceptacion
**************************************** 
*/
function checkDeberesDeclarante(check){
	//vemos si esta marcado
	if(check.checked){
		var $mensaje = "De conformidad con lo establecido en la Ley Orgánica 15/1999, de 13 de diciembre, de Protección de Datos de Carácter Personal, solicito la inscripción en el Registro General de Protección de Datos del fichero de datos de carácter personal al que hace referencia el presente formulario de notificación.";
		$mensaje += "\n\r";	
		$mensaje += "Asimismo, bajo mi responsabilidad manifiesto que dispongo de representación suficiente para solicitar la inscripción de este fichero en nombre del responsable del fichero y que éste está informado del resto de obligaciones que se derivan de la LOPD.";
		$mensaje += "\n\r";
		$mensaje += "Igualmente, declaro que todos los datos consignados son ciertos y que el responsable del fichero ha sido informado de los supuestos legales que habilitan el tratamiento de datos especialmente protegidos, así como la cesión y la transferencia internacional de datos.";
//		$mensaje += "\n\r";
//		$mensaje += "La Agencia Española de Protección de Datos podrá requerir que se acredite la representación de la persona que formula la presente notificación.";
		
		if(!confirm($mensaje)){
			check.checked=false;
		}
	}
	
}


/* 
*********************************************
JAVASCRIPT PARA validacion finalidades nt09
*********************************************
*/
function verificaFinalidades(){
	
	//limpiamos el contenido del mensaje manual
	if(document.getElementById('formularioNOTA:sms_manual') != null){
		document.getElementById('formularioNOTA:sms_manual').innerHTML = '';
	} 
	
	if (document.getElementById('formularioNOTA:hiddenFinalidades').value=="" || document.getElementById('formularioNOTA:hiddenFinalidades').value=="vacio"){
		//mostramos el alert
		alert("Ha de seleccionar al menos una finalidad");
		
		//insertamos el mensaje de error
		document.getElementById('formularioNOTA:sms_manual').innerHTML = '<span class="error">Ha de seleccionar al menos una finalidad</span>';;
		
//		errores = document.getElementById('formularioNOTA:hiddenFinalidades').parentNode.appendChild(newChild));
//		errores.innerHHTML ='<span class="error>Ha de seleccionar al menos una finalidad</span>';
		
		return false;
	} else if(document.getElementById('formularioNOTA:hiddenFinalidades').value.length > 23) {
		alert("Ha seleccionado demasiadas finalidades(máximo 6)");
		
		//insertamos el mensaje de error
		document.getElementById('formularioNOTA:sms_manual').innerHTML = '<span class="error" >Ha seleccionado demasiadas finalidades(máximo 6)</span>';
		
		return false;
	} else {
		return true;
	}
	
}

/* 
*********************************************
JAVASCRIPT PARA validacion Origen datos nt10
*********************************************
*/
function verificaOrigenDatos2() {
	
	var origen = false;
	var colectivos = false;
	
	//limpiamos el contenido de los mensajes js
	if(document.getElementById('formularioNOTA:sms_manual_origen') != null){
		document.getElementById('formularioNOTA:sms_manual_origen').innerHTML = '';
	} 
	
	if(document.getElementById('formularioNOTA:sms_manual_colectivos') != null){
		document.getElementById('formularioNOTA:sms_manual_colectivos').innerHTML = '';
	} 
	
	
	
	//evaluar si alguno de los checkboxes estï¿½ marcado
	if (document.getElementById('formularioNOTA:interesado').checked){
		origen = true;
	} else if (document.getElementById('formularioNOTA:otrasPersonasFcas').checked){
		origen = true;
	} else if (document.getElementById('formularioNOTA:origenFuentesPublicas').checked){
		origen = true;
	} else if (document.getElementById('formularioNOTA:origenRegistrosPublicos').checked){
		origen = true;
	} else if (document.getElementById('formularioNOTA:origenEntidadPrivada').checked){
		origen = true;
	} else if (document.getElementById('formularioNOTA:origenAdmonPublica').checked){
		origen = true;
	} else {
		//si ninguno estï¿½ marcado, establece el error de validacion
		document.getElementById('formularioNOTA:sms_manual_origen').innerHTML = '<span class="error" >Debe seleccionar al menos una opción</span>';
	}
	
	//verificamos si existen colectivos
	if (document.getElementById('formularioNOTA:hiddenColectivos').value==""){
		//si el hidden estï¿½ vacio miramos en otros colectivos
		if (document.getElementById('formularioNOTA:otrosColectivos').value==""){
			//si esta vacio lanzamos el error
			document.getElementById('formularioNOTA:sms_manual_colectivos').innerHTML = '<span class="error" >Debe seleccionar al menos un colectivo de la lista o escribirlo en otros datos si no se encuentra en esta</span>';
		} else {
			colectivos = true;
		}
	} else {
		//si existen contenidos, miramos que no tenga mas de 6 seleccionados
		if(document.getElementById('formularioNOTA:hiddenColectivos').value.length < 23) {
			colectivos = true;
		} else {
			document.getElementById('formularioNOTA:sms_manual_colectivos').innerHTML = '<span class="error" >Ha seleccionado demasiados colectivos (máximo 6)</span>';
		}
		
	}
	
	//si alguna es falsa devolvemos false
	return (origen && colectivos);	
	
}

/* 
*********************************************
JAVASCRIPT PARA actualizacion otros colectivos en check.onclick
valdrï¿½ para varios
*********************************************
*/
function toggleOtros(check, otros ){
	
	try{
		var otrosTA = document.getElementById(otros);
		
		if(check.checked){
			otrosTA.disabled = false;
			otrosTA.readOnly = false;
			otrosTA.style.display="inline";
		} else {
			otrosTA.value = '';
			otrosTA.disabled = true;
			otrosTA.readOnly = true;	
			otrosTA.style.display="none";
		}
	}
	catch(err) {
		}
}

/* 
*********************************************
JAVASCRIPT PARA actualizacion otros colectivos en check.onclick
valdrï¿½ para varios
*********************************************
*/


function loadColectivos(){ //nt10OrigenDatos
	var check = document.getElementById('formularioNOTA:checkOtrosColectivos');	
	toggleOtros(check, 'formularioNOTA:otrosColectivos' );
	
}

function loadOtrosTipos(){ //nt11TipoDatos
	var check = document.getElementById('formularioNOTA:checkOtrosTipos');
	toggleOtros(check, 'formularioNOTA:otrosTipos' );
}

function loadOtrosCesiones(){ //nt13CesionDatos
	var check = document.getElementById('formularioNOTA:checkOtrosCesionDatos');
	toggleOtros(check, 'formularioNOTA:otrosDestinatariosText' );
}



/* 
*********************************************
JAVASCRIPT PARA validacion Otros Destinatarios de Cesiones nt10
*********************************************
*/

function verificaOrigenDatos() {
	var _continuar=true;
	var nomCheck	="checkOtrosColectivos";
	var nomTextArea ="otrosColectivos";
	var nomSMS		="sms_otrosColectivos";
	
	var _check= document.getElementById("formularioNOTA:"+nomCheck).checked;    
	if (_check==true){

		var _textArea = document.getElementById("formularioNOTA:"+nomTextArea).value;    			

		if (_textArea==""){
			document.getElementById("formularioNOTA:"+nomSMS).style.display='inline';
			_continuar=false;
			}
		else
			document.getElementById("formularioNOTA:"+nomSMS).style.display='none';
		}
	else
		document.getElementById("formularioNOTA:"+nomSMS).style.display='none';

	
	if (_continuar== true)
		return verificaOrigenDatos2();
	else
		return false;
	
	}//verificaOrigenDatos


/* 
*********************************************
JAVASCRIPT PARA validacion Otros Destinatarios de Cesiones nt13
*********************************************
*/

function verificaOtrosDestinatariosCesiones() {
	var _continuar=true;
	
	var _check= document.getElementById("formularioNOTA:checkOtrosCesionDatos").checked;    
	if (_check==true){

		var _textArea = document.getElementById("formularioNOTA:otrosDestinatariosText").value;    			

		if (_textArea==""){
			document.getElementById("formularioNOTA:sms_otrosDestinatariosText").style.display='inline';
			_continuar=false;
			}
		else
			document.getElementById("formularioNOTA:sms_otrosDestinatariosText").style.display='none';
		}
	else
		document.getElementById("formularioNOTA:sms_otrosDestinatariosText").style.display='none';

	return _continuar;
	
	}//verificaOtrosDestinatariosCesiones
	
/* 
*********************************************
JAVASCRIPT PARA validacion tipo Datos nt11
*********************************************
*/

function verificaTipoDatos() {
	var _continuar=true;
	
	var _checkOtrosTipos = document.getElementById("formularioNOTA:checkOtrosTipos").checked;    
	if (_checkOtrosTipos==true){
		var _otrosTipos = document.getElementById("formularioNOTA:otrosTipos").value;    			
		if (_otrosTipos==""){
			document.getElementById("formularioNOTA:smsMotivo").style.display='inline';
			_continuar=false;
			}
		else{
			if(document.getElementById("formularioNOTA:smsMotivo")!=null){
				document.getElementById("formularioNOTA:smsMotivo").style.display='none';
			}
		}
		}
	else{
		if(document.getElementById("formularioNOTA:smsMotivo")!=null){
			document.getElementById("formularioNOTA:smsMotivo").style.display='none';
		}		
	}
	if (_continuar== true)
		return verificaTipoDatos2();
	else
		return false;
	}//verificaTipoDatos

				
function verificaTipoDatos2() {
	//limpiamos el contenido de los mensajes js
	if(document.getElementById('formularioNOTA:sms_manual_datosIden')){
		document.getElementById('formularioNOTA:sms_manual_datosIden').innerHTML = '';
	} 
	
	if(document.getElementById('formularioNOTA:sms_manual_infracciones')){
		document.getElementById('formularioNOTA:sms_manual_infracciones').innerHTML = '';
	} 
	

	var identificativos = false;
	var infracciones = false;
	
	//evaluar si alguno de los checkboxes de datos identificativos esta marcado
	if (document.getElementById('formularioNOTA:datosDniNif').checked){
		identificativos = true;
	} else if (document.getElementById('formularioNOTA:datosNssMutualidad').checked){
		identificativos = true;
	} else if (document.getElementById('formularioNOTA:datosNombreApellidos').checked){
		identificativos = true;
	} else if (document.getElementById('formularioNOTA:datosTargetaSanitaria').checked){
		identificativos = true;
	} else if (document.getElementById('formularioNOTA:datosDireccion').checked){
		identificativos = true;
	} else if (document.getElementById('formularioNOTA:datosTelefono').checked){
		identificativos = true;
	}  else if (document.getElementById('formularioNOTA:datosFirma').checked){
		identificativos = true;
	} else if (document.getElementById('formularioNOTA:datosHuella').checked){
		identificativos = true;
	} else if (document.getElementById('formularioNOTA:datosImagenVoz').checked){
		identificativos = true;
	} else if (document.getElementById('formularioNOTA:datosMarcasFisicas').checked){
		identificativos = true;
	} else if (document.getElementById('formularioNOTA:datosFirmaElectronica').checked){
		identificativos = true;
	}  else if (document.getElementById('formularioNOTA:datosOtrosDatosBiometricos').checked){
		identificativos = true;
	}  else if (document.getElementById('formularioNOTA:datosNumRegistroPersonal')!=null && document.getElementById('formularioNOTA:datosNumRegistroPersonal').checked){
		identificativos = true;		
	}   else if (document.getElementById('formularioNOTA:otrosDatosIdentificativos').value.length > 0 ){
		identificativos = true;
	} else {
		//si ninguno estï¿½ marcado, establece el error de validacion
		document.getElementById('formularioNOTA:sms_manual_datosIden').innerHTML = '<span class="error" >Debe marcar al menos una opcion o indicar un valor en el campo de texto</span>';
	}
		
	//como incidencias solo se renderiza en pub, comprobamos si existen los elementos
	//evaluamos el hidden que indica si son required en funciï¿½n de nt09
	if(document.getElementById('formularioNOTA:requiredInfracciones')){
		if(document.getElementById('formularioNOTA:requiredInfracciones').value == 'true'){
			if(document.getElementById('formularioNOTA:datosInfraccionesPenales').checked){
				infracciones = true;
			} else if(document.getElementById('formularioNOTA:datosInfraccionesAdministrativas').checked){
				infracciones = true;
			} else {
				document.getElementById('formularioNOTA:sms_manual_infracciones').innerHTML = '<span class="error" >Debe seleccionar al menos una opción. Es obligatorio por la finalidad elegida.</span>';
			}
		} else {
			infracciones = true;
		}
	} else {
		infracciones = true;
	}
	
	return (identificativos && infracciones);
	
	
}


/*
sdeandres 30/10/2014
Funciï¿½n utilizada en el nt21Modificacion.jsf, para controlar la pulsaciï¿½n de checks de modificaciï¿½n o supresion
*/
function modificarOSuprimir(objeto) {

	if (objeto=="blqDerechoOpoSupr")
		document.getElementById("formularioNOTA:blqDerechoOpoModif").checked=false;
	else if (objeto=="blqDerechoOpoModif")
		document.getElementById("formularioNOTA:blqDerechoOpoSupr").checked=false;

	else if (objeto=="blqEncargadoModif")
		document.getElementById("formularioNOTA:blqEncargadoSupr").checked=false;
	else if (objeto=="blqEncargadoSupr")
		document.getElementById("formularioNOTA:blqEncargadoModif").checked=false;


	else if (objeto=="blqCesionModif")
		document.getElementById("formularioNOTA:blqCesionSupr").checked=false;
	else if (objeto=="blqCesionSupr")
		document.getElementById("formularioNOTA:blqCesionModif").checked=false;

	else if (objeto=="blqTIModif")
		document.getElementById("formularioNOTA:blqTISupr").checked=false;
	else if (objeto=="blqTISupr")
		document.getElementById("formularioNOTA:blqTIModif").checked=false;
	}//modificarOSuprimir


function verificaCheckSeleccionadoParaModificacion() {
	
	var hayTablaInscritos=false;
	var hayTablaDiffResponsable=false;
	
	if ( document.getElementById("formularioNOTA:tablaInscritosModif") != null )
		hayTablaInscritos=true;		
	
	else if ( document.getElementById("formularioNOTA:groupDiffResponsableModif") != null) 
		hayTablaDiffResponsable=true;
	
	else if ( document.getElementById("formularioNOTA:resumenFicherosEditar") != null) 
		hayTablaDiffResponsable=true;


	if (hayTablaInscritos==false && hayTablaDiffResponsable==false ){
		alert("DEBE SELECCIONAR AL MENOS UN FICHERO PARA SER MODIFICADO");
		return false;
	}


	
	if      (document.getElementById("formularioNOTA:blqDerechoOpoModif").checked==true) return true;
	else if (document.getElementById("formularioNOTA:blqDerechoOpoSupr").checked==true) return true;
	else if (document.getElementById("formularioNOTA:blqEncargadoSupr").checked==true) return true;
	else if (document.getElementById("formularioNOTA:blqEncargadoModif").checked==true) return true;
	else if (document.getElementById("formularioNOTA:blqCesionSupr").checked==true) return true;
	else if (document.getElementById("formularioNOTA:blqCesionModif").checked==true) return true;
	else if (document.getElementById("formularioNOTA:blqTISupr").checked==true) return true;
	else if (document.getElementById("formularioNOTA:blqTIModif").checked==true) return true;
	else if (document.getElementById("formularioNOTA:blqResponsable").checked==true) return true;	
	else if (document.getElementById("formularioNOTA:blqTipoDato").checked==true) return true;
	else if (document.getElementById("formularioNOTA:blqMedidasSeg").checked==true) return true;
	else if (document.getElementById("formularioNOTA:blqFinalidad").checked==true) return true;
	else if (document.getElementById("formularioNOTA:blqOrigen").checked==true) return true;
	else if (document.getElementById("formularioNOTA:blqDisposicion") !=null && document.getElementById("formularioNOTA:blqDisposicion").checked==true) return true;
	else {
		alert("AVISO\n\nDEBE SELECCIONAR AL MENOS UN BLOQUE DE DATOS PARA PODER MODIFICAR LA INSCRIPCI\u00d3N DE EL/LOS FICHERO/S SELECCIONADOS");
		return false;
		}
	
}



function verificaCheckSeleccionadoParaSupresion() {
	
	var hayTablaInscritos=false;
	var hayTablaDiffResponsable=false;
	
	if ( document.getElementById("formularioNOTA:tablaInscritosSupr") != null )
		hayTablaInscritos=true;		
	if ( document.getElementById("formularioNOTA:groupDiffResponsable") != null) 
		hayTablaDiffResponsable=true;


	if (hayTablaInscritos==false && hayTablaDiffResponsable==false ){
		alert("DEBE SELECCIONAR AL MENOS UN FICHERO PARA SER SUPRIMIDO");
		return false;
	}
	else
		return true;


	
}

/*
cgonzalez 11/11/2014
Funciï¿½n utilizada en los listboxes para mostrar el mensaje de alerta al pasar a izquierda
*/
function comboMsg(){
	if (document.getElementById("formularioNOTA:comboMsg")){
		if(document.getElementById("formularioNOTA:comboMsg").value != ""){
			alert(document.getElementById("formularioNOTA:comboMsg").value);
			document.getElementById("formularioNOTA:comboMsg").value = "";
		}
		
		//sad - mensaje de alerta si el numero de elementos es 6
		
		if(document.getElementById("formularioNOTA:verMaxMsg").value != ""){			
			alert( document.getElementById("formularioNOTA:verMaxMsg").value );
			document.getElementById("formularioNOTA:verMaxMsg").value = "";
		}
				
	}
	
}

/*
cgonzalez 13/11/2014
funcion que emula pulsar un boton dado su id
pulsa el click pero no llega al action COMPROBAR
*/
function pulsaBoton(idBoton){
	alert("llegamos a la funcion js para pulsar el boton \""+idBoton+"\"");
	var boton = document.getElementById(idBoton);
	boton.submit;
	
	//document.getElementById("formularioNOTA").submit();
}


// NO FUNCIONA COMPROBAR
function fnWidget(){
	alert("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");
	siguiente.hide();
}



//-------------------------------------------------------------
	var verMsgIdeologia = true;
	var verMsgODEP = true;
	var verMsgInfracciones = true;
	var verMsgAlertCesionDatos = true;
	var verMsgAlertTransfInt = true;
	
	
			
	function msgIdeologia() {
		if (verMsgIdeologia)
			alert( document.getElementById("formularioNOTA:verMsgIdeologia").value );
		verMsgIdeologia = false;
	}//msgIdeologia
	
	function msgODEP() {
		if (verMsgODEP)
			alert( document.getElementById("formularioNOTA:verMsgODEP").value );
		verMsgODEP = false;
	}//msgODEP
	
	function msgInfracciones() {
		if (verMsgInfracciones)
			alert( document.getElementById("formularioNOTA:verMsgInfracciones").value );
		verMsgInfracciones = false;
	}//msgInfracciones
	

	function msgAlertCesionDatos() {
		if (verMsgAlertCesionDatos)
			alert( document.getElementById("formularioNOTA:verMsgAlertCesionDatos").value );
		verMsgAlertCesionDatos = false;
	}//msgAlertCesionDatos

	
	function msgAlertTransfInt(){
		if (verMsgAlertTransfInt)
			alert( document.getElementById("formularioNOTA:verMsgAlertTransfInt").value );
		verMsgAlertTransfInt = false;
	}//msgAlertTransfInt
	
	
	var verMsgAlertTransfIntPuertoSeguro = true;
	
	function msgAlertTransfIntPuertoSeguro(){
		//vemos si no se mostro todavia el mensaje
		if (verMsgAlertTransfIntPuertoSeguro){
			//comprobamos el valor del select
			
			if (document.getElementById("formularioNOTA:paisOtroTI")){
				if ( document.getElementById("formularioNOTA:paisOtroTI").value == "UP" ){
					alert( document.getElementById("formularioNOTA:verMsgAlertTransfIntPuertoSeguro").value );
					verMsgAlertTransfIntPuertoSeguro = false;
				}
			} else {
				alert("no entra");
			}
		}
	}//msgAlertTransfIntPuertoSeguro
	
	
//-------------------------------------------------------------

function resetCheckBoxesModif(){
	//alert("RESET");
	document.getElementById("formularioNOTA:txtIdxCheckBoxesModif").value="";	
	document.getElementById("formularioNOTA:numInscritos").value= "0";

	var _numDiff = parseInt(document.getElementById("formularioNOTA:numDiff").innerHTML);
	document.getElementById("formularioNOTA:numFicheros").innerHTML= _numDiff;

	verificarNumFicheros();
	}


function verificarNumFicheros(){
	//alert("verificarNumFicheros");
	var _totSolicitudes =  parseInt(document.getElementById("formularioNOTA:totSol").innerHTML);
	
	var _numInscritos = parseInt(document.getElementById("formularioNOTA:numInscritos").value);
	var _numDiff = parseInt(document.getElementById("formularioNOTA:numDiff").innerHTML);
	
	if (_totSolicitudes >= gMaxSolicitudes){
		alert("JARL");
		document.getElementById("formularioNOTA:addFile").disabled=true;	
		document.getElementById("formularioNOTA:addFile").className="botonGris";
	}
	else
		document.getElementById("formularioNOTA:addFile").disabled=false;
	
	
	if (_totSolicitudes+_numInscritos+_numDiff <= gMaxSolicitudes){
		document.getElementById("formularioNOTA:numFicheros").innerHTML= _numInscritos+_numDiff;
		var _total = _numInscritos+_numDiff;
		//alert("TOTAL: "+document.getElementById("formularioNOTA:numFicheros").innerHTML);
	}
	
	if (_total>1)
		habilitaChecksModif(false);		
	else
		habilitaChecksModif(true);
	}
	
function habilitaChecksModif(status){
	// Identificacion y finalidad del fichero
	document.getElementById("formularioNOTA:blqFinalidad").disabled=!status;		
	
	// Origen y procedencia de los datos
	document.getElementById("formularioNOTA:blqOrigen").disabled=!status;		

	//Cesiones
	document.getElementById("formularioNOTA:blqCesionModif").disabled=!status;		
	document.getElementById("formularioNOTA:blqCesionSupr").disabled=!status;		

	//TI
	document.getElementById("formularioNOTA:blqTIModif").disabled=!status;		
	document.getElementById("formularioNOTA:blqTISupr").disabled=!status;		

	if (status==false){
		document.getElementById("formularioNOTA:blqOrigen").checked=false;	
		document.getElementById("formularioNOTA:blqFinalidad").checked=false;
		document.getElementById("formularioNOTA:blqTIModif").checked=false;
		document.getElementById("formularioNOTA:blqTISupr").checked=false;
		document.getElementById("formularioNOTA:blqCesionModif").checked=false;
		document.getElementById("formularioNOTA:blqCesionSupr").checked=false;
	}
	
}//




function verificarIdAutorizacion(){
	var obtTabla = document.getElementById('formularioNOTA:tablaImportadores');
	
	if ( (obtTabla && document.getElementById('formularioNOTA:cdAutorizacionTI').value!="") ||
		 (!obtTabla && document.getElementById('formularioNOTA:cdAutorizacionTI').value=="")        
		){
		return true;
		}
	else{
		return false;
		}
	}
	

function verOpcionesFormTipo(valor){
	
	if (valor==true){
		document.getElementById('formularioNOTA:panelFormTipo').style.visibility="visible";
		return false;
		}
	else {
		//document.getElementById('formularioNOTA:panelFormTipo').style.visibility="none";
		//document.getElementById('formularioNOTA:hiddenTipoOperacion').value="1";
		setTipoOperacion("1");
		document.getElementById('formularioNOTA:hiddenCdFormTipo').value="NORMAL";
		return true;
		}
	
	} 
	
function executeFormTipo(cdForm,dsForm){
	setTipoOperacion(dsForm);
	document.getElementById('formularioNOTA:hiddenCdFormTipo').value=cdForm;
	document.getElementById('formularioNOTA:btnLanzarFormTipo').click();
	return true;
	} 

function validarCampoLite(thisone, msgError) {
	    //alert("es valid: "+msgError);
		if (thisone.value!=""){
			thisone.className ="form-txt";
			document.getElementById("formularioNOTA:"+msgError).style.display="none";            
			}
    	}
		
function setMiClase(id,clase){				
	document.getElementById(id).className=clase;	
	}


 function validarOperacionSupresion(){
	
	if (validarMotivoyDestinoSupresion()==true){        
		if (verificaCheckSeleccionadoParaSupresion())
			if(confirm('Va a proceder a suprimir los ficheros seleccionados\n\n\u00bfEsta usted seguro?')){
				javascript:TINY.box.show('Enviando datos...',0,0,0,0,1200);
				return true;
			} else {
				return false;
			}
		else
			return false;
		
	}
	else
		return false;
		
}
   
   
function validarMotivoyDestinoSupresion(){
	
		var _destino = document.getElementById("formularioNOTA:txtDestino").value;
        var _motivos = document.getElementById("formularioNOTA:txtMotivos").value;
    
		if (_motivos=="")
        	document.getElementById("formularioNOTA:sms_motivos").style.display='inline';
		else
	        document.getElementById("formularioNOTA:sms_motivos").style.display='none';
        	
        
        if (_destino=="")
        	document.getElementById("formularioNOTA:sms_destino").style.display='inline';
		else
	        document.getElementById("formularioNOTA:sms_destino").style.display='none';

		var _titu = document.getElementById("formularioNOTA:titularidad").value;

		if (_titu=="PUB"){
	    	
			var	_okDisposicion=false;
			
			var _diario_oficial = document.getElementById("formularioNOTA:diario_oficial").value;
			var _num_boletin= document.getElementById("formularioNOTA:num_boletin").value;			
			var _fechaPub = document.getElementById("formularioNOTA:fecha_publicacion_input").value;
      		document.getElementById("formularioNOTA:fecha_publicacion_hidden").value=_fechaPub;
			var _nombre_disp = document.getElementById("formularioNOTA:nombre_disp").value;
			if (_diario_oficial=="null") 
				_diario_oficial="";




			// comprobamos si hay algo cumplimentado ... si asi fuese, requerimos los 4 campos como obligatorios
			if (_diario_oficial!="" || _num_boletin!="" || _fechaPub!="" || _nombre_disp!="") {
				if (_diario_oficial=="") document.getElementById("formularioNOTA:sms_diario_oficial").style.display='inline';
				else 			   document.getElementById("formularioNOTA:sms_diario_oficial").style.display='none';
							
				
				if (_num_boletin=="") document.getElementById("formularioNOTA:sms_num_boletin").style.display='inline';
				else 			   document.getElementById("formularioNOTA:sms_num_boletin").style.display='none';
							
				
				if (_fechaPub=="") document.getElementById("formularioNOTA:sms_fecha_publicacion").style.display='inline';
				else 			   document.getElementById("formularioNOTA:sms_fecha_publicacion").style.display='none';
				
				
				if (_nombre_disp=="") document.getElementById("formularioNOTA:sms_nombre_disp").style.display='inline';
				else 			   document.getElementById("formularioNOTA:sms_nombre_disp").style.display='none';
				
				if (_diario_oficial!="" && _num_boletin!="" && _fechaPub!="" && _nombre_disp!=""){
					_okDisposicion =true;
					limpiarDisposicionesSupresion();
					}
				else
					alert("Este apartado no es obligatorio, pero en caso de rellenar al menos uno de los datos, deberá cumplimentar los siguientes campos: \n\n     -Diario Oficial de Publicación\n     -Número de Boletín\n     -Fecha de Publicación\n     -Nombre de la Disposición");
					
								
			}
			else{ //los 4 campos estan vacios
				_okDisposicion =true;				
				limpiarDisposicionesSupresion();
			}
			
			
			
			
			
		}//titu
		
		
		if (_motivos!="" && _destino!="" && _titu=="PRI"){			
			return true;			
		}
		else if (_motivos!="" && _destino!="" && _titu=="PUB" && _okDisposicion==true){			
			return true;
		}
		else {
			return false;
		}
			
	}
	
	
	function comprobarFicherosSubidos(numMax, numFileSelect, msgAlert){
		
		if (numFileSelect==null) 
			numFileSelect=0;
		
		if ( numFileSelect >= numMax){
			alert(msgAlert);
			return false;
			}
		else{
			return true;
			}                        			
	 }
	 
	 
 function limpiarDisposicionesSupresion(){
	document.getElementById("formularioNOTA:sms_diario_oficial").style.display='none';
	document.getElementById("formularioNOTA:sms_num_boletin").style.display='none';
	document.getElementById("formularioNOTA:sms_fecha_publicacion").style.display='none';
	document.getElementById("formularioNOTA:sms_nombre_disp").style.display='none';
	 }

function clave() {
	if(document.getElementById("formularioNOTA:textoClave")){
		var texto = document.getElementById("formularioNOTA:textoClave").innerHTML;	
		var texto1 = document.getElementById("formularioNOTA:textoClave1").innerHTML;
		var texto2 = document.getElementById("formularioNOTA:textoClave2").innerHTML;
		var autofirma = document.getElementById("formularioNOTA:autofirma").innerHTML;
	
	}else{
		var texto = document.getElementById("textoClave").innerHTML;	
		var texto1 = document.getElementById("textoClave1").innerHTML;
		var texto2 = document.getElementById("textoClave2").innerHTML;
		var autofirma = document.getElementById("autofirma").innerHTML;
	}
	var confirmAFirma = confirm(texto + "\n" + texto1 + "\n" + texto2);
	var URLactual = window.location;	
	if(!confirmAFirma){
		
		var navInfo = window.navigator.appVersion.toLowerCase();  
		var so = 'Ruta enlace descarga AFirma - Sistema Operativo';  
			
		if(navInfo.indexOf('win') != -1){ 
			if (navigator.userAgent.indexOf("WOW64") != -1 || navigator.userAgent.indexOf("Win64") != -1 ){// Windows 64 bits
				so = 'AutoFirma64.zip';
			} else {// Windows 32 bits
				so = 'AutoFirma32.zip';
			}
		}
		else if(navInfo.indexOf('linux') != -1) { 
			so = 'AutoFirma_Linux.zip'; 
		}else if(navInfo.indexOf('mac') != -1) {
			so = 'AutoFirma_Mac.zip'; 
		}
//					setTimeout (function(){}, 15000);
		var ventana = window.open(autofirma + so);
		if(ventana.onload())
		{
			ventana.close();
		}
		
	}else{
		return true;
	}

}