function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  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=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_changeProp(objId,x,theProp,theValue) { //v9.0
  var obj = null; with (document){ if (getElementById)
  obj = getElementById(objId); }
  if (obj){
    if (theValue == true || theValue == false)
      eval("obj.style."+theProp+"="+theValue);
    else eval("obj.style."+theProp+"='"+theValue+"'");
  }
}

function limita(obj, elEvento, max)
{
	var elem=obj;
	
	var evento=elEvento || window.event;
	var cod=evento.charCode || evento.keyCode;
	
	// 37 izquierda
	// 38 arriba
	// 39 derecha
	// 40 abajo
	// 8  backspace
	// 46 suprimir
	
	if(cod==37 || cod==38 || cod==39 || cod==40 || cod==8 || cod==46)
		return true;  
	
	if(elem.value.length<max)
		return true;
	
	return false;
}

function cuenta(obj, evento, max, div)
{
	var elem=obj.value;
	var info=document.getElementById(div);
	
	info.innerHTML=max-elem.length;
}

function validarEntero(valor)
{ 
	valor=parseInt(valor);
	
	if(isNaN(valor))
		return false;
	else
		return true;
}

function vacio(q) 
{
	for(i=0; i<q.length; i++)
		if(q.charAt(i)!=" ")
			return true;
	
	return false;
}

function valida(valor, valor1) 
{
	if(vacio(document.formulario.cantidad.value)==false)
	{
		alert("La cantidad a financiar no puede estar vacía.");
		document.formulario.cantidad.focus();
		
		return false;
	}
	else if(document.formulario.cantidad.value<valor)
	{
		alert("La cantidad a financiar debe ser mayor de "+valor+".");
		document.formulario.cantidad.focus();
		
		return false;
	}
	else if(validarEntero(document.formulario.cantidad.value)==false)
	{
		alert("La cantidad a financiar debe ser un número entero.");
		document.formulario.cantidad.focus();
		
		return false;
	}
	else if(document.formulario.meses.value<valor1)
	{
		alert("La cantidad a pagar debe ser mayor de "+valor1+".");
		document.formulario.meses.focus();
		
		return false;
	}
}

function enviarFormulario(valor, valor1)
{ 
	if(valida(valor, valor1)!=false)
		document.formulario.submit();
}

function mostrarSeccion(num, idioma)
{
	var seccion;
	
	eval("seccion=seccion"+num+";");
	
	if(seccion==false)
	{
		seccion=true;
		
		document.getElementById("ampliar"+num).innerHTML="Reducir Información";
		new Effect.BlindDown("seccion"+num, { duration:1.0 });
	}
	else
	{
		seccion=false;
		
		document.getElementById("ampliar"+num).innerHTML="Ampliar Información";
		new Effect.BlindUp("seccion"+num, { duration:1.0 });
	}
	
	eval("seccion"+num+"=seccion;");
}

