var GUILD = {};

function BUFFED_LOADGUILD(guildid) {
	BUFFED_ROOSTER_REQUEST(guildid);	
	document.write("<div id='guild_data'></div>");
	window.setTimeout("BUFFED_SHOWGUILD()",800);	
}

function BUFFED_ROOSTER_REQUEST(guildid){
	
	var h=document.getElementsByTagName("head")[0];

	element=document.createElement("script");
	element.id="BUFFED_GUILD_REQUEST";
	element.type="text/javascript";
	element.src="http://www.buffed.de/public/war/js/guild/"+guildid+".js";
	
	h.appendChild(element);
	
	var h=document.getElementsByTagName("head")[0];

	var l=document.createElement("link");
	l.type="text/css";
	l.href="http://wardata.buffed.de/css/buffed-ext-war-guild.css";
	l.rel="stylesheet";
	h.appendChild(l);
	
}

function BUFFED_ADDGUILD(data){
	if(typeof data == "object"){
		GUILD = data;
	}
}


function BUFFED_SHOWGUILD(){
	
	var datadiv = document.getElementById("guild_data");
	var t = document.createElement("table");
		t.width = "100%"
		t.className = "db-guild-table"
		t.border = "0";
		t.cellSpacing = "0";
	var th = document.createElement("thead");
	var	thr = th.appendChild(document.createElement("tr"));
		var th1 = document.createElement("th")
			th1.width = "50%";
			th1.setAttribute("nowrap", 'true');
			th1.setAttribute("align", 'left');
		var th2 = document.createElement("th")
			th2.width = "5%";
		var th3 = document.createElement("th")
			th3.width = "20%";
		var th4 = document.createElement("th")
			th4.width = "5%";
		var th5 = document.createElement("th")
			th5.width = "20%";
			th5.setAttribute("nowrap", 'true');
			
			th1.innerHTML = "<span class=\"theadline\">Name</span>";
			th2.innerHTML = "<span class=\"theadline\">Karriere</span>";
			th3.innerHTML = "<span class=\"theadline\">Titel</span>";
			th4.innerHTML = "<span class=\"theadline\">Rang</span>";
			th5.innerHTML = "<span class=\"theadline\">Letzter login</span>";
	
		thr.appendChild(th1);
		thr.appendChild(th2);
		thr.appendChild(th3);
		thr.appendChild(th4);
		thr.appendChild(th5);

		t.appendChild(th);
	var to = t.appendChild(document.createElement("tbody"));
	
	for(p=0;p<GUILD.length;p++){
		
		
		var tr =  to.appendChild(document.createElement("tr"));
		var td1 = document.createElement("td")
			td1.setAttribute("nowrap", 'true');
			td1.setAttribute("align", 'left');
		var td2 = document.createElement("td")
		var td3 = document.createElement("td")
		var td4 = document.createElement("td")
		var td5 = document.createElement("td")
			td5.setAttribute("nowrap", 'true');
		var img = document.createElement("img");

		if (typeof GUILD[p].id == "string"){
			td1.innerHTML="<a href=\"http://wardata.buffed.de/char/view/"+GUILD[p].id+"\">"+GUILD[p].name+"</a>";
		}else{
			td1.innerHTML=GUILD[p].name;
		}

		img.src="http://wardata.buffed.de/img/icons/war/24/"+GUILD[p].career+".png";
		td2.appendChild(img);
		td3.innerHTML=GUILD[p].title;
		td4.innerHTML=GUILD[p].rank;
		td5.innerHTML=GUILD[p].lastlogin;
		
		tr.appendChild(td1);
		tr.appendChild(td2);
		tr.appendChild(td3);
		tr.appendChild(td4);
		tr.appendChild(td5);
	}
	
	datadiv.appendChild(t);
	
}