// JavaScript Document function goBack() { window.history.back(); } function desplegar_menu() { $("#menu").toggleClass("mobile_active"); } function desplega_newsletter() { $(".contenidor_newsletter").slideToggle(); } function desplega_any(id, id_des) { $(id).slideToggle(); var ele = document.getElementById(id_des) ele.classList.toggle("open"); } function desplega_acte(id_acte,id_contenidor) { var id_remove = $("#"+id_contenidor+" div.active").attr('id'); if(!$("#"+id_acte).hasClass("active")) { $("#"+id_acte).slideDown().addClass("active"); $("#link_"+id_acte).find('span').remove(); $("#link_"+id_acte).append(" - Tancar"); } $("#"+id_remove).slideUp().removeClass("active"); $("#link_"+id_remove).find('span').remove(); $("#link_"+id_remove).append(" - Veure més"); } function scroll_a_id(id) { $("html,body").animate({scrollTop:$(id).offset().top}); } function obrir_video_slide(video) { $.magnificPopup.open({ items: { src: video, // can be a HTML string, jQuery object, or CSS selector type: 'iframe' }, callbacks:{ close: function(){$(".slide_gran").cycle('resume');} } }); $(".slide_gran").cycle('pause'); } function canvia_periodicitat(obj) { $("#periodicitat").val(obj.value); $(".boto_periodicitat").removeClass("active"); $("#"+obj.id).addClass("active"); } function canvia_quantitat(valor) { valor=valor.replace(",","."); valor=valor.replace("€",""); $("#valor_eur").val( (Math.round(valor*100)/100) + " €" ); $("#amount_targeta").val(Math.round(valor*100)); $("#opcions_quantitat div").removeClass("active"); try { $("#qty_"+valor).parent().addClass("active"); }catch(e){}; } function inserir_nova_quantitat(obj) { $("#opcions_quantitat div").removeClass("active"); $(obj).parent().addClass("active"); } function comprova_quantitat(valor) { valor=valor.replace("_","").replace(",",".").replace(" ","").replace("€",""); $("#valor_personal").val(valor+" €"); valor=parseFloat(valor); if(valor.length == 0 || isNaN(valor) || valor <= 0) { canvia_quantitat("100€"); } else canvia_quantitat(valor+"€"); } function mostra_empreses(id_directori,lletra) { $(".lletres_empreses a").removeClass("active"); $("#lletra_"+lletra).addClass("active"); $("#llistat_empreses_"+id_directori).html("Carregant empreses..."); if($(window).width() < 650) { $('html,body').animate({scrollTop:$("#llistat_empreses_"+id_directori).offset().top-20}); } $.ajax({ type: "POST", url: 'https://www.caritasgirona.cat/index.php?id='+id_directori+'&no_index=true&lletra='+lletra, dataType: "html", success: function(data) { $("#llistat_empreses_"+id_directori).html(data); } }); } function comprova_forma_pagament(obj) { if(obj.value == "domiciliacio") { $("#pagament_domiciliacio").css('display','block'); $("#pagament_targeta").css('display','none'); $("#boto_enviar_donatiu").css('display','inline-block'); $("#nom_titular,#opcions_iban,#opcions_periodicitat").css('display','block'); } else if(obj.value == "targeta") { $("#nom_titular,#opcions_iban,#opcions_periodicitat").css('display','none'); } } function initialize(x,y,canvas,markerTitle) { x = parseFloat(x); y = parseFloat(y); var myLatlng = new google.maps.LatLng(x,y); var myOptions = { zoom: 15, center: myLatlng, mapTypeId: google.maps.MapTypeId.ROADMAP } var map = new google.maps.Map(document.getElementById(canvas), myOptions); var marker = new google.maps.Marker({ position: myLatlng, map: map, icon: 'https://www.caritasgirona.cat//templates/PUBLIC/img/marcador_mapa.png', title: markerTitle }); } function comprova_form_contacte() { error = ""; frm = document.frm_contacte; //Obligatori nom, telefon, email // if(frm.nom.value.length < 3 || frm.nom.value == "Nom") // error += 'Ompli el camp: Nom\n'; // if(frm.telefon.value.length < 3 || frm.telefon.value == "Telèfon") // error += 'Ompli el camp: Telèfon\n'; // if(frm.xmal.value.length < 3 || frm.xmal.value == "E-mail") // error += 'Ompli el camp: E-mail\n'; // else if(!(/\S+@\S+\.\S+/.test(frm.xmal.value))) // error += 'Email incorrecte\n'; if(!frm.check_condicions.checked) error += 'Cal acceptar les condicions abans de continuar\n'; if(frm.captcha_client.value.length < 4) error += 'Escriu el codi\n'; if(error) alert(error); else frm.submit(); } function comprova_form_newsletter() { error = ""; frm = document.frm_newsletter; if(frm.name.value.length < 3 || frm.name.value == "Nom") error += 'Ompli el camp: Nom\n'; if(frm.xmal.value.length < 3 || frm.xmal.value == "E-mail") error += 'Ompli el camp: E-mail\n'; else if(!(/\S+@\S+\.\S+/.test(frm.xmal.value))) error += 'Email incorrecte\n'; if(!frm.check_condicions.checked) error += 'Cal acceptar les condicions abans de continuar\n'; if(error) alert(error); else frm.submit(); } function validaData(data){ var dtCh= "/"; var minYear=1900; var maxYear=2100; function isInteger(s){ var i; for (i = 0; i < s.length; i++){ var c = s.charAt(i); if (((c < "0") || (c > "9"))) return false; } return true; } function stripCharsInBag(s, bag){ var i; var returnString = ""; for (i = 0; i < s.length; i++){ var c = s.charAt(i); if (bag.indexOf(c) == -1) returnString += c; } return returnString; } function daysInFebruary (year){ return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 ); } function DaysArray(n) { for (var i = 1; i <= n; i++) { this[i] = 31 if (i==4 || i==6 || i==9 || i==11) {this[i] = 30} if (i==2) {this[i] = 29} } return this } function isDate(dtStr){ var daysInMonth = DaysArray(12) var pos1=dtStr.indexOf(dtCh) var pos2=dtStr.indexOf(dtCh,pos1+1) var strDay=dtStr.substring(0,pos1) var strMonth=dtStr.substring(pos1+1,pos2) var strYear=dtStr.substring(pos2+1) strYr=strYear if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1) if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1) for (var i = 1; i <= 3; i++) { if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1) } month=parseInt(strMonth) day=parseInt(strDay) year=parseInt(strYr) if (pos1==-1 || pos2==-1){ return false } if (strMonth.length<1 || month<1 || month>12){ return false } if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){ return false } if (strYear.length != 4 || year==0 || yearmaxYear){ return false } if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){ return false } return true } if(isDate(data)){ return true; }else{ return false; } } function valida_nif_cif_nie( a ) { var temp = a.toUpperCase(); var cadenadni = "TRWAGMYFPDXBNJZSQVHLCKE"; if( temp!= '' ) { //si no tiene un formato valido devuelve error if( ( !/^[A-Z]{1}[0-9]{7}[A-Z0-9]{1}$/.test( temp ) && !/^[T]{1}[A-Z0-9]{8}$/.test( temp ) ) && !/^[0-9]{8}[A-Z]{1}$/.test( temp ) ) { return 0; } //comprobacion de NIFs estandar if( /^[0-9]{8}[A-Z]{1}$/.test( temp ) ) { posicion = a.substring( 8,0 ) % 23; letra = cadenadni.charAt( posicion ); var letradni = temp.charAt( 8 ); if( letra == letradni ) { return 1; } else { return -1; } } //algoritmo para comprobacion de codigos tipo CIF suma = parseInt(a.charAt(2))+parseInt(a.charAt(4))+parseInt(a.charAt(6)); for( i = 1; i < 8; i += 2 ) { temp1 = 2 * parseInt( a.charAt( i ) ); temp1 += ''; temp1 = temp1.substring(0,1); temp2 = 2 * parseInt( a.charAt( i ) ); temp2 += ''; temp2 = temp2.substring( 1,2 ); if( temp2 == '' ) { temp2 = '0'; } suma += ( parseInt( temp1 ) + parseInt( temp2 ) ); } suma += ''; n = 10 - parseInt( suma.substring( suma.length-1, suma.length ) ); //comprobacion de NIFs especiales (se calculan como CIFs) if( /^[KLM]{1}/.test( temp ) ) { if( a.charAt( 8 ) == String.fromCharCode( 64 + n ) ) { return 1; } else { return -1; } } //comprobacion de CIFs if( /^[ABCDEFGHJNPQRSUVW]{1}/.test( temp ) ) { temp = n + ''; if( a.charAt( 8 ) == String.fromCharCode( 64 + n ) || a.charAt( 8 ) == parseInt( temp.substring( temp.length-1, temp.length ) ) ) { return 2; } else { return -2; } } //comprobacion de NIEs //T if( /^[T]{1}[A-Z0-9]{8}$/.test( temp ) ) { if( a.charAt( 8 ) == /^[T]{1}[A-Z0-9]{8}$/.test( temp ) ) { return 3; } else { return -3; } } //XYZ if( /^[XYZ]{1}/.test( temp ) ) { temp = temp.replace( 'X','0' ) temp = temp.replace( 'Y','1' ) temp = temp.replace( 'Z','2' ) pos = temp.substring(0, 8) % 23; if( a.toUpperCase().charAt( 8 ) == cadenadni.substring( pos, pos + 1 ) ) { return 3; } else { return -3; } } } return 0; } $( document ).ready(function() { $('#opcions_quantitat > div').on('click', function() { $(this).css('background', '#d31a21'); $(this).find('input').css('background', '#d31a21'); $(this).siblings().css('background', '#ff5455'); $(this).siblings().find('input').css('background', '#ff5455'); }); $('#boto_popup_donatiu').on('click', function() { $('#popup_donation').css('display', 'flex'); }); $('#popup_donation .close_popup').on('click', function() { $('#popup_donation').css('display', 'none'); }); });