// JavaScript Document

var desplegadoActual = null;  // Global.  Almacena la capa visible actualmente

function conmuta(objId){
	// Conmuta la visibilidad de una capa
	// objId : Id de la capa a ocultar o mostrar
	
	if(desplegadoActual != null && desplegadoActual != objId){
		var actual = document.getElementById(desplegadoActual);
		actual.style.display="none";		
	}
	var objeto = document.getElementById(objId);
	if(objeto.style.display == "none"){
		objeto.style.display = "block";
	}else{
		objeto.style.display = "none";
	}
	desplegadoActual = objId;
}


//  Scriptlets code written by Jeremy Edmiston
//  The functions have been adapted from various sources
//  and re-written to provide maximum flexibility
//  and compatability with various browsers.

//Global Declarations
var ie = (document.all) ? true : false;

function toggleClass(objClass){
//  This function will toggle obj visibility of an Element
//  based on Element's Class
//  Works with IE and Mozilla based browsers

  if (getElementByClass(objClass).style.display=="none"){
    showClass(objClass)
  }else{
    hideClass(objClass)
  }
}

function hideClass(objClass){
//  This function will hide Elements by object Class
//  Works with IE and Mozilla based browsers

var elements = (ie) ? document.all : document.getElementsByTagName('*');
  for (i=0; i<elements.length; i++){
    if (elements[i].className==objClass){
      elements[i].style.display="none"
    }
  }
}

function showClass(objClass){
//  This function will show Elements by object Class
//  Works with IE and Mozilla based browsers
var elements = (ie) ? document.all : document.getElementsByTagName('*');
  for (i=0; i<elements.length; i++){
    if (elements[i].className==objClass){
      elements[i].style.display="block"
    }
  }
}

function toggleID(objID){
//  This function will toggle obj visibility of an Element
//  based on Element's ID
//  Works with IE and Mozilla based browsers
var element = (ie) ? document.all(objID) : document.getElementById(objID);
  if (element.style.display=="none"){
    showID(objID)
  }else{
    hideID(objID)
  }
}

function hideID(objID){
//  This function will hide Elements by object ID
//  Works with IE and Mozilla based browsers
var element = (ie) ? document.all(objID) : document.getElementById(objID);
  element.style.display="none"
}

function showID(objID){
//  This function will show Elements by object ID
//  Works with IE and Mozilla based browsers
var element = (ie) ? document.all(objID) : document.getElementById(objID);
  element.style.display="block"
}

function getElementByClass(objClass){
//  This function is similar to 'getElementByID' since there
//  is no inherent function to get an element by it's class
//  Works with IE and Mozilla based browsers
var elements = (ie) ? document.all : document.getElementsByTagName('*');
  for (i=0; i<elements.length; i++){
    //alert(elements[i].className)
    //alert(objClass)
    if (elements[i].className==objClass){
    return elements[i]
    }
  }
}

// FUCNIONES QUE HEMOS IDO AÑADIENDO NOSOTROS

//funcion global para ejecutar al cargar la pagina
//añadimos la clase radioButton solo para los inputs de tipo radio
var wpJ = jQuery.noConflict();
wpJ("document").ready(function(){
  wpJ("input:radio").addClass("radioButton");
  wpJ("input:checkbox").addClass("radioButton");
})

// Funcion para cambiar de pestaña en los escaparates
function cambiaPestana(clase_a_ocultar, id_a_mostrar) {
	wpJ(clase_a_ocultar).hide();
	wpJ(id_a_mostrar).show();
}

// Funcion para los popups de los escaparates
function pop(nom_popup,ancho,alto,imagen,desc) {
	alto=(alto*1)+15;
	if (imagen.toUpperCase().indexOf(".PDF")!=-1){
	 	window.open(imagen,'','directories=no,location=no,menubar=no,scrollbars=yes,status=no,toolbar=no,resizable=yes');	
	}else{
		nom_vent=window.open ('/templates/moll_escaparate_popup.php?desc='+desc+'&imagen='+imagen,nom_popup,'height='+alto+',width='+ancho+',location=no,menubar=no,personalbar=no,scrollbars=no,status=no,titlebar=no,toolbar=no'); 	
	}
}

