function nfl_Get(v_id){
 var v_l=document.getElementById(v_id);
 if (document.all){ v_l=document.all[v_id]; }
 return v_l;
}

function local(v_id){
 return nfl_Get(v_id);
}

function nfl_AbsElePos(element) {
 if (typeof element == "string") element = nfl_Get(element)
 if (!element) return{top:0,left:0};
 var y = 0;
 var x = 0;
 while (element.offsetParent) {
  x += element.offsetLeft;
  y += element.offsetTop;
  element = element.offsetParent;
 }
 return {top:y,left:x};
}

function setRedim() {
 var myWidth = 0;
 if( typeof( window.innerWidth ) == 'number' ) {
  myWidth = window.innerWidth;
 } else if( document.documentElement && document.documentElement.clientWidth) {
  myWidth = document.documentElement.clientWidth;
 } else if( document.body && document.body.clientWidth ) {
  myWidth = document.body.clientWidth;
 }
 if (myWidth >= 1023) {
  nfl_Get('plana').style.width="900px";
 } else {
  nfl_Get('plana').style.width="88%";
 }
}

window.onresize=setRedim;

function precarima(lis) {
 var d=document;
 if(d.images){
  if(!d.x_precar) d.x_precar=new Array();
  var i,a,j;
  a=lis.split(",");
  if (a.length==1){
   alert(lis);
  }
  for(i=0; i<a.length; i++) {
   j=d.x_precar.length;
   if (a[i].indexOf("#")!=0){
    d.x_precar[j]=new Image();
    d.x_precar[j].src=a[i];
   }
  }
 }
}

function posaestil(title) {
 var i, a;
 for(i=0; (a=document.getElementsByTagName("link")[i]); i++) {
  if(a.getAttribute("rel").indexOf("style")!=-1 && a.getAttribute("title")) {
   a.disabled = true;
   if(a.getAttribute("title")==title) a.disabled=false;
  }
 }
}

function loginon(){
 if (nfl_Get("flogin").style.display=="block") {
  nfl_Get("flogin").style.display="none";
 } else {
  nfl_Get("flogin").style.display="block";
  nfl_Get("flogin").username.focus();
 }
}
function loginoff(){
 nfl_Get("flogin").style.display="none";
}

function veure_emap(vUrl) {
 var sUrl='http://194.224.156.182/emap/planol/start.asp?'+vUrl;
 var oWindow=window.open(sUrl,'MapServerWin','toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=no,resizable=yes,width=780,height=550,left=0,top=0');
 oWindow.focus();
}

function gen_emap(vtramer,vcc,vnro,cbis) {
 if ( vtramer == 'S') {
  cbis=cbis.toUpperCase();
  vcc='0000'+vcc;
  vcc=vcc.substring(vcc.length-4,vcc.length);
  var vbis=' ';
  if ('ABCDEFGHIJKLMNOPQRSTUVWXYZ'.indexOf(cbis)!=-1) {vbis=cbis;}
  vnro='000'+vnro;
  vnro=vnro.substring(vnro.length-3,vnro.length);
  var vUrl="subcmd=SS&searchstr=Numeraci\%F3:CLAU_PORTE%20like%20\'"+vcc+vnro+vbis+"%\'";  
  document.write('<A href=\'#\' onclick="javascript:veure_emap(\''+vUrl+'\');"><IMG src=\'/imgfiles/1/logo_emap.gif\' alt=\'Veure plànol\' border=0></A>');
 } else {
  document.write('&nbsp;');
 }
}

function val_cerca_nou(obj) {
 var bVals = new Array();var valor = "";
 var aVals = obj.value.replace(/(^\s*|\s*$)/g,'').split('"');
 for (var i in aVals ){
  aVals[i]=aVals[i].replace(/(^\s*)/g,'');
  if (aVals[i]!='') {if (i%2==0){bVals[bVals.length]=aVals[i].replace(/\s+/g,'+');}else{bVals[bVals.length]='"'+aVals[i]+'"';}}
 }
 valor=bVals.join("+");
 valor=valor.replace(/\++/g,'+');
 obj.value=valor;
 return true;
}

