// cst014-formularios.js  - Validación de formularios - (c) 2002-2010 Juan Rodríguez, consultor & Begues Internet, s.l.

function ConfirmarBorrar()
  { if (confirm("¿Seguro que desea borrar el formulario?\n\nSi pulsa <Aceptar>, \nse borrarán todos los datos que haya introducido."))
    return true
    return false }

err01="Revise el teléfono indicado";
err02="Revise la dirección de correo electrónico. \n";
err05="Debe confirmar que conoce y acepta \nlas condiciones de publicación \ny criterios de gestión\ndel Directorio de Castelldefels.";

function VerificarFormulario(proc) {
if (navigator.userAgent.indexOf("Firefox")!=-1) {JRcF=document.getElementById("JRcF")}
validar_Nombre=/[aeiouAEIOU]/;
validar_Telefono=/[^0-9\s]/;
validar_Correo_1=/^(.+\@.+\..+)$/;
validar_Correo_2=/@{2,}/;
validar_Correo_3=/[^@.abcdefghijklmnopqrstuvwxyz0123456789_\-\ABCDEFGHIJKLMNOPQRSTUVWXYZ]/;
if (JRcF.realname.value == "") {alert ('Por favor,\n\nIndique su nombre, \no el de la persona con la que \npodemos contactar.\n\nGracias.'); JRcF.realname.focus(); return false}

if ( (!validar_Nombre.test(JRcF.realname.value) ) || (JRcF.realname.value.length < 3 ) ) {alert ('Por favor,\n\nRevise el contenido de \"Su nombre\".\n\nGracias.'); JRcF.realname.focus(); return false}
if ((JRcF.Telefono.value == "") && (JRcF.email.value == "")) {alert ('Por favor,\n\nIndique un teléfono\no una dirección de correo electrónico,\npara poder contactar con Vd.\n\nGracias.'); JRcF.Telefono.focus(); return false}
if (validar_Telefono.test(JRcF.Telefono.value) ) {alert ("Por favor,\n\n"+err01+".\nUtilice sólo números.\n\nGracias."); JRcF.Telefono.focus(); return false}
if ( (JRcF.Telefono.value !=="") && (JRcF.Telefono.value.length < 9 ) ) {alert ("Por favor, \n\n"+err01+",\nparece que esté incompleto.\n\nGracias."); JRcF.Telefono.focus(); return false} 
if ( !JRcF.email.value =="") {
if ( (!validar_Correo_1.test(JRcF.email.value) ) || (JRcF.email.value.length <6 ) ) {alert ("Por favor, \n\n"+err02+"\nGracias."); JRcF.email.focus(); return false; }
if (validar_Correo_2.test(JRcF.email.value)) {alert ("Por favor,\n\n"+err02+"El signo @ se ha utilizado más de una vez.\n\nGracias."); JRcF.email.focus(); return false}
if (validar_Correo_3.test(JRcF.email.value) ) {alert ("Por favor,\n\n"+err02+"Contiene caracteres no válidos.\n\nGracias."); JRcF.email.focus(); return false} }
JRcF.recipient.value=CorreoWeb;

if (proc==215) {if (!JRcF.Condiciones.checked) {alert ("Por favor, \n\n"+err05+" \n\nGracias."); return false} }
if (proc==216) {if (!JRcF.Condiciones.checked) {alert ("Por favor, \n\n"+err05+" \n\nGracias."); return false} }
if (proc==218) {if (!JRcF.Condiciones.checked) {alert ("Por favor, \n\n"+err05+" \n\nGracias."); return false} }
if (proc==220) {if (!JRcF.Condiciones.checked) {alert ("Por favor, \n\n"+err05+" \n\nGracias."); return false} }
if (proc==223) {if (!JRcF.Condiciones.checked) {alert ("Por favor, \n\n"+err05+" \n\nGracias."); return false} }
if (proc==224) {if (!JRcF.Condiciones.checked) {alert ("Por favor, \n\n"+err05+" \n\nGracias."); return false} }
conforme=1;

if (proc==280) {
JRcF.Remitente.value=JRcF.realname.value;
Asunto="";
if (JRcF.Asunto_01.checked) {Asunto=Asunto +JRcF.Asunto_01.value +", "}
if (JRcF.Asunto_02.checked) {Asunto=Asunto +JRcF.Asunto_02.value +", "}
if (JRcF.Asunto_03.checked) {Asunto=Asunto +JRcF.Asunto_03.value +", "}
if (JRcF.Asunto_04.checked) {Asunto=Asunto +JRcF.Asunto_04.value +", "}
if (JRcF.Asunto_05.checked) {Asunto=Asunto +JRcF.Asunto_05.value +", "}
if (JRcF.Asunto_07.checked) {Asunto=Asunto +JRcF.Asunto_07.value +", "}
if (JRcF.Asunto_08.checked) {Asunto=Asunto +JRcF.Asunto_08.value +", "}
if (JRcF.Asunto_09.checked) {Asunto=Asunto +JRcF.Asunto_09.value +", "}
if (JRcF.Asunto_10.checked) {Asunto=Asunto +JRcF.Asunto_10.value +", "}
if (JRcF.Asunto_11.checked) {Asunto=Asunto +JRcF.Asunto_11.value +", "}
if (JRcF.Asunto_12.checked) {Asunto=Asunto +JRcF.Asunto_12.value +", "}
var A99=JRcF.Asunto_99.value; 
if ( A99=="" && Asunto=="" ) {Asunto="(cst280) Directorio de Castelldefels"} else {Asunto="(cst280) " +Asunto +A99; LongitudAsunto=Asunto.length; if (A99=="") {Asunto=Asunto.slice(0, LongitudAsunto -2)}  }
JRcF.subject.value =Asunto}

if (conforme==1) {return true} else {return false} }

