PageSourceSearch

https://www.ajuntamentabrera.cat/comu/js/lib.js?v=2

js ajuntamentabrera.cat collected 2026-10-02 06:30:12 UTC 39,732 bytes, 1,387 lines download raw bytes

1var ie = (document.all)? true:false;
2var ns = (document.layers)? true:false;
3var ns6 = document.getElementById && !document.all;
4
5// false: IE 7, mozilla, safari, opera 9 , true: IE6, older browsers
6var oldBrowser = window.XMLHttpRequest ? false : true;
7
8var IExplore = (navigator.appName == "Microsoft Internet Explorer");
9var BrowserVer = parseInt(navigator.appVersion);
10var NetScape = (navigator.appName=="Netscape")?1:0;	
11var ie8 = (ie && BrowserVer<=4?true:false);
12
13
14// Comprova si s'ha iniciat la càrrega d'una API externa
15function isModuleLoading(modul) {
16	if (!window["loadedmodul"]) {
17		window["loadedmodul"] = "";
18	}
19	
20	if (window["loadedmodul"].indexOf("["+modul+"]")==-1)
21		return false;
22	else
23		return true;
24}
25
26// Indica que s'ha iniciat la càrrega d'una API externa
27function setModuleLoading(modul) {
28	if (!window["loadedmodul"]) {
29		window["loadedmodul"] = "";
30	}
31	
32	if (window["loadedmodul"].indexOf("["+modul+"]")==-1) {
33		// Crea un allista amb els noms del mòduls carregats
34		window["loadedmodul"] += "[" + modul + "]";
35	}
36}
37
38function mostraAfegirComentari(div_afegir_comentari) {
39	if (!$("#" + div_afegir_comentari).is(':visible')) {
40		$("#" + div_afegir_comentari).show();
41		
42		if (document.forms['formu1'].elements['nom_usuari']) {
43			document.forms['formu1'].elements['nom_usuari'].focus();
44		} else if (document.forms['formu1'].elements['comentari']) {
45			document.forms['formu1'].elements['comentari'].focus();
46		}
47	} else
48		$("#" + div_afegir_comentari).hide();
49	
50	return false;
51}
52
53function seleccionaCert() {
54	var cerificat;
55	if ($.browser.msie && (parseFloat($.browser.version)<9)) {
56		cerificat = document.applets['certViewer'].obteCertificat();
57	} else {
58		cerificat = document.embeds['certViewer'].obteCertificat();
59	}
60	
61	if (cerificat!=null && cerificat!='') {
62		if (cerificat.indexOf("ERROR")==-1) {
63			document.forms["certificat"].elements['certBase64'].value = cerificat;
64		} else
65			return false;
66	} else
67		return false;
68	
69	return true;
70}
71
72
73/*
74 * Comprova podem accedir a la url per ssl
75 * si és així redirecciona a aquesta url
76 */
77function ssl_check_and_redirect(url) {
78    $.ajax({
79        url: url,
80        dataType: "script",
81        success: function(){
82            window.location.replace(url);
83        }
84    });
85}  
86
87
88function TractaTxt(camp) {
89	var rExp = /’/gi;
90	camp.value = camp.value.replace(rExp,"'");
91}
92	
93function replaceCharacters(conversionString,inChar,outChar) {
94	var convertedString = conversionString.split(inChar);
95	convertedString = convertedString.join(outChar);
96	return convertedString;
97}
98	
99function Imprimir() {
100	window.print(); 
101}
102	
103
104// Example: showHideLayers(Layer1,'','show',Layer2,'','hide');
105function showHideLayers() { 
106  var i, visStr, obj, args = showHideLayers.arguments;
107  for (i=0; i<(args.length-2); i+=3) {
108    if ((obj = findObj(args[i])) != null) {
109      visStr = args[i+2];
110      if (obj.style) {
111        obj = obj.style;
112        if(visStr == 'show') visStr = 'visible';
113        else if(visStr == 'hide') visStr = 'hidden';
114      }
115      obj.visibility = visStr;
116    }
117  }
118}
119
120function showHideLayers2() { 
121  var i, visStr, obj, args = showHideLayers2.arguments;
122  for (i=0; i<(args.length-2); i+=3) {
123    if ((obj = findObj(args[i])) != null) {
124      visStr = args[i+2];
125      if (obj.style) {
126        obj = obj.style;
127        if(visStr == 'show') {
128			obj.visibility = 'visible';
129			obj.display = 'block';
130		}
131        else if(visStr == 'hide') {
132			obj.visibility = 'hidden';
133			obj.display = 'none';
134		}
135      }
136    }
137  }
138}
139
140// Example: obj = findObj("image1");
141function findObj(theObj, theDoc)
142{
143  	var p, i, foundObj;
144  
145  	if(!theDoc) theDoc = document;
146  	if( (p = theObj.indexOf("?")) > 0 && parent.frames.length) {
147		theDoc = parent.frames[theObj.substring(p+1)].document;
148		theObj = theObj.substring(0,p);
149  	}
150  	if(!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj];
151  	for (i=0; !foundObj && i < theDoc.forms.length; i++) 
152		foundObj = theDoc.forms[i][theObj];
153  	for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++) 
154		foundObj = findObj(theObj,theDoc.layers[i].document);
155  	if(!foundObj && document.getElementById) foundObj = document.getElementById(theObj);
156  
157  	return foundObj;
158}
159
160
161
162function MM_preloadImages() { //v3.0
163  	var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
164    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
165    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
166}
167
168function MM_swapImgRestore() { //v3.0
169  	var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
170}
171
172function MM_findObj(n, d) { //v4.01
173  	var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
174    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
175  	if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
176  	for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
177  	if(!x && d.getElementById) x=d.getElementById(n); return x;
178}
179
180function MM_swapImage() { //v3.0
181	var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
182   	if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
183}
184
185
186function DoModal(pag, wi, he) {
187	var seleccio;	
188	var w = 800, h = 600;
189	var popW = wi, popH = he;
190	
191	/* Centrem la finestra a la pantalla */
192	if (document.all || document.layers) {
193	   w = screen.availWidth;
194	   h = screen.availHeight;
195	}
196	
197	var leftPos = (w-popW)/2;
198	var topPos = (h-popH)/2;	
199			
200	winpop = window.open(pag,"Modal","status=0,top=" + topPos + ",left=" + leftPos + ",toolbar=0,scrollbars=no,menubar=0,directories=0,height="+ he + ",width=" + wi);
201	if (!winpop.opener)
202		winpop.opener = self;
203	self.name = "opener";
204	winpop.focus();
205}
206
207function ObreFinestra(pag, wi, he) {
208	var popW = wi, popH = he;
209	
210	var h = $(window).height();
211	var w = $(window).width();
212	
213	var leftPos = (w - popW)/2;
214	var topPos = (h - popH)/2;	
215			
216	winpop = window.open(pag, "Modal", "status=0,top=" + topPos + ",left=" + leftPos + ",toolbar=0,scrollbars=2,menubar=0,directories=0,height="+ he + ",width=" 
216+ wi);
217	if (!winpop.opener)
218		winpop.opener = self;
219	self.name = "opener";
220	winpop.focus();
221}
222		
223//Example: preloadImages('file.gif', 'http://www.x.com/y.gif');
224function preloadImages()
225{
226  if(document.images)
227  {
228    if(!document.imageArray) document.imageArray = new Array();
229    var i,j = document.imageArray.length, args = preloadImages.arguments;
230    
231    for(i=0; i<args.length; i++)
232    {
233      if (args[i].indexOf("#")!=0)
234      {
235        document.imageArray[j] = new Image;
236        document.imageArray[j++].src = args[i];
237      }
238    }
239  }
240}
241
242
243
244/*
245function SeleccionaDia (y,m,d) {
246	var formocult = window.document.forms['formocult'];
247	formocult.data.value = d + '-' + m + '-' + y;
248	formocult.calendari.value = '';
249	
250	var options2 = {
251		success:	DiaSel_Retorn, 
252		dataType:	'html',
253		type: 		'POST'
254	};
255	
256	$(formocult).ajaxSubmit(options2);
257}
258
259		
260// Funció que s'executa després rebre la resposta del servidor
261function DiaSel_Retorn(respostaHTML) {
262	$('#Calendari_Dades').html(respostaHTML); 
263}
264
265*/
266
267function AmagaSelect(param) {
268	//if (document.all) document.body.className = "fix";		
269	if ($.browser.msie && oldBrowser) {
270		if (param) 
271			document.body.className = "fix";	
272		else 
273			document.body.className = "";
274	}
275}
276
277
278//Funcions per marcar dia actiu en el calendari dels portlets
279function MarcaDiaCal (y,m,d,MesActual) {
280	// Desmarca els dia seleccionat previament
281	if ($("#" + MesActual.getFullYear() + "_"+ (MesActual.getMonth()+1) +"_" + MesActual.getDate())) {
282		$("#" + MesActual.getFullYear() + "_"+ (MesActual.getMonth()+1) +"_" + MesActual.getDate()).removeClass("diaSeleccionat");
283	}
284	
285	// Marca el dia seleccionat
286	if ($("#" + y + "_"+ m +"_" + d)) {
287		$("#" + y + "_"+ m +"_" + d).addClass("diaSeleccionat");
288	}
289}
290
291function NumDecimalsOk(s,delimitador,numerodecimals) {   
292
293	var i = 0;
294    while (i<s.length&&s.charAt(i)!=delimitador)
295       i++;
296    //Elimina el delimitador
297	if (i<s.length)
298		i++;
299		
300	if(s.substring(i, s.length).length<=numerodecimals)
301		return true
302	else
303		return false;
304}
305
306
307// Transforma un node XML a texte
308function xml2Str(xmlNode)
309{
310  try {
311    // Gecko-based browsers, Safari, Opera.
312    return (new XMLSerializer()).serializeToString(xmlNode);
313  }
314  catch (e) {
315    try {
316      // Internet Explorer.
317      return xmlNode.xml;
318    }
319    catch (e)
320    {//Strange Browser ??
321     alert('Xmlserializer not supported');
322    }
323  }
324  return false;
325}
326
327function hasCSS() {
328	var _d = document.createElement('div');
329	_d.id = 'css_test';
330	$('body').append(_d);
331	$('#css_test').css({width:'1px',height:'1px',display:'none'});
332	var _v = ($('#css_test').width() != 1) ? false : true;
333	$('#css_test').remove();
334	return _v;
335}
336
337
338var opts_issu = {
339	//ceebox display settings
340	animSpeed: "normal", // animation resize transition speed (can be set to "slow","normal","fast", or in milliseconds like 1000)
341	easing: "swing", // supports use of the easing plugin for resize anim (http://gsgd.co.uk/sandbox/jquery/easing/)
342	fadeOut: 400, //speed that ceebox fades out when closed or advancing through galleries
343	fadeIn: 400, //speed that ceebox fades in when opened or advancing through galleries
344	overlayColor: "#000",
345	overlayOpacity: 0.8,
346	// color settings for background, text, and border. If these are set to blank then it uses css colors. If set here it overrides css. This becomes useful with metadata and color animations which allows you to change colors from link to link.
347	boxColor: "", //background color for ceebox.
348	textColor: "", //color for text in ceebox.
349	borderColor: "", //outside border color.
350	borderWidth: "3px", //the border on ceebox. Can be used like css ie,"4px 2px 4px 2px"
351	padding: 15, //ceebox padding
352	margin: 150, //minimum margin between ceebox inside content and browser frame (this does not count the padding and border; I know it's odd. I'll likely change how it works at some point)
353	height: 600,
354	width: 800
355};
356
357function showISSUmin(obj, id_doc) {
358	var parent = $(obj).parent().get(0);
359	
360	$(obj).text('Amaga');
361	
362	// Mostra la caixa
363	$("<div id='ISSUDoc_min'></div>").insertAfter(parent).animate({opacity: 1}, opts_issu.animSpeed, function() {
364		$(obj).off('click').on('click', function() {
365			$("#ISSUDoc_min").fadeOut('slow', function() {
366				$(obj).text('Veure').click(function() {showISSUmin(obj ,id_doc);});
367				
368				$(this).remove();
369			});
370		});
371	});
372	
373	// Inserta el flash a la caixa
374	$('#ISSUDoc_min').flash({
375		swf: 'http://static.issuu.com/webembed/viewers/style1/v2/IssuuReader.swf',
376		height: 150,
377		width: 200,
378		encodeParams: true,
379		allowFullScreen: true,
380		wmode: 'transparent',
381		menu: false,
382		flashvars: {
383			jsAPIClientDomain: 'aceba.idisc.es',
384	        mode: 'mini',
385	        documentId: id_doc
386	        /*
387	        showFlipBtn: 'true',
388	       	layout: 'http%3A%2F%2Fskin.issuu.com%2Fv%2Flight%2Flayout.xml',
389	        docName: 'nom docu',
390	        username: 'press',
391	        loadingInfoText: 'Introducing%20Smart%20Look%20by%20Issuu',
392	        et: '1251881404594',
393	        er: '57'
394	        */
395		}
396	});
397	
398	return false;
399}
400
401function showISSU(id_doc) {
402	// Mostra el fons
403	if ($("#ISSUDoc_fons").size()===0){
404		$("<div id='ISSUDoc_fons'></div>").css({
405				 opacity : opts_issu.overlayOpacity,
406				 position: "absolute",
407				 top: 0,
408				 left: 0,
409				 backgroundColor: opts_issu.overlayColor,
410				 width: "100%",
411				 height: $(document).height(),
412				 zIndex: 3000
413			}).appendTo($("body")).click(function() {
414				$("#ISSUDoc").fadeOut('slow', function() { $(this).remove(); $("#ISSUDoc_fons").remove();});
415			});
416	}
417	
418	// Mostra la caixa que contindrà el flash amb el document issu
419	if ($("#ISSUDoc").size()===0){
420		var pos = boxPosISSU(opts_issu); //set up margin and position
421		
422		// Propietats css de la caixa 
423		var boxCSS = {
424			position: pos.position,
425			zIndex: 3002,
426			top: "50%",
427			left: "50%",
428			height: opts_issu.height + "px",
429			width: opts_issu.width + "px",
430			marginLeft: pos.mleft + 'px',
431			marginTop: pos.mtop + 'px',
432			opacity:0,
433			borderWidth:opts_issu.borderWidth,
434			borderColor:opts_issu.borderColor,
435			backgroundColor:opts_issu.boxColor,
436			color: opts_issu.textColor
437		};
438		
439		$("<div id='ISSUDoc'></div>").css(boxCSS).appendTo("body").animate({opacity:1},opts_issu.animSpeed,function(){
440			$("<a href='#' id='ISSUDoc_Close' title='Close'>close</a>").appendTo("#ISSUDoc").click(function() {
441				$("#ISSUDoc").fadeOut('slow', function() { $(this).remove(); $("#ISSUDoc_fons").remove();});
442			});
443		});
444	}
445	
446	// Inserta el flash a la caixa
447	$('#ISSUDoc').flash({
448		swf: 'http://static.issuu.com/webembed/viewers/style1/v2/IssuuReader.swf?mode=mini&amp;backgroundColor=%23222222&amp;documentId=' + id_doc,
449		height: 600,
450		width: 800,
451		encodeParams: true,
452		allowFullScreen: true,
453		wmode: 'transparent',
454		menu: false
455	});
456	return false;
457}
458
459// Returns margin and positioning from opts values
460function boxPosISSU(opts){ 
461	// 1. set up base sizes and positions
462	var pos = "fixed",scroll = 0, reg = /[0-9]+/g, b = cssParse(opts.borderWidth, reg);
463	// 2. IE 6 Browser fixes
464	if (!window.XMLHttpRequest) {
465		if ($("#cee_HideSelect") === null) {$("body").append("<iframe id='cee_HideSelect'></iframe>");} //fixes IE6's form select z-index issue
466		pos = "absolute"; //IE 6 positioning is special... and I mean that in the most demeaning way possible
467		scroll = parseInt((document.documentElement && document.documentElement.scrollTop || document.body.scrollTop),10);
468	}
469	
470	this.mleft = parseInt(-1*((opts.width) / 2 + Number(b[3])),10);
471	this.mtop = parseInt(-1*((opts.height) / 2 + Number(b[0])),10) + scroll;
472	this.position = pos;
473	
474	return this;
475}
476
477// Parses string into separate values for each side which is required for color anim and other uses
478function cssParse(css,reg) { 
479	var temp = css.match(reg),rtn = [],l = temp.length;
480	if (l > 1) {
481		rtn[0] = temp[0];
482		rtn[1] = temp[1];
483		rtn[2] = (l == 2) ? temp[0] : temp[2];
484		rtn[3] = (l == 4) ? temp[3] : temp[1];
485	} else {rtn = [temp,temp,temp,temp];}
486	
487	return rtn;
488}
489
490
491function setCookie(c_name, value, exdays, secure) {
492	// secure parameter set true by default in ffn project
493	secure = (typeof secure !== 'undefined') ?  secure : true;
494	// extend caducity days
495	exdays = (typeof exdays !== 'undefined' && exdays) ?  exdays : 1;
496	
497	var exdate = new Date();
498	exdate.setDate(exdate.getDate() + exdays);
499	
500	var c_value = escape(value) + "; expires=" + exdate.toUTCString();
501	c_value += "; path=/";
502	c_value += (secure===true) ? ";secure" : "";
503	
504	document.cookie = c_name + "=" + c_value;
505}
506
507function getCookie(c_name) {
508	var c_value = document.cookie;
509	var c_start = c_value.indexOf(" " + c_name + "=");
510	if (c_start == -1) {
511		c_start = c_value.indexOf(c_name + "=");
512	}
513	if (c_start == -1) {
514		c_value = null;
515	} else {
516		c_start = c_value.indexOf("=", c_start) + 1;
517		var c_end = c_value.indexOf(";", c_start);
518		if (c_end == -1) {
519			c_end = c_value.length;
520		}
521		c_value = unescape(c_value.substring(c_start,c_end));
522	}
523	return c_value;
524}
525
526function delete_cookie(c_name) {
527	  document.cookie = c_name + '=; expires=Thu, 01 Jan 1970 00:00:01 GMT;';
528}
529
530function modulo(cifras, divisor) {
531    /*
532      El entero más grande en Javascript es 9.007.199.254.740.990 (2^53)
533      que tiene 16 cifras, de las cuales las 15 últimas pueden tomar cualquier valor.
534      El divisor y el resto tendrán 2 cifras. Por lo tanto CUENTA como tope
535      puede ser de 13 cifras (15-2) y como mínimo de 1 cifra.
536    */
537    var CUENTA = 10;
538    var largo = cifras.length;
539    var resto = 0;
540    for (var i=0; i<largo; i+=CUENTA) {
541      var dividendo = resto + "" + cifras.substr(i, CUENTA);
542      resto = dividendo % divisor;
543    }
544    return resto;
545  }
546
547function isEmail (s)
548{   if (isEmpty(s)) 
549       if (isEmail.arguments.length == 1) return defaultEmptyOK;
550       else return (isEmail.arguments[1] == true);
551   
552    // is s whitespace?
553    if (isWhitespace(s)) return false;
554    
555    // there must be >= 1 character before @, so we
556    // start looking at character position 1 
557    // (i.e. second character)
558    var i = 1;
559    var sLength = s.length;
560
561    // look for @
562    while ((i < sLength) && (s.charAt(i) != "@"))
563    { i++
564    }
565
566    if ((i >= sLength) || (s.charAt(i) != "@")) return false;
567    else i += 2;
568
569    // look for .
570    while ((i < sLength) && (s.charAt(i) != "."))
571    { i++
572    }
573
574    // there must be at least one character after the .
575    if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
576    else return true;
577}
578
579function isEmpty(s)
580{   return ((s == null) || (s.length == 0))
581}
582
583
584//whitespace characters
585var whitespace = " \t\n\r";
586
587//Returns true if string s is empty or 
588//whitespace characters only.
589
590function isWhitespace (s)
591
592{   var i;
593
594 // Is s empty?
595 if (isEmpty(s)) return true;
596
597 // Search through string's characters one by one
598 // until we find a non-whitespace character.
599 // When we do, return false; if we don't, return true.
600
601 for (i = 0; i < s.length; i++)
602 {   
603     // Check that current character isn't whitespace.
604     var c = s.charAt(i);
605
606     if (whitespace.indexOf(c) == -1) return false;
607 }
608
609 // All characters are whitespace.
610 return true;
611}
612
613function validarIBAN(IBAN) {
614	  
615	// Remove spaces and to upper case
616	var iban = IBAN.replace( / /g, "" ).toUpperCase(),
617		ibancheckdigits = "",
618		leadingZeroes = true,
619		cRest = "",
620		cOperator = "",
621		countrycode, ibancheck, charAt, cChar, bbanpattern, bbancountrypatterns, ibanregexp, i, p;
622
623	// Check for IBAN code length.
624	// It contains:
625	// country code ISO 3166-1 - two letters,
626	// two check digits,
627	// Basic Bank Account Number (BBAN) - up to 30 chars
628	var minimalIBANlength = 5;
629	if ( iban.length < minimalIBANlength ) {
630        return false;
631    }
632  
633	// Check the country code and find the country specific format
634	countrycode = iban.substring( 0, 2 );
635	bbancountrypatterns = {
636		"AL": "\\d{8}[\\dA-Z]{16}",
637		"AD": "\\d{8}[\\dA-Z]{12}",
638		"AT": "\\d{16}",
639		"AZ": "[\\dA-Z]{4}\\d{20}",
640		"BE": "\\d{12}",
641		"BH": "[A-Z]{4}[\\dA-Z]{14}",
642		"BA": "\\d{16}",
643		"BR": "\\d{23}[A-Z][\\dA-Z]",
644		"BG": "[A-Z]{4}\\d{6}[\\dA-Z]{8}",
645		"CR": "\\d{17}",
646		"HR": "\\d{17}",
647		"CY": "\\d{8}[\\dA-Z]{16}",
648		"CZ": "\\d{20}",
649		"DK": "\\d{14}",
650		"DO": "[A-Z]{4}\\d{20}",
651		"EE": "\\d{16}",
652		"FO": "\\d{14}",
653		"FI": "\\d{14}",
654		"FR": "\\d{10}[\\dA-Z]{11}\\d{2}",
655		"GE": "[\\dA-Z]{2}\\d{16}",
656		"DE": "\\d{18}",
657		"GI": "[A-Z]{4}[\\dA-Z]{15}",
658		"GR": "\\d{7}[\\dA-Z]{16}",
659		"GL": "\\d{14}",
660		"GT": "[\\dA-Z]{4}[\\dA-Z]{20}",
661		"HU": "\\d{24}",
662		"IS": "\\d{22}",
663		"IE": "[\\dA-Z]{4}\\d{14}",
664		"IL": "\\d{19}",
665		"IT": "[A-Z]\\d{10}[\\dA-Z]{12}",
666		"KZ": "\\d{3}[\\dA-Z]{13}",
667		"KW": "[A-Z]{4}[\\dA-Z]{22}",
668		"LV": "[A-Z]{4}[\\dA-Z]{13}",
669		"LB": "\\d{4}[\\dA-Z]{20}",
670		"LI": "\\d{5}[\\dA-Z]{12}",
671		"LT": "\\d{16}",
672		"LU": "\\d{3}[\\dA-Z]{13}",
673		"MK": "\\d{3}[\\dA-Z]{10}\\d{2}",
674		"MT": "[A-Z]{4}\\d{5}[\\dA-Z]{18}",
675		"MR": "\\d{23}",
676		"MU": "[A-Z]{4}\\d{19}[A-Z]{3}",
677		"MC": "\\d{10}[\\dA-Z]{11}\\d{2}",
678		"MD": "[\\dA-Z]{2}\\d{18}",
679		"ME": "\\d{18}",
680		"NL": "[A-Z]{4}\\d{10}",
681		"NO": "\\d{11}",
682		"PK": "[\\dA-Z]{4}\\d{16}",
683		"PS": "[\\dA-Z]{4}\\d{21}",
684		"PL": "\\d{24}",
685		"PT": "\\d{21}",
686		"RO": "[A-Z]{4}[\\dA-Z]{16}",
687		"SM": "[A-Z]\\d{10}[\\dA-Z]{12}",
688		"SA": "\\d{2}[\\dA-Z]{18}",
689		"RS": "\\d{18}",
690		"SK": "\\d{20}",
691		"SI": "\\d{15}",
692		"ES": "([a-zA-Z]{2})\\s*\\t*(\\d{2})\\s*\\t*(\\d{4})\\s*\\t*(\\d{4})\\s*\\t*(\\d{2})\\s*\\t*(\\d{10})",
693		"SE": "\\d{20}",
694		"CH": "\\d{5}[\\dA-Z]{12}",
695		"TN": "\\d{20}",
696		"TR": "\\d{5}[\\dA-Z]{17}",
697		"AE": "\\d{3}\\d{16}",
698		"GB": "[A-Z]{4}\\d{14}",
699		"VG": "[\\dA-Z]{4}\\d{16}"
700	};
701
702	bbanpattern = bbancountrypatterns[ countrycode ];
703
704	// As new countries will start using IBAN in the
705	// future, we only check if the countrycode is known.
706	// This prevents false negatives, while almost all
707	// false positives introduced by this, will be caught
708	// by the checksum validation below anyway.
709	// Strict checking should return FALSE for unknown
710	// countries.
711	if ( typeof bbanpattern !== "undefined" ) {
712		ibanregexp = new RegExp( "^[A-Z]{2}\\d{2}" + bbanpattern + "$", "" );
713		if ( !( ibanregexp.test( iban ) ) ) {
714			return false; // Invalid country specific format
715		}
716    }
717
718	// Now check the checksum, first convert to digits
719	ibancheck = iban.substring( 4, iban.length ) + iban.substring( 0, 4 );
720	for ( i = 0; i < ibancheck.length; i++ ) {
721		charAt = ibancheck.charAt( i );
722		if ( charAt !== "0" ) {
723			leadingZeroes = false;
724  
725 }
726		if ( !leadingZeroes ) {
727			ibancheckdigits += "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ".indexOf( charAt );
728    }
729    
730    }
731  
732	// Calculate the result of: ibancheckdigits % 97
733	for ( p = 0; p < ibancheckdigits.length; p++ ) {
734		cChar = ibancheckdigits.charAt( p );
735		cOperator = "" + cRest + "" + cChar;
736		cRest = cOperator % 97;
737    }
738
739	return cRest === 1;
740  
741 }
742	 
743
744//Mostra el error en el formulari sota de l'element que ha provocat l'error i s'amaga automàticament
745function MostraError(error, element) {
746	// Obté l'objecte amb el nom indicat
747	if (element) {		
748		var pos = $(element).position();
749		if (pos) {		
750			var camp = $(element).attr("name");			
751			var parent = $(element).parent().get(0);
752			
753			$(element).off("focusout");
754			$(element).off("focusin");
755			$(element).off("keypress");
756			$("#tooltip-error-" + camp).remove();
757			$(parent).append('<div id="tooltip-error-' + camp + '" class="tooltip-error"><div class="fletxa-tooltip"></div><div class="contingut-tooltip"></div></div>');
758			
759			if (error=="") {
760				return true;
761			}
762			$("#tooltip-error-" + camp).css("top", pos.top + $(element).outerHeight(false) + 3 + "px");
763			$("#tooltip-error-" + camp).css("left", pos.left  + "px");
764			$("#tooltip-error-" + camp).show();
765			
766			// Inserta el text en el tooltip
767			$("#tooltip-error-" + camp + " .contingut-tooltip").html(error);
768			
769			$(element).on("focusout", function (event) {
770				if (Validar($(this))) {
771					$("#tooltip-error-" + camp).hide();
772					$(element).removeClass("error-camp");
773				} else {
774					$("#tooltip-error-" + camp).show();
775					$(element).addClass("error-camp");	
776				}			
777			});
778			
779			$(element).on("focusin" ,function (event) {
780				if (Validar($(this))) {
781				$("#tooltip-error-" + camp).hide();
782				$(element).removeClass("error-camp");
783				}
784			});
785			
786			$(element).on("keypress" ,function (event) {
787				if (Validar($(this))) {
788					$("#tooltip-error-" + camp).hide();
789					$(element).removeClass("error-camp");
790				}
791			});
792			
793			//setTimeout("$('#tooltip-error-' + camp).hide()",2000);
794		}
795		
796		
797		$(element).addClass("error-camp");
798		
799		//element.focus();
800	}
801}
802
803
804function ValidaForm(form, focus) {
805	var valid = true;
806	var obj;
807	
808	focus = typeof focus !== 'undefined' ? focus : false;
809	
810	// Comprova tots els camps de class formobj del formulari
811	$(".formobj, .checkbox, .formobj-data, .radiobutton", form).each(function() {
812		// Comprova fins que troba un camp no vàlid
813		if (valid) {
814			var vali = Validar($(this));
815			valid = vali;
816			// Si és un camp no vàlid guarda l'objecte
817			if (!vali) {
818				obj = this;
819		}
820		}
821	});
822	
823	if (valid) {
824		$(".condicions", form).each(function() {
825			if ($(this).get(0).type=="checkbox") {
826				if (!$(this).get(0).checked) {
827					MostraError(err_condicions, $(this));
828					valid=false;
829				}
830			}
831		});
832	}
833	
834	
835	if (form.pagar && form.pagar.value=="S") {
836		try {
837			if (!CalculaTotal(form.name)) {
838				return false;
839			}
840		} catch (e) {
841			alert(err_txt_calcul_import);
842			return false;
843		}
844	}
845	
846	
847	// Posa el focus en el primer camp no validat
848	if (obj && focus) {
849		try {
850			obj.focus();
851		} catch (e) {
852			
853		}
854	}
855	
856	return valid;
857}
858
859function Validar(obj) {
860	var val = obj.val();
861	
862	val = $.trim(val);
863	
864	
865	var classes = obj.attr("class").split(" ");
866	for (var i=0; i<classes.length; i++) {
867		var tipus = classes[i];
868		
869		if (tipus=='Req') {
870			if (obj.get(0).type=="checkbox") {
871				if (!obj.get(0).checked) {
872					MostraError(err_txt_blanc, obj);	
873					return false;
874				}
875			} else if (obj.get(0).type=="radio") {
876				var name = obj.attr("name");
877				if ($("input:radio[name="+name+"]:checked").length == 0) {
878					MostraError(err_txt_blanc, obj);	
879					return false;	
880				}
881			} else if (val=="") {
882				MostraError(err_txt_blanc, obj);	
883				return false;
884			}
885		}
886	
887		if (tipus=='NIF' && val!="") {
888			if (!validarNIF(val)) {
889				MostraError(err_txt_NIF, obj);
890				return false;
891			}
892		} else if (tipus=='Hora' && val!="") {
893			if (!validarHora(val)) {
894				MostraError(err_txt_Hora, obj);
895				return false;
896			}
897		} else if (tipus=='Data' && val!="") {
898			var dateFormat = "dd/MM/yyyy";
899			if (obj.attr("data-dateformat") && obj.attr("data-dateformat")!="") {
900				dateFormat = obj.attr("data-dateformat");
901			}
902			if (!isDate(val, dateFormat)) {
903				MostraError(err_txt_Data, obj);
904				return false;
905			}
906		} else if ((/^FixLen_[0-9]+$/).test(tipus)) {
907			var len = parseInt(tipus.replace("FixLen_", ""));
908			if (len!=val.length) {
909				MostraError(err_txt_LongFix.replace(/%N%/, len), obj);
910				return false;
911			}
912			
913		} else if ((/^Moneda_[0-9]+$/).test(tipus)&&val!="") {
914			if (!isFloat(val)) {
915				MostraError(err_txt_Numeric, obj);
916				return false;
917			}
918			var decimals = tipus.replace("Moneda_", "");
919			if (!NumDecimalsOk(val,decimalPointDelimiter, decimals)) {
920				MostraError(err_txt_Decimals.replace(/%N%/, decimals), obj);
921				return false;
922			}
923		} else if (tipus=='Numeric'&&val!="") {
924			if (!isSignedFloat(val)) {
925				MostraError(err_txt_Numeric, obj);
926				return false;
927			}
928		} else if (tipus=='Enter'&&val!="") {
929			if (!isInteger(val)) {
930				MostraError(err_txt_Enter, obj);
931				return false;
932			}
933		} else if (tipus=='Email'&&val!="") {
934			if (!isEmail(val)) {
935				MostraError(err_txt_Email, obj);
936				return false;
937			}
938			// Comprova que coincideixi amb el camp de check d'email
939			if (obj.attr("data-email-check") && obj.attr("data-email-check")!="") {
940				var objchk = $("input:text[name=" + obj.attr("data-email-check") + "]").get(0);
941				
942				if (objchk && objchk.value!=val) {
943					MostraError(err_txt_Email_chk, obj);	
944					return false;	
945				}
946			}
947		} else if (tipus=='IBAN'&&val!="") {
948			if (!CheckIBAN(val)) {
949				MostraError(err_txt_IBAN, obj);
950				return false;
951			}
952		} else if (tipus=='URL'&&val!="") {
953			//if (!isInteger(obj.val()))
954			//	MostraError(error_txt, obj);
955		} else if (tipus=='UTM'&&val!="") {
956			if (!isFloat(val)) {
957				MostraError(err_txt_Float.replace(/%1%/, decimalPointDelimiter), obj);
958				return false;
959			}
960		} else {
961			//alert(obj.val() + " " + tipus);
962		}
963	}
964	
965	if (obj) {
966		var camp = $(obj).attr("name");
967		if(typeof($(obj).attr('multiple'))!=="undefined"){
968			camp = $(obj).attr("id");
969		}
970		
971		$("#tooltip-error-" + camp).hide();
972		$(obj).removeClass("error-camp");
973		$(obj).off('focusout');
974		$(obj).off('focusin');
975	}
976	
977	return true;
978}
979
980/**
981 * Vaida un NIF o NIE
982 * @param val
983 * @returns
984 */
985function validarNIF(value) {
986	var validChars = 'TRWAGMYFPDXBNJZSQVHLCKET';
987	var nifRexp = /^[0-9]{8}[TRWAGMYFPDXBNJZSQVHLCKET]{1}$/i;
988	var nieRexp = /^[XYZ]{1}[0-9]{7}[TRWAGMYFPDXBNJZSQVHLCKET]{1}$/i;
989	var str = value.toString().toUpperCase();
990	
991	if (!nifRexp.test(str) && !nieRexp.test(str)) return false;
992
993	var nie = str
994		.replace(/^[X]/, '0')
995		.replace(/^[Y]/, '1')
996		.replace(/^[Z]/, '2');
997
998	var letter = str.substr(-1);
999	var charIndex = parseInt(nie.substr(0, 8)) % 23;
1000
1001	if (validChars.charAt(charIndex) === letter) return true;
1002		
1003	return false;
1004}
1005
1006function validarHora(val) {
1007	// regular expression to match required time format
1008    var re = /^(\d{1,2}):(\d{2})([ap]m)?$/;
1009
1010    if(val != '') {
1011      if(regs = val.match(re)) {
1012        if(regs[3]) {
1013          if(regs[1] < 1 || regs[1] > 12) 
1014            return false;
1015        } else {
1016          if(regs[1] > 23)
1017            return false;      
1018        }
1019        if(regs[2] > 59) 
1020          return false;      
1021      } else 
1022        return false;
1023    }
1024	
1025	return true;
1026}
1027
1028
1029function CalculaTotal(formulari) {
1030	var formulari_obj = $("#" + formulari).get(0);
1031	
1032	// Obté l'import
1033	var total_obj;
1034	if ($("select>option[data-valor]", formulari_obj).get(0)) {
1035		total_obj = $("select>option[data-valor]:selected", formulari_obj);
1036	} else {
1037		total_obj = $("input[data-valor]", formulari_obj);
1038	}
1039	
1040	if (!total_obj.get(0)) {
1041		return false;
1042	}
1043	
1044	// Obté el valors dels totals
1045	var total = total_obj.attr("data-valor");
1046	var total_base = total_obj.attr("data-valor");
1047	
1048	
1049	// Comprova que sigui un nombre
1050	if (!isSignedFloat(total)) {
1051		MostraError(err_txt_Numeric, total_obj.get(0));
1052		return false;
1053	}
1054	// Reemplaça el separador de decimals
1055	total = parseFloat(total.replace(decimalPointDelimiter, ".")); 
1056	total_base = total; 
1057	
1058	// Afegeix el valor dels camps que tenen imports calculats
1059	$("input[data-calcular-import]", formulari_obj).each(function() {
1060		var unitats = $(this).val();
1061		var camp = $(this).attr("data-calcular-import");
1062		var valor = $("#" + camp, formulari_obj).val();
1063		
1064		if (valor.trim()!="") {
1065			if (!isSignedFloat(valor)) {
1066				MostraError(err_txt_Numeric, $("#" + camp, formulari_obj).get(0));
1067				return false;
1068			}
1069			
1070			if (!isSignedFloat(unitats)) {
1071				MostraError(err_txt_Numeric,  $(this).get(0));
1072				return false;
1073			}
1074			
1075			valor = parseFloat(valor.replace(decimalPointDelimiter, ".")); 
1076			unitats = parseFloat(unitats.replace(decimalPointDelimiter, "."));
1077			
1078			total = total + (valor * unitats);
1079			
1080			// Si s'ha marcat que ha d'incloure el valor en la base, l'inclou
1081			if ($(this).attr("data-incloure-base")=="S") {
1082				//console.log("inclou en base:" + total_base);
1083				total_base  = total_base + (valor * unitats);
1084			}
1085		}
1086	});
1087	
1088	
1089	// Aplica modificadors de camps checkbox i radio
1090	$("input[data-afegir-import]:checked", formulari_obj).each(function() {
1091		var valor = $(this).attr("data-afegir-import").trim();
1092		if (valor!="") {
1093			// Comprova si està en %
1094			if (valor.charAt(valor.length - 1)=="%") {
1095				valor = valor.substring(0, valor.length - 1);
1096				valor = parseFloat(valor.replace(decimalPointDelimiter, ".")); 
1097				
1098				total = total + (total_base * valor /100);
1099			} else {
1100				valor = parseFloat(valor.replace(decimalPointDelimiter, "."));
1101				total = total + valor;
1102			}
1103		}
1104	});
1105	
1106	// Aplica modificadors de camps select
1107	$("select>option[data-afegir-import]:selected", formulari_obj).each(function() {
1108		var valor = $(this).attr("data-afegir-import");
1109		if (valor!="") {
1110			// Comprova si està en %
1111			if (valor.charAt(valor.length - 1)=="%") {
1112				valor = valor.substring(0, valor.length - 1);
1113				valor = parseFloat(valor.replace(decimalPointDelimiter, ".")); 
1114				
1115				total = total + (total_base * valor /100);
1116			} else {
1117				valor = parseFloat(valor.replace(decimalPointDelimiter, "."));
1118				total = total + valor;
1119			}
1120		}
1121	});
1122	
1123	
1124	// Aplica modificadors de camps moneda
1125	$("input[data-camp-percentatge]", formulari_obj).each(function() {
1126		var percentatge = $(this).val();
1127		var camp = $(this).attr("data-camp-percentatge");
1128		var valor = $("#" + camp, formulari_obj).val();
1129		
1130		if (valor.trim()!="") {
1131			if (!isSignedFloat(valor)) {
1132				MostraError(err_txt_Numeric, $("#" + camp, formulari_obj).get(0));
1133				return false;
1134			}
1135			
1136			if (!isSignedFloat(percentatge)) {
1137				MostraError(err_txt_Numeric,  $(this).get(0));
1138				return false;
1139			}
1140			
1141			valor = parseFloat(valor.replace(decimalPointDelimiter, ".")); 
1142			percentatge = parseFloat(percentatge.replace(decimalPointDelimiter, "."));
1143			
1144			total = total + (valor * percentatge /100);
1145		}
1146	});
1147	
1148	// Mostra l'import total
1149	var total_show = total.toFixed(2).replace(".", decimalPointDelimiter);
1150	formulari_obj.elements["import"].value = total_show + "";
1151	$('#' + formulari + "_total").html(total_show + " " + moneda);
1152	
1153	// Comprova que el total sigui superior a 0
1154	if (total<=0) {
1155		$('#' + formulari + "_total").html($('#' + formulari + "_total").html() + "<br /><span class=\"error-import\">" + err_txt_valor_positiu + "</span>");
1156		return false;
1157	}
1158	
1159	return true;
1160}
1161
1162function EnviarPagar(formulari) {
1163	if (ValidaForm(document.forms[formulari])) {
1164		try {
1165			if (CalculaTotal(formulari)) {
1166				var form = window.document.forms[formulari];
1167				form.pagar.value = 'S';
1168				form.submit();
1169			}
1170		} catch (e) {
1171			alert("Error en el càlcul del formulari!");
1172	
1173		}
1174	}
1175}
1176
1177
1178function CanviSrcImg(elem) {
1179	var classes = $(elem).attr("class").split(" ");
1180	if (classes.length>0) {
1181		var src_aux;
1182		if ($(elem).find("img").get(0)) {
1183			src_aux = $(elem).find("img").get(0).src;
1184			$(elem).find("img").get(0).src = classes[1];
1185			$(elem).removeClass(classes[1]);
1186			$(elem).addClass(src_aux);
1187		}
1188	}
1189}
1190
1191
1192function mostraInfoPictograma(hid){
1193	//var obj = $('#'+hid).html();
1194	$.fancybox({href: "#"+hid,maxWidth: 500, autoDimensions: false});
1195}
1196
1197
1198/**
1199 * Validació camp telèfon.
1200 * @param inputtxt
1201 * @returns
1202 */
1203function phonenumber(inputtxt) {
1204  inputtxt = inputtxt.trim();
1205
1206  //var phoneno = /^[\+]?[(]?[0-9]{3}[)]?[-\s\.]?[0-9]{3}[-\s\.]?[0-9]{4,6}$/im;
1207  var phoneno = /^[\+]?[0-9()\s\.]+$/i;
1208  
1209  if(inputtxt.match(phoneno)) {
1210	  //alert("Valid phone number: "+inputtxt);
1211	  return true;
1212  }  
1213  else {
1214	 //alert("Invalid phone number: "+inputtxt);
1215    return false;
1216  }
1217}
1218var id_sec_form = new Array();
1219
1220
1221function setSectionFielValue(element, field, value) {
1222	
1223	$('form[id="formu' + element + '"] *[name="' + field + '"]').val(value);
1224	
1225}
1226
1227function AddSectionReturn(element, num_seccio) {
1228	
1229	var button = $('form[id="formu' + element + '"] button[data-seccio]').get(0);
1230	
1231	if (!button) return false;
1232	
1233	var seccio = $(button).data("seccio");
1234	var maxseccio = parseInt($(button).data("maxseccio"));
1235	
1236	// Nº d'elements en la secció
1237	var num_seccions = $('form[id="formu' + element + '"] div[data-seccio="' + seccio + '"]').length;
1238	
1239	var restants = $('form[id="formu' + element + '"] input[name=restants]').val();
1240	
1241	// Comprovar si el nº de seccions actuals > max
1242	if (num_seccions>=maxseccio) return false;
1243	
1244	// Comprova si nº d'enviaments restants disponibles
1245	if (num_seccions>=restants) return false;
1246	
1247	
1248	// Repeteix la secció
1249	var div_seccio = $('form[id="formu' + element + '"] div[data-seccio="' + seccio + '"]').first().get(0);
1250	var div_last_seccio = $('form[id="formu' + element + '"] div[data-seccio="' + seccio + '"]').last().get(0);
1251	
1252	if (!div_seccio) return;
1253	
1254	var cloned = $(div_seccio).clone(false);
1255	
1256	// Neteja valors dels elements copiats
1257	$("input[type=text]", cloned).val(null);
1258	
1259	
1260	// Afegeix un icona de borrat a la secció afegida
1261	if ($('div.borra-seccio', cloned).length<1) {
1262		$(cloned).prepend("<div class=\"borra-seccio\" data-form=\"formu" + element + "\">X</div>");
1263	}
1264
1265	$(cloned).insertAfter(div_last_seccio);
1266	
1267	// Incrementa comptador elements secció
1268	if (typeof(id_sec_form[seccio])==='undefined') {
1269		id_sec_form[seccio] = 0;
1270	} 
1271	id_sec_form[seccio] = seccio;
1272	
1273	// Renombra inputs 
1274	$("input", cloned).each(function () {
1275		$(this).attr("name", $(this).attr("name") + "_" + seccio + "_" + num_seccio);
1276	});
1277	$("select", cloned).each(function () {
1278		$(this).attr("name", $(this).attr("name") + "_" + seccio + "_" + num_seccio);
1279	});
1280	
1281	// Vincular el clic de l'icona a removeSection
1282	$('div.borra-seccio', cloned).on('click', removeSection);
1283	
1284	// Si nº seccions actual > max desabilitar boto
1285	num_seccions++;
1286	if (num_seccions>=maxseccio) { $(this).prop('disabled', true); }
1287	if (num_seccions>=restants) { $(this).prop('disabled', true); }
1288	
1289	return false;
1290	
1291}
1292
1293
1294/**
1295 * Add a multiple section in a form
1296 * @param e Event
1297 * @returns
1298 */
1299function AddSection(e) {
1300	e.preventDefault();
1301	
1302	var seccio = $(this).data("seccio");
1303	var element = $(this).data("element");
1304	var maxseccio = parseInt($(this).data("maxseccio"));
1305	
1306	if (!seccio || !element || !maxseccio) return false;
1307	
1308	// Nº d'elements en la secció
1309	var num_seccions = $('form[id="formu' + element + '"] div[data-seccio="' + seccio + '"]').length;
1310	
1311	var restants = $('form[id="formu' + element + '"] input[name=restants]').val();
1312	
1313	
1314	// Comprovar si el nº de seccions actuals > max
1315	if (num_seccions>=maxseccio) return false;
1316	
1317	// Comprova si nº d'enviaments restants disponibles
1318	if (num_seccions>=restants) return false;
1319	
1320	// Repeteix la secció
1321	var div_seccio = $('form[id="formu' + element + '"] div[data-seccio="' + seccio + '"]').first().get(0);
1322	var div_last_seccio = $('form[id="formu' + element + '"] div[data-seccio="' + seccio + '"]').last().get(0);
1323	
1324	if (!div_seccio) return;
1325	
1326	var cloned = $(div_seccio).clone(false);
1327	
1328	// Neteja valors dels elements copiats
1329	$("input[type=text]", cloned).val(null);
1330	
1331	
1332	// Afegeix un icona de borrat a la secció afegida
1333	if ($('div.borra-seccio', cloned).length<1) {
1334		$(cloned).prepend("<div class=\"borra-seccio\" data-form=\"formu" + element + "\">X</div>");
1335	}
1336
1337	$(cloned).insertAfter(div_last_seccio);
1338	
1339	// Incrementa comptador elements secció
1340	if (typeof(id_sec_form[seccio])==='undefined') {
1341		id_sec_form[seccio] = 0;
1342	} 
1343	id_sec_form[seccio]++;
1344	
1345	// Renombra inputs 
1346	$("input", cloned).each(function () {
1347		$(this).attr("name", $(this).attr("name") + "_" + seccio + "_" + id_sec_form[seccio]);
1348	});
1349	$("select", cloned).each(function () {
1350		$(this).attr("name", $(this).attr("name") + "_" + seccio + "_" + id_sec_form[seccio]);
1351	});
1352	
1353	// Vincular el clic de l'icona a removeSection
1354	$('div.borra-seccio', cloned).on('click', removeSection);
1355	
1356	// Si nº seccions actual > max desabilitar boto
1357	num_seccions++;
1358	if (num_seccions>=maxseccio) { $(this).prop('disabled', true); }
1359	if (num_seccions>=restants) { $(this).prop('disabled', true); }
1360	
1361	return false;
1362}
1363
1364/**
1365 * Remove a multiple section in a form
1366 * @param e Event
1367 * @returns
1368 */
1369function removeSection(e) {
1370	var div_seccio = $(this).closest("div[data-seccio]");
1371	var form_id = $(this).data("form");
1372	
1373	if (div_seccio.length>0) {
1374		var seccio = $(div_seccio).data("seccio");
1375		
1376		$(div_seccio).remove();
1377		var restants = $('form[id="' + form_id + '"] input[name=restants]').val();
1378		var addbutton = $('form[id="' + form_id + '"] button[data-seccio="' + seccio + '"]');
1379		var maxseccio = addbutton.data('maxseccio');
1380		maxseccio = parseInt(maxseccio);
1381		
1382		var num_seccions = $('form[id="' + form_id + '"] div[data-seccio="' + seccio + '"]').length;
1383		
1384		// trona a habilitar el botó
1385		if (num_seccions<maxseccio && num_seccions<restants) {$(addbutton).attr('disabled', false);}
1386	}	
1387}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.