var vis_skema = function(){
	this.autoMouse=false;
}

vis_skema.prototype.Print = function(nr, hold, runde, modstander)
{
  if (nr==1)	
	{
		SkemaMsgWindow=window.open(window.location.href+"&hold="+hold+"&printer="+nr,"displayWindow","toolbar=no,    width=800,height=680,directories=no,status=yes,    scrollbars=yes,resize=yes,menubar=yes");	  
		SkemaMsgWindow.focus();
	}
  if (nr==2)
	{
		KlubMsgWindow=window.open(window.location.href+"&hold="+hold+"&printer="+nr,"displayWindow","toolbar=no,    width=800,height=680,directories=no,status=yes,    scrollbars=yes,resize=yes,menubar=yes");
		KlubMsgWindow.focus();
	}
  if (nr==3)
	{
		StyMsgWindow=window.open(window.location.href+"&hold="+hold+"&printer="+nr,"displayWindow","toolbar=no,    width=800,height=680,directories=no,status=yes,    scrollbars=yes,resize=yes,menubar=yes");
		StyMsgWindow.focus();
	}
  if (nr==4)
	{
		PosMsgWindow=window.open(window.location.href+"&hold="+hold+"&printer="+nr,"displayWindow","toolbar=no,    width=800,height=680,directories=no,status=yes,    scrollbars=yes,resize=yes,menubar=yes");
		PosMsgWindow.focus();
	}
  if (nr==5)
	{
		RouMsgWindow=window.open(window.location.href+"&modstander="+modstander+"&runde="+runde+"&hold="+hold+"&printer="+nr,"displayWindow","toolbar=no,    width=800,height=680,directories=no,status=yes,    scrollbars=yes,resize=yes,menubar=yes");
		RouMsgWindow.focus();
	}
  if (nr==6)
	{
		PerMsgWindow=window.open(window.location.href+"&modstander="+modstander+"&runde="+runde+"&hold="+hold+"&printer="+nr,"displayWindow","toolbar=no,    width=800,height=680,directories=no,status=yes,    scrollbars=yes,resize=yes,menubar=yes");
		PerMsgWindow.focus();
	}
}
vis_skema.prototype.sortPlac = function(res,mp,nr)
{
  var plac = 1; 
	for (n=1; n<=res.length; n++)
	{
	  if (n!=nr && res[n]>res[nr]) plac++;
	  if (n!=nr && res[n]==res[nr] && mp[n]>mp[nr]) plac++;
	}
  return plac;
}

vis_skema.prototype.Change_Auto_View = function(obj)
{
  if (obj.autoMouse) obj.autoMouse = false
  else obj.autoMouse = true;
 	telm.deleteAllElement(obj.autoViewOnOff);
	if (obj.autoMouse) telm.textNode("<br>(ON)",obj.autoViewOnOff);
	else  telm.textNode("<br>(OFF)",obj.autoViewOnOff);
 	var oLink = window.location.pathname.split("/");
 	oLink.pop()
	setCookie("Auto_View", obj.autoMouse, 360)
}
vis_skema.prototype.ShowPersonResultAuto = function(Obj,nr,navn)
{
  if (!Obj.autoMouse) return false
  else Obj.ShowPosition(Obj,nr,navn);
}

vis_skema.prototype.ShowPersonExpected = function(r1,r2)
{
  return ratingBeregn.beregnforventet(r1,r2)
}


vis_skema.prototype.ShowPersonResult = function(Obj,nr, navn)
{
  telm.deleteAllElement(Obj.PersonInfoCont);
  if (telm.testIe())  Obj.PersonInfoCont.innerHTML = "<a name='personInfo'></a>";
	else this.a = telm.element("a",Obj.PersonInfoCont,"name='personInfo'");
	this.ShowPersonResultForm = telm.element("form",Obj.PersonInfoCont,"method='POST'","action='javascript: void(0);'","name='opretBrugerForm'");
	this.sTable = telm.element("table",this.ShowPersonResultForm,"class='holdskak'");
	this.tBody = telm.element("tbody",this.sTable,"bordercolor='#000000'");
	this.tr = telm.element("tr",this.tBody,"class='tab_rakke0'");
	this.td = telm.element("td",this.tr,"class='tab_note2'");
	this.td.colSpan = 3 
	telm.textNode("Resultatliste for " + navn,this.td);

	this.td = telm.element("td",this.tr,"align='right'","class='tab_note2'");
	if (Obj.noPrinter)	{
		this.A = telm.element("a",this.td,"href='JavaScript: skema.Print(6)'","style='float: right;'");
		this.printer = telm.element("img",this.A,"src='modul/holdskak/images/print.gif'","alt='Print skema'","style='border: none;'");
	}
}

vis_skema.prototype.ShowPositionAuto = function(Obj)
{
  if (!Obj.autoMouse) return false
  else Obj.ShowPosition(Obj);
}

