function printTitle(theTitle){
	document.write("<table cellpadding = 0 cellspacing = 0 border = 0 background = '/shared/wow-com/images/basics/events/wareffort/category_title.gif' width = 365><tr><td width = 30><img src = '/shared/wow-com/images/layout/pixel.gif' height = 27 width = 30></td><td><b><font color = ffbb03 size = 2>"+ theTitle +"</font></b></td></tr></table>");
}

function switchLanguage(thisLanguage)
{
  if (thisLanguage == 0) currentLanguage = "all";
  else if (thisLanguage == 1) currentLanguage = "en";
  else if (thisLanguage == 2) currentLanguage = "fr";
  else if (thisLanguage == 3) currentLanguage = "de";
  document.getElementById("childNode").innerHTML="Loading: "+currentLanguage+"...";
  printList(currentFaction);
}

function switchFaction(thisFaction)
{
  if (thisFaction == 0) currentFaction = "both";
  else if (thisFaction == 1) currentFaction = "alliance";
  else if (thisFaction == 2) currentFaction = "horde";
  document.getElementById("childNode").innerHTML="Loading: "+currentLanguage+"...";
  printList(currentFaction);
}

function printBar(server, i, setbg){

	iSaved = i;
	i = server * 47 + i;
    
	gatheredSingle = gathered[0][i];
	needed = neededArray[iSaved];
	divided = gatheredSingle/needed * 150;
	percentage = Math.floor(gatheredSingle/needed * 100);
    
	if (setbg == 1)
		backgroundColor = "/shared/wow-com/images/basics/events/wareffort/bluebar.gif";	
	else
		backgroundColor = "/shared/wow-com/images/basics/events/wareffort/greenbar.gif";
	document.write("<table background = '/shared/wow-com/images/basics/events/wareffort/item.gif' cellpadding = 0 cellspacing = 0 border = 0 height = 25 width = 365>");
	document.write("<tr><td width = 10><img src = '/shared/wow-com/images/layout/pixel.gif' height = 25 width = 10></td>");
	document.write("<td><img src = '/shared/wow-com/images/layout/pixel.gif' height = 25 width = 5></td>");
	document.write("<td width = 95>");

	if (setbg == 1)
		document.write("<font color = 'e0f4ff'>" +resourcesName[iSaved] + "</font>");
	else
		document.write(resourcesName[iSaved]);
	
	document.write("</td>");
	document.write("<td width = 13><img src = '/shared/wow-com/images/layout/pixel.gif' width = 13 height = 1></td>");
	document.write("<td><div style = 'width: 150;'><div style = 'width: "+ divided +"; background: url("+ backgroundColor +");'>")

	if (percentage != 0)
		document.write("<img src = /shared/wow.com/images/layout/pixel.gif height = '15' width = '1'>");
	
	document.write("</div></div></td>");
	document.write("<td width = 80>"+ gatheredSingle +"/"+ needed +"</td></tr>");
	document.write("<tr><td colspan =4></td><td><div style = 'position: relative; top: -18; width: 145; left: 70;'><div style = 'position: absolute;'>"+ percentage +"%</div></div></td></tr></table>");
	
}

function printTotal(AorH){

	if (AorH == 0) {
		gatheredSingle = gatheredAlliance;
		needed = allianceTotal;
		textTotal = textAllianceTotal;
	} else {
		gatheredSingle = gatheredHorde;
		needed = hordeTotal;
		textTotal = textHordeTotal;	
	}
	
	percentage = Math.floor(gatheredSingle/needed * 100);
	divided = gatheredSingle/needed * 150;
	backgroundColor = "/shared/wow-com/images/basics/events/wareffort/tealbar.gif";	
	document.write("<table background = '/shared/wow-com/images/basics/events/wareffort/item.gif' cellpadding = 0 cellspacing = 0 border = 0 height = 25 width = 365>");
	document.write("<tr><td width = 15><img src = '/shared/wow-com/images/layout/pixel.gif' height = 25 width = 15></td>");
	document.write("<td><img src = '/shared/wow-com/images/layout/pixel.gif' height = 25 width = 5></td>");
	document.write("<td width = 90>" +textTotal + "</td>");
	document.write("<td width = 13><img src = '/shared/wow-com/images/layout/pixel.gif' width = 13 height = 1></td>");
	document.write("<td><div style = 'width: 150;'><div style = 'width: "+ divided +"; background: url("+ backgroundColor +");'>")

	if (percentage != 0)
		document.write("<img src = /shared/wow-com/images/layout/pixel.gif height = '15' width = '1'>");
	
	document.write("</div></div></td>");
	document.write("<td width = 80>"+ gatheredSingle +"/"+ needed +"</td></tr>");
	document.write("<tr><td colspan =4></td><td><div style = 'position: relative; top: -15; width: 145; left: 70;'><div style = 'position: absolute;'>"+ percentage +"%</div></div></td></tr></table>");
}

