		
function verImagen(imagen,id){
var texto="";
var cruz = "<div style='background-color:#FFFFFF'><span style='background-color:#b7c9cc;margin-right:0px; margin-top:0px;float:right;display:block' class='f_text2'><b>&nbsp;X&nbsp;</span>";
var imagen = "<center><img src="+imagen+"?ale="+String(Math.random())+">";
texto ="<table style='border: 0px solid #b7c9cc; background-color:#FFFFFF' width='100%' height='400'><tr align='center'><td>"
texto = texto + imagen
texto = texto + "</td></tr><table>" 
texto = texto + "<table width='100%' height='22px' style='border: 1px solid #9A4062; background-color:#891637'><tr align='center'></tr></table>"
document.getElementById('ejcproc2').style.display="block"
document.getElementById('ejcproc').style.display="block"
document.getElementById('ejcproc2').innerHTML=cruz+texto+"</div>"
centrarWrapper()

}


function verImagenBus(imagen,id){
var texto="";
var cruz = "<div style='background-color:#FFFFFF'><span style='background-color:#b7c9cc;margin-right:0px; margin-top:0px;float:right;display:block' class='f_text2'><b>&nbsp;X&nbsp;</span>";
var imagen = "<center><img src="+imagen+"?ale="+String(Math.random())+">";
texto ="<table style='border: 0px solid #b7c9cc; background-color:#FFFFFF' width='100%' height='400'><tr align='center'><td>"
texto = texto + imagen
texto = texto + "</td></tr><table>" 
texto = texto + "<table width='100%' height='22px' style='border: 1px solid #9A4062; background-color:#891637'><tr align='center'></tr></table>"
parent.document.getElementById('ejcproc2').style.display="block"
parent.document.getElementById('ejcproc').style.display="block"
parent.document.getElementById('ejcproc2').innerHTML=cruz+texto+"</div>"
parent.centrarWrapper()

}

//segun el parámetro cargamos un valor u otro en el frame
function cargarContenido(valor){

	if (valor=="home"){
		ajustarFrame('2')
		window.top.menu.location.href = "inicabecera.php"
		window.top.vista.location.href = "presentacion.php"
	}else{
		ajustarFrame('1')
		if (valor=="comp"){
			window.top.menu.location.href = "cabecera.php?button=8"
			window.top.vista.location.href = "perfil.php"
		}
		if (valor=="far"){
			window.top.menu.location.href = "cabecera.php?button=1"
			window.top.vista.location.href = "ecfam.php"
		}
		if (valor=="pla"){
			window.top.menu.location.href = "cabecera.php?button=6"
			window.top.vista.location.href = "terceros.php"
		}
		if (valor=="qui"){
			window.top.menu.location.href = "cabecera.php?button=3"
			window.top.vista.location.href = "ecqui.php"
		}
		if (valor=="vec"){
			window.top.menu.location.href = "cabecera.php?button=2"
			window.top.vista.location.href = "ecpro.php"
		}
		if (valor=="cont"){
			window.top.menu.location.href = "cabecera.php?button=9"
			window.top.vista.location.href = "contactar.php"
		}
	}

}

function ajustarFrame(tipo){
	var objsFrameset=top.document.getElementsByTagName("frameset");
	if (tipo=="1"){
		objsFrameset[0].rows="130,*"
	}else{
		objsFrameset[0].rows="102,*"
	}
}

function desconectar(){
	parent.top.window.location.href="desconectar.php"

}

function verImagen2(imagen,id){
var texto="";
var cruz = "<div style='background-color:#891637'><span style='background-color:#891637;margin-right:0px; margin-top:0px;float:right;display:block' class='f_text2'>&nbsp;X&nbsp;</span>";
var comentario = document.getElementById('idimg'+id).alt
var imagen = "<img src="+imagen+"?ale="+String(Math.random())+" VALIGN='middel'>";
texto ="<table style=' background-color:#891637' width='100%' height='530'><tr align='center'><td VALIGN='bottom'><br><br><br><br><br><br><br>"
texto = texto + imagen
texto = texto + "</td></tr><table>" 
document.getElementById('ejcproc2').style.display="block"
document.getElementById('ejcproc').style.display="block"
document.getElementById('ejcproc2').innerHTML=cruz+texto+"<div>"
ocultarContenido()
centrarWrapper()
}