vis_skema.prototype.ShowPosition = function(Obj)
{
  telm.deleteAllElement(Obj.Klub_Info_Cont);
  
  // Workaround bug in Ie
  if (telm.testIe())  Obj.Klub_Info_Cont.innerHTML = "<a name='Klub_Info'></a>";
	else this.a = telm.element("a",Obj.Klub_Info_Cont,"name='Klub_Info'");
	this.br = telm.element("br",Obj.Klub_Info_Cont);

	this.ShowPositionForm = telm.element("form",Obj.Klub_Info_Cont,"method='POST'","action='javascript: void(0);'","name='opretBrugerForm'");
	this.sTable = telm.element("table",this.ShowPositionForm,"class='holdskak'");
	this.tBody = telm.element("tbody",this.sTable,"bordercolor='#000000'");
	this.tr = telm.element("tr",this.tBody,"class='tab_rakke0'");
	this.td = telm.element("td",this.tr,"class='tab_note2'");
	this.td.colSpan = 3 
	telm.textNode("Stillingen i " + Obj.overskrift,this.td);

	this.td = telm.element("td",this.tr,"align='right'","class='tab_note2'");
	if (Obj.noPrinter)	{
		this.A = telm.element("a",this.td,"href='JavaScript: skema.Print(4)'","style='float: right;'");
		this.printer = telm.element("img",this.A,"src='modul/holdskak/images/print.gif'","alt='Print skema'","style='border: none;'");
	}

	this.tr = telm.element("tr",this.tBody,"class='tab_rakke0'");
	this.td = telm.element("td",this.tr,"class='printer_nr'");
	telm.textNode("Nr.",this.td);
	this.td = telm.element("td",this.tr,"class='printer_navn'");
	telm.textNode("Hold",this.td);
	this.td = telm.element("td",this.tr,"class='printer_pt'");
	telm.textNode("Point",this.td);
	this.td = telm.element("td",this.tr,"class='printer_mp'");
	telm.textNode("Match Point",this.td);
	var naf = 1; 
	for (var NrK=1; NrK<=Obj.antal_klubber; NrK++)
	{
		for (var hldNr=1; hldNr<=Obj.antal_klubber; hldNr++)
		{
		  if (Obj.td_plac[hldNr].value == NrK)
		  {
				this.tr = telm.element("tr",this.tBody);
				if ((naf/2)==parseInt(naf/2)) this.tr.className = 'tab_rakke0'; else this.tr.className = 'tab_rakke1';
				this.td = telm.element("td",this.tr,"class='printer_nr'");
				telm.textNode(Obj.td_plac[hldNr].value,this.td);
				this.td = telm.element("td",this.tr,"class='printer_navn'");
				telm.textNode(Obj.hold[hldNr-1].hold_navn,this.td);
				this.td = telm.element("td",this.tr,"class='printer_pt'");
				telm.textNode(""+Obj.sumResultat[hldNr],this.td);
				this.td = telm.element("td",this.tr,"class='printer_mp'");
				telm.textNode(""+Obj.mp[hldNr],this.td);
				naf++;	  
			}
		}
	  
	}
  if (!Obj.noPrinter) telm.deleteAllElement(Obj.skemaForm);
//	if (!Obj.noPrinter) setTimeout(prePrint, 100); 
	if (Obj.noPrinter) 
	{
 		document.getElementById("cms_krop").style.height=""; 
  	testheight();
	}
}

vis_skema.prototype.ShowRoundAuto = function(Obj,runde,hold,modstander)
{
  if (!Obj.autoMouse) return false
  else Obj.ShowRound(Obj,runde,hold,modstander);
}

vis_skema.prototype.getRaring = function(Obj,hold,id)
{
  for (var i=0; i<Obj.styrkeliste[hold-1].id.length; i++)
  {
		if (id==Obj.styrkeliste[hold-1].id[i]) return Obj.styrkeliste[hold-1].rating[i];
	}
	return 0;
}


