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 checkMail(formId) {
	thisForm = document.getElementById(formId);
	var filter  = /^(.+\@.+\..+)$/;

	if (!filter.test(thisForm.email.value)) alert('Por favor revise la ortografia de su email');
	else {
		thisForm.action="news_process.php";
		thisForm.submit();
	}
}

function delItemPedido(itemNum) {
	if (confirm("¿Está seguro de que desea eliminar este artículo de su pedido?"))
	    {
		thisForm = document.getElementById('form_delpedido');
		thisForm.delitem.value = itemNum;
		thisForm.submit();
	    }
}

function showPicsProd(action, numPags) {
	if (action==0) newPag = pag - 1;
	else newPag = pag + 1;

	document.getElementById('lista_nav_'+pag).className='';
	document.getElementById('lista_nav_'+newPag).className='on';

	pag = newPag;

	if (pag == 1 || pag == numPags) {
		document.getElementById('nav_'+action).className='';
		document.getElementById('nav_null_'+action).className='nav';
	}

	if (action==0 && pag < numPags && document.getElementById('nav_null_1').className == 'nav') {
		document.getElementById('nav_1').className='nav';
		document.getElementById('nav_null_1').className='';
	}

	if (action==1 && pag > 1 && document.getElementById('nav_null_0').className == 'nav') {
		document.getElementById('nav_0').className='nav';
		document.getElementById('nav_null_0').className='';
	}
}

function checkPedido() {
	thisForm = document.getElementById('form_pedido');
	var campos = thisForm.campossel.value;
	var formOk = 1;

	if (campos != "")
	    {
		var expCampos = campos.split("-");

		for(i=0; i<expCampos.length;i++) {
			thisCampo = document.getElementById(expCampos[i]+'-1');
			if (formOk == 1 && thisCampo.options[thisCampo.selectedIndex].value=='') {
				formOk = 0;
				alert('Debe seleccionar las opciones específicas del producto');
			}
		}
	    }
	if (formOk==1) {
		thisForm.submit();
	}
}

function actualizaContProd () {
	thisForm = document.getElementById('form_pedido');
	var campos = thisForm.campossel.value;

	var c=new Array(0,0,0,0,0);

	if (campos != "")
	    {
		var expCampos = campos.split("-");

		for(i=0; i<expCampos.length;i++) {
			thisCampo = document.getElementById(expCampos[i]+'-1');
			if (thisCampo.options[thisCampo.selectedIndex].value!='') c[i]=thisCampo.options[thisCampo.selectedIndex].value;
		}
	    }

	xajax_upd_ficha_prod(thisForm.prid.value, c[0], c[1], c[2], c[3], c[4]);
}

function checkRegister() {
	thisForm = document.getElementById('formregistro');
	var camposRek = new Array('nombre', 'apellidos', 'direccion', 'cp', 'localidad', 'telefono', 'movil', 'email', 'password1', 'password2', 'dni');
	var selectsRek = new Array('provincia', 'dia_nac', 'mes_nac', 'anyo_nac');
	var formOk = 1;

	for(i=0; i<selectsRek.length;i++) {
		thisCampo = document.getElementById(selectsRek[i]+'-1');
		if (thisCampo.options[thisCampo.selectedIndex].value=='') {
			formOk = 0;
			thisCampo.style.border="1px solid #C40001";
			thisCampo.style.color="#C40001";
		}
	}

	for(i=0; i<camposRek.length;i++) {
		thisCampo = document.getElementById(camposRek[i]+'-1');
		if (thisCampo.value=='') {
			formOk = 0;
			thisCampo.style.border="1px solid #C40001";
			thisCampo.style.color="#C40001";
		}
	}
	if (formOk == 0) alert('Asegúrese de haber rellenado todos los campos');

	var filter  = /^(.+\@.+\..+)$/;

	if (formOk==1) {
		if (!filter.test(document.getElementById('email-1').value)) alert('Por favor revise la ortografia de su email');
		else if (document.getElementById('password1-1').value != document.getElementById('password2-1').value) alert('Las dos contraseñas introducidas no coinciden');
		else if (!thisForm.acepto_cond.checked) alert('Debe leer y aceptar las condiciones del servicio');
		else {
			thisForm.action="";
			thisForm.submit();
		}
	}
}