function actualizarFotoMueble(operacion)
{
	var pos;
	var respuesta;
	var ficha;
	var codMueble;
	var numMueble;
	var fotoMueble;
	var descrMueble;
	var precioMueble;
	var oXmlHttp;
	
	oXmlHttp=zXmlHttp.createRequest();
	
	oXmlHttp.open("get", "/actualizar-foto-mueble.php?codigo="+cod_mueble+"&numero="+num_mueble+"&operacion="+operacion+"&tienda="+document.formulario.tienda.value+"&rand="+Math.random(), true);
	oXmlHttp.onreadystatechange=function()
	{
		if(oXmlHttp.readyState==4)
		{
			if(oXmlHttp.status==200)
			{
				respuesta=unescape(oXmlHttp.responseText);
				respuesta=respuesta.replace(/\+/gi, " ");
				
				pos=respuesta.indexOf("##");
				codMueble=respuesta.substr(0, pos);
				respuesta=respuesta.substr((pos+2), respuesta.length);
				pos=respuesta.indexOf("##");
				numMueble=respuesta.substr(0, pos);
				respuesta=respuesta.substr((pos+2), respuesta.length);
				pos=respuesta.indexOf("##");
				fotoMueble=respuesta.substr(0, pos);
				respuesta=respuesta.substr((pos+2), respuesta.length);
				pos=respuesta.indexOf("##");
				descrMueble=respuesta.substr(0, pos);
				precioMueble=respuesta.substr((pos+2), respuesta.length);
				
				cod_mueble=codMueble;
				num_mueble=numMueble;
				ficha=document.getElementById("NumMueble");
				ficha.innerHTML=num_mueble;
				ficha=document.getElementById("FotoMueble");
				ficha.innerHTML=fotoMueble;
				ficha=document.getElementById("DescMueble");
				ficha.innerHTML=descrMueble;
				ficha=document.getElementById("PrecioMueble");
				ficha.innerHTML=precioMueble;
				ficha=document.getElementById("AhrefMueble");
				ficha.href="javascript:imprimir('/muebles-imprimir/"+codMueble+"/');";
				
				document.formulario.mueble.value=cod_mueble;
			}
		}
	}
	
	oXmlHttp.send(null);
}

function actualizarMueble(codigo)
{
	var pos;
	var respuesta;
	var ficha;
	var codMueble;
	var numMueble;
	var fotoMueble;
	var descrMueble;
	var precioMueble;
	var oXmlHttp;
	
	oXmlHttp=zXmlHttp.createRequest();
	
	oXmlHttp.open("get", "/actualizar-mueble.php?codigo="+codigo+"&numero="+num_mueble+"&tienda="+document.formulario.tienda.value+"&rand="+Math.random(), true);
	oXmlHttp.onreadystatechange=function()
	{
		if(oXmlHttp.readyState==4)
		{
			if(oXmlHttp.status==200)
			{
				document.formulario.mueble.value=codigo;
				
				respuesta=unescape(oXmlHttp.responseText);
				respuesta=respuesta.replace(/\+/gi, " ");
				
				pos=respuesta.indexOf("##");
				codMueble=respuesta.substr(0, pos);
				respuesta=respuesta.substr((pos+2), respuesta.length);
				pos=respuesta.indexOf("##");
				numMueble=respuesta.substr(0, pos);
				respuesta=respuesta.substr((pos+2), respuesta.length);
				pos=respuesta.indexOf("##");
				fotoMueble=respuesta.substr(0, pos);
				respuesta=respuesta.substr((pos+2), respuesta.length);
				pos=respuesta.indexOf("##");
				descrMueble=respuesta.substr(0, pos);
				precioMueble=respuesta.substr((pos+2), respuesta.length);
				
				cod_mueble=codMueble;
				num_mueble=numMueble;
				ficha=document.getElementById("NumMueble");
				ficha.innerHTML=num_mueble;
				ficha=document.getElementById("FotoMueble");
				ficha.innerHTML=fotoMueble;
				ficha=document.getElementById("DescMueble");
				ficha.innerHTML=descrMueble;
				ficha=document.getElementById("PrecioMueble");
				ficha.innerHTML=precioMueble;
				ficha=document.getElementById("AhrefMueble");
				ficha.href="javascript:imprimir('/muebles-imprimir/"+codMueble+"/');";
			}
		}
	}
	
	oXmlHttp.send(null);
}

function comprobarMasInfo(idioma)
{
	var goodEmail;
	goodEmail=document.formulario.email.value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\.info)|(\..{2,2}))$)\b/gi);
	
	if(document.formulario.nombre.value.length==0)
		alert("Es imprescindible que indiques tu nombre y apellidos.");
	else if(document.formulario.ciudad.value.length==0)
		alert("Es imprescindible que indiques tu ciudad.");
	else if(document.formulario.email.value.length==0)
		alert("Es imprescindible que indiques tu e-mail.");
	else if(!goodEmail)
		alert("El formato de tu e-mail es incorrecto.");
	else if(document.formulario.consulta.value.length==0)
		alert("Es imprescindible que indiques tu consulta.");
	else if(document.formulario.acepta.value==false)
		alert("Es imprescindible que aceptes las condiciones legales antes de continuar.");
	else
	{
		document.formulario.action="/enviaremail-masinfo/";
		document.formulario.method="post";
		document.formulario.submit();
	}
}