function printServerTotal(){

		gatheredSingle = gatheredTotal;
		needed = neededTotal;
		textTotal = textServerTotal;
	
	percentage = Math.floor(gatheredSingle/needed * 100);
	divided = gatheredSingle/needed * 554;
	backgroundColor = "/shared/wow-com/images/basics/events/wareffort/servertotalbar.gif";	
	document.write("<table background = '/shared/wow-com/images/basics/events/wareffort/"+userLanguage+"/servertotal.gif' width = 743 cellpadding = 0 cellspacing = 0 border =0><tr><td><img src = '/shared/wow-com/images/layout/pixel.gif' height = 38></td>");
	document.write("<td width = '143'><img src = '/shared/wow-com/images/layout/pixel.gif' height = 38 width = 143></td><td><div style = 'width: 554;'><div style = 'width: "+ divided +"; background: url("+ backgroundColor +");'>")

	if (percentage != 0)
		document.write("<img src = /shared/wow-com/images/layout/pixel.gif height = '20' width = '1'>");
	document.write("</div></div></td>");
	document.write("<td width = '105'></td></tr>");
	document.write("<tr><td colspan=2></td><td><div style = 'position: relative; top: -25; width: 160px; left: 170;'><div style = 'position: absolute;'><b><font color = ffffff>"+ percentage +"% - "+ gatheredSingle +"/"+ needed +"</font></b></div></div></td></tr></table>");
}

function printBottom() {
	document.write("<table border = 0 cellpadding = 0 cellspacing = 0><tr><td><img src = '/shared/wow-com/images/basics/events/wareffort/category_bottom.gif'></td></tr></table>");
}

