var diasSemana="LMXJVSDF";
function ingridOpePro(a){this.per=this.fre=0;this.repl=[];this.todos=this.fin=this.ini=0;a=a.split("|");var e=a[0].trim();if(e.length)if(this.per=e.charAt(e.length-1),0>"DSMA".indexOf(this.per))this.per=0;else{this.fre=parseInt(e);this.fre||(this.fre=1);if(1<a.length){e=a[1].trim();if("D"==this.per)this.todos="T"==e.toUpperCase();else if("S"==this.per)this.repl=str2diasSemana(e);else if("M"==this.per)for(var e=e.split(" "),g=0;g<e.length;g++){var c=parseInt(e[g]);c&&this.repl.push(c)}else if("A"==this.per)for(e=
e.split(" "),g=0;g<e.length;g++)(c=ingra.diames.dc(e[g]))&&this.repl.push(c);this.repl.sort(function(a,c){return a-c})}2<a.length&&"A"!=this.per&&(e=a[2].trim(),a=e.split("-"),this.ini=ingra.diames.dc(a[0]),this.fin=ingra.diames.dc(a[1]))}}
ingridOpePro.prototype.enPeriodo=function(a,e,g,c){if(2E7>a)return[];var k=[];e<a&&(e=a,c||(e=ingra.fec.agrega(e,1)));if("D"==this.per){var l=this.fre;if(this.todos)if(1==l)for(c=e;c<g;c=ingra.fec.agrega(c,1))k.push(c);else{if(a<e){var m=ingra.fec.diasEntre(a,e);a=ingra.fec.agrega(a,m-m%l)}for(c=a;c<g;c=ingra.fec.agrega(c,l))c>=e&&k.push(c)}else if(1==l){c=e;for(var s=ingra.fec.semanaDia(e);c<g;c=ingra.fec.agrega(c,1),s++)5>s%7&&k.push(c)}else for(a<e&&(m=ingra.fec.diasEntre(a,e),a=ingra.fec.agrega(a,
m-m%35)),c=a,m=0,s=ingra.fec.semanaDia(a);c<g;c=ingra.fec.agrega(c,1),s++)5>s%7&&(c>=e&&!(m%l)&&k.push(c),m++)}else if("S"==this.per)if(l=7*this.fre,a<e&&(m=ingra.fec.diasEntre(a,e),a=ingra.fec.agrega(a,m-m%l)),this.repl.length)for((s=ingra.fec.semanaDia(a))&&(a=ingra.fec.agrega(a,-s)),m=a;m<g;m=ingra.fec.agrega(m,l))for(a=0;a<this.repl.length;a++){c=(c=this.repl[a])?ingra.fec.agrega(m,c):m;if(c>=g)return k;c>=e&&k.push(c)}else for(c=a;c<g;c=ingra.fec.agrega(c,l))c>=e&&k.push(c);else if("M"==this.per){if(a<
e)for(l=ingra.fec.ano(a),s=ingra.fec.mes(a),m=ingra.fec.dia(a);;){for(s+=this.fre;12<s;)s-=12,l++;c=1E4*l+100*s+m;if(c>e)break;a=c}if(this.repl.length)for(l=ingra.fec.ano(a),m=ingra.fec.mes(a);;m+=this.fre){for(;12<m;)l++,m-=12;for(a=0;a<this.repl.length;a++){c=1E4*l+100*m+this.repl[a];if(c>=g)return k;c>=e&&k.push(c)}}else for(c=a;c<g;c=ingra.fec.agrega(c,0,this.fre))c>=e&&k.push(c)}else if("A"==this.per){for(c=this.fre;a+1E4*c<e;)a+=1E4*c;if(this.repl.length)for(l=ingra.fec.ano(a);;l+=this.fre)for(a=
0;a<this.repl.length;a++){c=1E4*l+this.repl[a];if(c>=g)return k;c>=e&&k.push(c)}else for(c=a;c<g;c=ingra.fec.agrega(c,0,0,this.fre))c>=e&&k.push(c)}return k};
ingridOpePro.prototype.siguiente=function(a,e){if("D"==this.per){if(this.todos)return e?a:ingra.fec.agrega(a,fre);var g=ingra.fec.semanaDia(a);if(5<=g)return ingra.fec.agrega(a,7-g);if(e)return a;for(var c=0;c<fre;)a=ingra.fec.agrega(a,1),g++,5>g%7&&c++;return a}if(e&&!this.repl.length)return a;if("S"==this.per){if(!this.repl.length)return ingra.fec.agrega(a,7*this.fre,0,0);c=ingra.fec.semanaDia(a);for(g=0;g<this.repl.length;g++){var k=this.repl[g];if(k>c-e)return k-c&&(a=ingra.fec.agrega(a,k-c)),
a}return ingra.fec.agrega(a,this.repl[0]-c+7*this.fre)}if("M"==this.per){if(!this.repl.length)return ingra.fec.agrega(a,0,this.fre,0);c=ingra.fec.dia(a);for(g=0;g<this.repl.length;g++)if(k=this.repl[g],k>c-e)return ingra.fec.dia(a,k);return ingra.fec.pon(this.repl[0],fecmes(a)+this.fre,ingra.fec.ano(a))}if("A"==this.per){if(!this.repl.length)return ingra.fec.agrega(a,0,0,this.fre);c=a%1E4;for(g=0;g<this.repl.length;g++)if(k=this.repl[g],k>c-e)return 1E4*ingra.fec.ano(a)+k;return ingra.fec.pon(this.repl[0]%
100,this.repl[0]/100,ingra.fec.ano(a)+this.fre)}return a};function ingridOpe(a){for(var e in a)this[e]=a[e];this.monta()}ingridOpe.prototype.monta=function(){for(var a=this.protie.toUpperCase(),e=a.split(";"),g=this.prol=[],c=0;c<e.length;c++)if(a=e[c].trim())a=new ingridOpePro(a),a.fre&&g.push(a);2!=g.length||g[1].ini||(g[1].ini=g[0].fin,g[1].fin=g[0].ini)};
ingridOpe.prototype.siguiente=function(a,e){for(var g=0,c=0;c<this.prol.length;c++){var k=this.prol[c],l=k.siguiente(a,e);if(k.ini)for(;!anomesDentro(l,k.ini,k.fin);){if(l>a+1E4)return 0;l=k.siguiente(l,!1)}if(!g||g>l)g=l}return g};
ingridOpe.prototype.enPeriodo=function(a,e,g,c){if(2E7>a)return[];for(var k=[],l=0;l<this.prol.length;l++){var m=this.prol[l],s=m.enPeriodo(a,e,g,c);if(m.ini)for(var L=0;L<s.length;L++)anomesDentro(s[L],m.ini,m.fin)&&k.push(s[L]);else k=k.length?k.concat(s):s}1<this.prol.length&&k.sort(function(a,c){return a-c});return k};
function str2diasSemana(a){for(var e=[],g=a.length,c=0;c<g;c++){var k=diasSemana.indexOf(a.charAt(c));if(!(0>k)&&(e.push(k),c<g-2&&"-"==a.charAt(c+1))){var c=c+2,l=diasSemana.indexOf(a.charAt(c));if(!(0>l))for(k++;k<=l;k++)e.push(k)}}e.sort(function(a,c){return a-c});return e}function anomesDentro(a,e,g){if(!e)return 1;a%=1E4;return e<g?a>=e&&a<g:a>=e||a<g};var conSeleccionPrevision=0;
function ingridCalendario(a){function e(){B=JSON.parse(ingra.memoria.lee("ingra_calendario_"+u.basedatos,"{}"));B.opel||(B.opel=[]);B.tral||(B.tral=[]);for(var h=0;h<B.opel.length;h++){var b=B.opel[h];!b.vis&&(b=S[b.ide])&&(b.vis=0)}for(h=0;h<B.tral.length;h++)if(b=B.tral[h],!b.vis&&(b=T[b.ide]))b.vis=0}function g(h){for(var b=[],J=0;J<h.length;J++)b.push(h[J].tari);W.graba("presenta/"+b)}function c(h,b){0>b&&(b+=4);3<b&&(b-=4);document.getElementById("conAgrupacion").selectedIndex=b;E();h.preventDefault&&
h.preventDefault();return 0}function k(h){var b=1;h&&(b*=q);0==w?r=ingra.fec.agrega(r,0,-b):1==w?r=ingra.fec.agrega(r,-7*b):2==w&&(r=ingra.fec.agrega(r,-b));r<K&&(r=K);return E()}function l(h){var b=1;h&&(b*=q);0==w?r=ingra.fec.agrega(r,0,b):1==w?r=ingra.fec.agrega(r,7*b):2==w&&(r=ingra.fec.agrega(r,b));return E()}function m(h,b){h?0==w?(w=1,r=n[b]):1==w?(w=2,r=n[b]):(w=0,r=ingra.fec.pon(1,1,ingra.fec.ano(n[0]))):0==w?(w=2,r=n[b]):1==w?(w=0,r=ingra.fec.pon(1,1,ingra.fec.ano(n[0]))):w=1;r<K&&(r=K);
E()}function s(h,b,J){if(!h.id)return[];var d=h.id.split(",");if(3>d.length)return[];var a=parseInt(d[0]);h=parseInt(d[1]);for(var f=parseInt(d[2]),c=p[a],a=c.plll[h][f],d=[],f=0;f<a.length;f++)if(!f||a[f].tari!=a[f-1].tari){var C=a[f];J&&C.ope.opei||d.push(C)}if(b)for(C=d[0],b.push("SELECCIÓN:"+C.con.cod+" · "+C.ope.cod+" · "+C.tra.cod+" ["+d.length+"] de "+ingra.fec.ac(n[h])+" a "+ingra.fec.ac(n[h+1])),f=0;f<d.length;f++)C=d[f],b.push(f+1+": "+C.con.cod+" · "+C.ope.cod+" · "+C.tra.cod+" en "+ingra.fec.ac(C.fec));
if(y&&!J)for(b=0;b<d.length;b++)if(C=d[b],!C.ope.opei){J=C.con.i;for(var e=p[J],a=J;a<p.length;a++){c=p[a];if(a>J&&c.niv<=e.niv)break;for(h=0;h<c.tl.length;h++){var t=c.tl[h];if(t.ope.opei==C.ope.ide){for(f=0;f<d.length&&d[f].tari!=t.tari;f++);f==d.length&&d.push(t)}}}}return d}function L(h,b){for(var a=[],d=[],c=document.querySelectorAll("td .seleccion"),f=0;f<c.length;f++){var x=c[f];x.id&&(x=s(x,h?d:null,b),a=a.concat(x))}c={};for(f=0;f<a.length;f++)c[a[f].tari]=a[f];x=[];for(f in c)x.push(c[f]);
return h?d.length?d.join("<br>")+"<br>TAREAS ÚNICAS: "+a.length+" > "+x.length:"NO HAY SELECCIÓN":x}function ca(h,b){function a(){for(var b=0;b<g.length;b++)g[b].fec=ingra.fec.agrega(g[b].fec,e,x)}function d(){for(var b=[e,x],h=0;h<g.length;h++)b.push(g[h].tari);W.graba("graba/fecpro/"+b.join(","),function(b){b.error||a();E()})}if(1==y){var c=h.id;if(c){var f=b.id;if(f&&(c=c.split(","),parseInt(c[0]),c=parseInt(c[1]),f=f.split(","),parseInt(f[0]),f=parseInt(f[1]),c!=f)){var x=w?0:f-c,e=w?ingra.fec.diasEntre(n[c],
n[f]):0,g=L();M?window.dialogoPregunta?dialogoPregunta("Confirmar","¿Quiere mover las tareas seleccionas"+(x?" "+x+" meses":"")+(e?" "+e+" dias":"")+"?",d):d():(a(),E());return 0}}}}function da(h,b){function a(){for(var b=0;b<d.length;b++){var c=d[b],f=c.ope.dur*c.ope.protiecan;c.tra.num--;c.tra.hor-=f;c.trai=h.ide;c.tra=h;c.tra.num++;c.tra.hor+=f}}if(1==y){var d=L();if(M){for(var c=[h.ide],f=0;f<d.length;f++)c.push(d[f].tari);W.graba("graba/trai/"+c,function(h){h.error||a();E();b&&b()})}else a(),
E();return 0}}function E(){y=document.getElementById("conAgrupacion").selectedIndex;!P&&conSeleccionPrevision&&(Q=document.getElementById("conPrevision").selectedIndex);if(w)if(1==w){q=13;var h=ingra.fec.semana(r),b=ingra.fec.semanaDia(r);F=[];a=0;for(d=ingra.fec.agrega(r,-b);a<q;a++)n[a]=d,b=h+a,52<b&&(b-=52),F[a]=b+"ª "+ingra.fec.dia(d)+"/"+ingra.fec.mes(d),d=ingra.fec.agrega(d,7),n[a+1]=d}else for(q=14,F=[],a=0,d=r;a<q;a++)n[a]=d,F[a]=ingra.fec.dia(d),d=ingra.fec.agrega(d,1),n[a+1]=d;else{q=12;
F=[];for(var a=0,d=ingra.fec.dia(r,1);a<q;a++)n[a]=d,F[a]=ingra.fec.nombreMes[ingra.fec.mes(d)-1],d=ingra.fec.agrega(d,0,1),n[a+1]=d}for(var c=n[0],f=n[q],x=!P&&Q,a=0;a<p.length;a++){h=p[a];h.plll=[];for(var e=0;e<q;e++)h.plll[e]=[];if(h.tl&&h.visible)for(e=0;e<h.tl.length;e++)if(b=h.tl[e],!(b.fec>=f||b.fec<c&&(!x||!b.ope.protie))&&b.ope.vis&&b.tra.vis){var g=x&&b.ope.protie?b.ope.enPeriodo(b.fec,c,f,!0):[b.fec],t=h;if(!t.abierto)for(var v=a-1;0<=v&&(t=p[v],v&&!(t.abierto&&t.niv<h.niv));v--);for(var k=
0;k<g.length;k++){d=g[k];for(v=0;v<q&&!(d<n[v+1]);v++);if(v!=q){d=t.plll[v];v=0;if(y)for(var z=d.length-1;0<=z;z--){var A=d[z],l=A[0];if(l.opei==b.ope.opei){A.push(b);v=1;break}}v||d.push([b])}}}}for(a=0;a<p.length;a++)for(h=p[a],v=0;v<q;v++)if(d=h.plll[v],d.length){for(z=0;z<d.length;z++)for(A=d[z],b=A[0],c=b.fec>=n[v],f=z-1;0<=f;f--)if(x=d[f],l=x[0],e=l.fec>=n[v],l.opei==b.opei&&l.trai==b.trai&&(l.ope.opei||c==e)){d[z]=x.concat(A);d.splice(f,1);z--;break}d.sort(function(b,h){return!b[0].ope.opei&&
h[0].ope.opei?-1:b[0].ope.opei&&!h[0].ope.opei?1:b.length>h.length?-1:b.length<h.length?1:0})}ea()}function ea(){var h=[];h.push("<table id='datos'>");var b="class='cabeza1' title='Columna siguiente/anterior' style='cursor:pointer;'",a="class='cabeza12' title='Página siguiente/anterior' style='cursor:pointer;'",d="<th rowspan=2 "+a+">"+(U?"Familia":"Espacio")+"</th>",c="<th rowspan=2 "+a+">Total</th>";if(0==w){for(var a=1,f=ingra.fec.ano(n[0]);a<q&&!(ingra.fec.ano(n[a])>f);a++);var e="<th colspan="+
a+" "+b+" > Año "+f+"</th>";a<q&&(e+="<th colspan="+(q-a)+" "+b+" > Año "+(f+1)+"</th>");h.push("<tr>"+d+e+c+"</tr>");f="";for(d=0;d<F.length;d++)f+="<th class='cabeza2' style='cursor:pointer;' title='Salta a semanas' >"+F[d]+"</th>";h.push("<tr>"+f+"</tr>")}else if(1==w){f=ingra.fec.agrega(n[0]+4);a=ingra.fec.semana(f);f=ingra.fec.ano(f);a=53-a;a>q&&(a=q);e="<th colspan="+a+" "+b+" > "+(1<a?"Semanas de "+f:"")+"</th>";a<q&&(e+="<th colspan="+(q-a)+" "+b+" > "+(1<q-a?"Semanas de "+(f+1):"")+"</th>");
h.push("<tr>"+d+e+c+"</tr>");f="";for(d=0;d<F.length;d++)f+="<th class='cabeza2' style='cursor:pointer;' title='Salta a días' >"+F[d]+"</th>";h.push("<tr style='cursor:default;'>"+f+"</tr>")}else{for(var a=1,e=ingra.fec.mes(n[0]),f=ingra.fec.ano(n[0]),g,k;a<q&&(g=ingra.fec.mes(n[a]),k=ingra.fec.ano(n[a]),g==e);a++);e="<th colspan="+a+" "+b+" > "+(1<a?ingra.fec.nombreMes[e-1]+" de "+f:"")+"</th>";a<q&&(e+="<th colspan="+(q-a)+" "+b+" > "+(1<q-a?ingra.fec.nombreMes[g-1]+" de "+k:"")+"</th>");h.push("<tr>"+
d+e+c+"</tr>");b=ingra.fec.semanaDia(n[0]);f="";for(d=0;d<F.length;d++)c=4<(b+d)%7?" color:#f00;":"",a="LMXJVSD",f+="<th class='cabeza2' title='Salta a años'  style='cursor:pointer;"+c+"'>"+F[d]+" "+a.charAt((b+d)%7)+"</th>";h.push("<tr>"+f+"</tr>")}for(d=0;d<p.length;d++)if(c=p[d],c.abierto){g=[];e=k=0;f="";d<p.length-1&&p[d+1].niv>c.niv&&(f=" title='Abre/Cierra AbreTodo' style='cursor:pointer;'");g.push("<th id='"+d+",-1' class='familia' "+f+">"+c.cod+" · "+c.res+"</th>");for(var t=0;t<q;t++)if(c.visible){for(var v=
c.plll[t],f="",l=0,z=0,A=0;A<v.length;A++){var b=v[A],m=b[0],r=0<m.ope.opei,s=m.fec>=n[t],u=!m.ope.protie,l=l+b.length;if(y)for(a=0;a<b.length;a++)z+=b[a].ope.dur;else z+=b.length*m.ope.dur;r=" id='"+d+","+t+","+A+"' "+(u?"class='correctiva'":r?"class='ligada'":s?"class='programada'":"");if(2==y)f+="<div "+r+" title='"+b.length+" · "+m.ope.cod+" · "+m.tra.cod+"' >"+ingra.icono.html(m.ope.ico)+"</div>";else if(3!=y){u=b.length;s=0;if(y)for(a=0;a<b.length;a++)b[a].ope.opei&&s++;b=u-s;s&&(b+="+"+s);
b+=" · "+m.ope.cod;X&&m.tra.cod&&(b+=" · "+m.tra.cod);f+="<div "+r+" >"+b+"</div>"}}3==y&&(f=G(l,z));g.push("<td id='"+d+","+t+"' >"+f+"</td>");k+=l;N&&(e+=z)}else g.push("<td>-</td>");g.push("<th id='"+d+",-2' class='total' title='Presenta/Oculta contenido' style='cursor:pointer;'>"+G(k,e)+"</th>");h.push("<tr class='nivel"+c.niv+"' >"+g.join("")+"</tr>")}D=[];O=[];for(t=0;t<q;t++)D[t]=O[t]=0;for(d=0;d<p.length;d++)if(c=p[d],c.visible)for(t=0;t<q;t++){v=c.plll[t];for(A=z=l=0;A<v.length;A++)if(b=
v[A],m=b[0],m.ope.vis&&m.tra.vis)if(l+=b.length,y)for(a=0;a<b.length;a++)z+=b[a].ope.dur;else z+=b.length*m.ope.dur;D[t]+=l;O[t]+=z}if(N){g=[];for(A=0;A<D.length;A++)g.push("<div class='totales'>"+G(D[A],O[A])+"</div>");g.push(G(ingra.mat.sum(D),ingra.mat.sum(O)));h.push("<tr class='total2'><th>Total tareas<br>(Total horas)</th><th>"+g.join("</th><th>")+"</th></tr>")}else{g=[];for(A=0;A<D.length;A++)g.push("<div class='totales'>"+G(D[A])+"</div>");g.push(G(ingra.mat.sum(D)));h.push("<tr class='total2'><th>Total tareas</th><th>"+
g.join("</th><th>")+"</th></tr>")}h.push("</table>");document.getElementById("datos").innerHTML=h.join("");Z()}function G(a,b){b=Math.round(b);return a?b?ingra.ac(a)+"<br>("+ingra.ac(b,0)+")":ingra.ac(a):""}function Z(){var a=$("#anexos .selec");if(a.length){var a=a[0].id,b=document.querySelector("#anexos div");902==a&&Y(b);903==a&&aa(b)}}function V(a){if(!a){B={opel:[],tral:[]};for(a=0;a<H.length;a++){var b=H[a];b.vis||B.opel.push({ide:b.ide,vis:b.vis})}for(a=0;a<I.length;a++)b=I[a],b.vis||B.tral.push({ide:b.ide,
vis:b.vis});ingra.memoria.graba("ingra_calendario_"+u.basedatos,JSON.stringify(B));E()}if(a=document.getElementById("901"))a.innerHTML="Operaciones de mantenimiento"+(B.opel.length?" (filtradas)":"");X&&(a=document.getElementById("902"))&&(a.innerHTML="Grupos de trabajo"+(B.tral.length?" (filtrados)":""))}function fa(){var a=[];a.push("<h2>");a.push("<button id='901'> Operaciones de mantenimiento </button>");X&&a.push("<button id='902'> Grupos de trabajo </button>");a.push("<button id='903'> Gráfica de Barras </button>");
a.push("<button id='904'> Estadística </button>");a.push("<button id='905'> Selección </button>");a.push("<button id='906'> Ayuda </button>");a.push("</h2>");a.push("<div style='text-align:center;'></div>");document.getElementById("anexos").innerHTML=a.join("");V(!0);$("#anexos button").click(function(a){var c=parseInt(this.id);if(906==c)return window.open("http://ayuda.ingra.es/ingra/ingridCalendario.htm");a=document.querySelector("#anexos div");if($(this).hasClass("selec"))a.innerHTML="",$(this).toggleClass("selec");
else switch($("#anexos button").removeClass("selec"),$(this).toggleClass("selec"),c){case 901:return ba(a);case 902:return Y(a);case 903:return aa(a);case 904:for(var c=[],d=[],h=0,f=0;f<p.length;f++){var e=p[f];d[e.niv]||(d[e.niv]={en:0,tn:0});d[e.niv].en++;d[e.niv].tn+=e.tl.length;h+=e.tl.length}c.push("<table>");c.push("<tr><th>Nivel</th><th>Número de "+(U?"familias":"espacios")+"</th><th>Número de conceptos</th></tr>");for(f=0;f<d.length;f++)c.push("<tr><td>"+f+"º</td><td>"+ingra.ac(d[f].en)+
"</td><td>"+ingra.ac(d[f].tn)+"</td></tr>");c.push("<tr><th>Total</th><th>"+ingra.ac(p.length)+"</th><th>"+ingra.ac(h)+"</th></tr>");c.push("</table>");a.innerHTML=c.join("");break;case 905:return a.innerHTML=L(!0)}})}function ba(a){var b=[];b.push("<table>");b.push("<tr><th id='visible' style='cursor:pointer;' title='Cambia la visibilidad de todas las operaciones'>Visible</th><th>Icono</th><th>Código</th><th>Descripción</th><th>Ligada</th><th>NºConceptos<br>donde se aplica</th><th>NºTareas<br>anuales/concepto</th><th>NºTareas<br>anuales teóricas</th>"+
(N?"<th>Duración<br>tarea (h)</th><th>Cantidad<br>anual (h)</th>":"")+"</tr>");for(var c=0,d=0,e=0,f=0;f<H.length;f++){var g=H[f];b.push("<tr>");b.push("<td><input type='checkbox' "+(g.vis?"checked":"")+"/></td>");b.push("<td>"+ingra.icono.html(g.ico)+"</td>");b.push("<td style='text-align:left;'>"+g.cod+"</td>");b.push("<td style='text-align:left;'>"+g.res+"</td>");b.push("<td style='text-align:left;'>"+(g.ope?g.ope.cod:"")+"</td>");b.push("<td style='text-align:right;'>"+ingra.ac(g.num)+"</td>");
c+=g.num;b.push("<td style='text-align:right;'>"+ingra.ac(ingra.red(g.protiecan,2),-1)+"</td>");var k=g.num*g.protiecan,d=d+k;b.push("<td style='text-align:right;'>"+ingra.ac(k,0)+"</td>");N&&(k=g.dur*g.num*g.protiecan,e+=k,b.push("<td style='text-align:right;'>"+ingra.ac(g.dur,1)+"</td>"),b.push("<td style='text-align:right;'>"+ingra.ac(k,0)+"</td>"));b.push("</tr>")}b.push("<tr><th></th><th></th><th></th><th></th><th></th><th style='text-align:right;'>"+ingra.ac(c)+"</th><th></th><th style='text-align:right;'>"+
ingra.ac(d)+"</th>"+(N?"<th></th><th style='text-align:right;'>"+ingra.ac(e,0)+"</th>":"")+"</tr>");b.push("</table>");a.innerHTML=b.join("");$(":checkbox",a).click(function(a){a=$(this).parent().parent().index();if(1>a)return 0;H[a-1].vis=$(this).is(":checked");V()});$("#visible",a).click(function(b){for(b=0;b<H.length;b++){var c=H[b];c.vis=c.vis?0:1}ba(a);V()})}function Y(a){var b=[];b.push("<table>");b.push("<tr><th id='visible' style='cursor:pointer;' title='Cambia la visibilidad de todos los grupos'>Visible</th><th>Icono</th><th>Código</th><th>Descripción</th><th>NºTareas</th><th>NºHoras</th>"+
(M&&1==y?"<th>Acción</th>":"")+"</tr>");for(var c=0,d=0,e=0;e<I.length;e++){var f=I[e];b.push("<tr>");b.push("<td><input type='checkbox' "+(f.vis?"checked":"")+"/></td>");b.push("<td>"+ingra.icono.html(f.ico)+"</td>");b.push("<td style='text-align:left;'>"+f.cod+"</td>");b.push("<td style='text-align:left;'>"+f.res+"</td>");b.push("<td style='text-align:right;'>"+ingra.ac(f.num)+"</td>");c+=f.num;b.push("<td style='text-align:right;'>"+ingra.ac(f.hor,0)+"</td>");d+=f.hor;M&&1==y&&b.push("<td><button title='Mueve la selección actual al este grupo de trabajo''>Mueve selección</button></td>");
b.push("</tr>")}b.push("<tr><th></th><th></th><th></th><th></th><th style='text-align:right;'>"+ingra.ac(c)+"</th><th style='text-align:right;'>"+ingra.ac(d,0)+"</th>"+(M&&1==y?"<th></th>":"")+"</tr>");b.push("</table>");a.innerHTML=b.join("");$(":checkbox",a).click(function(a){a=$(this).parent().parent().index();if(1>a)return 0;I[a-1].vis=$(this).is(":checked");V()});$("button",a).click(function(b){b=$(this).parent().parent().index();if(1>b)return 0;da(I[b-1],function(){Y(a)})});$("#visible",a).click(function(b){for(b=
0;b<I.length;b++){var c=I[b];c.vis=c.vis?0:1}Y(a);V()})}function aa(a){function b(a){a.ancho||(a.ancho=1E3);a.alto||(a.alto=300);a.enHoriz||(a.enHoriz=0);for(var b="",c=0;c<a.numl.length;c++)b+=c?"|":"",b+=a.numl[c].join(",");c="";c=a.enHoriz?(a.ejeyl?"0:|"+a.ejeyl.reverse().join("|"):"")+(a.ejexl?"|1:|"+a.ejexl.reverse().join("|"):""):(a.ejexl?"0:|"+a.ejexl.join("|"):"")+(a.ejeyl?"|1:|"+a.ejeyl.join("|"):"");b="http://chart.apis.google.com/chart?chs="+a.ancho+"x"+a.alto+"&chbh=a&chds=a&chxt=x,y&cht="+
(a.enHoriz?"bhg":"bvg")+(a.tit?"&chtt="+a.tit.replace(/ /g,"+"):"")+"&chco=A2C180,FFCC33&chd=t:"+b+"";c&&(b+="&chxl="+c);a.titl&&(b+="&chdl="+a.titl.join("|"));a.enHtml&&(b="<img src='"+b+"' width='"+a.ancho+"' height='"+a.alto+"' alt=''/>");return b}var c=[];N?c.push(b({titl:["Tareas","Horas"],ejexl:F,numl:[D,O],enHtml:1})):c.push(b({ejexl:F,numl:[D],enHtml:1}));a.innerHTML=c.join("")}var q=12,n=[],F=[],K,N=0,P=0,U=0,M=0,r=0,R=1,X,w=0,y=1,Q=1,D,O,u,p=[],H=[],I=[],S={},T={},W={tipo:0,graba:null};
$.extend(W,a);var B={};this.actual=function(){return"h"+P+"f"+U+"a"+y+"r"+Q+"p"+w+"t"+r+"n"+R};this.presenta=function(){var a=L(!1,y);if(a.length)return g(a)};this.monta=function(a){u=a;ingra.icono.inicia(u.icos);delete u.icos;P=u.conHistorico?u.conHistorico:0;U=u.conFamilias?u.conFamilias:0;M=u.conEdicion?u.conEdicion:0;var b=u.conParam;b||(b="");a=b.indexOf("a");0<=a&&(y=parseInt(b.substr(a+1)));a=b.indexOf("r");0<=a&&conSeleccionPrevision&&(Q=parseInt(b.substr(a+1)));a=b.indexOf("p");0<=a&&(w=
parseInt(b.substr(a+1)));a=b.indexOf("n");0<=a&&(R=parseInt(b.substr(a+1)));u.tit||(u.tit="");(p=u.conl)||(p=[]);K=9999E4;for(a=0;a<p.length;a++){b=p[a];b.tl||(b.tl=[]);for(var n=0;n<b.tl.length;n++){var d=b.tl[n];d.fec&&K>d.fec&&(K=d.fec)}}9999E4==K&&(K=ingra.fec.actual());r=K;for(a=b=0;a<p.length;a++)p[a].niv||b++;R=1<b?0:1;for(a=0;a<p.length;a++)b=p[a],b.abierto=b.niv<=R,b.visible=!0;H=u.opel;S={};for(a=N=0;a<H.length;a++)b=H[a]=new ingridOpe(H[a]),b.num=0,b.vis=1,S[b.ide]=b,b.dur?N=1:b.dur=0;
for(a=0;a<H.length;a++)b=H[a],b.ope=b.opei?S[b.opei]:null,b.ope||(b.opei=0);H.sort(function(a,b){var c=a.ope?a.ope.cod:a.cod,d=b.ope?b.ope.cod:b.cod;return c>d?1:c<d||!a.opei?-1:b.opei?a.protiecan>b.protiecan?-1:b.protiecan<a.protiecan||a.cod>b.cod?1:a.cod<b.cod?-1:0:1});X=!!u.tral.length;I=u.tral;I.push({ico:0,ide:0,cod:"",res:"Resto de tareas"});T={};for(a=0;a<I.length;a++)b=I[a],b.num=0,b.hor=0,b.vis=1,T[b.ide]=b;for(a=0;a<p.length;a++)for(b=p[a],b.i=a,n=0;n<b.tl.length;n++){d=b.tl[n];d.i=n;d.con=
b;d.ope=S[d.opei];d.ope.num++;if(d.ope.opei)for(var q=a-1;0<=q;q--)for(var f=p[q],x=0;x<f.tl.length;x++){var C=f.tl[x];if(C.opei==d.ope.opei){d.trai=C.trai;d.lig=C;q=0;break}}d.tra=T[d.trai];d.tra||(d.tra=T[d.trai=0]);d.tra.num++;d.tra.hor+=d.ope.dur*d.ope.protiecan}e();if(b=document.getElementById("titulo"))b.innerHTML="<h1>"+u.tit+"</h1><h2>"+((P?"Histórico":"Planificación")+" del Mantenimiento por "+(U?"Familias":"Espacios"))+"</h2>";if(b=document.getElementById("logo1"))b.innerHTML=u.logo1?"<img alt='' src='"+
u.logo1+"' />":M?"<div style='font-size:1.5em; color:#0080ff;'>conectado<br>EN EDICIÓN</div>":"<div style='font-size:1.5em;'>conectado<br>NO EDITABLE</div>";if(b=document.getElementById("logo2"))b.innerHTML=u.logo2?"<img alt='' src='"+u.logo2+"' />":M?"<div style='font-size:1.5em; color:#0080ff;'>conectado<br>EN EDICIÓN</div>":"<div style='font-size:1.5em;'>conectado<br>NO EDITABLE</div>";document.getElementById("ingridCalendario").innerHTML="<div id='datos'></div><br><div id='anexos'></div>";a=[];
a.push("Con agrupación: <select id='conAgrupacion' title='[FlechaAbajo]+ [FlechaArriba]-' >");a.push("\t\t<option>Tareas sin agrupar</option>");a.push("\t\t<option>Tareas agrupadas en órdenes</option>");a.push("\t\t<option>Iconos</option>");a.push("\t\t<option>Solo número de tareas y horas</option>");a.push("\t\t</select>&nbsp;&nbsp;&nbsp;");!P&&conSeleccionPrevision&&(a.push("Con tareas: <select id='conPrevision' title='[P]' >"),a.push("\t\t<option>Solo programadas</option>"),a.push("\t\t<option>Programadas y previstas</option>"),
a.push("\t\t</select>"));document.getElementById("param").innerHTML=a.join("");document.getElementById("conAgrupacion").selectedIndex=y;!P&&conSeleccionPrevision&&(document.getElementById("conPrevision").selectedIndex=Q);var B=null;$("#conAgrupacion").change(function(a){E();Z()});conSeleccionPrevision&&$("#conPrevision").change(function(a){E()});iD.gestorEventoEliminaTodos();iD.gestorEventoAgrega(document,"keydown",function(a){var b=a.keyCode,d=String.fromCharCode(b);if(27==b)$(".seleccion").toggleClass("seleccion"),
B&&(B=null,document.body.style.cursor="default");else{if(37==b||33==b||109==b)return k(33==b);if(39==b||34==b||107==b)return l(34==b);if(38==b)return c(a,y-1);if(40==b)return c(a,y+1);if("P"==d)return P||!conSeleccionPrevision?a=void 0:(document.getElementById("conPrevision").selectedIndex=Q?0:1,a=E()),a;if("A"==d)return c(a,y?0:1);if("I"==d)return c(a,2);if("T"==d)return c(a,3)}},!1);iD.gestorEventoAgrega($("#datos")[0],"mousewheel",function(a){if(!a.shiftKey&&!a.ctrlKey)return 0<a.wheelDelta?l():
k(),a.stopPropagation&&a.stopPropagation(),a.preventDefault&&a.preventDefault(),0},!1);$("#datos").click(function(a){var b=a.target;if(a.ctrlKey)return $(b).trigger("contextmenu",a);if("cabeza12"==b.className)l(!0);else if("cabeza1"==b.className)l();else if("cabeza2"==b.className)m(!0,$(b).index());else if("familia"==b.className){a=parseInt(a.target.id);b=p[a];for(a+=1;a<p.length;a++){var c=p[a];if(c.niv<=b.niv)break;c.abierto=c.niv==b.niv+1?!c.abierto:0}E()}else if("total"==b.className){a=parseInt(a.target.id);
b=p[a];b.visible=!b.visible;for(a+=1;a<p.length;a++){c=p[a];if(c.niv<=b.niv)break;c.visible=b.visible}E()}else a:{b.id||(b=b.parentNode),a=b.id.split(","),3==a.length?$(b).toggleClass("seleccion"):2==a.length&&$("> div",b).toggleClass("seleccion"),b=[];a=[];for(var d=0;d<D.length;d++)b[d]=a[d]=0;for(var c=document.querySelectorAll("td .seleccion"),e=0;e<c.length;e++){var f=c[e];if(f.id){d=f.id.split(",");if(3>d.length)break a;for(var g=parseInt(d[0]),h=parseInt(d[1]),d=parseInt(d[2]),d=p[g].plll[h][d],
k=g=0;k<d.length;k++){var n=d[k];b[h]++;a[h]+=n.ope.dur;g++}g||$(f).toggleClass("seleccion")}}c=[];if(N){c.push("Total tareas<br>(Total horas)");for(d=0;d<D.length;d++)e="<div>"+G(D[d],O[d])+"</div>",b[d]&&(e+="<div class='seleccion'>"+G(b[d],a[d])+"</div>"),c.push(e);e="<div>"+G(ingra.mat.sum(D),ingra.mat.sum(O))+"</div>";b&&(e+="<div class='seleccion'>"+G(ingra.mat.sum(b),ingra.mat.sum(a))+"</div>")}else{c.push("Total tareas");for(d=0;d<D.length;d++)e="<div>"+G(D[d])+"</div>",b[d]&&(e+="<div class='seleccion'>"+
G(b[d])+"</div>"),c.push(e);e="<div>"+G(ingra.mat.sum(D))+"</div>";b&&(e+="<div class='seleccion'>"+G(ingra.mat.sum(b))+"</div>")}c.push(e);e="<th>"+c.join("</th><th>")+"</th>";$("tr.total2").html(e)}}).bind("contextmenu",function(a){var b=a.target;if(a.ctrlKey)return $(b).trigger("contextmenu",a);if("cabeza12"==b.className)k(!0);else if("cabeza1"==b.className)k();else if("cabeza2"==b.className)m(!1,$(b).index());else if("familia"==b.className){var c=parseInt(a.target.id),b=p[c];R=b.niv+1;for(c=0;c<
p.length;c++)b=p[c],b.abierto=b.niv<=R;E()}else"total"!=b.className&&(b=s(b,null,y),g(b));a.preventDefault&&a.preventDefault();a.stopPropagation&&a.stopPropagation();return 0}).bind("mousedown",function(a){a.preventDefault();M&&1==y&&(a=a.target,$(a).hasClass("seleccion")&&(B=a,document.body.style.cursor="move"))}).bind("mouseup",function(a){a.preventDefault();B&&(ca(B,a.target),B=0,document.body.style.cursor="default")});E();fa()}};