function checkFinPedido() {
	thisForm = document.getElementById('formreg_pedido');
	var camposRek = new Array('direccion', 'cp', 'localidad', 'telefono');
	var selectsRek = new Array('provincia');
	var formOk = 1;

	for(i=0; i<selectsRek.length;i++) {
		thisCampo = document.getElementById(selectsRek[i]+'-1');
		if (formOk == 1 && thisCampo.options[thisCampo.selectedIndex].value=='') {
			formOk = 0;
			alert('Asegúrese de haber rellenado todos los campos');
		}
	}

	for(i=0; i<camposRek.length;i++) {
		thisCampo = document.getElementById(camposRek[i]+'-1');
		if (formOk == 1 && thisCampo.value=='') {
			formOk = 0;
			alert('Asegúrese de haber rellenado todos los campos');
		}
	}

	if (formOk==1) {
		formaPago1 = document.getElementById('forma_pago-1');
		formaPago2 = document.getElementById('forma_pago-2');
		if (!formaPago1.checked && !formaPago2.checked) alert("Seleccione una forma de pago");
		else {
			thisForm.method="POST";
			thisForm.action="carro_fin.php";
			thisForm.submit();
		    }
	}
}

function checkContact() {
	thisForm = document.getElementById('formcontacto');
	var camposRek = new Array('nombre', 'apellidos', 'direccion', 'cp', 'localidad', 'telefono', 'movil', 'email', 'consulta');
	var selectsRek = new Array('provincia', 'tienda', 'conocido');
	var formOk = 1;

	for(i=0; i<selectsRek.length;i++) {
		thisCampo = document.getElementById(selectsRek[i]+'-1');
		if (thisCampo.options[thisCampo.selectedIndex].value=='') {
			if (selectsRek[i]=="conocido") {
				thisOtro = document.getElementById('conocido_otro-1');
				if (thisOtro.value=='') {
					formOk = 0;
					thisOtro.style.border="1px solid #C40001";
					thisOtro.style.color="#C40001";
				}
			}
			else {
				formOk = 0;
				thisCampo.style.border="1px solid #C40001";
				thisCampo.style.color="#C40001";
			}
		}
	}

	for(i=0; i<camposRek.length;i++) {
		thisCampo = document.getElementById(camposRek[i]+'-1');
		if (thisCampo.value=='') {
			formOk = 0;
			thisCampo.style.border="1px solid #C40001";
			thisCampo.style.color="#C40001";
		}
	}
	if (formOk == 0) alert('Asegúrese de haber rellenado todos los campos');

	var filter  = /^(.+\@.+\..+)$/;

	if (formOk==1) {
		if (!filter.test(document.getElementById('email-1').value)) alert('Por favor revise la ortografia de su email');
		else {
			thisForm.action="";
			thisForm.submit();
		}
	}
}

function checkLogin() {
	thisForm = document.getElementById('formlogin');
	var camposRek = new Array('user', 'pwd');
	var formOk = 1;

	for(i=0; i<camposRek.length;i++) {
		if (document.getElementById(camposRek[i]+'-1')) {
			thisCampo = document.getElementById(camposRek[i]+'-1');
			if (thisCampo.value=='') {
				formOk = 0;
				thisCampo.style.border="1px solid #C40001";
				thisCampo.style.color="#C40001";
			}
		}
	}
	if (formOk == 0) alert('Debe introducir su email y contraseña para poder loguearse');

	if (formOk==1) {
		thisForm.action="";
		thisForm.submit();
	}
}