function printList(faction)
{
x = 0;
y = 0;
document.getElementById("childNode").innerHTML= "&nbsp;";

stringHTML = month = day = "";

while (x < totalServers)
{
if (sortedAlliance[x][1] == 0 || sortedHorde[x][1] == 0) break;
  switch(faction)
  {
	case "alliance": thisLanguage = realms[sortedAlliance[x][0]][1]; break;
	case "horde": thisLanguage = realms[sortedHorde[x][0]][1]; break;
	case "both": thisLanguage = realms[sorted[x][0]][1]; break;
  }

  if(thisLanguage == currentLanguage || currentLanguage == "all")
  {
  switch(faction)
  {
	case "alliance":
	  thisDivided = sortedAlliance[x][1]/allianceTotal * 308;
	  thisRealm = realms[sortedAlliance[x][0]][0]; //sortedAlliance[x][0]  realmID
	  thisLink = "wareffort.html?"+sortedAlliance[x][0];
	  thisGathered = sortedAlliance[x][1]+"/"+allianceTotal;
	  thisPercentage = Math.floor(sortedAlliance[x][1]/allianceTotal * 100);
	  thisType = realms[sortedAlliance[x][0]][2];
	  thisGong = sortedAlliance[x][5];
	  if (realms[sortedAlliance[x][0]][3] != 60) { 
        month = (realms[sortedAlliance[x][0]][4] < 10 ? "0" + realms[sortedAlliance[x][0]][4] : realms[sortedAlliance[x][0]][4]);
        day = (realms[sortedAlliance[x][0]][3] < 10 ? "0" + realms[sortedAlliance[x][0]][3] : realms[sortedAlliance[x][0]][3]);
      thisGongDate = month+ "/"+ day; } else thisGongDate = gateOpened;
	  break;
	case "horde":
	  thisDivided = sortedHorde[x][1]/hordeTotal * 308;
	  thisRealm = realms[sortedHorde[x][0]][0];
	  thisLink = "wareffort.html?"+sortedHorde[x][0];
	  thisGathered = sortedHorde[x][1]+"/"+hordeTotal;
	  thisPercentage = Math.floor(sortedHorde[x][1]/hordeTotal * 100);
	  thisType = realms[sortedHorde[x][0]][2];
	  thisGong = sortedHorde[x][5];
      if (realms[sortedHorde[x][0]][3] != 60) { 
        month = (realms[sortedHorde[x][0]][4] < 10 ? "0" + realms[sortedHorde[x][0]][4] : realms[sortedHorde[x][0]][4]);
        day = (realms[sortedHorde[x][0]][3] < 10 ? "0" + realms[sortedHorde[x][0]][3] : realms[sortedHorde[x][0]][3]);
      thisGongDate = month+ "/"+ day; } else thisGongDate = gateOpened;
	  break;
	case "both":
	  thisDivided = sorted[x][1]/neededTotal * 308;
	  thisRealm = realms[sorted[x][0]][0];
	  thisLink = "wareffort.html?"+sorted[x][0];
	  thisGathered = sorted[x][1]+"/"+neededTotal;
	  thisPercentage = Math.floor(sorted[x][1]/neededTotal * 100);
	  thisType = realms[sorted[x][0]][2];
	  thisGong = sorted[x][5];
      if (realms[sorted[x][0]][3] != 60) { 
        month = (realms[sorted[x][0]][4] < 10 ? "0" + realms[sorted[x][0]][4] : realms[sorted[x][0]][4]);
        day = (realms[sorted[x][0]][3] < 10 ? "0" + realms[sorted[x][0]][3] : realms[sorted[x][0]][3]);
      thisGongDate = month+ "/"+ day; } else thisGongDate = gateOpened;
	  break;
	}

	y++;
	gateStatus = "<img src = '/shared/wow-com/images/basics/events/wareffort/gate_red.gif'></td><td width = 43>"+gateClosed;
	if (thisPercentage >= 100)
	{
	  supplyStatus = "<img src = '/shared/wow-com/images/basics/events/wareffort/supplies_green.gif'></td><td width = 43>"+suppliesDone+"";
	  if (thisGong) gateStatus = "<img src = '/shared/wow-com/images/basics/events/wareffort/gate_green.gif'></td><td width = 43>"+thisGongDate;
	}
	else supplyStatus = "<img src = '/shared/wow-com/images/basics/events/wareffort/supplies_red.gif'></td><td width = 43>";
	//supplyStatus = "<img src = '/shared/wow-com/images/basics/events/wareffort/supplies_red.gif'></td><td width = 43>";
	//gateStatus = "<img src = '/shared/wow-com/images/basics/events/wareffort/gate_red.gif'></td><td width = 43> Closed ";
	stringHTML += "\
	<table border = 0 cellpadding = 0 cellspacing = 0 background = /shared/wow-com/images/basics/events/wareffort/serverlist_item.gif width = 743 height = 24>\
	  <tr>\
	    <td width = 7><img src = /shared/wow-com/images/layout/pixel.gif height = 24 width = 7></td>\
		<td width = 146><b><font color = ffffff >"+y+"</font></b>. <a href = "+thisLink+">"+thisRealm+"</a></td>\
		<td width = 41 align = center><font color = c80000>"+thisType+"</font></td>\
		<td><img src = /shared/wow-com/images/layout/pixel.gif height = 1 width = 4></td>\
		<td width = 308>\
	      <div style = 'width: 308;'>\
	        <div style = 'width: "+ thisDivided +"; background: url(/shared/wow-com/images/basics/events/wareffort/tealbar.gif);'><img src = /shared/wow-com/images/layout/pixel.gif height = '15' width = '1'></div>\
	      </div>\
	    </td>\
		<td width = 92 >&nbsp;&nbsp;&nbsp;"+thisGathered+"</td>\
		<td>"+ supplyStatus + "</td>\
		<td>"+ gateStatus + "</td>\
	  </tr>\
	  <tr>\
	    <td colspan = 3><div style = 'position: relative; top: -18; left: 350;'><div style = 'position: absolute;'>"+ thisPercentage +"%</div></div></td>\
	  </tr>\
	</table>";
  }	
  x++;
}

document.getElementById("childNode").innerHTML=stringHTML;
}
	