function mostrarDetalle(objeto){
var cruz = "<span style='background-color:#891637;margin-right:0px; margin-top:0px;float:right;display:block' class='f_text2'>&nbsp;X&nbsp;</span>";
document.getElementById('ejcproc2').style.display="block"
document.getElementById('ejcproc').style.display="block"
document.getElementById('ejcproc2').innerHTML=cruz+objeto.innerHTML
centrarWrapper()
mostrarContenido(1)
}

function abrirUrl(url){
	window.location.href="http://"+location.host+url
}
function abrirURLframe(url){
	window.top.vista.location.href="http://"+location.host+url
}
function centrarWrapper (){
    var correctorPercent = 1;//En caso de definir las dimensiones del wrapper en porcentajes.
    if (window.innerWidth > document.getElementById('ejcproc2').offsetWidth - correctorPercent){
        document.getElementById('ejcproc2').style.left = '50%';
        document.getElementById('ejcproc2').style.marginLeft = (-1) * document.getElementById('ejcproc2').offsetWidth / 2 + 'px';
        document.getElementById('ejcproc').style.marginLeft = (-1) * document.getElementById('ejcproc').offsetWidth / 2 + 'px';
    }
    if (window.innerHeight > document.getElementById('ejcproc2').offsetHeight - correctorPercent){
        document.getElementById('ejcproc2').style.top = '50%';
        document.getElementById('ejcproc2').style.marginTop = (-1) * document.getElementById('ejcproc2').offsetHeight / 2 + 'px';
        document.getElementById('ejcproc').style.marginTop = (-1) * document.getElementById('ejcproc').offsetHeight / 2 + 'px';
    }
}

function visualizar(valor){
	if (document.getElementById('ejcproc2').style.display=="block"){
		document.getElementById('ejcproc2').style.display="none"
		document.getElementById('ejcproc').style.display="none"
		mostrarContenido()
	}
}

function verProducto(id){
	document.getElementById('peticionesIframe').src="verproducto.php?Cid="+id
}

function verProductoGeneral(id){
	document.getElementById('peticionesIframe').src="verproductogeneral.php?Cid="+id
}

function verNoticia(id){
	document.getElementById('peticionesIframe').src="vernoticia.php?Cid="+id
}

function verArchivo(id){
	document.getElementById('peticionesIframe').src="verarchivo.php?Cid="+id
}

function verFichero(tipo, valor){
	var ancho = 800;
	var alto = 600;
	var x = (screen.width/2) - (ancho/2);
	var y = (screen.height/2) - (alto/2) - 20;
	var finalurl2 = "descargarFichero.php?tipo="+tipo+"&Cid="+valor+"&ale="+String(Math.random());
	parent.document.getElementById('peticionesIframeFichero').src=finalurl2
}


//Funcion de busqueda general para toda la web
function busquedaGeneral(){
	var query = document.forms[0].buscar.value
	if (trim(query) ==""){
	alert("Debe de introducir algún caracter para realizar una búsqueda")
		return;
	}
	
	query = "( gama like '"+query+"%' or texto_desc like '"+query+"%' or nombre like '"+query+"%')"
	window.top.vista.document.forms[0].query.value=query
	window.top.vista.document.forms[0].submit();
}


function buscarproductos(){

	var cat = document.forms[0].Cidioma.value
	var tit= document.forms[0].Cgama.value
	var desc =document.forms[0].Cdescprod.value
	if (cat=="-" && tit=="-" && desc ==""){
		alert("Debe de introducir algún caracter para realizar una búsqueda")
		return;
	}
	
	//montamos la query ej JS categoria like '$idioma' or titulo like '%$titulo%' or descripcion  like '%$desc%'
	var query = "";
	
	if (cat !="-"){
		query = "categoria = '"+cat+"' ";  
	}
	
	if (tit !="-"){
		if (query ==""){
  			query = " gama = '"+replaceSubstring(tit, '+',' ')+"' ";
		}else{
			query += " and gama = '"+replaceSubstring(tit, '+',' ')+"' ";
		}
	}
	
	if (desc !=""){
		if (query ==""){
			query = " texto_desc  like '%"+desc+"%' or nombre like '%"+desc+"%'  ";  
			query += " or gama  like '%"+desc+"%'  ";
		}else{
			query += " and texto_desc  like '%"+desc+"%' or nombre like '%"+desc+"%' ";
			query += " or gama  like '%"+desc+"%'  ";
		}
	}
	document.forms[0].query.value= "( " +query+" )";
	document.forms[0].busqueda.value="1";
	document.forms[0].submit();
}

