function List(){this.current=this.end=this.head=null;this.size=0}List.prototype.add=function(b){b={obj:b,next:null};this.head?this.end=this.end.next=b:this.current=this.end=this.head=b;this.size++};List.prototype.del=function(b){for(var d=this.head,t=0;t<b;t++)d=d.next;d.next=d.next.next?d.next.next:null;this.size--};List.prototype.next=function(){var b=null;this.current&&(b=this.current.obj,this.current=this.current.next);return b};List.prototype.hasnext=function(){return null!=this.current?!0:!1};
var colorNoList={0:"blue",1:"black",2:"brown",3:"green",4:"lightblue",5:"lightgreen",6:"orange",7:"pink",8:"purple",9:"red",10:"yellow",11:"navy",12:"teal",13:"gray",14:"indigo",15:"slategray",16:"chocolate",17:"darkgreen",18:"violet",19:"darkslategray",20:"lime",21:"aqua",22:"maroon",23:"olive",24:"silver",25:"fuchsia",BK:"black2",WT:"white2",BL:"blue2",RD:"red2",YL:"yellow2",length:26};
function dataNode(b,d,t,g,f,n,k,a,r,e,c,p,h,m){this.id=b;this.value=d?d.split(","):null;this.type=t;this.color=g?g.split(","):null;this.colorNo=f?f.split(","):null;this.baseVal=n?n.split(","):null;this.href=k?k.split(","):null;this.target=a?a.split(","):null;this.text=r?r.split("|"):null;this.attr=e?e.split("|"):null;this.zeroBorder=c?c:!0;this.graphThick=p?p:19;this.paddingLeft=h?h:0;this.paddingRigth=m?m:0}
function travel(b,d,t){"IBAR"==b.tagName&&"1"==b.nodeType&&d.add(new dataNode(b.id,b.getAttribute("value"),b.getAttribute("type"),b.getAttribute("color"),b.getAttribute("colorNo"),b.getAttribute("baseVal"),b.getAttribute("href"),b.getAttribute("target"),b.getAttribute("text"),b.getAttribute("optionAttributes"),b.getAttribute("zeroBorder"),b.getAttribute("graphThick"),b.getAttribute("paddingLeft"),b.getAttribute("paddingRigth")));for(var g=b.childNodes.length,f=0;f<g;f++)travel(b.childNodes[f],d,t)}
function addComma(b){var d=String(b);for(b=0;b<d.length/3;b++)d=d.replace(/^([+-]?\d+)(\d\d\d)/,"$1,$2");return d}function getNumberOnly(b){return-1!=b.search(/([0-9]+)/)?Number(RegExp.$1):isNaN(b)?0:Number(b)}
function adjustBar(){var b=0,d=0,t=document.getElementById("viewTable"),g=document.getElementsByTagName("iBar"),f=document.getElementsByTagName("iHead"),n=new List;var k="W";var a=null,r=0;if(!g||0==g.length)return!0;for(i=0;i<g.length;i++){if(null==g[i].id)return alert("Please establish the attribute [id]."),!1;var e=g[i].getAttribute("type");if(null==e)return alert("Please establish the attribute [type].id="+g[i].id),!1;var c=g[i].getAttribute("value");if(null==c)return alert("Please establish the attribute [value].id="+
g[i].id),!1;if(("0"==e||"2"==e)&&null==g[i].getAttribute("baseVal"))return alert("Please establish the attribute [baseVal].id="+g[i].id),!1;if("1"==e||"6"==e){var p=g[i].getAttribute("color");if(p&&c.split(",").length!=p.split(",").length)return alert("Please establish the attribute [value="+c+"] and the attribute [color="+p+"] by one to one. id="+g[i].id),!1;var h=g[i].getAttribute("colorNo");if(h&&c.split(",").length!=h.split(",").length)return alert("Please establish the attribute [value] and the attribute [color] by one to one. id="+
g[i].id),!1;if(!p&&!h)return alert("Please establish which it is, the attribute [color] or the attribute [colorNo]. id="+g[i].id),!1}c=g[i].id.split("_");if(null==a)a=c[c.length-1],r++,k="5">e?"W":"H";else if(a==c[c.length-1]){if(r++,"5">e&&"H"==k||"5"<=e&&"W"==k)return alert("A vertical line is intermingled with horizontal beam."),!1}else break}k=g.length/r;e=Array(k);c=Array(k);for(a=p=0;a<k;a++){for(h=g[a*r].parentNode;null!=h&&"TD"!=h.tagName;)h=h.parentNode;c[a]=h;var m=h.childNodes,q=new List;
for(i=0;i<m.length;i++)"BR"==m[i].tagName?(n.add(q),q=new List):travel(m[i],q,n);0<q.size&&n.add(q);if("5"<=g[a].getAttribute("type")){for(e[a]=document.createElement("div");h.hasChildNodes()&&1E4>p;)e[a].appendChild(m[0]),p++;h.appendChild(e[a])}}for(;n.hasnext();){for(listSwap=n.next();listSwap.hasnext();){a=listSwap.next();if("1"==a.type||"6"==a.type)for(i=0;a.value&&i<a.value.length;i++)d+=1*a.value[i];"6"==a.type&&(b=d>b?d:b,d=0)}b=d>b?d:b;listSwap.current=listSwap.head;d=0}n.current=n.head;
d=f&&0<f.length&&f[0].getAttribute("width")?f[0].getAttribute("width"):getClientWidth()-t.offsetWidth-30;for(a=0;a<k;a++)e[a]&&(e[a].style.position="relative",e[a].style.height="100px",e[a].style.width=d+"px",e[a].style.borderBottom="solid 1px gray");for(;n.hasnext();)for(listSwap=n.next(),g=0;listSwap.hasnext();){a=listSwap.next();switch(a.type){case "0":iLabel=document.createElement("div");iLabel.style.position="relative";iLabel.style.top="0px";iLabel.style.height="15px";iLabel.style.width="0px";
iLabel.innerHTML="<font size='2'>"+a.value[0]+"</font><br/><img src='../image/arrow.gif'/>";k=0<a.value[0].indexOf("%")?a.value[0].replace("%","")/100:1*a.value[0];e=0;if(null!=a.baseVal)for(i=0;i<a.baseVal.length;i++)e+=a.baseVal[i];iLabel.style.left=Math.round(1*k*e/b*d)-8+"px";k=document.getElementById(a.id).parentNode;iBarObject=document.getElementById(a.id);k.insertBefore(iLabel,iBarObject);a.attr&&a.attr[i]&&(c=$(iLabel).attr("class"),$(iLabel).attr($.parseJSON(a.attr[i])),$(iLabel).addClass(c));
k.removeChild(iBarObject);break;case "1":k=document.getElementById(a.id).parentNode;iBarObject=document.getElementById(a.id);for(i=0;a.value&&i<a.value.length;i++){if(c=a.color?a.color[i]:null)var l=0==c.indexOf("src:")?c.substring(4)+".png":"../image/W_"+c.toLowerCase()+".png";else if(c=a.colorNo?a.colorNo[i]:null)l=colorNoList[c],l||(c=parseInt(c,10)%colorNoList.length,l=colorNoList[c]),l=l?"../image/W_"+l+".png":"../image/W_blue.png";a.text&&a.text[i]?(iCenter=document.createElement("div"),iCenter.style.backgroundImage=
"url("+l+")",iCenter.id=a.id,iCenter.style.height=a.graphThick+"px",iCenter.innerHTML=a.text[i],$(iCenter).addClass("inline-block"),$(iCenter).addClass("iBarDiv")):(iCenter=document.createElement("img"),iCenter.src=l,iCenter.id=a.id,iCenter.height=a.graphThick);e=Math.round(a.value[i]/b*d);0<a.paddingLeft&&a.paddingLeft<e&&(iCenter.style.paddingLeft=a.paddingLeft+"px",e-=a.paddingLeft);0<a.paddingRigth&&a.paddingRigth<e&&(iCenter.style.paddingRigth=a.paddingRigth+"px",e-=a.paddingRigth);0==e&&"true"==
a.zeroBorder&&(e=1);iCenter.style.width=e+"px";iCenter.style.verticalAlign="middle";k.insertBefore(iCenter,iBarObject);a.href&&a.target&&a.href[i]&&a.target[i]&&$(iCenter).wrapAll('<a href="'+a.href[i]+'" target="'+a.target[i]+'"></a>');a.attr&&a.attr[i]&&(c=$(iCenter).attr("class"),$(iCenter).attr($.parseJSON(a.attr[i])),$(iCenter).addClass(c))}k.removeChild(iBarObject);break;case "2":arrVal1=a.value;arrVal2=a.baseVal;if(null==arrVal1||null==arrVal2)break;for(i=e=p=c=0;i<arrVal1.length;i++)c+=1*
arrVal1[i],0==Math.round(arrVal1[i]/b*d)&&(e+=2);if(null!=arrVal2)for(j=0;j<arrVal2.length;j++)p+=1*arrVal2[j];c>p&&(h=a.color?a.color[0]:"red",k=document.getElementById(a.id).parentNode,iBarObject=document.getElementById(a.id),iDiv1=document.createElement("div"),iDiv1.style.height="0px",iDiv2=document.createElement("div"),iDiv2.style.position="relative",iDiv2.id=a.id,iDiv2.style.border="dashed "+h+" 2px",iDiv2.style.top="-19px",iDiv2.style.left=Math.round(p/b*d)+"px",iDiv2.style.height="17px",c=
Math.round((c-p)/b*d),c=4<c?c-4:0,iDiv2.style.width=c+e+"px",iDiv1.appendChild(iDiv2),k.insertBefore(iDiv1,iBarObject),a.href&&a.target&&$(iDiv1).wrapAll('<a href="'+a.href+'" target="'+a.target+'"></a>'),a.attr&&a.attr[i]&&(c=$(iDiv1).attr("class"),$(iDiv1).attr($.parseJSON(a.attr[i])),$(iDiv1).addClass(c)),k.removeChild(iBarObject));break;case "6":k=document.getElementById(a.id).parentNode;iBarObject=document.getElementById(a.id);for(i=e=0;a.value&&i<a.value.length;i++){if(c=a.color[i])l=0==c.indexOf("src:")?
c.substring(4)+".png":"../image/H_"+c.toLowerCase()+".png";else if(c=a.colorNo[i])l=colorNoList[c],l||(c=parseInt(c,10)%colorNoList.length,l=colorNoList[c]),l=l?"../image/H_"+l+".png":"../image/H_blue.png";iCenter=document.createElement("img");iCenter.src=l;iCenter.id=a.id;swapW=Math.floor(d/r);swapW=20<swapW?20:swapW;iCenter.width=swapW;swapH=Math.round(a.value[i]/b*100);swapH=0<swapH?swapH:0;iCenter.height=swapH;iDiv=document.createElement("div");iDiv.style.position="absolute";iDiv.style.top=100-
swapH-e+"px";iDiv.style.left=swapW*g+"px";iDiv.style.fontSize="0";k.appendChild(iDiv);iDiv.appendChild(iCenter);e+=swapH;a.href&&a.target&&$(iCenter).wrapAll('<a href="'+a.href+'" target="'+a.target+'"></a>');a.attr&&a.attr[i]&&(c=$(iCenter).attr("class"),$(iCenter).attr($.parseJSON(a.attr[i])),$(iCenter).addClass(c))}k.removeChild(iBarObject)}g++}if(f&&0<f.length){n=f.length;r=Math.pow(10,Math.floor(Math.LOG10E*Math.log(b)));a=Math.floor(b/r)*r/2;g=a/b*d;b=f[0].getAttribute("leftLoc")?f[0].getAttribute("leftLoc").split(","):
null;r=f[0].getAttribute("leftVal")?f[0].getAttribute("leftVal").split(","):null;l=0;if(null==b)l=g,b=[g];else for(i=0;i<b.length;i++)b[i]*=d,l+=Number(b[i]);null==r&&(r=[addComma(a)]);l>d&&(l=d);a=f[0].getAttribute("rightVal")?f[0].getAttribute("rightVal"):addComma(2*a);g=f[0].getAttribute("rightLoc")?d*f[0].getAttribute("rightLoc")-l:2*g-l;0>g&&(g=0);l+g>d&&(g=d-l);k=f[0].getAttribute("leftBorderStyle")?f[0].getAttribute("leftBorderStyle"):"dotted gray 1px";e=f[0].getAttribute("rightBorderStyle")?
f[0].getAttribute("rightBorderStyle"):"dotted gray 1px";c=f[0].getAttribute("adjustLeft")?f[0].getAttribute("adjustLeft"):0;p=f[0].getAttribute("adjustRight")?f[0].getAttribute("adjustRight"):0;h=Array(n);m=Array(n);q=Array(n);d=f[0].parentNode.offsetWidth>d?f[0].parentNode.offsetWidth:d;var v=f[0].parentNode.offsetHeight;t=t.offsetHeight;for(i=0;i<n;i++){h[i]=document.createElement("div");h[i].style.width=d+"px";h[i].style.height=v+"px";h[i].style.position="relative";h[i].style.margin="0";h[i].style.padding=
"0";h[i].style.border="0";m[i]=Array(b);var u=0;for(j=0;j<b.length;j++)m[i][j]=document.createElement("div"),m[i][j].style.position="absolute",m[i][j].style.left=u+"px",m[i][j].style.width=b[j]+"px",m[i][j].style.textAlign="right",u+=b[j],$(m[i][j]).text(r[j]),m[i][j].style.borderRight=k,$(m[i][j]).addClass("leftAdjustBar"),h[i].appendChild(m[i][j]);q[i]=document.createElement("div");q[i].style.position="absolute";q[i].style.left=l+"px";q[i].style.width=g+"px";q[i].style.textAlign="right";$(q[i]).text(a);
q[i].style.borderRight=e;$(q[i]).addClass("rightAdjustBar");h[i].appendChild(q[i]);f[i].parentNode.insertBefore(h[i],f[i]);for(j=0;j<b.length;j++)m[i][j].style.lineHeight=getNumberOnly(h[i].style.height)-c+"px";q[i].style.lineHeight=getNumberOnly(h[i].style.height)-p+"px";if(0==i){for(j=0;j<b.length;j++)m[i][j].style.height=t+"px";q[i].style.height=t+"px"}}for(i=0;i<f.length;)f[0].parentNode.removeChild(f[0])}};