vis_skema.prototype.ShowRound = function(Obj,runde,hold,modstander)
{
  telm.deleteAllElement(Obj.Klub_Info_Cont);
  
  // Workaround bug in Ie
  if (telm.testIe())  Obj.Klub_Info_Cont.innerHTML = "<a name='Klub_Info'></a>";
	else this.a = telm.element("a",Obj.Klub_Info_Cont,"name='Klub_Info'");
	this.br = telm.element("br",Obj.Klub_Info_Cont);

	this.ShowPositionForm = telm.element("form",Obj.Klub_Info_Cont,"method='POST'","action='javascript: void(0);'","name='opretBrugerForm'");
	this.sTable = telm.element("table",this.ShowPositionForm,"class='holdskak'");
	this.tBody = telm.element("tbody",this.sTable,"bordercolor='#000000'");
	this.tr = telm.element("tr",this.tBody,"class='tab_rakke0'");
	this.td = telm.element("td",this.tr,"class='tab_note2'");
	this.td.colSpan = 3; 
	telm.textNode("Enkelt resultater for " + Obj.hold[hold-1].hold_navn + " runde "+ runde,this.td);

	this.td = telm.element("td",this.tr,"align='right'","class='tab_note2'");
	if (Obj.noPrinter)	{
		this.A = telm.element("a",this.td,"href='JavaScript: skema.Print(5,"+hold+","+runde+","+modstander+")'","style='float: right;'");
		this.printer = telm.element("img",this.A,"src='modul/holdskak/images/print.gif'","alt='Print skema'","style='border: none;'");
	}
	this.tr = telm.element("tr",this.tBody,"class='tab_rakke1'");
	this.td = telm.element("td",this.tr,"class='printer_navn'");
	this.td.colSpan = 4 
	if (Obj.skema[hold][runde].sted=="h"){
	  var hHold = hold;
		var uHold = modstander;
	}
	else {
		var hHold = modstander;
  	var uHold = hold;
	}
	var hSumRes = 0;
	var uSumRes = 0;
	for (br=1; br<=Obj.antal_spillere; br++)
	{
		if (typeof Obj.resultater =="object" && typeof Obj.resultater[runde]=="object" && typeof Obj.resultater[runde][hHold]=="object" && typeof Obj.resultater[runde][hHold][br]=="object") {
		 if (Obj.resultater[runde][hHold][br].resultat=="1" || Obj.resultater[runde][hHold][br].resultat=="(1)")  hSumRes++;
		 if (Obj.resultater[runde][hHold][br].resultat=="½")  hSumRes +=.5;

		}
		
		if (typeof Obj.resultater =="object" && typeof Obj.resultater[runde]=="object" && typeof Obj.resultater[runde][uHold]=="object" && typeof Obj.resultater[runde][uHold][br]=="object") {
		 if (Obj.resultater[runde][uHold][br].resultat=="1" || Obj.resultater[runde][uHold][br].resultat=="(1)")  uSumRes++;
		 if (Obj.resultater[runde][uHold][br].resultat=="½")  uSumRes +=.5;
		}
	}
	var hres = (hSumRes/2)*2 == parseInt(hSumRes/2*2);
	var ures = (uSumRes/2)*2 == parseInt(uSumRes/2*2);
	if (!hres) hSumRes = parseInt(hSumRes)+"½";
	if (!ures) uSumRes = parseInt(uSumRes)+"½";
	if (hSumRes=="0½") hSumRes = "½";
	if (uSumRes=="0½") uSumRes = "½";
	telm.textNode("<b>" +Obj.hold[hHold-1].hold_navn + "</b>",this.td);
	telm.textNode(" - ",this.td);
	telm.textNode("<b>"+Obj.hold[uHold-1].hold_navn+"</b>",this.td);
	telm.textNode("<span style='position: relative; padding-left: 30px;'></span>"+hSumRes+ " - " +uSumRes,this.td);
	this.showRatingExp = telm.element("span",this.td);
	this.tr = telm.element("tr",this.tBody,"class='tab_rakke0'");
	this.td = telm.element("td",this.tr,"class='printer_nr'");
	telm.textNode("Br.",this.td);
	this.td = telm.element("td",this.tr,"class='printer_navn'");
	telm.textNode("Spiller "+Obj.hold[hHold-1].hold_navn,this.td);
	this.td = telm.element("td",this.tr,"class='printer_pt'");
	telm.textNode("Res.",this.td);
	this.td = telm.element("td",this.tr,"class='printer_navn'");
	telm.textNode("Spiller "+Obj.hold[uHold-1].hold_navn,this.td);
	var hRatingSum=0;	
	var uRatingSum=0;	
	for (br=1; br<=Obj.antal_spillere; br++)
	{
		if (typeof Obj.resultater =="object" && typeof Obj.resultater[runde]=="object" && typeof Obj.resultater[runde][hHold]=="object" && typeof Obj.resultater[runde][hHold][br]=="object")
		{
		  var hNavn = Obj.resultater[runde][hHold][br].navn;
		  var hNavnId = Obj.resultater[runde][hHold][br].person_id;
		  var hResultat = Obj.resultater[runde][hHold][br].resultat;
		  var hRrating = Obj.getRaring(Obj,hHold,hNavnId);
		}
		else 
		{
		  var hNavn = "";
		  var hNavnId = "";
		  var hResultat = "";
		  var hRrating = 0;
		}
		
		if (typeof Obj.resultater =="object" && typeof Obj.resultater[runde]=="object" && typeof Obj.resultater[runde][uHold]=="object" && typeof Obj.resultater[runde][uHold][br]=="object")
		{
		  var uNavn = Obj.resultater[runde][uHold][br].navn;
		  var uNavnId = Obj.resultater[runde][uHold][br].person_id;
		  var uResultat = Obj.resultater[runde][uHold][br].resultat;
		  var uRrating = Obj.getRaring(Obj,uHold,uNavnId);
		}
		else 
		{
		  var uNavn = "";
		  var uNavnId = "";
		  var uResultat = "";
		  var uRrating = 0;
		}
		var hRatingDif=Obj.ShowPersonExpected(hRrating,uRrating);	
		var uRatingDif=Obj.ShowPersonExpected(uRrating,hRrating);	
		hRatingSum+=hRatingDif;	
		uRatingSum+=uRatingDif;	
		
		this.tr = telm.element("tr",this.tBody,"class='tab_rakke0'");
		if ((br/2)==parseInt(br/2)) this.tr.className = 'tab_rakke0'; else this.tr.className = 'tab_rakke1';
		this.td = telm.element("td",this.tr,"class='printer_nr'");
		telm.textNode(br,this.td);
		this.td = telm.element("td",this.tr,"class='printer_navn'");
		this.A = telm.element("a",this.td);
		this.td.title = "Rating: "+hRrating;
		this.A.href = "?modul=holdskak/spiller_info.php&infoFunktion=vis_spiller_data&spiller_id="+hNavnId+"&klub_id="+Obj.hold[hHold-1].klub_id+"&sprog=dk&Change_klub=0&activ_menu="+Obj.activ_menu;
		telm.textNode(hNavn,this.A);
		telm.textNode(" ("+hRatingDif+")",this.td);
		this.td = telm.element("td",this.tr,"class='printer_pt'");
		telm.textNode(hResultat + " - " + uResultat,this.td);
		this.td = telm.element("td",this.tr,"class='printer_navn'");
		this.A = telm.element("a",this.td);
		this.td.title = "Rating: "+uRrating;
		this.A.href = "?modul=holdskak/spiller_info.php&infoFunktion=vis_spiller_data&spiller_id="+uNavnId+"&klub_id="+Obj.hold[uHold-1].klub_id+"&sprog=dk&Change_klub=0&activ_menu="+Obj.activ_menu;
		telm.textNode(uNavn,this.A);
		telm.textNode(" ("+uRatingDif+")",this.td);
		
	}

	telm.textNode(" ("+(Math.round(hRatingSum*100)/100)+" - "+(Math.round(uRatingSum*100)/100)+")",this.showRatingExp);
	if (Obj.noPrinter) 
	{
		this.tr = telm.element("tr",this.tBody,"class='tab_rakke0'");
		if ((br/2)==parseInt(br/2)) this.tr.className = 'tab_rakke0'; else this.tr.className = 'tab_rakke1';
		this.td = telm.element("td",this.tr,"class='printer_nr'");
		this.td.colSpan = 7 
		telm.textNode("Forventet score i parentes.",this.td);
	}
	
  if (!Obj.noPrinter) telm.deleteAllElement(Obj.skemaForm);
//	if (!Obj.noPrinter) setTimeout(prePrint, 100); 
	if (Obj.noPrinter) 
	{
		this.PersonInfoCont = telm.element("div",Obj.Klub_Info_Cont);
 		document.getElementById("cms_krop").style.height=""; 
  	testheight();
	}
}