function buscarnoticias(){
	var desc =document.forms[0].Cdescprod.value
	var query = "";
	if (desc ==""){
		alert("Debe de introducir algún caracter para realizar una búsqueda")
		return;
	}
	
	if (desc !=""){
		if (query ==""){
			query = " titulo  like '%"+desc+"%' or texto like '%"+desc+"%'  ";  
		}else{
			query += " or titulo  like '%"+desc+"%' or texto like '%"+desc+"%' ";
		}
	}
	document.forms[0].query.value= "( " +query+" )";
	document.forms[0].busqueda.value="1";
	document.forms[0].submit();
}

function buscardocumentos(){

	var cat = document.forms[0].Cidioma.value
	var desc =document.forms[0].Cdescprod.value
	if (cat=="-" && desc ==""){
		alert("Debe de introducir algún caracter para realizar una búsqueda")
		return;
	}
	
	//montamos la query ej JS categoria like '$idioma' or titulo like '%$titulo%' or descripcion  like '%$desc%'
	var query = "";
	
	if (cat !="-"){
		query = "categoria = '"+cat+"' ";  
	}
	if (desc !=""){
		if (query ==""){
			query = " nombre  like '%"+desc+"%' or descripcion like '%"+desc+"%'  ";  
		}else{
			query += " or nombre  like '%"+desc+"%' or descripcion like '%"+desc+"%' ";
		}
	}
	document.forms[0].query.value= "( " +query+" )";
	document.forms[0].busqueda.value="1";
	document.forms[0].submit();
}

function verDiv(valor){
	if (document.getElementById(valor).style.display=="none"){
			document.getElementById(valor).style.display="block"
	}else{
		document.getElementById(valor).style.display="none"
	}
}

function cambioIdioma(idioma){
	var path= window.location.href.indexOf("?")
	var path2 = window.top.vista.location.href.indexOf("?")
	
	//if (idioma=="esp"){
		if (path==-1){
			window.location.href=window.location.href+"?idioma="+idioma+"&ale="+String(Math.random());;
		}else{
			window.location.href=window.location.href.substring(0,path)+"?idioma="+idioma+"&ale="+String(Math.random());;
		}
		if (path2==-1){
			window.top.vista.location.href=window.top.vista.location.href+"?idioma="+idioma+"&ale="+String(Math.random());;
		}else{
			window.top.vista.location.href=window.top.vista.location.href.substring(0,path2)+"?idioma="+idioma+"&ale="+String(Math.random());;
		}
	//}else{
	//	window.top.vista.location.href="construccion.php?idioma="+idioma+"&ale="+String(Math.random());;
	//}
}

function verImagenVentana(imagen){
	var ancho = 900;
	var alto = 590;
	var x = (screen.width/2) - (ancho/2);
	var y = (screen.height/2) - (alto/2) - 20;
	var path=location.href.substring(0,location.href.lastIndexOf("/"))
	var finalurl = location.protocol+"//"+location.host +"/hps/php/visImage.php?path="+path+"&img="+imagen+"&ale="+String(Math.random())
	WinImagen = window.open(finalurl,"Imagen","top=" + y + ",left=" + x + ",resizable=0,statusbar=yes,scrollbars=yes,width=" + ancho + ",height=" + alto);//creo una pantalla vacia sin documentos
	WinImagen.focus();
}

function verDetalle(id,carpeta){
	var path=location.href.substring(0,location.href.lastIndexOf("/"))
	var finalurl = location.protocol+"//"+location.host +"/hps/php/visDetalle.php?path="+path+"&id="+id+"&carpeta="+carpeta+"&ale="+String(Math.random())
	window.document.getElementById('peticionesIframe').src =finalurl
}