function comprobarComprar(idioma)
{
	var goodEmail;
	goodEmail=document.formulario.email.value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\.info)|(\..{2,2}))$)\b/gi);
	
	if(document.formulario.nombre.value.length==0)
		alert("Es imprescindible que indiques tu nombre.");
	else if(document.formulario.ciudad.value.length==0)
		alert("Es imprescindible que indiques tu ciudad.");
	else if(document.formulario.email.value.length==0 && document.formulario.telefono.value.length==0)
		alert("Es imprescindible que indiques tu e-mail y/o tu número de teléfono.");
	else if(document.formulario.email.value.length!=0 && !goodEmail)
		alert("El formato de tu e-mail es incorrecto.");
	else if(document.formulario.acepta.value==false)
		alert("Es imprescindible que aceptes las condiciones legales antes de continuar.");
	else
	{
		document.formulario.action="/enviaremail-comprar/";
		document.formulario.method="post";
		document.formulario.submit();
	}
}

function comprobarContacto(idioma)
{
	var goodEmail;
	goodEmail=document.formulario.email.value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\.info)|(\..{2,2}))$)\b/gi);
	
	if(document.formulario.nombre.value.length==0)
	{
		alert("Es imprescindible que indiques tu nombre.");
		document.formulario.nombre.focus();
	}
	else if(document.formulario.apellidos.value.length==0)
	{
		alert("Es imprescindible que indiques tus apellidos.");
		document.formulario.apellidos.focus();
	}
	else if(document.formulario.provincia.value.length==0)
	{
		alert("Es imprescindible que indiques tu provincia.");
		document.formulario.provincia.focus();
	}
	else if(document.formulario.localidad.value.length==0)
	{
		alert("Es imprescindible que indiques tu localidad.");
		document.formulario.localidad.focus();
	}
	else if(document.formulario.email.value.length==0)
	{
		alert("Es imprescindible que indiques tu e-mail.");
		document.formulario.email.focus();
	}
	else if(!goodEmail)
	{
		alert("El formato de tu e-mail es incorrecto.");
		document.formulario.email.focus();
	}
	else if(document.formulario.consulta.value.length==0)
	{
		alert("Es imprescindible que indiques tu consulta.");
		document.formulario.consulta.focus();
	}
	else if(document.formulario.acepta.checked==false)
	{
		alert("Es imprescindible que aceptes las condiciones legales antes de continuar.");
		document.formulario.acepta.focus();
	}
	else
	{
		document.formulario.action="/enviaremail-contacto/";
		document.formulario.method="post";
		document.formulario.submit();
	}
}

function comprobarNewsletter(idioma)
{
	var goodEmail;
	goodEmail=document.formulario.news_email.value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\.info)|(\..{2,2}))$)\b/gi);
	
	if(document.formulario.news_nombre.value.length==0 || document.formulario.news_nombre.value=="Tu nombre")
	{
		alert("Es imprescindible que indiques tu nombre.");
		document.formulario.news_nombre.focus();
	}
	else if(document.formulario.news_email.value.length==0 || document.formulario.news_email.value=="Tu e-mail")
	{
		alert("Es imprescindible que indiques tu e-mail.");
		document.formulario.news_email.focus();
	}
	else if(!goodEmail)
	{
		alert("El formato de tu e-mail es incorrecto.");
		document.formulario.news_email.focus();
	}
	else
	{
		document.formulario.action="/enviaremail-newsletter/";
		document.formulario.method="post";
		document.formulario.submit();
	}
}