function popupGenerico(fuente, ancho, alto, scroll){ 
	window.open(fuente, '_blank', 'width='+ancho+', height='+alto+', top=1px, left=1px, status=yes, scrollbars='+scroll); 
}

function quitaAcentos(texto){
	texto=texto.replace("á", "a");
	texto=texto.replace("é", "e");
	texto=texto.replace("í", "i");
	texto=texto.replace("ó", "o");
	texto=texto.replace("ú", "u");
	return texto;
}

function censuraTexto(texto){
	texto=quitaAcentos(texto.toLowerCase());
	for(i=0; i<arrayPalabras.length; i++){ 
		if (texto.indexOf(arrayPalabras[i])>-1){
			if (texto.indexOf(arrayPalabras[i])!=0 && ((texto.charCodeAt(texto.indexOf(arrayPalabras[i])-1)>=65 && texto.charCodeAt(texto.indexOf(arrayPalabras[i])-1)<=90) || (texto.charCodeAt(texto.indexOf(arrayPalabras[i])-1)>=97 && texto.charCodeAt(texto.indexOf(arrayPalabras[i])-1)<=122))) return false;
			if (texto.substring(texto.indexOf(arrayPalabras[i])+arrayPalabras[i].length, 1)!='' && ((texto.charCodeAt(texto.indexOf(arrayPalabras[i])+arrayPalabras[i].length)>=65 && texto.charCodeAt(texto.indexOf(arrayPalabras[i])+arrayPalabras[i].length)<=90) || (texto.charCodeAt(texto.indexOf(arrayPalabras[i])+arrayPalabras[i].length)>=97 && texto.charCodeAt(texto.indexOf(arrayPalabras[i])+arrayPalabras[i].length)<=122))) return false;
			return arrayPalabras[i];
		}
	}
	return false;
}

function abreRevista(webroot,sec_id) {
	if (sec_id>0) lin=webroot+'revista/seccion.htm?id='+sec_id;
	else lin=webroot+'revista/revistaBodaclick/novias_revista_marcos.htm';
	window.open(lin,'revistanovias_' + sec_id, 'screenX=0,left=0,screenY=0,top=0,width=' + screen.width + ',height=' + screen.height + ',menubar=no,resizable=no,titlebar=no,alwaysRaised=yes,status=no,fullscreen=1,scrollbars=NO');
}

function imprimir(idReportaje,webroot,logo)
{
  window.open (webroot+"templates/versionImpresaReportaje.php?idReportaje="+idReportaje+"&logo="+logo,"Version_Impresa","top=0,left=0,width=700,height=700");
}

function strpos(str, ch) {
	for (var i = 0; i < str.length; i++)
	if (str.substring(i, i+ch.length) == ch) return i;
	return -1;
}

//Buscador columna derecha y album
function tecla(evento,webroot)
{
 if (evento.keyCode)
	iAscii = evento.keyCode;
else if (evento.which)
	iAscii = evento.which;
else
	 return false;
if (iAscii == 13) buscar('',webroot);
}
// Buscador columna derecha
function buscar(textoAviso,webroot) {
	if (escape(document.getElementById('busqueda').value)=="") {
		alert (textoAviso);
		return;
	}
	//alert (webroot+'?search='+escape(document.getElementById('busqueda').value));
	location.href='/?search='+escape(document.getElementById('busqueda').value);
}

// Combo de las secciones para ir a una planta
function irPlanta(bdMollNacional) {
	var f=document.getElementById("selectIrPlanta");
	//Miro si ha seleccionado o no alguna opción
	if (f.selectedIndex == 0){
		location.href= "/?moll=" + bdMollNacional;
	}else{
		location.href=f.options[f.selectedIndex].value;
	}
	
}