txtAltaMapas='<input type="checkbox" name="Mapas" onclick="AltaResena(310)" value="Sí" />Alta en los mapas del Directorio';
txtAltaMapasPromo2x1='<input type="checkbox" checked="checked" name="Mapas" onclick="AltaResena(310)" value="Sí" />Alta en los mapas del Directorio';
txtAltaLogo='<input type="checkbox" name="Logotipo" onclick="AltaResena(312)" value="Sí" />Inclusión de logotipo en la reseña';
txtAltaLogoPromo2x1='<input type="checkbox" checked="checked" name="Logotipo" onclick="AltaResena(312)" value="Sí" />Inclusión de logotipo en la reseña';
txtAviso100='Cuotas de alta (sólo primer año) para cada servicio que contrate.';
txtAvisoPromo2x1='Servicios inseparables de la oferta 2 años x 1';
var capDatos; var alta; var Epigrafe; var vistaSolicitud=0; var EpigrafeDatosCapturados=0; var NewEpigrafe="";

function BorrarInputs() {for (var i=0; i < document.getElementById('JRcF').Solicitud.length; i++) {document.getElementById('JRcF').Solicitud[i].checked=false} }

function AltaResena(a) {
if (navigator.userAgent.indexOf("Firefox")!=-1) {JRcF=document.getElementById("JRcF")}
alta=a;
if (alta < 299) {
document.getElementById("coste110").innerHTML=""; 
document.getElementById("coste120").innerHTML="";
document.getElementById("coste130").innerHTML="";
document.getElementById("coste132").innerHTML=""; document.getElementById("tar132").innerHTML="0 &euro;";
document.getElementById("coste134").innerHTML=""; document.getElementById("tar134").innerHTML="0 &euro;";
document.getElementById("coste140").innerHTML="";
document.getElementById("coste150").innerHTML="";
document.getElementById("coste210").innerHTML=""; document.getElementById("tar210").innerHTML="99 &euro;";
document.getElementById("coste220").innerHTML=""; document.getElementById("tar220").innerHTML="59 &euro;";
document.getElementById("coste230").innerHTML=""; document.getElementById("tar230").innerHTML="29 &euro;";
document.getElementById("coste250").innerHTML=""; document.getElementById("tar250").innerHTML="0 &euro;";
if (alta==110) {tarResena=99};
if (alta==120) {tarResena=59};
if (alta==130) {tarResena=29};
if (alta==132) {tarResena=0; Epigrafe=22};
if (alta==134) {tarResena=0; Epigrafe=26};
if (alta==140) {tarResena=0; Epigrafe=20; capDatos=32};
if (alta==150) {tarResena=0; Epigrafe=22; capDatos=34};
if (alta==210) {tarResena=99; tnr=198};
if (alta==220) {tarResena=59; tnr=118};
if (alta==230) {tarResena=29; tnr=58};
if (alta==250) {tarResena=0; tarMapa=0; tarLogo=0; tnm=29; tnl=19; txtPlazo=4; Epigrafe=24; capDatos=30};
document.getElementById("coste"+alta).innerHTML=tarResena+" &euro;"; AltaMapas=0; AltaLogo=0}

if (alta==110 || alta==120 || alta==130) {
tarMapa=29; tarLogo=19; txtPlazo=1; Epigrafe=20; capDatos=30;
document.getElementById("txtAltaMapas").innerHTML=txtAltaMapas; document.getElementById("tarAltaMapa").innerHTML=tarMapa+" &euro;";
document.getElementById("txtAltaLogo").innerHTML=txtAltaLogo; document.getElementById("tarAltaLogo").innerHTML=tarLogo+" &euro;";
document.getElementById("txtAviso").innerHTML=txtAviso100; aBloque(12)}

if (alta==132 || alta==134) {
tarMapa=0; tarLogo=0; tnr=29; tnm=29; tnl=19; txtPlazo=0; capDatos=30;
document.getElementById("tar"+alta).innerHTML="<span style='text-decoration:line-through'>"+tnr+" &euro;</span>";
document.getElementById("txtAltaMapas").innerHTML=txtAltaMapas; document.getElementById("tarAltaMapa").innerHTML="<span style='text-decoration:line-through'>"+tnm+" &euro;</span>";
document.getElementById("txtAltaLogo").innerHTML=txtAltaLogo; document.getElementById("tarAltaLogo").innerHTML="<span style='text-decoration:line-through'>"+tnl+" &euro;</span>";
document.getElementById("txtAviso").innerHTML=txtAviso100; aBloque(12)}

if (alta==140 || alta==150) {
tarMapa=0; tarLogo=0; ; txtPlazo=0; 
document.getElementById("txtAltaMapas").innerHTML=txtAltaMapas; document.getElementById('JRcF').Mapas.checked=false;
document.getElementById("txtAltaLogo").innerHTML=txtAltaLogo; document.getElementById('JRcF').Logotipo.checked=false; cBloque(12) }

if (alta==210 || alta==220 || alta==230) {
tarMapa=29; tarLogo=19; txtPlazo=2; Epigrafe=20; capDatos=30;
document.getElementById("txtAltaMapas").innerHTML=txtAltaMapasPromo2x1; document.getElementById("tarAltaMapa").innerHTML=tarMapa+" &euro;";
document.getElementById("coste310").innerHTML=tarMapa+" &euro;"; AltaMapas=tarMapa;
document.getElementById("txtAltaLogo").innerHTML=txtAltaLogoPromo2x1; document.getElementById("tarAltaLogo").innerHTML=tarLogo+" &euro;";
document.getElementById("coste312").innerHTML=tarLogo+" &euro;"; AltaLogo=tarLogo;
document.getElementById("tar"+alta).innerHTML="<span style='text-decoration:line-through'>"+tnr+" &euro;</span>";
document.getElementById("txtAviso").innerHTML=txtAvisoPromo2x1; aBloque(12)}

if (alta==250) {
document.getElementById("tar250").innerHTML="<span style='text-decoration:line-through'>de 29 a 99</span>";
document.getElementById("txtAltaMapas").innerHTML=txtAltaMapasPromo2x1; document.getElementById("tarAltaMapa").innerHTML="<span style='text-decoration:line-through'>"+tnm+" &euro;</span>";
document.getElementById("coste310").innerHTML=tarMapa+" &euro;";
document.getElementById("txtAltaLogo").innerHTML=txtAltaLogoPromo2x1; document.getElementById("tarAltaLogo").innerHTML="<span style='text-decoration:line-through'>"+tnl+" &euro;</span>";
document.getElementById("coste312").innerHTML=tarLogo+" &euro;";
document.getElementById("txtAviso").innerHTML=""; aBloque(12)}

aBloque(14); 
if (document.getElementById("JRcF").Mapas.checked) {document.getElementById("coste310").innerHTML=tarMapa+" &euro;"; AltaMapas=tarMapa} else {document.getElementById("coste310").innerHTML=""; AltaMapas=0}
if (document.getElementById("JRcF").Logotipo.checked) {document.getElementById("coste312").innerHTML=tarLogo+" &euro;"; AltaLogo=tarLogo} else {document.getElementById("coste312").innerHTML=""; AltaLogo=0}

Tarifas=tarResena+AltaMapas+AltaLogo;
document.getElementById("TotalConceptos").innerHTML="Tarifas<br />I.V.A.<br />Total pedido";
iva=Tarifas*16/100; TotalPedidoConIva=Tarifas+iva;
document.getElementById("TotalImportes").innerHTML=Tarifas.toFixed(2)+" &euro;" +"<br />"+iva.toFixed(2)+" &euro;<br />" +TotalPedidoConIva.toFixed(2)+" &euro;";

if (txtPlazo==0) {txtAvisoPlazo="Reseña gratuita mientras sus datos<br />sean confirmados anualmente"}
if (txtPlazo==1) {txtAvisoPlazo="Tarifa anual"}
if ((txtPlazo==1) & (AltaMapas > 0)) {txtAvisoPlazo=txtAvisoPlazo+"<br />+ mapas (sólo primer año)"}
if ((txtPlazo==1) & (AltaLogo > 0)) {txtAvisoPlazo=txtAvisoPlazo+"<br />+ logo (sólo primer año)"}
if (txtPlazo==2) {txtAvisoPlazo="Tarifas para 2 años.<br />El segundo le sale gratis."}
if (txtPlazo==4) {txtAvisoPlazo="Reseña gratuita durante el primer año.<br />¡ Ser el primero tiene sus ventajas !"}
document.getElementById("TotalAvisos").innerHTML=txtAvisoPlazo;
if (EpigrafeDatosCapturados==0) {EpigrafeDatosCapturados=Epigrafe}
if (EpigrafeDatosCapturados != Epigrafe) {cBloques(); anularPaso(3); anularPaso(4); aBloque(10); EpigrafeDatosCapturados=Epigrafe}
habilitarPaso(2); }

