
LVL=new Array(); LVL[1]=127; LVL[0]=127; m=.05; for (i=1;i<101;i++) { if (i>1) { LVL[i]=Math.floor(LVL[i-1]+(LVL[i-1]*m)); m=m+.0015; }}
function mysortfn(a,b) { c=a.split("|"); d=b.split("|"); return d[0]-c[0]; }
function calcLevel(e) { j1=128; l1=1; m1=.05; for (i1=1; i1<100; i1++) { k1=parseInt(j1+(j1*m1)); m1=m1+.0015; if (e >= j1) { l1=i1; } j1=k1; } return l1; }
function Comma(number) { number = '' + number; if (number.length > 3) { mod = number.length % 3; output = (mod > 0 ? (number.substring(0,mod)) : ''); for (i1=0 ; i1 < Math.floor(number.length / 3); i1++) { if ((mod == 0) && (i1 == 0)) output += number.substring(mod+ 3 * i1, mod + 3 * i1 + 3); else output+= ',' + number.substring(mod + 3 * i1, mod + 3 * i1 + 3); } return (output); } else return number; }
function displayclan() {
  bg="#fcf9f0"; exp=0; lvl=0; bug=""; Mexp=0;
  for (i=0; i<NumMembers; i++) {
    D=T[i].split("|");
    for (j=0; j<na; j++) {
      R=S[j].split("|");
      if (R[1].toLowerCase()==D[1].toLowerCase()) {
        if (R[12]) {} else { R[12]=0; }

        if (FORMD=="Total") {
          AddLevel=calcLevel(R[3])+calcLevel(R[4])+calcLevel(R[5])+calcLevel(R[6])+calcLevel(R[7])+calcLevel(R[8])+calcLevel(R[9])+calcLevel(R[10])+calcLevel(R[11])+calcLevel(R[12]);
          lvl=lvl+AddLevel;
          AddExp=parseInt(R[3])+parseInt(R[4])+parseInt(R[5])+parseInt(R[6])+parseInt(R[7])+parseInt(R[8])+parseInt(R[9])+parseInt(R[10])+parseInt(R[11]);
          Mexp=Mexp+AddExp;
          T[i]=AddLevel+"|"+D[1]+"|"+D[2]+"|"+AddLevel+"|"+AddExp+"|";
        }
        
        if (FORMD=="Overall") {
          AddLevel=calcLevel(R[3])+calcLevel(R[4])+calcLevel(R[5])+calcLevel(R[6])+calcLevel(R[7])+calcLevel(R[8])+calcLevel(R[9])+calcLevel(R[10])+calcLevel(R[11])+calcLevel(R[12]);
          lvl=lvl+AddLevel;
          if (R[12]) {} else { R[12]="0"; }
          AddExp=parseInt(R[3])+parseInt(R[4])+parseInt(R[5])+parseInt(R[6])+parseInt(R[7])+parseInt(R[8])+parseInt(R[9])+parseInt(R[10])+parseInt(R[11])+parseInt(R[12]);
          Mexp=Mexp+AddExp;
          T[i]=AddExp+"|"+D[1]+"|"+D[2]+"|"+AddLevel+"|"+AddExp+"|";
        }

        if (FORMD=="Combat") {
          lvl=lvl+calcLevel(R[3]);
          Mexp=Mexp+parseInt(R[3]);
          T[i]=calcLevel(R[3])+"|"+D[1]+"|"+D[2]+"|"+calcLevel(R[3])+"|"+parseInt(R[3])+"|";
        }
        if (FORMD=="Magic") {
          lvl=lvl+calcLevel(R[4]);
          Mexp=Mexp+parseInt(R[4]);
          T[i]=calcLevel(R[4])+"|"+D[1]+"|"+D[2]+"|"+calcLevel(R[4])+"|"+parseInt(R[4])+"|";
        }
        if (FORMD=="Fishing") {
          lvl=lvl+calcLevel(R[5]);
          Mexp=Mexp+parseInt(R[5]);
          T[i]=calcLevel(R[5])+"|"+D[1]+"|"+D[2]+"|"+calcLevel(R[5])+"|"+parseInt(R[5])+"|";
        }
        if (FORMD=="Cooking") {
          lvl=lvl+calcLevel(R[6]);
          Mexp=Mexp+parseInt(R[6]);
          T[i]=calcLevel(R[6])+"|"+D[1]+"|"+D[2]+"|"+calcLevel(R[6])+"|"+parseInt(R[6])+"|";
        }
        if (FORMD=="Mining") {
          lvl=lvl+calcLevel(R[7]);
          Mexp=Mexp+parseInt(R[7]);
          T[i]=calcLevel(R[7])+"|"+D[1]+"|"+D[2]+"|"+calcLevel(R[7])+"|"+parseInt(R[7])+"|";
        }
        if (FORMD=="Smithing") {
          lvl=lvl+calcLevel(R[8]);
          Mexp=Mexp+parseInt(R[8]);
          T[i]=calcLevel(R[8])+"|"+D[1]+"|"+D[2]+"|"+calcLevel(R[8])+"|"+parseInt(R[8])+"|";
        }
        if (FORMD=="Range") {
          lvl=lvl+calcLevel(R[9]);
          Mexp=Mexp+parseInt(R[9]);
          T[i]=calcLevel(R[9])+"|"+D[1]+"|"+D[2]+"|"+calcLevel(R[9])+"|"+parseInt(R[9])+"|";
        }
        if (FORMD=="PVP") {
          lvl=lvl+calcLevel(R[10]);
          Mexp=Mexp+parseInt(R[10]);
          T[i]=calcLevel(R[10])+"|"+D[1]+"|"+D[2]+"|"+calcLevel(R[10])+"|"+parseInt(R[10])+"|";
        }
        if (FORMD=="Arson") {
          lvl=lvl+calcLevel(R[11]);
          Mexp=Mexp+parseInt(R[11]);
          T[i]=calcLevel(R[11])+"|"+D[1]+"|"+D[2]+"|"+calcLevel(R[11])+"|"+parseInt(R[11])+"|";
        }
        if (FORMD=="PK") {
          Mexp=Mexp+parseInt(R[12]);
          T[i]=parseInt(R[12])+"|"+D[1]+"|"+D[2]+"|"+"|"+parseInt(R[12])+"|";
        }

        //         1        2       3       4       5       6       7       8       9      10      11        12    13
        // |$CharName|$overall|$ExpCbt|$ExpMag|$ExpFsh|$ExpCok|$ExpMin|$ExpSmt|$ExpRng|$ExpPVP|$ExpFir|$CharBones|        
        
      }
    }    
  }  

  document.write("<p align=center><center><table width=80%><tr>");
  document.write("<td align=center><font color=purple>##</font></td><td align=center><font color=purple>Member Name</font></td>");
  document.write("<td align=center><font color=purple>Rank</font></td>");
  document.write("<td align=center><font color=purple>"+FORMD+"</font></td><td align=center><font color=purple>Experience</font></td>");
  document.write("</tr><tr><td colspan=5><hr></td></tr>");

  SORT=0; T.sort(mysortfn);

  for (i=0; i<NumMembers; i++) {
    D=T[i].split("|");
    document.write("<tr style=\"background-color: "+bg+";\" onMouseover=\"this.style.backgroundColor=\'#ffffc0\';\" onMouseout=\"this.style.backgroundColor=\'"+bg+"\';\">");    
    document.write("<td align=center>"+(i+1)+"</td>");
    document.write("<td align=center><a href=?a=profile&user="+D[1]+"&session="+session+">"+D[1]+"</a></td>");
    document.write("<td align=center>"+D[2]+"</td>");
    document.write("<td align=center>"+D[3]+"</td>");
    document.write("<td align=center>"+Comma(D[4])+"</td>");
  }
  
  document.write("</tr><tr><td colspan=5><hr></td></tr>");
  
  document.write("<tr style=\"background-color: "+bg+";\" onMouseover=\"this.style.backgroundColor=\'#ffffc0\';\" onMouseout=\"this.style.backgroundColor=\'"+bg+"\';\">");
  document.write("<td> </td><td> </td><td> </td><td align=center>"+Comma(lvl)+"</td><td align=center>"+Comma(Mexp)+"</td>");
  
  document.write("</tr></table></center><p><br><br>");

}