vis_skema.prototype.Create_Skema = function()
{
  this.autoMouse = getCookie("Auto_View")=="true";
	this.noPrinter=true
  var oLink = window.location.href.split("&");
  var lPar = oLink.pop().split("=")
	if (lPar[0]=="printer") 
	{
 		var aHold = oLink.pop().split("=")
 		var hold=aHold[1];
 		var aRunde = oLink.pop().split("=")
 		var runde=aRunde[1];
		var aModstander = oLink.pop().split("=")
 		var modstander=aModstander[1];
 		
	  telm.deleteAllElement(document.getElementById("cms_container"));
	  this.skemaCont = telm.element("div",document.getElementById("cms_container"));
  	var oLink = window.location.pathname.split("/");
  	oLink.pop()
		var fileref=document.createElement("link")
		fileref.setAttribute("rel", "stylesheet");
		fileref.setAttribute("type", "text/css");
		fileref.setAttribute("href", "http://" + window.location.hostname + oLink.join("/") + "/system/css/skak_tabel_print.css");
		document.getElementsByTagName("head").item(0).appendChild(fileref)
		this.noPrinter=false
		if (lPar[1]==2)
		{
			this.Klub_Info_Cont = telm.element("div",this.skemaCont);
			this.Create_Klub_Info(this,hold)	  
		  return false;
		}
		if (lPar[1]==3)
		{
			this.Klub_Info_Cont = telm.element("div",this.skemaCont);
			this.Create_Styrkeliste(this,hold)	  
		  return false;
		}
		if (lPar[1]==4)
		{
			this.PrintShowPosition = true;
		}
		if (lPar[1]==5)
		{
			this.PrintShowRound = true;
			this.Klub_Info_Cont = telm.element("div",this.skemaCont);
			this.ShowRound(this,runde,hold,modstander)	  
		  return false;
		}
	}
	
  telm.deleteAllElement(this.skemaCont);
	this.skemaForm = telm.element("form",this.skemaCont,"method='POST'","action='javascript: void(0);'","name='opretBrugerForm'");
	this.sTable = telm.element("table",this.skemaForm,"class='holdskak'");
	this.tBody = telm.element("tbody",this.sTable,"bordercolor='#000000'");
	this.tr = telm.element("tr",this.tBody,"class='tab_rakke0'");
	this.td = telm.element("td",this.tr,"class='tab_overskrift'");
	this.td.colSpan = this.antal_runder*3 + 2 
	telm.textNode(this.overskrift,this.td);

	this.td = telm.element("td",this.tr,"class='Auto_View'","align='center'");
	this.td.colSpan = 2; 
	
	if (this.noPrinter)	
	{
		telm.addEvent(this.td,"click", skema.Change_Auto_View,this)
		telm.textNode("auto view",this.td);
		this.autoViewOnOff = telm.element("span",this.td);
	  if (this.autoMouse) telm.textNode("<br>(ON)",this.autoViewOnOff);
		else  telm.textNode("<br>(OFF)",this.autoViewOnOff);
	}
	this.td = telm.element("td",this.tr,"class='tab_overskrift'");
	if (this.noPrinter)	this.A = telm.element("a",this.td,"href='JavaScript: skema.Print(1)'","style='float: right;'");
	if (this.noPrinter)	this.printer = telm.element("img",this.A,"src='modul/holdskak/images/print.gif'","alt='Print skema'","style='border: none;'");

	this.tr = telm.element("tr",this.tBody,"class='tab_rakke1'");
	this.td = telm.element("td",this.tr,"class='tab_nummer'");
	this.td.colSpan = 2; 
	telm.textNode("Dato eller Uge",this.td);
	this.datoTekst = new Array();
	datoArray = this.dato_liste.split(",");
  for (rundeNr=0; rundeNr<this.antal_runder; rundeNr++)
  {
		this.td = telm.element("td",this.tr,"class='tab_dato'");
		this.td.colSpan = 3; 
		telm.textNode(datoArray[rundeNr],this.td);
// datoer
	}
	this.td = telm.element("td",this.tr,"class='tab_stillingen'");
	this.td.colSpan = 3; 
	telm.textNode("Stillingen",this.td);
	if (this.noPrinter)		{
	  this.td.style.cursor = "pointer";
	 	telm.addEvent(this.td,"mousedown", skema.ShowPosition,this) 
	 	telm.addEvent(this.td,"mouseover", skema.ShowPositionAuto,this) 
	}

	this.tr = telm.element("tr",this.tBody,"class='tab_rakke0'");
	this.td = telm.element("td",this.tr,"class='tab_nummer'");
	telm.textNode("Nr.",this.td);
	this.td = telm.element("td",this.tr,"class='tab_hoved'");
	telm.textNode("Hold / Runde",this.td);
  for (rundeNr=1; rundeNr<=this.antal_runder; rundeNr++)
  {
		this.td = telm.element("td",this.tr,"class='tab_hoved'");
		this.td.colSpan = 3; 
		telm.textNode(rundeNr,this.td);
	}
	this.td = telm.element("td",this.tr,"class='tab_antalpoint1'");
	telm.textNode("Pt.",this.td);
	this.td = telm.element("td",this.tr,"class='tab_mp1'");
	telm.textNode("MP",this.td);
	this.td = telm.element("td",this.tr,"class='tab_place1'");
	telm.textNode("Nr.",this.td);

	this.modstander = new Array();
	this.gruppeHold = new Array();
	this.td_mp = new Array();
	this.td_plac = new Array();
	this.sumResultat = new Array()
	for (holdNr=1; holdNr<=this.antal_klubber; holdNr++)
	{
		this.modstander[holdNr] = new Array();
		this.tr = telm.element("tr",this.tBody);
		if ((holdNr/2)==parseInt(holdNr/2)) this.tr.className = 'tab_rakke0'; else this.tr.className = 'tab_rakke1';
		this.td = telm.element("td",this.tr,"class='tab_nummer'");
		telm.textNode(holdNr,this.td);
		this.td = telm.element("td",this.tr,"class='tab_navn'");
		if (this.noPrinter)		this.A = telm.element("a",this.td,"href='#Klub_Info");
		if (this.noPrinter)	telm.textNode(this.hold[holdNr-1].hold_navn,this.A);
		else telm.textNode(this.hold[holdNr-1].hold_navn,this.td);
		if (this.noPrinter)		telm.addEvent(this.A,"click", skema.Create_Klub_Info,this,holdNr)
		if (this.noPrinter)		telm.addEvent(this.A,"mouseover", skema.autoFunction,this,holdNr)
// holdnavn

		this.sumResultat[holdNr] = 0;
	  for (rundeNr=1; rundeNr<=this.antal_runder; rundeNr++)
	  {
			this.modstander[holdNr][rundeNr] = new Array();
			this.td = telm.element("td",this.tr,"class='tab_sort'","title='Udekamp'");
			if (this.skema[holdNr][rundeNr].sted=="u")	telm.textNode(this.skema[holdNr][rundeNr].modstander_nr,this.td);
// udekamp

			this.td = telm.element("td",this.tr,"class='tab_resul'","title='Resultat'");
			telm.textNode(this.skema[holdNr][rundeNr].resultat,this.td);
			if (this.noPrinter)		{
			  this.td.style.cursor = "pointer";
			 	telm.addEvent(this.td,"mousedown", skema.ShowRound,this,rundeNr,holdNr,this.skema[holdNr][rundeNr].modstander_nr);
			 	telm.addEvent(this.td,"mouseover", skema.ShowRoundAuto,this,rundeNr,holdNr,this.skema[holdNr][rundeNr].modstander_nr);
			}
			this.res = this.skema[holdNr][rundeNr].resultat.split("½").join(".5");
			this.skema[holdNr][rundeNr].resultat = parseFloat(this.res)
			if (this.skema[holdNr][rundeNr].resultat) this.sumResultat[holdNr] += parseFloat(this.res);
//			if (this.skema[holdNr][rundeNr].resultat.indexOf("½")) this.sumResultat[holdNr] += .5;
// resultat
			
			this.td = telm.element("td",this.tr,"class='tab_hvid'","title='Hjemmekamp'","align='right'");
			if (this.skema[holdNr][rundeNr].sted=="h")	telm.textNode(this.skema[holdNr][rundeNr].modstander_nr,this.td);

// Hjemmekamp
		}
		this.td = telm.element("td",this.tr,"class='tab_antalpoint1'");
		this.resString = ""+this.sumResultat[holdNr];
		this.resString=this.resString.split(".5").join("½");
		if (this.resString=="0½") this.resString = "½";
		telm.textNode(this.resString,this.td);
		this.td_mp[holdNr] = telm.element("td",this.tr,"class='tab_mp1'");
		this.td_plac[holdNr] = telm.element("td",this.tr,"class='tab_place1'");
	}
	this.mp = new Array();
	for (holdNr=1; holdNr<=this.antal_klubber; holdNr++)
	{
	  this.mp[holdNr] = 0;
	  for (rundeNr=1; rundeNr<=this.antal_runder; rundeNr++)
		{
		  if (this.skema[holdNr][rundeNr].resultat > this.skema[this.skema[holdNr][rundeNr].modstander_nr][rundeNr].resultat) this.mp[holdNr]+=2;
		  if (this.skema[holdNr][rundeNr].resultat!=0 && this.skema[holdNr][rundeNr].resultat == this.skema[this.skema[holdNr][rundeNr].modstander_nr][rundeNr].resultat) this.mp[holdNr]++;
		}	  
		telm.textNode("" + this.mp[holdNr],this.td_mp[holdNr]);
	}

	for (holdNr=1; holdNr<=this.antal_klubber; holdNr++)
	{
	  var plac = this.sortPlac(this.sumResultat,this.mp,holdNr)
		telm.textNode(plac,this.td_plac[holdNr]);
		this.td_plac[holdNr].value = plac;
	}

	for (x=0; x<this.noter.length; x++)
	{
		if (this.noPrinter || x==0)
		{
		  this.tr = telm.element("tr",this.tBody);
			this.td = telm.element("td",this.tr,"class='tab_note3'");
			this.td.colSpan = this.antal_runder*3 + 5 
			telm.textNode(this.noter[x],this.td);
		}
	}
	this.Klub_Info_Cont = telm.element("div",this.skemaCont);
	if (this.PrintShowPosition)	this.ShowPosition(this)
	if (!this.noPrinter) setTimeout(prePrint, 100); 

	if (this.noPrinter) 
	{
	 	document.getElementById("cms_krop").style.height=""; 
	  testheight();
	}
}

