﻿var arenacharts = new function(){
    this.clear = true;
    this.showplayerfaction = function(id,info,A,H){
        var obj = document.getElementById(id);
        if (obj){
            var T = A+H;
            var pA = this.percent(A,T);
            var pH = this.percent(H,T);
            if (T>=0){
                var chartheight = 240;
                var hA,hH;
                //减去head的高度,4px
                if (pA==0&&pH==100){
                    hA=1;
                    pH=chartheight;
                }
                if (pH==0&&pA==100){
                    hH=1;
                    hA=chartheight;
                }
                if (pH==0&&pA==0){
                    hH=1;
                    hA=1;
                }
                hA = parseInt(chartheight*pA/100)-4;
                hH = parseInt(chartheight*pH/100)-4;
                var html = [];
                html.push("<div class=\"charttitle\">")
                html.push(info.title);
                html.push("</div>");
                html.push("<div class=\"chartelement\">― ")
                html.push(info.element);
                html.push("</div>");
                html.push("<div class=\"chartcontent\">")
                html.push("<div style=\"float:left;clear:both;position:relative;height:"+chartheight+"px;width:200px;padding-left:50px;border-bottom:2px solid #999999;border-left:2px solid #999999;border-right:2px solid #999999;\">");
	            html.push("<p style=\"position:absolute;font-size:11px;width:80px;top:0px;left:3px;padding:0px;margin:0px;color:#999999;\">100%</p>");
	            html.push("<p style=\"position:absolute;font-size:11px;width:80px;top:0px;right:3px;text-align:right;padding:0px;margin:0px;color:#999999;\">"+T+"</p>");
	            html.push("    <div style=\"height:100%;float:left;width:40px;margin-right:50px;\">");
		        html.push("        <div style=\"height:"+(chartheight-hA)+"px;position:relative;font-size:11px;background:url(images/greenhead.png) no-repeat bottom center;\"><p style=\"position:absolute;width:80px;left:-25%;bottom:8px;padding:0px;margin:0px;color:#999999;\">"+A+" ("+pA+"%)</p></div>");
		        html.push("        <div style=\"background:url(images/greenbar.png) repeat-y;height:"+hA+"px;\"></div>");
	            html.push("    </div>");
	            html.push("    <div style=\"height:100%;float:left;width:40px;border-bottom:none;\">");
		        html.push("        <div style=\"height:"+(chartheight-hH)+"px;position:relative;font-size:11px;background:url(images/redhead.png) no-repeat bottom center;\"><p style=\"position:absolute;width:80px;left:-25%;bottom:8px;padding:0px;margin:0px;color:#999999;\">"+H+" ("+pH+"%)</p></div>");
		        html.push("        <div style=\"background:url(images/redbar.png) repeat-y;height:"+hH+"px;\"></div>");
	            html.push("    </div>");
                html.push("</div>");
                html.push("<div style=\"float:left;clear:both;height:20px;width:200px;padding-left:50px;\">");
	            html.push("    <div style=\"line-height:20px;color:#1EFF00;text-align:center;float:left;width:40px;margin-right:50px;\">联盟</div>");
	            html.push("    <div style=\"line-height:20px;color:red;text-align:center;float:left;width:40px;\">部落</div>");
                html.push("</div>");
                html.push("");
                html.push("</div>");
                if (this.clear){
                    obj.innerHTML = html.join('');
                }
                else{
                    obj.innerHTML = obj.innerHTML + html.join('');
                }
            }
        }
    };
    this.percent = function(count,total) {
        if (count<=0||total<=0){return 0}
 	    if (count>=total){return 100}
        if (count<total){
            var a=count/total;
            a = Number(a.toFixed(4))*100;
            return a.toFixed(2);
        }
    };
    this.rtrimzero = function (o){
        return new String(o).replace(/(0-9)\.(0*$)/g, "");
	};
}