function displayclans() {
  if (SORT) {} else { SORT="Total"; }
  for (i=0; i<NumClan; i++) {
    D=C[i].split("|");
    exp=0;
    lvl=0;
    sortvalue=0;
    NumMember=0;
    for (j=2; j<99; j++) {
      if (D[j]=="x") {
        j=100;
      } else {
        NumMember++;
        for (k=0;k<na;k++) {
          R=S[k].split("|");
          if (R[12]) {} else { R[12]=0; }
          if (R[1].toLowerCase()==D[j].toLowerCase()) {
            if (SORT=="Total") {
              lvl=lvl+calcLevel(R[3])+calcLevel(R[4])+calcLevel(R[5])+calcLevel(R[6])+calcLevel(R[7])+calcLevel(R[8])+calcLevel(R[9])+calcLevel(R[10])+calcLevel(R[11])+calcLevel(R[12]);
              exp=exp+parseInt(R[3])+parseInt(R[4])+parseInt(R[5])+parseInt(R[6])+parseInt(R[7])+parseInt(R[8])+parseInt(R[9])+parseInt(R[10])+parseInt(R[11])+parseInt(R[12]);
              sortvalue=lvl;
            }
            if (SORT=="Overall") {
              lvl=lvl+calcLevel(R[3])+calcLevel(R[4])+calcLevel(R[5])+calcLevel(R[6])+calcLevel(R[7])+calcLevel(R[8])+calcLevel(R[9])+calcLevel(R[10])+calcLevel(R[11])+calcLevel(R[12]);
              exp=exp+parseInt(R[3])+parseInt(R[4])+parseInt(R[5])+parseInt(R[6])+parseInt(R[7])+parseInt(R[8])+parseInt(R[9])+parseInt(R[10])+parseInt(R[11])+parseInt(R[12]);
              sortvalue=exp;
            }
            if (SORT=="Combat") { lvl=lvl+calcLevel(R[3]); exp=exp+parseInt(R[3]); sortvalue=lvl; }
            if (SORT=="Magic") { lvl=lvl+calcLevel(R[4]); exp=exp+parseInt(R[4]); sortvalue=lvl; }
            if (SORT=="Fishing") { lvl=lvl+calcLevel(R[5]); exp=exp+parseInt(R[5]); sortvalue=lvl; }
            if (SORT=="Cooking") { lvl=lvl+calcLevel(R[6]); exp=exp+parseInt(R[6]); sortvalue=lvl; }
            if (SORT=="Mining") { lvl=lvl+calcLevel(R[7]); exp=exp+parseInt(R[7]); sortvalue=lvl; }
            if (SORT=="Smithing") { lvl=lvl+calcLevel(R[8]); exp=exp+parseInt(R[8]); sortvalue=lvl; }
            if (SORT=="Range") { lvl=lvl+calcLevel(R[9]); exp=exp+parseInt(R[9]); sortvalue=lvl; }
            if (SORT=="PVP") { lvl=lvl+calcLevel(R[10]); exp=exp+parseInt(R[10]); sortvalue=lvl; }
            if (SORT=="Arson") { lvl=lvl+calcLevel(R[11]); exp=exp+parseInt(R[11]); sortvalue=lvl; }
            if (SORT=="PK") { if (R[12]) { lvl=lvl+parseInt(R[12]); exp=exp+parseInt(R[12]); sortvalue=exp; } else { sortvalue=0; }}  
            //         1        2       3       4       5       6       7       8       9      10      11        12    13
            // |$CharName|$overall|$ExpCbt|$ExpMag|$ExpFsh|$ExpCok|$ExpMin|$ExpSmt|$ExpRng|$ExpPVP|$ExpFir|$CharBones|        
          }
        }
      }
    }
    C[i]=sortvalue+"|"+D[1]+"|"+NumMember+"|"+exp+"|"+lvl+"|";
  }

  document.write("<p align=center><center><table width=80%><tr>");
  document.write("<td align=center><font color=purple>##</font></td><td align=center><font color=purple>Clan Name</font></td>");
  document.write("<td align=center><font color=purple>Members</font></td>");
  if (SORT=="PK") {
    document.write("<td align=center><font color=purple> </font></td><td align=center><font color=purple>"+SORT+"</font></td>");
  } else {
    document.write("<td align=center><font color=purple>"+SORT+"</font></td><td align=center><font color=purple>Experience</font></td>");
  }
  document.write("</tr><tr><td colspan=5><hr></td></tr>");
  
  bg="#fcf9f0";

  C.sort(mysortfn);

  for (i=0; i<NumClan; i++) {
    D=C[i].split("|");
    document.write("<tr style=\"background-color: "+bg+";\" onMouseover=\"this.style.backgroundColor=\'#ffffc0\';\" onMouseout=\"this.style.backgroundColor=\'"+bg+"\';\">");
    document.write("<td align=center>"+(i+1)+"</td>");
    document.write("<td align=center><a href=\"?a=clan&b="+D[1]+"&d="+SORT+"&session="+session+"\">"+D[1]+"</a></td>");
    document.write("<td align=center>"+D[2]+"</td>");
    if (SORT=="PK") {
      document.write("<td align=center> </td>");
    } else {
      document.write("<td align=center>"+Comma(D[4])+"</td>");
    }
    document.write("<td align=center>"+Comma(D[3])+"</td>");
  }
  document.write("</tr><tr><td colspan=5><hr></td></tr>");
  document.write("<tr style=\"background-color: "+bg+";\" onMouseover=\"this.style.backgroundColor=\'#ffffc0\';\" onMouseout=\"this.style.backgroundColor=\'"+bg+"\';\">");
  document.write("</tr></table></center>");
}







