/**
 * Esta función muestra/oculta un div cuyo id es pasado como parámetro.
 *     Parámetros: divId = El Id del div a mostrar / ocultar.
 *     			   mostrar = Indica si se muestra el div o no.
 * 						· true: El div es mostrado.
 *						· false: El div es ocultado.
 *
 *
 */
 function visibilidadDiv(divId, mostrar){
	if(document.getElementById(divId).style == null){
		var valor;
		if(mostrar == true){
			valor = 'show';
		}else if(mostrar == false){
			valor = 'hide';
		}
		document.getElementById(divId).visibility = valor;
	}else{
		if(mostrar == true){
			valor = 'visible';
		}else if(mostrar == false){
			valor = 'hidden';
		}
		document.getElementById(divId).style.visibility = valor;
	}	
}

/**
 * Esta función rellena un div, cuyo id es pasado como parámetro, con dos tablas una de ellas sirve para realizar
 * el efecto de un borde, y la otra contiene una fila, con una celda, que contiene el valor del elemento de array 
 * también pasado como parámetro. Paara introducir varios valores en el div, dichos valores se encuentran
 * en el elemento del array, separados por un separador (,|@...).
 * 		Parámetros: divId = El Id del div a rellenar. (Por compatibilidad con Mozilla se utiliza id).
 * 					elementoArray = El elemento del array en el que se encutra el/los valor/es para rellenar la celda.
 *					separador = Caracter utilizado para separar los diferentes valores.
 *      Los valores son introducidos en el div...
 *					'· '+valor1+'<br>'+
 *					'· '+valor2+'<br>'+
 *					...
 *					'· '+valorN+'<br>';			
 *
 */
function escribirDiv(divId, elementoArray, separador){
	var divHtml = '';
	if((elementoArray != null)&&(elementoArray.length > 0)){
		divHtml = '<table border="0" cellspacing="0" cellpadding="1" bgcolor="#226daa">'+
	                    '<tr>'+ 
                          '<td>'+ 
                            '<table border="0" cellspacing="0" cellpadding="5">'+
                              '<tr>'+
                                '<td class="fuenteNormal" bgcolor="#fff0d9">';
		while(elementoArray.toString().length > 0){								
			var indexSeparador = elementoArray.toString().indexOf(separador);
			if(indexSeparador > 0){
				divHtml += '· '+elementoArray.toString().substring(0, indexSeparador)+'<br>';
				elementoArray = elementoArray.toString().substring(indexSeparador+1, elementoArray.toString().length);
			}else{
				divHtml += '· '+elementoArray.toString()+'<br>';		
				elementoArray = "";
			}
		}
		divHtml += '</td>'+
                 '</tr>'+
              '</table>'+
            '</td>'+
          '</tr>'+
        '</table>';		
	}
	document.getElementById(divId).innerHTML = unescape(divHtml);
	if(document.getElementById(divId).style == null){
		document.getElementById(divId).left=posX;
		document.getElementById(divId).top=posY;
		document.getElementById(divId).visibility = 'show';		
	}else{
	 	document.getElementById(divId).style.left=posX;
		document.getElementById(divId).style.top=posY;
		document.getElementById(divId).style.visibility = 'visible';		
	}
	
}  

/**
 * Esta función recorre todos los elementos cuyo tag es DIV, y los 
 * oculta.
 */
function ocultarDivs(){
	var arrayDivs = document.getElementsByTagName('div');
	for(i=0; i<arrayDivs.length; i++){
		arrayDivs[i].style.visibility = 'hidden';
	}
}

/**
 * Esta función oculta y muestra los divs
 */
function ocultarMostrarDivs(divId, elementoArray, separador){
	ocultarDivs();
	escribirDiv(divId, elementoArray, separador);
}