function cBloques() {cBloque(1); cBloque(10); cBloque(19); cBloque(20); cBloque(22); cBloque(24); cBloque(26); cBloque(29); cBloque(30); cBloque(32); cBloque(34); cBloque(38); cBloque(39); cBloque(40); cBloque(49)}

function VerSolicitud() {
aBloque(10); aBloque(Epigrafe); aBloque(38); aBloque(capDatos); aBloque(40); cBloque(49); vistaSolicitud=1; var i=1;
document.getElementById("PiePosicionado").style.position="relative"; document.getElementById("PiePosicionado").style.top=0;
for (i=1; i<=4; i++) {document.getElementById("Paso"+i).className="pasoViable"} }

urlPaso1='<a href="#" onclick="irPaso1()" title="Paso 1: Seleccione un tipo de reseña"><strong>1</strong>Seleccione un<br />tipo de reseña</a>';
urlPaso2='<a href="#" onclick="irPaso2()" title="Paso 2: Indique cual es su actividad"><strong>2</strong>Indique cual<br />es su actividad</a>';
urlPaso3='<a href="#" onclick="irPaso3()" title="Paso 3: Sus datos a publicar"><strong>3</strong>Sus datos<br />a publicar</a>';
urlPaso4='<a href="#" onclick="irPaso4()" title="Paso 4: Sobre Vd."><strong>4</strong>Solicitante de<br />la reseña</a>';

