
function findobj(n, d)
  {
    var p,i,x;
    if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length)
      {d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
    if(!(x=d[n])&&d.all) x=d.all[n];
    for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
    for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=findobj(n,d.layers[i].document);
    return x;
  }

function swapimg()
  {
    var i,j=0,x,a=swapimg.arguments;
    document.MM_sr=new Array;
    for(i=0;i<(a.length-1);i+=2)
     if ((x=findobj(a[i]))!=null)
      {x.src=a[i+1];}
  }

function swap(img,indice) {
	swapimg(img,images[indice].src);
}

function swap2(img,indice) {
	swapimg(img,carrusel[indice].src);
}

function swap2_producto(img,indice) {
		swapimg(img,carrusel_producto[indice].src);
}

var imagenes=new Array('empresa_off','empresa_on','catalogo_off','catalogo_on','noticias_off','noticias_on','ubicacion_off','ubicacion_on','contacto_off','contacto_on','aviso_off','aviso_on');
var images=new Array(imagenes.length);
for (i=0;i<imagenes.length;i++) {
	images[i]=new Image();
	images[i].src='../images/menu/'+imagenes[i]+'.png';
}

var nfoto=0;
if (!fotos) var fotos = new Array();
var carrusel=new Array(fotos.length);
	for (i=0;i<carrusel.length;i++) {
		carrusel[i]=new Image();
		carrusel[i].src='./images/normal/'+fotos[i];
		//carrusel[i].alt = pies[i];
	}

var nfoto_producto=0;
if (!fotos_producto) var fotos_producto = new Array();
var carrusel_producto=new Array(fotos_producto.length);
	for (i=0;i<carrusel_producto.length;i++) {
		carrusel_producto[i]=new Image();
		carrusel_producto[i].src='./fotos/normal/'+fotos_producto[i];
	}

function apaga() {
if (this.id) {
	var numero=this.id.split('opcion').join('');
	var indice=2*numero-2;
	swap('img'+numero,indice);
	}
}
function enciende() {
if (this.id) {
	this.focus();
	var numero=this.id.split('opcion').join('');
	var indice=2*numero-1;
	swap('img'+numero,indice);
	}
}

function cambiamenos() {
	if (nfoto>0) {
	var indice=nfoto-1;
	swap2('foto',indice);
	document.getElementById('foto').alt=pies[indice];
	document.getElementById('foto').title=pies[indice];
	document.getElementById('foto').height=altos[indice];
	document.getElementById('pie_foto').innerHTML = pies[indice];
	nfoto--;
	document.getElementById('f_sig').src='../images/siguiente.png';
	document.getElementById('nfoto').innerHTML=nfoto+1;
	}
	if (nfoto==0) document.getElementById('f_ant').src='../images/sizer.png';
	return false;
}
function cambiamas() {
	if (nfoto<carrusel.length-1) {
		var indice=nfoto+1;
		swap2('foto',indice);
		document.getElementById('foto').alt=pies[indice];
		document.getElementById('foto').title=pies[indice];
		document.getElementById('foto').height=altos[indice];
		document.getElementById('pie_foto').innerHTML = pies[indice];
		nfoto++;
		document.getElementById('f_ant').src='../images/anterior.png';
		document.getElementById('nfoto').innerHTML=nfoto+1;
	}
	
		
	if (nfoto==carrusel.length-1) document.getElementById('f_sig').src='../images/sizer.png';
	return false;
}

function ampliar_foto() {
	//	var ventana = window.open('./images/zoom/'+fotos[nfoto], 'ampliada', 'width=320,height=300,resizable=yes');
	// aqui => carrusel gigante
	mostrar_carrusel_producto = false;
	var ventana = window.open('../carrusel_grande.html', 'ampliada', 'width=620,height=550,resizable=no,scrollbars=yes');
	ventana.focus();
	return false;
}

function cambiamenos_producto() {
	if (nfoto_producto>0) {
	var indice=nfoto_producto-1;
	swap2_producto('foto_producto',indice);
	document.getElementById('foto_producto').alt=pies_producto[indice];
	document.getElementById('foto_producto').title=pies_producto[indice];
	document.getElementById('foto_producto').height=altos_producto[indice];
	document.getElementById('pie_foto_producto').innerHTML = pies_producto[indice];
	nfoto_producto--;
	document.getElementById('f_sig_producto').src='../images/siguiente.png';
	document.getElementById('nfoto_producto').innerHTML=nfoto_producto+1;
	}
	if (nfoto_producto==0) document.getElementById('f_ant_producto').src='../images/sizer.png';
	return false;
}

function cambiamas_producto() {
	if (nfoto_producto<carrusel_producto.length-1) {
		var indice=nfoto_producto+1;
		swap2_producto('foto_producto',indice);
		document.getElementById('foto_producto').alt=pies_producto[indice];
		document.getElementById('foto_producto').title=pies_producto[indice];
		document.getElementById('foto_producto').height=altos_producto[indice];
		document.getElementById('pie_foto_producto').innerHTML = pies_producto[indice];
		nfoto_producto++;
		document.getElementById('f_ant_producto').src='../images/anterior.png';
		document.getElementById('nfoto_producto').innerHTML=nfoto_producto+1;
	}	
	if (nfoto_producto==carrusel_producto.length-1) document.getElementById('f_sig_producto').src='../images/sizer.png';
	return false;
}