vis_skema.prototype.autoFunction = function(Obj,nr)
{
 if (Obj.autoMouse===false) return false;
 else Obj.Create_Klub_Info(Obj,nr);
}

vis_skema.prototype.Create_Klub_Info = function(Obj,nr)
{
  telm.deleteAllElement(Obj.Klub_Info_Cont);
  
  // Workaround bug in Ie
  if (telm.testIe())  Obj.Klub_Info_Cont.innerHTML = "<a name='Klub_Info'></a>";
	else this.a = telm.element("a",Obj.Klub_Info_Cont,"name='Klub_Info'");
	this.br = telm.element("br",Obj.Klub_Info_Cont);
	this.Klub_Info = telm.element("form",Obj.Klub_Info_Cont,"method='POST'","action='javascript: void(0);'","name='Klub_Info_Form'");
	this.sTable = telm.element("table",Obj.Klub_Info_Cont,"class='holdskak'");
	this.tBody = telm.element("tbody",this.sTable,"bordercolor='#000000'");
	this.tr = telm.element("tr",this.tBody,"class='tab_rakke0'");
	this.td = telm.element("td",this.tr,"class='tab_note2'");
	this.td.colSpan = 2 
	telm.textNode("Holdopstilling for " + skema.hold[nr-1].hold_navn,this.td);

	this.td = telm.element("td",this.tr,"align='right'","class='tab_note2'");
	if (Obj.noPrinter)	this.A = telm.element("a",this.td,"href='JavaScript: skema.Print(2,"+nr+")'","style='float: right;'");
	if (Obj.noPrinter)	this.printer = telm.element("img",this.A,"src='modul/holdskak/images/print.gif'","alt='Print skema'","style='border: none;'");

	this.tr = telm.element("tr",this.tBody,"class='tab_rakke1'");
		this.td = telm.element("td",this.tr,"class='tab_nummer'");
		telm.textNode("Nr.",this.td);
	  
		this.td = telm.element("td",this.tr,"class='hold_info1'");
		telm.textNode("Navn",this.td);
	  
		this.td = telm.element("td",this.tr,"class='hold_info2'");
		telm.textNode("Rating",this.td);
	  this.holdlederSat = false;
	  this.rating=0;
	for (naf=0; naf<skema.hold_spillere[nr-1].navn.length; naf++)
	{
		this.tr = telm.element("tr",this.tBody);
		if ((naf/2)==parseInt(naf/2)) this.tr.className = 'tab_rakke0'; else this.tr.className = 'tab_rakke1';
		this.td = telm.element("td",this.tr,"class='tab_nummer'");
		telm.textNode(skema.hold_spillere[nr-1].nr[naf],this.td);
	  if (skema.hold_spillere[nr-1].id[naf] == skema.hold_spillere[nr-1].holdlederId){
		  this.holdlederSat = true;
		  this.ekstraText = " (holdleder) tlf.: " + skema.hold_spillere[nr-1].holdleder_tlf;
		}
		else this.ekstraText = "";
	  
		this.td = telm.element("td",this.tr,"class='hold_info1'");
		telm.textNode(skema.hold_spillere[nr-1].navn[naf]+this.ekstraText,this.td);
	  
		this.td = telm.element("td",this.tr,"class='hold_info2'");
		telm.textNode(skema.hold_spillere[nr-1].rating[naf],this.td);
	  this.rating+= parseInt(skema.hold_spillere[nr-1].rating[naf]);
	}
		this.tr = telm.element("tr",this.tBody);
		if ((naf/2)==parseInt(naf/2)) this.tr.className = 'tab_rakke0'; else this.tr.className = 'tab_rakke1';
		this.td = telm.element("td",this.tr,"class='tab_nummer'");
	  
		this.td = telm.element("td",this.tr,"class='hold_info1'");
		telm.textNode("Ratinggennemsnit: ",this.td);
		this.td = telm.element("td",this.tr,"class='hold_info2'");
		telm.textNode(parseInt(this.rating/naf),this.td);
		naf++;
	if (!this.holdlederSat){
		this.tr = telm.element("tr",this.tBody);
		if ((naf/2)==parseInt(naf/2)) this.tr.className = 'tab_rakke0'; else this.tr.className = 'tab_rakke1';
		this.td = telm.element("td",this.tr,"class='tab_nummer'");
	  
		this.td = telm.element("td",this.tr,"class='hold_info1'");
		telm.textNode("Holdleder: " + skema.hold_spillere[nr-1].holdleder+ " tlf.: "+ skema.hold_spillere[nr-1].holdleder_tlf,this.td);
		this.td = telm.element("td",this.tr,"class='hold_info2'");
		naf++;
	}
		this.tr = telm.element("tr",this.tBody);
		if ((naf/2)==parseInt(naf/2)) this.tr.className = 'tab_rakke0'; else this.tr.className = 'tab_rakke1';
		this.td = telm.element("td",this.tr,"class='hold_info1'");
		this.td.colSpan = 3 
		telm.textNode(" " ,this.td);
		naf++;
		  
		this.tr = telm.element("tr",this.tBody);
		this.td = telm.element("td",this.tr,"class='tab_note2'");
		this.td.colSpan = 3 
		telm.textNode("Klubinformation for " + skema.klub_info[nr-1].navn ,this.td);
		naf++;
		  
		this.tr = telm.element("tr",this.tBody);
		this.tr.className = 'tab_rakke0';
		this.td = telm.element("td",this.tr,"class='hold_info1'");
		this.td.colSpan = 3 
		telm.textNode("Spillested: " + skema.klub_info[nr-1].sted,this.td);
		naf++;
		  
		this.tr = telm.element("tr",this.tBody);
		this.tr.className = 'tab_rakke0';
		this.td = telm.element("td",this.tr,"class='hold_info1'");
		this.td.colSpan = 3 
		telm.textNode("Adresse: " + skema.klub_info[nr-1].adresse + ", " + skema.klub_info[nr-1].byen,this.td);
		naf++;
		  
		this.tr = telm.element("tr",this.tBody);
		this.tr.className = 'tab_rakke0';
		this.td = telm.element("td",this.tr,"class='hold_info1'");
		this.td.colSpan = 3 
		telm.textNode("Klubaften: " + skema.klub_info[nr-1].klubaften,this.td);
		naf++;
		  
		this.tr = telm.element("tr",this.tBody);
		this.tr.className = 'tab_rakke0';
		this.td = telm.element("td",this.tr,"class='hold_info1'");
		this.td.colSpan = 3 
		telm.textNode("Hjemmeside: ",this.td);
		if (skema.klub_info[nr-1].web)
		{
			this.A= telm.element("a",this.td,"href='http://"+skema.klub_info[nr-1].web+"'","target='_blank'");
			telm.textNode(skema.klub_info[nr-1].web,this.A);
		}
		naf++;
		  
		this.tr = telm.element("tr",this.tBody);
		this.tr.className = 'tab_rakke0';
		this.td = telm.element("td",this.tr,"class='hold_info1'");
		this.td.colSpan = 3 
		telm.textNode("Formand: " + skema.klub_info[nr-1].formand_navn,this.td);
		naf++;
		  
		this.tr = telm.element("tr",this.tBody);
		this.tr.className = 'tab_rakke0';
		this.td = telm.element("td",this.tr,"class='hold_info1'");
		this.td.colSpan = 3 
		telm.textNode("Adresse: " + skema.klub_info[nr-1].formand_adresse + ", " + skema.klub_info[nr-1].formand_post_nr + " " + skema.klub_info[nr-1].formand_bynavn,this.td);
		naf++;
		  
		this.tr = telm.element("tr",this.tBody);
		this.tr.className = 'tab_rakke0';
		this.td = telm.element("td",this.tr,"class='hold_info1'");
		this.td.colSpan = 3 
		telm.textNode("Tlf.: " + skema.klub_info[nr-1].formand_tlf,this.td);
		naf++;
		  
		this.tr = telm.element("tr",this.tBody);
		this.tr.className = 'tab_rakke0';
		this.td = telm.element("td",this.tr,"class='hold_info1'");
		this.td.colSpan = 3 
		telm.textNode("E-mail: ",this.td);
		if (skema.klub_info[nr-1].formand_email)
		{
			this.A= telm.element("a",this.td,"href='mailto:"+skema.klub_info[nr-1].formand_email+"'","target='_blank'");
			telm.textNode(skema.klub_info[nr-1].formand_email,this.A);
		}
		naf++;
		if (Obj.noPrinter) Obj.Create_Styrkeliste(Obj,nr);	  
		if (Obj.noPrinter) 
		{
	 		document.getElementById("cms_krop").style.height=""; 
	  	testheight();
		}
		if (!Obj.noPrinter) setTimeout(prePrint, 100); 
}