function val_cerca(obj) {
 var valor=obj.value.replace(/^\s+/,'').replace(/\s+$/,'').replace(/\s+/g,' ').replace(/"\s/g,'"').replace(/\s"/g,'"').replace(/""/g,'" "');
 if(/\s/.test(valor) && !/"/.test(valor)) {valor=valor.replace(/\s/g,"%\\");}
 obj.value=valor;
 return true;
}

function ComparaData(dataI,dataF) {
 var patro = /^(\d{1,2})\/(\d{1,2})\/(\d{4})$/;
 var dataIni = dataI.match(patro);
 if (dataIni == null) { return false; }
 var dataFin = dataF.match(patro);
 if (dataFin == null) { return false; }
 var diaI = parseInt(dataIni[1],10);
 var mesI = parseInt(dataIni[2],10);
 var anyI = parseInt(dataIni[3],10);
 var diaF = parseInt(dataFin[1],10);
 var mesF = parseInt(dataFin[2],10);
 var anyF = parseInt(dataFin[3],10);
 if(anyI<anyF) { return true }
 if(anyI==anyF) {
  if(mesI<mesF) { return true; } 
  if(mesI==mesF) {
   if(diaI<diaF) {return true;}
  }
 }
 return false;
}

function esData(cadena) {
 var patro = /^(\d{1,2})\/(\d{1,2})\/(\d{4})$/;
 var esPatro = cadena.match(patro);
 if (esPatro == null) { return false; }
 var dia = parseInt(esPatro[1],10);
 var mes = parseInt(esPatro[2],10);
 var any = parseInt(esPatro[3],10);
 if (any < 1900 || any > 2100 ) { return false; }
 if (mes>12 || mes<1) { return false; }
 if (dia>31 || dia<1) { return false; }
 if (mes==4 || mes==6 || mes==9 || mes==11) {
  if (dia>30) { return false; }
 }
 if (mes==2) {
  if (dia>29) { return false; }
  if (dia==29) {
   if (any % 4 == 0) {
    if (any % 100 != 0 || any % 400 == 0) { return true; }
   }
   return false;
  }
 }
 return(true)
}

function esTexte(cadena) { //Controla q no sigui nomes una cadena de espais en blanc 
 var exp = /\w/;
 if(exp.test(cadena)) {
  return true;
 }
 return false;
}

function esJpg(cadena) { //Controla q nomes siguin .jpg
 var exp = /\.(jpg|JPG)$/;
 if(exp.test(cadena)) {
  return true;
 }
 return false;
}

function esGif(cadena) { //Controla q nomes siguin .gif
 var exp = /\.(gif|GIF)$/;
 if(exp.test(cadena)) {
  return true;
 }
 return false;
}

function esPng(cadena) { //Controla q nomes siguin .png
 var exp = /\.(png|PNG)$/;
 if(exp.test(cadena)) {
  return true;
 }
 return false;
}


function esNumero(cadena) { //Controla q nomes siguin numeros
 var exp = /\D/;
 if(cadena!='') { //hem de mirar si la cadena esta buida sino no funciona 
  if(exp.test(cadena)) {
   return false;
  } else {
   return true;
  }
 }
 return false;

 /*
 if(decimals!=0) {
  var patro="/^(\d{"+enters+"}),(\d{"+decimals+"})$/";
  alert(patro);
 } else {
  No borrar! aixo es per millorar la funcio i controlar numero de enters i decimals
  var patro="/^(\d{"+enters+"})$/";
  alert(patro);
 }
 var er = /\d/;
 if(cadena=~er) {
   alert("si");
 } else {
   alert("no");
 }
 */

}

function HexaADecimal(numero) {
 var R = numero.slice(1,3);
 var G = numero.slice(3,5);
 var B = numero.slice(5,7);
 R = parseInt(R,16);
 G = parseInt(G,16);
 B = parseInt(B,16);
 return R+","+G+","+B;
}

function abre_color_picker_color_resposta(vform, vcampo) {
 window.open("/common/color_picker/select_colores.window.html?form_name=" + vform + "&name=" + vcampo + "&num_colores=0","selector","width=395,height=320,top=200,left=200");
}

function esMail(cadena) {
 if(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(cadena)) { //testeja la expessio, si no ho fico aixi no funciona !?!?! :< 
  return true;
 }
 return false;
}

function veureOpi(identi) {
 if (nfl_Get('id'+identi).style.display=="none") {
  nfl_Get('id'+identi).style.display="inline";
  nfl_Get('img'+identi).style.display="none";
  nfl_Get('img'+identi+'_menos').style.display="inline";
 } else {
  nfl_Get('id'+identi).style.display="none";
  nfl_Get('img'+identi+'_menos').style.display="none";
  nfl_Get('img'+identi).style.display="inline";
 }
}

function veureDIV(identi) {
 if (nfl_Get('id'+identi).style.display=="none") {
  nfl_Get('id'+identi).style.display="block";
  nfl_Get('img'+identi).style.display="none";
  nfl_Get('img'+identi+'_menos').style.display="inline";
 } else {
  nfl_Get('id'+identi).style.display="none";
  nfl_Get('img'+identi+'_menos').style.display="none";
  nfl_Get('img'+identi).style.display="inline";
 }
}

function veureSPAN(identi) {
 if (nfl_Get('id'+identi).style.display=="none") {
  nfl_Get('id'+identi).style.display="inline";
  nfl_Get('img'+identi).style.display="none";
  nfl_Get('img'+identi+'_menos').style.display="inline";
 } else {
  nfl_Get('id'+identi).style.display="none";
  nfl_Get('img'+identi+'_menos').style.display="none";
  nfl_Get('img'+identi).style.display="inline";
 }
}

function veureAct() {
 if (nfl_Get('imgMenos').style.display=="none") {
  nfl_Get('imgMes').style.display="none";
  nfl_Get('imgMenos').style.display="inline";
  nfl_Get('llistatTot').style.display="block";
 } else {
  nfl_Get('imgMes').style.display="inline";
  nfl_Get('imgMenos').style.display="none";
  nfl_Get('llistatTot').style.display="none";
 }
}

function confirmar_desautoritzar(direccio,mail){
 if (confirm("De moment no hi ha manera de cancelar l'acció.\n\n Aceptar: Enviar mail per informar de la despublicació. \n Cancelar:No enviar mail.")) {
  document.location=direccio + mail;
 } else {
  document.location=direccio;
 }
}

/////INICI EINES AJAX/////

var G_peticioPendent = 0;
var DIV_CARREGANT1 = '<div class=\'classDivEina tdc\'><img src=\'\/imgfiles\/1\/carregant.gif\'\/> Carregant... <\/div>';
var DIV_CARREGANT2 = '<div style=\'text-align:center;float:right;\'><img src=\'\/imgfiles\/1\/carregant.gif\'\/> Carregant... <\/div>';
var star_carregant = '<div style=\'width:75px;height:14px;background:url(\/imgfiles\/1\/star2.gif) no-repeat 0 -84px;margin:0 auto;\'><\/div><span class=\'notetes_n\'> Carregant... <\/span>';
var ERROR_CONEXIO = '<div class=\'classDivEina tdc\'>Informaci&oacute; no disponible...<\/div>';

function carregaEina(eina){
 var url="/eines/get_eina.html"+eina;
 var hihaeina=nfl_Get("divEina").extra;
 if (hihaeina==eina) {
  nfl_Get("divEina").extra = "";
  nfl_Get("divEina").innerHTML = "";
 } else {
  nfl_Get("divEina").extra = eina;
  nfl_Get("divEina").innerHTML = DIV_CARREGANT1;
  ajaxCaller.get(url, null, onEinaResponse, false, null);
 }
 return false;
}

function submitEina(eina,frmE){
 var url="/eines/get_eina.html"+eina;
 var einaVars = new Array();
 var ielement;
 for(var i=0;i<frmE.elements.length;i++) {
  ielement = frmE.elements[i];
  einaVars[ielement.name]=encodeURIComponent(ielement.value);
 }
 nfl_Get("divEina").className += "fons_gris";
 ajaxCaller.postForPlainText(url,einaVars,onEinaResponse);
 return false;
}

function onEinaResponse(html, headers, callingContext){
 var einaHTML;
 try{
  einaHTML = html;
 }catch(err){
  einaHTML = ERROR_CONEXIO;
 }
 nfl_Get("divEina").innerHTML = einaHTML;
 nfl_Get("divEina").className = "";
}

function submitVotacio(origen,section,independent){
 if((independent==1)||((independent==0)&&(G_peticioPendent==0))){
  nfl_Get("content_section_"+section).innerHTML= star_carregant;
  G_peticioPendent= G_peticioPendent+1;
  var url= "/_ajax/Section.show"+origen;
  var section_independent= section+"_"+independent;
  ajaxCaller.get(url,null,onsubmitVotacioResponse,true,section_independent);
 }
 return false;
}

function onsubmitVotacioResponse(xml,headers,callingContext){
 var acteHTML;
 try{
  acteHTML= xml.getElementsByTagName("body")[0].firstChild.nodeValue;
 }catch(err){
  acteHTML= ERROR_CONEXIO;
 }
 var section_independent= callingContext.split("_");
 var section= section_independent[0];
// alert(section);
 var independent= section_independent[1];
// alert(independent);
 nfl_Get("content_section_"+section).innerHTML= acteHTML;
 if(independent==0){
  G_peticioPendent= G_peticioPendent-1;
 }
 return false;
}

/////FIN EINES AJAX///////

/**
 * SWFObject v1.5: Flash Player detection and embed - http://blog.deconcept.com/swfobject/
 *
 * SWFObject is (c) 2007 Geoff Stearns and is released under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 *
 */
if(typeof deconcept=="undefined"){var deconcept=new Object();}if(typeof deconcept.util=="undefined"){deconcept.util=new Object();}if(typeof deconcept.SWFObjectUtil=="undefined"){deconcept.SWFObjectUtil=new Object();}deconcept.SWFObject=function(_1,id,w,h,_5,c,_7,_8,_9,_a){if(!document.getElementById){return;}this.DETECT_KEY=_a?_a:"detectflash";this.skipDetect=deconcept.util.getRequestParameter(this.DETECT_KEY);this.params=new Object();this.variables=new Object();this.attributes=new Array();if(_1){this.setAttribute("swf",_1);}if(id){this.setAttribute("id",id);}if(w){this.setAttribute("width",w);}if(h){this.setAttribute("height",h);}if(_5){this.setAttribute("version",new deconcept.PlayerVersion(_5.toString().split(".")));}this.installedVer=deconcept.SWFObjectUtil.getPlayerVersion();if(!window.opera&&document.all&&this.installedVer.major>7){deconcept.SWFObject.doPrepUnload=true;}if(c){this.addParam("bgcolor",c);}var q=_7?_7:"high";this.addParam("quality",q);this.setAttribute("useExpressInstall",false);this.setAttribute("doExpressInstall",false);var _c=(_8)?_8:window.location;this.setAttribute("xiRedirectUrl",_c);this.setAttribute("redirectUrl","");if(_9){this.setAttribute("redirectUrl",_9);}};deconcept.SWFObject.prototype={useExpressInstall:function(_d){this.xiSWFPath=!_d?"expressinstall.swf":_d;this.setAttribute("useExpressInstall",true);},setAttribute:function(_e,_f){this.attributes[_e]=_f;},getAttribute:function(_10){return this.attributes[_10];},addParam:function(_11,_12){this.params[_11]=_12;},getParams:function(){return this.params;},addVariable:function(_13,_14){this.variables[_13]=_14;},getVariable:function(_15){return this.variables[_15];},getVariables:function(){return this.variables;},getVariablePairs:function(){var _16=new Array();var key;var _18=this.getVariables();for(key in _18){_16[_16.length]=key+"="+_18[key];}return _16;},getSWFHTML:function(){var _19="";if(navigator.plugins&&navigator.mimeTypes&&navigator.mimeTypes.length){if(this.getAttribute("doExpressInstall")){this.addVariable("MMplayerType","PlugIn");this.setAttribute("swf",this.xiSWFPath);}_19="<embed type=\"application/x-shockwave-flash\" src=\""+this.getAttribute("swf")+"\" width=\""+this.getAttribute("width")+"\" height=\""+this.getAttribute("height")+"\" style=\""+this.getAttribute("style")+"\"";_19+=" id=\""+this.getAttribute("id")+"\" name=\""+this.getAttribute("id")+"\" ";var _1a=this.getParams();for(var key in _1a){_19+=[key]+"=\""+_1a[key]+"\" ";}var _1c=this.getVariablePairs().join("&");if(_1c.length>0){_19+="flashvars=\""+_1c+"\"";}_19+="/>";}else{if(this.getAttribute("doExpressInstall")){this.addVariable("MMplayerType","ActiveX");this.setAttribute("swf",this.xiSWFPath);}_19="<object id=\""+this.getAttribute("id")+"\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" width=\""+this.getAttribute("width")+"\" height=\""+this.getAttribute("height")+"\" style=\""+this.getAttribute("style")+"\">";_19+="<param name=\"movie\" value=\""+this.getAttribute("swf")+"\" />";var _1d=this.getParams();for(var key in _1d){_19+="<param name=\""+key+"\" value=\""+_1d[key]+"\" />";}var _1f=this.getVariablePairs().join("&");if(_1f.length>0){_19+="<param name=\"flashvars\" value=\""+_1f+"\" />";}_19+="</object>";}return _19;},write:function(_20){if(this.getAttribute("useExpressInstall")){var _21=new deconcept.PlayerVersion([6,0,65]);if(this.installedVer.versionIsValid(_21)&&!this.installedVer.versionIsValid(this.getAttribute("version"))){this.setAttribute("doExpressInstall",true);this.addVariable("MMredirectURL",escape(this.getAttribute("xiRedirectUrl")));document.title=document.title.slice(0,47)+" - Flash Player Installation";this.addVariable("MMdoctitle",document.title);}}if(this.skipDetect||this.getAttribute("doExpressInstall")||this.installedVer.versionIsValid(this.getAttribute("version"))){var n=(typeof _20=="string")?document.getElementById(_20):_20;n.innerHTML=this.getSWFHTML();return true;}else{if(this.getAttribute("redirectUrl")!=""){document.location.replace(this.getAttribute("redirectUrl"));}}return false;}};deconcept.SWFObjectUtil.getPlayerVersion=function(){var _23=new deconcept.PlayerVersion([0,0,0]);if(navigator.plugins&&navigator.mimeTypes.length){var x=navigator.plugins["Shockwave Flash"];if(x&&x.description){_23=new deconcept.PlayerVersion(x.description.replace(/([a-zA-Z]|\s)+/,"").replace(/(\s+r|\s+b[0-9]+)/,".").split("."));}}else{if(navigator.userAgent&&navigator.userAgent.indexOf("Windows CE")>=0){var axo=1;var _26=3;while(axo){try{_26++;axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash."+_26);_23=new deconcept.PlayerVersion([_26,0,0]);}catch(e){axo=null;}}}else{try{var axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");}catch(e){try{var axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");_23=new deconcept.PlayerVersion([6,0,21]);axo.AllowScriptAccess="always";}catch(e){if(_23.major==6){return _23;}}try{axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash");}catch(e){}}if(axo!=null){_23=new deconcept.PlayerVersion(axo.GetVariable("$version").split(" ")[1].split(","));}}}return _23;};deconcept.PlayerVersion=function(_29){this.major=_29[0]!=null?parseInt(_29[0]):0;this.minor=_29[1]!=null?parseInt(_29[1]):0;this.rev=_29[2]!=null?parseInt(_29[2]):0;};deconcept.PlayerVersion.prototype.versionIsValid=function(fv){if(this.major<fv.major){return false;}if(this.major>fv.major){return true;}if(this.minor<fv.minor){return false;}if(this.minor>fv.minor){return true;}if(this.rev<fv.rev){return false;}return true;};deconcept.util={getRequestParameter:function(_2b){var q=document.location.search||document.location.hash;if(_2b==null){return q;}if(q){var _2d=q.substring(1).split("&");for(var i=0;i<_2d.length;i++){if(_2d[i].substring(0,_2d[i].indexOf("="))==_2b){return _2d[i].substring((_2d[i].indexOf("=")+1));}}}return "";}};deconcept.SWFObjectUtil.cleanupSWFs=function(){var _2f=document.getElementsByTagName("OBJECT");for(var i=_2f.length-1;i>=0;i--){_2f[i].style.display="none";for(var x in _2f[i]){if(typeof _2f[i][x]=="function"){_2f[i][x]=function(){};}}}};if(deconcept.SWFObject.doPrepUnload){if(!deconcept.unloadSet){deconcept.SWFObjectUtil.prepUnload=function(){__flash_unloadHandler=function(){};__flash_savedUnloadHandler=function(){};window.attachEvent("onunload",deconcept.SWFObjectUtil.cleanupSWFs);};window.attachEvent("onbeforeunload",deconcept.SWFObjectUtil.prepUnload);deconcept.unloadSet=true;}}if(!document.getElementById&&document.all){document.getElementById=function(id){return document.all[id];};}var getQueryParamValue=deconcept.util.getRequestParameter;var FlashObject=deconcept.SWFObject;var SWFObject=deconcept.SWFObject;