function anularPaso(ap) {
document.getElementById("Paso"+ap).className="pasoPdte";
if (ap==3) {cBloque(29); cBloque(39); document.getElementById("Paso3").innerHTML="<strong>3</strong>Sus datos<br />a publicar"}
if (ap==4) {cBloque(40); cBloque(49); document.getElementById("Paso4").innerHTML="<strong>4</strong>Solicitante de<br />la reseña"} }

function habilitarPaso(paso) {
if (paso==2) {urlPaso=urlPaso2; if (vistaSolicitud==0) {aBloque(19)} }
if (paso==3) {urlPaso=urlPaso3; if (vistaSolicitud==0) {aBloque(29)} }
if (paso==4) {urlPaso=urlPaso4; if (vistaSolicitud==0) {aBloque(39)} }
document.getElementById("Paso"+paso).className="pasoViable"; document.getElementById("Paso"+paso).innerHTML=urlPaso}

function irPaso1() {
urlPaso=urlPaso1; cBloques(); nuevaBarraPasos(1); aBloque(2); aBloque(10);
document.getElementById("PiePosicionado").style.position="relative"; document.getElementById("PiePosicionado").style.top=0; }

function irPaso2() {
urlPaso=urlPaso2; cBloques(); nuevaBarraPasos(2); aBloque(Epigrafe);
if (Epigrafe==20 & JRcF.Epigrafe.value !="")  {aBloque(29); habilitarPaso(3)}
if (Epigrafe==22 & JRcF.EpigrafeEntidades.value !="")  {aBloque(29); habilitarPaso(3)}
if (Epigrafe==24 & JRcF.EpigrafeSerPrimero.value !="")  {aBloque(29); habilitarPaso(3)}
if (Epigrafe==26 & JRcF.EpigrafeInformativo.value !="")  {aBloque(29); habilitarPaso(3)}
if (alta==150) {JRcF.EpigrafeEntidades.selectedIndex="4"; aBloque(29); habilitarPaso(3)}
posicionarPiePag() }