vis_skema.prototype.Create_Styrkeliste = function(Obj,nr)
{
	this.br = telm.element("br",Obj.Klub_Info_Cont);
	this.StyrkelisteForm = telm.element("form",Obj.Klub_Info_Cont,"method='POST'","action='javascript: void(0);'","name='Klub_Info_Form'");
	this.sTable = telm.element("table",this.StyrkelisteForm,"class='holdskak'");
	this.tBody = telm.element("tbody",this.sTable,"bordercolor='#000000'");
	this.tr = telm.element("tr",this.tBody,"class='tab_rakke0'");
	this.td = telm.element("td",this.tr,"class='tab_note2'");
	this.td.colSpan = 3 
	telm.textNode("Styrkeliste for " + skema.hold[nr-1].hold_navn,this.td);

	this.td = telm.element("td",this.tr,"align='right'","class='tab_note2'");
	if (Obj.noPrinter)	this.A = telm.element("a",this.td,"href='JavaScript: skema.Print(3,"+nr+")'","style='float: right;'");
	if (Obj.noPrinter)	this.printer = telm.element("img",this.A,"src='modul/holdskak/images/print.gif'","alt='Print skema'","style='border: none;'");

	this.tr = telm.element("tr",this.tBody,"class='tab_rakke1'");
		this.td = telm.element("td",this.tr,"class='tab_nummer'");
		telm.textNode("Nr.",this.td);
	  
		this.td = telm.element("td",this.tr,"class='hold_info1'");
		telm.textNode("Navn",this.td);
	  
		this.td = telm.element("td",this.tr,"class='hold_info2'");
		telm.textNode("Hold",this.td);

		this.td = telm.element("td",this.tr,"class='hold_info2'");
		telm.textNode("Rating",this.td);

	  this.rating=0;
	for (naf=0; naf<skema.styrkeliste[nr-1].id.length; naf++)
	{
		this.tr = telm.element("tr",this.tBody);
		if ((naf/2)==parseInt(naf/2)) this.tr.className = 'tab_rakke0'; else this.tr.className = 'tab_rakke1';

		this.td = telm.element("td",this.tr,"class='tab_nummer'");
		telm.textNode(skema.styrkeliste[nr-1].nr[naf],this.td);
	  
		this.td = telm.element("td",this.tr,"class='hold_info1'");

	  if (skema.styrkeliste[nr-1].id[naf] == skema.hold_spillere[nr-1].holdlederId){
		  this.ekstraText = " (holdleder) tlf.: " + skema.hold_spillere[nr-1].holdleder_tlf;
		}
		else this.ekstraText = "";

		if (skema.hold[nr-1].hold_nr == skema.styrkeliste[nr-1].hold_nr[naf])
		{
			this.B = telm.element("b",this.td);
			telm.textNode(skema.styrkeliste[nr-1].navn[naf] + this.ekstraText,this.B);
		}
		else 
		{
			telm.textNode(skema.styrkeliste[nr-1].navn[naf] + this.ekstraText,this.td);
		}

		this.td = telm.element("td",this.tr,"class='hold_info2'");
		telm.textNode(skema.styrkeliste[nr-1].hold_nr[naf],this.td);
	  
		this.td = telm.element("td",this.tr,"class='hold_info2'");
		telm.textNode(skema.styrkeliste[nr-1].rating[naf],this.td);
	}

	if (!Obj.noPrinter) setTimeout(prePrint, 100); 

	if (Obj.noPrinter) 
	{
 		document.getElementById("cms_krop").style.height=""; 
  	testheight();
	}
  
}