function ampliar_foto_producto() {
	//	var ventana = window.open('./images/zoom/'+fotos[nfoto], 'ampliada', 'width=320,height=300,resizable=yes');
	// aqui => carrusel gigante
	mostrar_carrusel_producto = true;
	var ventana = window.open('../carrusel_grande.html', 'ampliada', 'width=620,height=550,resizable=no,scrollbars=yes ');
	ventana.focus();
	return false;
}

function addEventos () {
	var x=document.getElementById('menu');
	if (!x) return;
	var y = x.getElementsByTagName('a');
	for (var n=0;n<y.length;n++) {
 		y[n].onmouseover = enciende;
		y[n].onfocus = enciende;
		y[n].onmouseout=apaga;
		y[n].onblur=apaga;
	}
	if (y.length == 5) { /* MODELO 3 */
		var aviso = document.getElementById('opcion6');
		if (aviso){
 			aviso.onmouseover = enciende;
			aviso.onfocus = enciende;
			aviso.onmouseout = apaga;
			aviso.onblur = apaga;
		}
	}	
	if (carrusel.length != 0){
		var ant=document.getElementById('anterior');
		ant.onclick=cambiamenos;
		var sig=document.getElementById('siguiente');
		sig.onclick=cambiamas;
		
		var amp=document.getElementById('ampliar');
		amp.onclick=ampliar_foto;	
			
		if (carrusel.length==1) document.getElementById('oculta_flechas').innerHTML='';
	}
	if (carrusel_producto.length != 0){
		var ant_producto=document.getElementById('anterior_producto');
		ant_producto.onclick=cambiamenos_producto;
		var sig_producto=document.getElementById('siguiente_producto');
		sig_producto.onclick=cambiamas_producto;
		
		var amp_producto=document.getElementById('ampliar_producto');
		amp_producto.onclick=ampliar_foto_producto;
			
		if (carrusel_producto.length==1) document.getElementById('oculta_flechas_producto').innerHTML='';
	}
}
window.onload=addEventos;

function envia_datos() {
	var datos = new Array('email','asunto','mensaje');
	var objeto;
	for (var i=0; i<datos.length; i++){
		objeto = eval('document.getElementById(\'' + datos[i] + '\')');
		if (objeto.value == ''){
			alert ('Debe rellenar todos los campos marcados como obligatorios.');
			objeto.focus();
			return false;
		}
		if (datos[i] == 'email'){
			var correo = document.getElementById('email').value;
			if (!correo.match("^([a-zA-Z0-9_\\-])+(\\.([a-zA-Z0-9_\\-])+)*@((\\[(((([0-1])?([0-9])?[0-9])|(2[0-4][0-9])|(2[0-5][0-5])))\\.(((([0-1])?([0-9])?[0-9])|(2[0-4][0-9])|(2[0-5][0-5])))\\.(((([0-1])?([0-9])?[0-9])|(2[0-4][0-9])|(2[0-5][0-5])))\\.(((([0-1])?([0-9])?[0-9])|(2[0-4][0-9])|(2[0-5][0-5]))\\]))|((([a-zA-Z0-9])+(([\\-])+([a-zA-Z0-9])+)*\\.)+([a-zA-Z])+(([\\-])+([a-zA-Z0-9])+)*))$")){
				alert('El mail introducido no parece válido.');
				objeto.focus();
				return false;
			}
		}
	}
}

function enviar() {
	var datos = new Array('nombre','cif','email','asunto','pedido');
	var objeto;
	for (var i=0; i<datos.length; i++){
		objeto = eval('document.getElementById(\'' + datos[i] + '\')');
		if (objeto.value == ''){
			alert ('Debe rellenar todos los campos marcados como obligatorios.');
			objeto.focus();
			return false;
		}
		if (datos[i] == 'email'){
			var correo = document.getElementById('email').value;
			if (!correo.match("^([a-zA-Z0-9_\\-])+(\\.([a-zA-Z0-9_\\-])+)*@((\\[(((([0-1])?([0-9])?[0-9])|(2[0-4][0-9])|(2[0-5][0-5])))\\.(((([0-1])?([0-9])?[0-9])|(2[0-4][0-9])|(2[0-5][0-5])))\\.(((([0-1])?([0-9])?[0-9])|(2[0-4][0-9])|(2[0-5][0-5])))\\.(((([0-1])?([0-9])?[0-9])|(2[0-4][0-9])|(2[0-5][0-5]))\\]))|((([a-zA-Z0-9])+(([\\-])+([a-zA-Z0-9])+)*\\.)+([a-zA-Z])+(([\\-])+([a-zA-Z0-9])+)*))$")){
				alert('El mail introducido no parece válido.');
				objeto.focus();
				return false;
			}
		}
	}
}