function irPaso3() {
contenidoMinimo='<p class="peque">Indique la información a publicar tal y como quiere que se vea. Es necesario un contenido mínimo para poder avanzar al paso 4.</p>';
urlPaso=urlPaso3; cBloques(); nuevaBarraPasos(3); aBloque(capDatos); aBloque(38);
document.getElementById("ContenidoMinimo"+capDatos).innerHTML=contenidoMinimo;
conDatos(capDatos);
if (capDatos==30 & c30 > 40) {habilitarPaso(4)}
if (capDatos==32 & c32 > 35) {habilitarPaso(4)}
if (capDatos==34 & c34 > 30) {habilitarPaso(4)}
posicionarPiePag() }

function irPaso4() {urlPaso=urlPaso4; nuevaBarraPasos(4); cBloques(); aBloque(40); aBloque(49); JRcF.Condiciones.checked=false; posicionarPiePag() }

function nuevaBarraPasos(paso) {
vistaSolicitud=0; var i=1;
for (i=1; i<=4; i++) {if (document.getElementById("Paso"+i).className=="pasoAct") {document.getElementById("Paso"+i).className="pasoViable"} }
document.getElementById("Paso"+paso).innerHTML=urlPaso; document.getElementById("Paso"+paso).className="pasoAct" 
}

function verificarEpigrafe() {
epiOk=1; NewEpigrafe=document.getElementById("NuevoEpigrafe").value.length;
if (Epigrafe==20 & JRcF.Epigrafe.value =="")  {JRcF.Epigrafe.selectedIndex="0"; epiOk=0};
if (Epigrafe==20 & NewEpigrafe >3) {epiOk=1}
if (Epigrafe==22 & JRcF.EpigrafeEntidades.value =="")  {JRcF.EpigrafeEntidades.selectedIndex="0"; epiOk=0};
if (Epigrafe==24 & JRcF.EpigrafeSerPrimero.value =="")  {JRcF.EpigrafeSerPrimero.selectedIndex="0"; epiOk=0};
if (Epigrafe==26 & JRcF.EpigrafeInformativo.value =="")  {JRcF.EpigrafeInformativo.selectedIndex="0"; epiOk=0}; 
if (epiOk==0) {anularPaso(3); anularPaso(4); irPaso2()};
if (epiOk==1) {habilitarPaso(3)} }

var c30=0; var c32=0; var c34=0;
function conDatos(cc) {
ccOk=0; c38Info=JRcF.c38_Info_adicional.value.length;
c30Tit=JRcF.c30_Titulo.value.length; c30L1=JRcF.c30_Linea1.value.length; c30L2=JRcF.c30_Linea2.value.length; c30Dir=JRcF.c30_Direccion.value.length; c30Tel=JRcF.c30_Telefono.value.length; c30Web=JRcF.c30_Web.value.length;
c30=c30Tit+c30L1+c30L2+c30Dir+c30Tel+c30Web+c38Info;
c32Tit=JRcF.c32_Titulo.value.length; c32L1=JRcF.c32_Linea1.value.length; c32Dir=JRcF.c32_Direccion.value.length; c32Tel=JRcF.c32_Telefono.value.length; c32Web=JRcF.c32_Web.value.length;
c32=c32Tit+c32L1+c32Dir+c32Tel+c32Web+c38Info;
c34Tit=JRcF.c34_Titulo.value.length; c34L1=JRcF.c34_Linea1.value.length; c34L2=JRcF.c34_Linea2.value.length; c34Editor=JRcF.c34_Editor.value.length; c34Web=JRcF.c34_Web.value.length;
c34=c34Tit+c34L1+c34L2+c34Editor+c34Web+c38Info;
if (cc==30 & c30 > 40) {ccOk=1}; if (cc==32 & c32 > 35) {ccOk=1}; if (cc==34 & c34 > 30) {ccOk=1} 
if (ccOk==0) {anularPaso(4)};
if (ccOk==0 & vistaSolicitud==1) {irPaso3()};
if (ccOk==1) {habilitarPaso(4)} 
} 

function verEpigrafe() {if (document.getElementById("Epigrafe").value !="")  {url=document.getElementById("Epigrafe").value; window.open(url, '_blank') } }
function verEpigrafeEntidades() {if (document.getElementById("EpigrafeEntidades").value !="")  {url=document.getElementById("EpigrafeEntidades").value; window.open(url, '_blank') } }
function verEpigrafeSerPrimero() {if (document.getElementById("EpigrafeSerPrimero").value !="")  {url=document.getElementById("EpigrafeSerPrimero").value; window.open(url, '_blank') } }
function verEpigrafeInformativo() {if (document.getElementById("EpigrafeInformativo").value !="")  {url=document.getElementById("EpigrafeInformativo").value; window.open(url, '_blank') } }
