﻿
function muestraOculta(id){if($('#'+id).is(":visible")){$('#'+id).hide(250);}else{$('#'+id).show(250);}}function menuLateral(){$(".subfamilias").css("display","none");}function disableEnterKey(e){var key;if(window.event){key=window.event.keyCode}else{key=e.which;}return(key!=13);}function ventanaPopup(URL){window.open(URL,"popup","width=700,height=600,scrollbars=NO")}function OnKeyUp(obj){if(window.event){e=event;}if(obj=="TxtBuscar"&&e.keyCode==13){window.location="/contactar.aspx";}else{}}var ruta="";function obtenProvincias(id,idprov,dropdownProvincias){if(dropdownProvincias){document.getElementById(dropdownProvincias).length=0;}else{document.getElementById('Provincia').length=0;}if(id.length>0){var opt=document.createElement("option");opt.text="Cargando...";opt.value="";if(dropdownProvincias){document.getElementById(dropdownProvincias).options.add(opt);}else{document.getElementById("Provincia").options.add(opt);}}$.ajax({url:ruta+"/ws.asmx/obtenProvincias",data:({id:id}),success:function(datosDevueltos){if(dropdownProvincias){document.getElementById(dropdownProvincias).length=0;}else{document.getElementById('Provincia').length=0;}for(i=0;i<datosDevueltos.getElementsByTagName('provinciaId').length;i++){var opt=document.createElement("option");if(datosDevueltos.getElementsByTagName('provinciaNombre')[i].firstChild){if(datosDevueltos.getElementsByTagName('provinciaNombre')[i].firstChild.data){opt.text=datosDevueltos.getElementsByTagName('provinciaNombre')[i].firstChild.data;}if(datosDevueltos.getElementsByTagName('provinciaId')[i].firstChild){opt.value=datosDevueltos.getElementsByTagName('provinciaId')[i].firstChild.data;}}if(dropdownProvincias){document.getElementById(dropdownProvincias).options.add(opt);}else{document.getElementById("Provincia").options.add(opt);}}if(idprov){if(dropdownProvincias){for(i=0;i<document.getElementById(dropdownProvincias).options.length;i++){if(document.getElementById(dropdownProvincias).options[i].value==idprov){document.getElementById(dropdownProvincias).options[i].selected=true;}}}else{for(i=0;i<document.getElementById("Provincia").options.length;i++){if(document.getElementById("Provincia").options[i].value==idprov){document.getElementById("Provincia").options[i].selected=true;}}}}}});}function seleccionaProvincia(dropdownProvincias){if(dropdownProvincias){document.getElementById(dropdownProvincias+"Hid").value=document.getElementById(dropdownProvincias).value;}else{document.getElementById("ProvinciaHid").value=document.getElementById("Provincia").value;}}function cargaDatosUsuario(id){$.ajax({url:ruta+"/ws.asmx/cargaDatosUsuario",data:({id:id}),success:function(datosDevueltos){if(datosDevueltos.getElementsByTagName('Cli_Nombre')[0].firstChild){document.getElementById("txt_nombre").value=datosDevueltos.getElementsByTagName('Cli_Nombre')[0].firstChild.data;}if(datosDevueltos.getElementsByTagName('Cli_Apellidos')[0].firstChild){document.getElementById("txt_apellidos").value=datosDevueltos.getElementsByTagName('Cli_Apellidos')[0].firstChild.data;}if(datosDevueltos.getElementsByTagName('Cli_Telf1')[0].firstChild){document.getElementById("txt_telf1").value=datosDevueltos.getElementsByTagName('Cli_Telf1')[0].firstChild.data;}if(datosDevueltos.getElementsByTagName('Cli_Telf2')[0].firstChild){document.getElementById("txt_telf2").value=datosDevueltos.getElementsByTagName('Cli_Telf2')[0].firstChild.data;}if(datosDevueltos.getElementsByTagName('Cli_DireccionEnvio')[0].firstChild){document.getElementById("txt_direccion").value=datosDevueltos.getElementsByTagName('Cli_DireccionEnvio')[0].firstChild.data;}if(datosDevueltos.getElementsByTagName('Cli_CPEnvio')[0].firstChild){document.getElementById("txt_cp").value=datosDevueltos.getElementsByTagName('Cli_CPEnvio')[0].firstChild.data;}if(datosDevueltos.getElementsByTagName('Cli_LocalidadEnvio')[0].firstChild){document.getElementById("txt_localidad").value=datosDevueltos.getElementsByTagName('Cli_LocalidadEnvio')[0].firstChild.data;}if(datosDevueltos.getElementsByTagName('Cli_PaisEnvio')[0].firstChild){for(i=0;i<document.getElementById("Pais").options.length;i++){if(document.getElementById("Pais").options[i].value==datosDevueltos.getElementsByTagName('Cli_PaisEnvio')[0].firstChild.data){document.getElementById("Pais").options[i].selected=true;if(datosDevueltos.getElementsByTagName('Cli_ProvinciaEnvio')[0].firstChild){obtenProvincias(datosDevueltos.getElementsByTagName('Cli_PaisEnvio')[0].firstChild.data,datosDevueltos.getElementsByTagName('Cli_ProvinciaEnvio')[0].firstChild.data,"Provincia")}}}}if(datosDevueltos.getElementsByTagName('Cli_DireccionFiscal')[0].firstChild){document.getElementById("txt_direccionFac").value=datosDevueltos.getElementsByTagName('Cli_DireccionFiscal')[0].firstChild.data;}if(datosDevueltos.getElementsByTagName('Cli_CPFiscal')[0].firstChild){document.getElementById("txt_cpFac").value=datosDevueltos.getElementsByTagName('Cli_CPFiscal')[0].firstChild.data;}if(datosDevueltos.getElementsByTagName('Cli_LocalidadFiscal')[0].firstChild){document.getElementById("txt_localidadFac").value=datosDevueltos.getElementsByTagName('Cli_LocalidadFiscal')[0].firstChild.data;}if(datosDevueltos.getElementsByTagName('Cli_PaisFiscal')[0].firstChild){for(i=0;i<document.getElementById("PaisFac").options.length;i++){if(document.getElementById("PaisFac").options[i].value==datosDevueltos.getElementsByTagName('Cli_PaisFiscal')[0].firstChild.data){document.getElementById("PaisFac").options[i].selected=true;if(datosDevueltos.getElementsByTagName('Cli_ProvinciaFiscal')[0].firstChild){obtenProvincias(datosDevueltos.getElementsByTagName('Cli_PaisFiscal')[0].firstChild.data,datosDevueltos.getElementsByTagName('Cli_ProvinciaFiscal')[0].firstChild.data,"ProvinciaFac")}}}}}})}function guardaDatosUsuario(Id,Nombre,Apellidos,DireccionFiscal,LocalidadFiscal,CpFiscal,PaisFiscal,ProvinciaFiscal,DireccionEnvio,LocalidadEnvio,CpEnvio,PaisEnvio,ProvinciaEnvio,Telf1,Telf2,Em,Fax,mensaje){$.ajax({url:ruta+"/ws.asmx/guardaDatosUsuario",data:({Id:Id,Nombre:Nombre,Apellidos:Apellidos,DireccionFiscal:DireccionFiscal,LocalidadFiscal:LocalidadFiscal,CpFiscal:CpFiscal,PaisFiscal:PaisFiscal,ProvinciaFiscal:ProvinciaFiscal,DireccionEnvio:DireccionEnvio,LocalidadEnvio:LocalidadEnvio,CpEnvio:CpEnvio,PaisEnvio:PaisEnvio,ProvinciaEnvio:ProvinciaEnvio,Telf1:Telf1,Telf2:Telf2,Em:Em,Fax:Fax}),success:function(datosDevueltos){if(mensaje=="si"){alert("Datos de usuario guardados correctamente");}},error:function(xhr,ajaxOptions,thrownError){}})}function AltaUsuario(NIF,Email,Password,Nombre,Apellidos,DireccionFiscal,LocalidadFiscal,CpFiscal,PaisFiscal,ProvinciaFiscal,DireccionEnvio,LocalidadEnvio,CpEnvio,PaisEnvio,ProvinciaEnvio,Telf1,Telf2,Fax){$.ajax({url:ruta+"/ws.asmx/AltaUsuario",data:({NIF:NIF,Email:Email,Password:Password,Nombre:Nombre,Apellidos:Apellidos,DireccionFiscal:DireccionFiscal,LocalidadFiscal:LocalidadFiscal,CpFiscal:CpFiscal,PaisFiscal:PaisFiscal,ProvinciaFiscal:ProvinciaFiscal,DireccionEnvio:DireccionEnvio,LocalidadEnvio:LocalidadEnvio,CpEnvio:CpEnvio,PaisEnvio:PaisEnvio,ProvinciaEnvio:ProvinciaEnvio,Telf1:Telf1,Telf2:Telf2,Fax:Fax}),success:function(datosDevueltos){createCookie("ckUsuario","UsuarioId="+datosDevueltos.getElementsByTagName('CodCli')[0].firstChild.data,15);createCookie("ckEm","UsuarioEm="+datosDevueltos.getElementsByTagName('Email')[0].firstChild.data,15);},error:function(xhr,ajaxOptions,thrownError){alert(xhr.responseText);}})}function aplicaCodigoPromocional(Codigo,ImporteTotal,GastosEnvio){if(document.getElementById("Descuento").innerHTML=="0"){$.ajax({url:ruta+"/ws.asmx/aplicaCodigoPromocional",data:({Codigo:Codigo,CliCodigo:readCookie("ckUsuario"),ImporteTotal:ImporteTotal,GastosEnvio:GastosEnvio}),success:function(datosDevueltos){descuento=datosDevueltos.getElementsByTagName('descuentoCantidad')[0].firstChild.data;document.getElementById("Descuento").innerHTML=descuento;document.getElementById("TotalApagar").innerHTML=parseFloat(document.getElementById("TotalApagar").innerHTML.replace(",",".")-descuento.replace(",",".")).toFixed(2);if(descuento==0){document.getElementById("CodigoNoValido").style.display="block";}else{document.getElementById("CodigoNoValido").style.display="none";}}})}}function CalcularPortes(peso,provincia,total){var tarifa=null;var f=document.forms[0];var e=f.elements["rdl_entrega"];if(e.length>1){for(var i=0;i<e.length;i++){if(e[i].checked){tarifa=e[i].value;break;}}}else{tarifa=e.value;}$.ajax({url:ruta+"/ws.asmx/CalculaPortes",data:({peso:peso,provincia:provincia,total:total,tarifa:tarifa}),success:function(datosDevueltos){document.getElementById("ResumenPortes").innerHTML=datosDevueltos.getElementsByTagName('portesCantidad')[0].firstChild.data;document.getElementById("TotalApagar").innerHTML=parseFloat(parseFloat(datosDevueltos.getElementsByTagName('portesCantidad')[0].firstChild.data.replace(",","."))-parseFloat(document.getElementById("Descuento").innerHTML.replace(".","").replace(",","."))+parseFloat(document.getElementById("Total").innerHTML.replace(".","").replace(",","."))).toFixed(2);CalcularReembolso(document.getElementById("TotalApagar").innerHTML);}})}function CalcularReembolso(importe){importe=importe.replace(".",",");$.ajax({url:ruta+"/ws.asmx/CalculaReembolso",data:({importe:importe}),success:function(datosDevueltos){if(document.getElementById("txtReembolso")){document.getElementById("txtReembolso").innerHTML=parseFloat(datosDevueltos.getElementsByTagName('reembolsoCantidad')[0].firstChild.data.replace(",",".")).toFixed(2);}}})}function guardaDatosPedido(CliCodi,FormPago,CestPeso,GEnvio,Descu,Prds,Entrega,Facturacion,emailNoRegistrado,FormaEntrega,Nif){switch(FormPago){case"1":document.getElementById("confirmacion").innerHTML="<p>Su pedido será procesado en cuanto recibamos la notificación de que el pago ha sido realizado.</p><p>En breve ser&aacute; redirigido a una p&aacute;gina segura del banco donde podr&aacute; realizar el pago.</p>";break;case"2":document.getElementById("confirmacion").innerHTML="<p>Su pedido se ha procesado correctamente. Nos pondremos en contacto con usted para confirmar los datos.</p><p>Muchas gracias por su confianza</p>";GEnvio=parseFloat(parseFloat(document.getElementById("txtReembolso").innerHTML.replace(",","."))+parseFloat(GEnvio.replace(",",".")));break;case"3":document.getElementById("confirmacion").innerHTML="<p>Su pedido será procesado en cuanto recibamos el justificante de transferencia.</p><p>Muchas gracias por su confianza</p>";break;}document.getElementById("confirmacion").innerHTML=document.getElementById("confirmacion").innerHTML+"<p><a href=\"/index.aspx\">&raquo; Ir a la portada</a></p>";$.ajax({url:ruta+"/ws.asmx/guardaDatosPedido",data:({CliCodi:CliCodi,FormPago:FormPago,CestPeso:CestPeso,GEnvio:GEnvio,Descu:Descu,Prds:Prds,Entrega:Entrega,Facturacion:Facturacion,emailNoRegistrado:emailNoRegistrado,FormaEntrega:FormaEntrega,Nif:Nif}),success:function(datosDevueltos){eraseCookie("ckCarrito");switch(FormPago){case"1":location.href="/Pago.aspx?imp="+datosDevueltos.getElementsByTagName('Importe')[0].firstChild.data.replace(",","").replace(".","")+"&Ped="+datosDevueltos.getElementsByTagName('Pedido')[0].firstChild.data+"&tpv=1";break;}},error:function(xhr,ajaxOptions,thrownError){alert(xhr.responseText);}})}function actualizaFormaPago(){if(document.getElementById("radPagoTarjeta").checked){document.getElementById("FormaPagoSeleccionada").value="1";}if(document.getElementById("radPagoReembolso")){if(document.getElementById("radPagoReembolso").checked){document.getElementById("FormaPagoSeleccionada").value="2";}}if(document.getElementById("radPagoTransferencia").checked){document.getElementById("FormaPagoSeleccionada").value="3";}}function recuperaContra(email){$.ajax({url:ruta+"/ws.asmx/RecuperaContra",data:({email:email}),success:function(datosDevueltos){if(datosDevueltos.getElementsByTagName('usuarioEmail').length>0){alert("Se han enviado los datos de acceso a: "+datosDevueltos.getElementsByTagName('usuarioEmail')[0].firstChild.data);}else{alert("No se ha encontrado ningún usuario con la dirección: "+email);}},error:function(xhr,ajaxOptions,thrownError){alert(xhr.responseText);}})}function validaCheck(oSrc,args){args.IsValid=document.getElementById("chk_aut").checked;}function validaEmail(oSrc,args){var valido=false;$.ajax({url:ruta+"/ws.asmx/compruebaEmail",data:({email:document.getElementById("Email").value}),async:false,success:function(datosDevueltos){if(datosDevueltos.getElementsByTagName('CliCodigo').length>0){valido=false;alert("Ya existe un usuario con esa dirección.\nPinche en 'Olvidé mi contraseña' si desea recuperarla.");}else{valido=true;}}});if(args){args.IsValid=valido;}else{return(valido);}}function hazLogin(oSrc,args){if(args){var loginValido=false;$.ajax({url:ruta+"/ws.asmx/login",data:({email:document.getElementById("txtEmail").value,contra:document.getElementById("txtContra").value}),async:false,success:function(datosDevueltos){if(datosDevueltos.getElementsByTagName('usuarioId').length>0){valido=true;document.getElementById("UsuarioId").value=datosDevueltos.getElementsByTagName('usuarioId')[0].firstChild.data;document.getElementById("UsuarioEm").value=datosDevueltos.getElementsByTagName('usuarioEmail')[0].firstChild.data;}else{valido=false;}},error:function(xhr,ajaxOptions,thrownError){alert(xhr.responseText);}});args.IsValid=valido;}else{$.ajax({url:ruta+"/ws.asmx/login",data:({email:document.getElementById("txtEmailReg").value,contra:document.getElementById("txtContraReg").value}),async:false,success:function(datosDevueltos){if(datosDevueltos.getElementsByTagName('usuarioId').length>0){valido=true;document.getElementById("UsuarioId").value=datosDevueltos.getElementsByTagName('usuarioId')[0].firstChild.data;document.getElementById("UsuarioEm").value=datosDevueltos.getElementsByTagName('usuarioEmail')[0].firstChild.data;document.getElementById("loginInvalido").style.display="none";}else{document.getElementById("loginInvalido").style.display="block";valido=false;}}});return valido;}}function anadeProducto(id){$.ajax({url:ruta+"/ws.asmx/anadeProducto",data:({id:id}),success:function(datosDevueltos){for(i=0;i<datosDevueltos.getElementsByTagName('cestaId').length;i++){alert("Cesta "+datosDevueltos.getElementsByTagName('cestaId')[i].firstChild.data);var api=$("div.overlay").overlay({api:true,expose:{color:'#000'},expose:'#000',effect:'apple',onBeforeLoad:function(){var wrap=this.getContent().find(".contentWrap");wrap.load("carrito.aspx");}});api.load();}}});}function createCookie(name,value,days){if(days){var date=new Date();date.setTime(date.getTime()+(days*24*60*60*1000));var expires="; expires="+date.toGMTString();}else var expires="";document.cookie=name+"="+value+expires+"; path=/";}function readCookie(name){var nameEQ=name+"=";var ca=document.cookie.split(';');for(var i=0;i<ca.length;i++){var c=ca[i];while(c.charAt(0)==' ')c=c.substring(1,c.length);if(c.indexOf(nameEQ)==0)return c.substring(nameEQ.length,c.length);}return null;}function eraseCookie(name){createCookie(name,"",-1);}function obtenIdProductosCookie(){var strProductosId="";var ProductosCarrito=new Array();ProductosCarrito=readCookie("ckCarrito").split("&");var Productos=new Array(ProductosCarrito.length,2);for(i=0;i<ProductosCarrito.length;i++){Productos[i]=ProductosCarrito[i].split("|")[0].substr(ProductosCarrito[i].split("|")[0].indexOf("=")+1,ProductosCarrito[i].split("|")[0].length-ProductosCarrito[i].split("|")[0].indexOf("="))+"-"+ProductosCarrito[i].split("|")[2]+"-"+ProductosCarrito[i].split("|")[3]+"-"+ProductosCarrito[i].split("|")[1];strProductosId=strProductosId+Productos[i]+"|"}strProductosId=strProductosId.substr(0,strProductosId.length-1);return strProductosId;}
