		
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('video').style.display="none"
document.getElementById('ejcproc2').innerHTML=cruz+texto+"</div>"
centrarWrapper()

}


function numbersonly(campo, e, dec)
{
var tecla;
var caracter;

if (window.event)
   tecla = window.event.keyCode;
else if (e)
   tecla = e.which;
else
   return true;
caracter = String.fromCharCode(tecla);

if ((tecla==null) || (tecla==0) || (tecla==8) || 
    (tecla==9) || (tecla==13) || (tecla==27) )
   return true;
else if ((("0123456789,-").indexOf(caracter) > -1))
   return true;
else if (dec && (caracter == "."))
   {
   campo.form.elements[dec].focus();
   return false;
   }
else
   return false;
}

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"
document.getElementById('video').style.display="none"
parent.document.getElementById('ejcproc2').innerHTML=cruz+texto+"</div>"
parent.centrarWrapper()

}


function validarContactar(){
	if (document.forms['contactar'].nombre.value==""){
		alert("Debe introducir un nombre de contacto")
		return false;
	}
	if (document.forms['contactar'].email.value==""){
		alert("Debe introducir un email de contacto")
		return false;
	}
	document.forms['contactar'].submit();
	
}

//segun el parámetro cargamos un valor u otro en el frame
function cargarContenido(valor){
	if (valor=="home"){
		ajustarFrame('1')
		window.top.menu.location.href = "cabecera.php"
		window.top.vista.location.href = "productos.php"
	}else{
		ajustarFrame('1')
		if (valor=="comp"){
			window.top.menu.location.href = "cabecera.php"
			window.top.vista.location.href = "perfil.php?p=6"
		}
		if (valor=="far"){
			window.top.menu.location.href = "cabecera.php"
			window.top.vista.location.href = "ecfam.php?p=1"
		}
		if (valor=="pla"){
			window.top.menu.location.href = "cabecera.php"
			window.top.vista.location.href = "terceros.php?p=4"
		}
		if (valor=="qui"){
			window.top.menu.location.href = "cabecera.php"
			window.top.vista.location.href = "ecqui.php?p=3"
		}
		if (valor=="vec"){
			window.top.menu.location.href = "cabecera.php"
			window.top.vista.location.href = "ecpro.php?p=2"
		}
		if (valor=="cont"){
			window.top.menu.location.href = "cabecera.php"
			window.top.vista.location.href = "contactar.php?p=9"
		}
	}
}

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('video').style.display="none"
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('video').style.display="none"
document.getElementById('ejcproc2').innerHTML=cruz+objeto.innerHTML
centrarWrapper()
mostrarContenido(1)
}

function abrirUrlImpacto(op, it){
	var ancho = 1000;
	var alto = 800;
	var x = (screen.width/2) - (ancho/2);
	var y = (screen.height/2) - (alto/2) - 20;
	var finalurl ="impacto.php?op="+op+"&it="+it+"&ale="+String(Math.random());
	WinNueva = window.open(finalurl,'','');//creo 
	WinNueva.focus();
}

function abrirUrl(url){
	window.location.href=url
}

function abrirFabricante(valor){
	if (valor !=""){
		window.location.href="visfabricantes.php?pr="+valor+"&ale="+String(Math.random());
	}
}

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"
		document.getElementById('video').style.display="block"
		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 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 validar(formulario){

	var elementos = document.forms[formulario].elements.length;
	var obj = "";
	var nomobj = "";

	try{
	for (fo = 0;fo < elementos; fo++){
		obj = document.forms[formulario].elements[fo]
		nomobj = obj.id.substring(obj.id.lastIndexOf('#')+1,25);

		if (obj.id.indexOf("#R#") != -1) {
		
			//"Requerido")
			if (trim(obj.value)==""){
				obj.style.backgroundColor = '#ff0000';
				alert("El campo '" + nomobj + "' es obligatorio");
				return false;
			}
		}
		if (obj.id.indexOf("#N#") != -1) {
			//"Numerico")
			if (isNumericField(obj.value)==false){
				obj.style.backgroundColor = '#ff0000';
				alert("El campo '" + nomobj + "' debe de ser numérico.");
				return false;
			}
		}
		
		if (obj.id.indexOf("#D#") != -1) {
			//"Numerico")
			if (isNumericField(obj.value)==false){
				obj.style.backgroundColor = '#ff0000';
				alert("El campo '" + nomobj + "' debe de ser numérico.");
				return false;
			}else{
				obj.value = obj.value.replace(',','.');
			}
		}
		
		if (obj.id.indexOf("#F#") != -1) {
			//"fecha")
			if (validarData(obj.value)==false){
				obj.style.backgroundColor = '#ff0000';
				alert("El campo '" + nomobj + "' no es una fecha valida.");
				return false;
			}
		}
		obj.style.backgroundColor = '#FFFFFF';
	}
	}catch (e){
		alert(e);
		return false;
	}
	
	//Si el formulario es el de alta o modificacion de datos de usuario, validamos que las dos pass sean iguales
	if (formulario =="identificarse" || formulario =="modifuser"){
		var pass1="";
		var pass2="";
		
		pass1= document.forms[formulario].password.value
		pass2= document.forms[formulario].pass2.value
		
		if (pass1 != pass2)	{
			alert("Las contraseñas no son iguales");
			return false;
		}
	}
}


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;
}