function validarEntrada(idioma){
if (document.forms[0].Clogin.value==""){
		alert("El campo usuario no puede estar vacío")
		return;
	}
if (document.forms[0].Cpass.value==""){
		alert("El campo contrasenya no puede estar vacío")
		return;
	}
	document.getElementById('form1').submit()
}


function validarContacte(idioma){
	if (!document.forms[0].acepto.checked) {
		alert("Debe de aceptar las condiciones");
		return;
	}
	
	if (document.forms[0].nombre.value==""){
		alert("El campo nombre no puede estar vacío")
		return;
	}
	
	if (document.forms[0].apellidos.value==""){
		alert("El campo apellidos no puede estar vacío")
			return;
	}

	if (document.forms[0].email.value==""){
		alert("El campo email no puede estar vacío")
			return;
	}
	document.getElementById('form1').submit()
}

function trim(cadena)
{
	for(i=0; i<cadena.length; )
	{
		if(cadena.charAt(i)==" ")
			cadena=cadena.substring(i+1, cadena.length);
		else
			break;
	}

	for(i=cadena.length-1; i>=0; i=cadena.length-1)
	{
		if(cadena.charAt(i)==" ")
			cadena=cadena.substring(0,i);
		else
			break;
	}
	
	return cadena;
}



function mostrarContenido(flag){
if (flag==null){
if (document.getElementById('ejcproc2').style.display=="block"){
	return;
}
}
var pos =0;
capas=document.getElementsByTagName('div');
	for (i=0;i<capas.length;i++){
		if ((capas[i].id.indexOf('imag') != -1) || (capas[i].id.indexOf('vid') != -1)){
			if ((capas[i].innerHTML.indexOf('#') ==-1) && (capas[i].innerHTML !="")){
				 pos = (capas[i].innerHTML.indexOf('images/'));
				if (pos > 0){
					var hg = capas[i].innerHTML.substring(pos+7,pos+8)
					if (hg !="'"){
						capas[i].style.display='block';
					}
				}
			}
		}
	}
}

function ocultarContenido(){

capas=document.getElementsByTagName('div');
	for (i=0;i<capas.length;i++){
		if ((capas[i].id.indexOf('imag') != -1) || (capas[i].id.indexOf('vid') != -1)){
			if ((capas[i].innerHTML.indexOf('#') ==-1)){
				capas[i].style.display='none';
			}
		}
	}
}
function isNumericField(Field)
{
  var newString = '';
  //Si comprobamos un campo numerico a "" retornamos error
  if (Field==""){
  	return false;
  }
  //Fer les voltes fins saber si es un numero o no
  for (i = 0; i < Field.length; i++)
  {
    ch = Field.substring(i, i+1);
    if (ch >= "0" && ch <= "9")
    {
      newString += ch;
    }
  }
  if (newString  == Field)
  {
    return true;
  }
  else
  {
    return false;
  }
}

function BuscarChecked(FieldRadio, buscarChecked)
{
//Mediante esta rutina comprobaremos si un campo de tipo checkbox (radio/Check button) tiene seleccionado el valor buscarChecked.
	for(i = 0; i<FieldRadio.length; i++)
	{
		if(FieldRadio[i].checked)
		{
			if(FieldRadio[i].value.toUpperCase() == buscarChecked)
			{
				 return 1;
			}
		}
	}
	if(i == FieldRadio.length) return -1;
}

//reemplaza el texto, tantas veces como lo encuentre
function replaceSubstring ( inputString, badString, goodString)
{
	fixedReplace = "";
	UI = inputString;
	UB = badString;
	badEnd = -1;
	badLoc = UI.indexOf(UB);
	if (badLoc != -1)
	{
		for (x=1; (badLoc != -1);x++)
		{
			fixedReplace = fixedReplace + inputString.substring((badEnd + 1), badLoc) + goodString;
			badEnd = badLoc + UB.length - 1;
			badLoc = UI.indexOf(UB, (badLoc + 1));
		}
	  	fixedReplace = fixedReplace + inputString.substring((badEnd+1),inputString.length);
	}
	else
	{
		fixedReplace = inputString;
	}
	return fixedReplace;
}