function recuerdaPwd() {
	thisForm = document.getElementById('formlogin');
	thisCampo = document.getElementById('user-1');
	if (thisCampo.value=='') alert('Introduzca su email y recibirá un correo con sus claves de acceso');
	else {
		thisForm.action="";
		thisAction = document.getElementById('actionn');
		thisAction.value="recordar";
		thisForm.submit();
	}
}

function checkNewPwd() {
	thisForm = document.getElementById('formlogin');
	if (document.getElementById('pwd1-1').value == "") alert('Introduzca una nueva contraseña de acceso');
	else if (document.getElementById('pwd1-1').value != document.getElementById('pwd2-1').value) alert('Las dos contraseñas introducidas no coinciden');
	else {
		thisForm.action="registro.php";
		thisForm.submit();
	}
}

function chngActSubmit (formId, newAction, inputAuxId, inputAuxValue) {
	thisForm = document.getElementById(formId);
	if (newAction!='') thisForm.action=newAction;
	if (inputAuxId!='') document.getElementById(inputAuxId).value=inputAuxValue;
	thisForm.submit();
}

function alertLogin () {
	alert("Debe estar logueado para utilizar este servicio.\n\nSi aún no está registrado, hágalo ahora en menos de 1 minuto");
	location.href="http://www.erescasacontemporanea.com/acceso";
}

function openWpedido(idPedido) {
	window.open('comprobante_print.php?pedido='+idPedido,'w'+idPedido,'width=630,height=420,scrollbars=YES');
}

function enviaConsulta(idProducto, selZona) {
	var nombre = document.getElementById('cons_nombre').value;
	var email = document.getElementById('cons_email').value;
	var mensaje = document.getElementById('cons_mensaje').value;

	xajax_envia_consulta(idProducto, selZona, nombre, email, mensaje);
    }

function selectOtro (selValue, idInput) {
	thisInput = document.getElementById(idInput);

	if (selValue == '') thisInput.style.visibility="visible";
	else thisInput.style.visibility="hidden";
}

function cambiaDisplay(idObj, tipo) {
	obj = document.getElementById(idObj);
	obj.style.display=tipo;
}

function enviaRecom() {
	var nombre1 = document.getElementById('nombre1-1').value;
	var email1 = document.getElementById('email1-1').value;
	var nombre2 = document.getElementById('nombre2-1').value;
	var email2 = document.getElementById('email2-1').value;

	if (document.getElementById('this_url_addr')) url = document.getElementById('this_url_addr').value;
	else url = '';

	xajax_envia_recomienda(nombre1, email1, nombre2, email2, url);
    }

function openRecom() {
	cambiaDisplay('recomend', 'block');
	xajax_crea_form_recom();
}

function showMapTiend(urlMap) {
	document.getElementById('navTiendaMap').style.display="none";
	document.getElementById('navTiendaFot').style.display="block";

	mapa = document.getElementById('foto_tienda');
	mapa.style.height = "281px";
	mapa.innerHTML = "<iframe src=\"" + urlMap + "\" id=\"gmapiframe\" width=\"100%\" height=\"100%\" scrolling=\"no\" frameborder=\"0\" marginheight=\"0\" marginwidth=\"0\"></iframe>";
}

function showPicTiend(urlMap) {
	document.getElementById('navTiendaFot').style.display="none";
	document.getElementById('navTiendaMap').style.display="block";

	mapa = document.getElementById('foto_tienda');
	mapa.style.height = "217px";
	mapa.innerHTML = "<img src=\"" + urlMap + "\" width=\"495\" height=\"217\" />";
}

function checkSubasta(minPrecio, idProd, idClie) {
	thisPuja= document.getElementById('input_puja');
	if (thisPuja.value <= minPrecio) alert('Debe superar la puja actual para adquirir esta subasta');
	else xajax_puja(thisPuja.value, idProd, idClie);
}