function comprobarFinanciacion(idioma)
{
	var goodEmail;
	goodEmail=document.formulario.email.value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\.info)|(\..{2,2}))$)\b/gi);
	
	if(document.formulario.nombre.value.length==0)
	{
		alert("Es imprescindible que indiques tu nombre.");
		document.formulario.nombre.focus();
	}
	else if(document.formulario.provincia.value.length==0)
	{
		alert("Es imprescindible que indiques tu provincia.");
		document.formulario.provincia.focus();
	}
	else if(document.formulario.localidad.value.length==0)
	{
		alert("Es imprescindible que indiques tu localidad.");
		document.formulario.localidad.focus();
	}
	else if(document.formulario.telefono.value.length==0)
	{
		alert("Es imprescindible que indiques tu teléfono.");
		document.formulario.telefono.focus();
	}
	else if(document.formulario.email.value.length==0)
	{
		alert("Es imprescindible que indiques tu e-mail.");
		document.formulario.email.focus();
	}
	else if(!goodEmail)
	{
		alert("El formato de tu e-mail es incorrecto.");
		document.formulario.email.focus();
	}
	else if(document.formulario.acepta.checked==false)
	{
		alert("Es imprescindible que aceptes las condiciones legales antes de continuar.");
		document.formulario.acepta.focus();
	}
	else
	{
		document.formulario.action="/enviaremail-financiacion/";
		document.formulario.method="post";
		document.formulario.submit();
	}
}

function imagen(carpeta, nombre)
{
	popup=window.open('/image.php?carpeta='+carpeta+'&nombre='+nombre, 'imagenAmpliada', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=670,height=430,left=100,top=100');
	popup.focus();
}

function descargar(carpeta, nombre)
{
	descarga.document.location.href="/download.php?carpeta="+carpeta+"&nombre="+nombre;
}

function imprimir(url)
{
	popup=window.open('http://www.muebleselrebajon.com'+url, 'impresion', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=670,height=500,left=100,top=100');
	popup.focus();
}

function tabular(e, obj)
{ 
	tecla=(document.all) ? e.keyCode : e.which;
	
	if(tecla!=13)
		return;
	
	frm=obj.form;
	
	for(i=0; i<frm.elements.length; i++)
		if(frm.elements[i]==obj)
		{ 
			if(i==frm.elements.length-1)
				i=-1;
			
			break;
		}
	
	frm.elements[i+1].focus();
	
	return false; 
}

function intro(e, obj)
{ 
	tecla=(document.all) ? e.keyCode : e.which;
	
	if(tecla!=13)
		return;
	
	comprobarBuscar();
	
	return false; 
}

function goto(pagina, destino)
{
	document.formulario.action="privado_"+pagina+".php";
	document.formulario.accion.value="consultar";
	document.formulario.target=destino;
	document.formulario.submit();
}

function gotoinicio(pagina, destino)
{
	document.formulario.action="procesa_"+pagina+".php";
	document.formulario.method="post";
	document.formulario.enctype="multipart/form-data";
	document.formulario.accion.value="inicio";
	document.formulario.target=destino;
	document.formulario.submit();
}

function nuevo()
{
	document.formulario.accion.value="inicio";
	document.formulario.submit();
}

function guardar()
{
	document.formulario.accion.value="guardar";
	document.formulario.submit();
}

function consultar()
{
	document.formulario.accion.value="consultar";
	document.formulario.submit();
}

function eliminar()
{
	var entrar;
	
	entrar=confirm("¿Está seguro que desea eliminar este registro?");
	
	if(entrar)
	{
		document.formulario.accion.value="eliminar";
		document.formulario.submit();
	}
	else
		event.returnValue=false;
}

function buscar(tabla)
{
	var x;
	
	x=window.open("buscador.php?tabla="+tabla,"v","status=0,resizable=0,toolbar=0,location=0,directories=0,menubar=0,scrollbars=0,width=645,height=465,top=50,left=50");
	
	event.returnValue=false;
}