function BuscarCualquierChecked(FieldRadio)
{
//Mediante esta rutina comprobaremos si un campo de tipo checkbox (radio/Check button) tiene algún valor seleccionado. Devolverá -1 en caso que NO haya nada seleccionado y 1 en caso que SI encuentre algún valor seleccionado.
try{
	for(i = 0; i <= FieldRadio.length; i++)
		{
		if(FieldRadio[i].checked) return 1;
	}
	if(i == FieldRadio.length) return -1;
}catch (Exception){
	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;
}
function validarData(Data2)
{ 
/*
	La validación que sigue es:
		- que el dia contenga 2 dígitos
		- que el mes contenga 2 dígitos
		- que el año al menos contenga 1 dígito para definirlo. 
				* Si se define con 1 dígito añade el sufijo 200
				* si se define con 2 dígitos añade el sufijo 20
				* y si se define con 3 dígitos añade el sufijo 2.
	En caso que la validación sea correcta, devolverá la fecha en formato correcto(dd/mm/aaaa);
	si no 
		si el error estaba en el formato del año --> devuelve -1;
		en otro caso devuelve false;
*/
	var Data = Data2;
	switch(Data.length)
	{
		case 10:
			iniAny = 6;
			finAny = 10;
			anadeAny = "";
			break;
		case 9:
			iniAny = 6;
			finAny = 9;
			anadeAny = "2";
			break;
		case 8:
			iniAny = 6;
			finAny = 8;
			anadeAny = "20";
			break;
		case 7:
			iniAny = 6;
			finAny = 7;
			anadeAny = "200";
			break;
		default:
			return false;
	}
	Separador = "/";
	Any = Data.substring(iniAny, finAny);
	if (isNumericField(Any)==true)
	{
		Any = anadeAny + Any;
		if (parseFloat(Any)<1900 || parseFloat(Any)>2100)
		{
			return false;
		}
	}
	else
	{
		return false;
	}
	Mes= Data.substring(3,5);
	if (isNumericField(Mes)==false) 
	{
		return false;
	}
	else
	{
		if((parseFloat(Mes)<1) || (parseFloat(Mes) > 12))
		{
			return false;
		}
	}
	Dia  = Data.substring(0,2);
	UltimDia=calclastday(parseFloat(Mes),parseFloat(Any)); 
	if (isNumericField(Dia)==false)
	{
		return false;
	}
	else
	{
		if((parseFloat(Dia)<1) || (parseFloat(Dia) > UltimDia))
		{
			return false;
		}
	}
	Separador1=Data.substring(2,3);
	Separador2=Data.substring(5,6);
	if (Separador1!=Separador || Separador2!=Separador)
	{
		return false;
	}
	return Dia + Separador + Mes + Separador + Any;
}
function calclastday(month,year)
{
	var monthsdays = new Array(0,31,28,31,30,31,30,31,31,30,31,30,31);
	if (((year % 4) == 0) & (month == 2))
	{
		if (((year % 100) == 0) & (month == 2))
		{
			if (((year % 400) == 0) & (month == 2))
			{
				return 29;
			}
			else
			{
				return monthsdays[month];
			}
		}
		else
		{
			return 29;
		}
	}
	else
	{
		return monthsdays[month];
	}
}