/*

	Funciones de javascript para la aplicación Tecnorail.

*/

	function pasaRatonHit( numero, score ){
		if( numero > 110) {
			return true;
		}
		var svgdoc = document.grafHits.getSVGDocument();
		if( svgdoc != null ) {
			var svgobj = svgdoc.getElementById("c_" + numero);
			if( svgobj != null ) {
				var svgstyle = svgobj.getStyle();
				//svgstyle.setProperty ('fill', 'red');
				svgstyle.setProperty ('visibility', 'visible');

			}

			var svgobj2 = svgdoc.getElementById("c2_" + numero);
			if( svgobj2 != null ) {
				var svgstyle = svgobj2.getStyle();
				//svgstyle.setProperty ('fill', 'red');
				svgstyle.setProperty ('visibility', 'hidden');
			}

			var porcent = svgdoc.getElementById( "porcent" );
			porcent.setAttribute ( "x",  numero*5 );
			porcent.getStyle().setProperty ('visibility', 'visible');
			porcent = porcent.getFirstChild();
			porcent.setData ( score+" %" );
		}
		return true;
	}


	function saleRatonHit( numero ){
		var svgdoc = document.grafHits.getSVGDocument();
		if( svgdoc != null ) {
			var svgobj = svgdoc.getElementById("c_" + numero);
			if( svgobj != null ) {
				var svgstyle = svgobj.getStyle();
				//svgstyle.setProperty ('fill', '#336699');
				svgstyle.setProperty ('visibility', 'hidden');
			}

			var svgobj2 = svgdoc.getElementById("c2_" + numero);
			if( svgobj2 != null ) {
				var svgstyle = svgobj2.getStyle();
				//svgstyle.setProperty ('fill', '#336699');
				svgstyle.setProperty ('visibility', 'visible');
			}

			var porcent = svgdoc.getElementById( "porcent" );
			porcent.getStyle().setProperty ('visibility', 'hidden');
		}
		return true;
	}




	function pasaRatonRelac( evt ){
		var svgdoc = document.grafRelac.getSVGDocument();
		var elemento = evt.getTarget();
		elemento.setAttribute('style','font-weight:bold;font-size:14;');
	}

	function saleRatonRelac( evt ){
		var svgdoc = document.grafRelac.getSVGDocument();
		var elemento = evt.getTarget();
		elemento.setAttribute('style','fill: #b52ed3;');
		elemento.setAttribute('style','font-size: 10;');
	}



	function elimina( evt, texto, numero ) {
		var svgdoc = document.grafRelac.getSVGDocument();
		if( svgdoc != null ) {
			var svgobj = svgdoc.getElementById("c_" + numero);
			if( svgobj != null ) {
				// Eliminación de la barra del gráfico.
				svgobj.getParentNode().removeChild( svgobj );
				// Eliminación de texto del porcentaje
				var svgobj2 = svgdoc.getElementById("t_" + numero);
				if( svgobj2 != null ) {
					svgobj2.getParentNode().removeChild( svgobj2 );
				}

				var svgobj3 = svgdoc.getElementById("c2_" + numero);
				if( svgobj3 != null ) {
					svgobj3.getStyle().setProperty ('visibility', 'visible');
				}


			}
		}

		var loDeAntes = window.document.busqueda.cadena.value ;

		if( loDeAntes.length > 0 ) {
			loDeAhora = loDeAntes + " " + texto;
		}else{
			loDeAhora = texto;
		}

		if( ( loDeAhora.length ) <= 120 ) {
			var elemento = evt.getTarget();
			padre=elemento.getParentNode()
			padre.removeChild(  elemento );
			window.document.busqueda.cadena.value = loDeAntes + " " + texto;
		}
	}


	function aniade( texto ) {
        var loDeAntes = window.document.busqueda.cadena.value ;
        window.document.busqueda.cadena.value = loDeAntes + " " + texto;
	}

	function confirma(){
		return confirm( "¿Confirma que desea borrar las normas seleccionadas?" );
	}


	function mostrarInterno( referencia, sTipoDocumento ){
		var venta2 = window.open( "../visual.jsp?norm="+referencia+ "&td=" + sTipoDocumento, "","scrollbars=yes,resizable=yes,width=800,height=450,status=no,location=no,toolbar=no");
		venta2.focus();
  		return true
	}

	function mostrar( referencia, sTipoDocumento ){
		var venta2 = window.open( "visual.jsp?norm="+referencia+ "&td=" + sTipoDocumento, "", "scrollbars=yes,resizable=yes,width=800,height=550,status=no,location=no,toolbar=no");
		venta2.focus();
  		return true
	}



	function comprobArchivo(){
	
	 	var documento = formAlta.archivo.value;
	
		if( documento.length==0 ) {
			alert( "Debe introducir un nombre de archivo para añadir al índice" ) ;
			return;
		}


		if( valorBotonRadio( formAlta.tipoDocumento ) == null ) {
			alert( "Debe indicar de qué tipo es el archivo que se quiere añadir al índice" ) ;
			return;
		}
		
	    formAlta.submit();
	}



	function activa( campo, totalCampos ) {
		for( var iA = 0; iA < totalCampos; iA++ ) {
			if( iA == campo ) {
				document.getElementById( "campo_" + iA ).style.visibility="visible";
				document.getElementById( "titulo_" + iA ).style.background="#7aaadd";
			}else{
				if( document.getElementById( "campo_" + iA ) != null ) {
					document.getElementById( "campo_" + iA ).style.visibility="hidden";
					document.getElementById( "titulo_" + iA ).style.background="#336699";
				}
			}
		}
	}
	
	
	
	

	function limpia( campo ) {
		if( campo.value == "dd/mm/aaaa" ) {
			campo.value = "" ;
		}
	}

	function restaura( campo ) {
		if( campo.value == "" ) {
			campo.value = "dd/mm/aaaa" ;
		}
	}





	function validar() {
	
//		if( document.busqueda.desde.value.length != 10 ) {
//			alert("Error en el formato de fecha, de \"Desde fecha de alta\" " );
//			return false;
//		}else if( document.busqueda.hasta.value.length != 10 ){
//			 alert("Error en el formato de fecha, de \"Hasta fecha de alta\" ");
//			 return false;
//		}else{
//			 if( document.busqueda.cadena.value.length == 0 ) return false;
//		}

		if( 	valorBotonRadio( document.busqueda.tipoDocumento ) == null ) {
			alert("Debe seleccionar un tipo de documento para buscar" ) ;
			return false;
		}
		
		if( 	valorBotonRadio( document.busqueda.nombreCampo ) == null )  {
			alert("Debe seleccionar un campo donde buscar en los documentos" ) ;
			return false;
		}

		
		return true;
	}//----------------------------------------------------------------------------------------------------------------------
	

	/*
	*		Devuelve el valor seleccionado de un grupo de botones de radio.
	*/
	function valorBotonRadio( botonRadio ) {
		
    	for( i=0; i<botonRadio.length; i++ ){
        	if( botonRadio[i].checked ) 
        		return botonRadio[i].value;
		}
		return null;
		
	}//----------------------------------------------------------------------------------------------------------------------



	/*
	*		desactiva un grupo de botones de radio.
	*/
	function limpiaRadios( botonRadio ) {
		
    	for( i=0; i<botonRadio.length; i++ ){
       		botonRadio[i].checked=false;
		}
		return null;
		
	}//----------------------------------------------------------------------------------------------------------------------


	
	
	function campos( valor, categoria ) {
		limpiaRadios( document.busqueda.nombreCampo ) ;
		elemento = "div_" + valor.value ;
		document.getElementById( "div_normas" ).style.display="none"; 
		document.getElementById( "div_cursos" ).style.display="none";
		document.getElementById( "div_libros" ).style.display="none"; 
		document.getElementById( "div_concursos" ).style.display="none"; 
		document.getElementById( elemento ).style.display=""; 

		document.busqueda.categorias.disabled="" ;

		for( i=0; i< document.forms[ 'busqueda' ].categorias.options.length; i++ ){
			document.forms[ 'busqueda' ].categorias.options[ 0 ] = null;
		}

		//--	Carga de los SELECT correspondientes al tipo de documento indicado.
		document.forms[ 'busqueda' ].categorias.options[ 0 ] = new Option( "(Todas)" , " " );
		document.forms[ 'busqueda' ].categorias.options[ 1 ] = new Option( "Electrificación" , "31" );
		document.forms[ 'busqueda' ].categorias.options[ 2 ] = new Option( "Infraestructura" , "29" );
		document.forms[ 'busqueda' ].categorias.options[ 3 ] = new Option( "Señalización" , "30" );
		document.forms[ 'busqueda' ].categorias.options[ 4 ] = new Option( "Vía" , "22" );
		document.forms[ 'busqueda' ].categorias.options[ 5 ] = new Option( "Telecomunicaciones" , "24" );

		if( elemento == "div_libros" ){
			document.forms[ 'busqueda' ].categorias.options[ 6 ] = new Option( "Otros" , "999" );
		}

		if( elemento == "div_concursos" ){
			document.forms[ 'busqueda' ].categorias.options[ 6 ] = new Option( "Materiales" , "998" );
			document.forms[ 'busqueda' ].categorias.options[ 7 ] = new Option( "Otros" , "999" );
		}

		if( categoria != null ){
			document.forms[ 'busqueda' ].categorias.value = categoria ;
		}
		
	}//----------------------------------------------------------------------------------------------------------------------
	
	
	
	
	
	
	
	
