var content = "";

function pTableTourn()
{
  return '<table cellspacing="0" cellpadding="0" border="0px" width="738px">';
}
function pTableTournLT()
{
  return '<td class="tournam-left-top">';
}
function pTableTournT()
{
  return '<td class="tournam-top">';
}
function pTableTournRT()
{
  return '<td class="tournam-right-top">';
}
function pTableTournL()
{
  return '<td class="tournam-left">';
}
function pTableTournS()
{
  return '<td style="background-color: #d0d0d0;">';
}

function pTableTournR()
{
  return '<td class="tournam-right">';
}
function pTableTournLB()
{
  return '<td class="tournam-left-bottom">';
}
function pTableTournB()
{
  return '<td class="tournam-bottom">';
}
function pTableTournRB()
{
  return '<td class="tournam-right-bottom">';
}

function pTableO(padding, spacing, bclass)
{
  return '<table cellpadding='+ padding +' cellspacing='+ spacing +' class='+ bclass +'>';
}
function pTableC()
{
  return '</table>';
}

function pTrO()
{
  return '<tr>';
}
function pTrC()
{
  return '</tr>';
}
function pTdO()
{
  return '<td>';
}
function pTdC()
{
  return '</td>';
}
	
function strAdd(msg)
{
  return content += '\n' + msg;
}

function tableTrTd(msg, cellspacing, cellpadding, bclass)
{
 strAdd(pTdO()); 
 strAdd(msg); 
 strAdd(pTdC()); 
 return content; 
}

function jsonLen(object)
{

 for(id in object){counter ++;}
 return counter; 
}

function diplayTur(id)
{
 var myvar = eval(id);
 strAdd(pTableTourn());
 strAdd(pTrO());
 strAdd(pTableTournLT());
 strAdd(pTdC());
 strAdd(pTableTournT());
 strAdd(pTdC());
 strAdd(pTableTournRT());
 strAdd(pTdC());
 strAdd(pTrC());
 strAdd(pTrO());
 strAdd(pTableTournL());
 strAdd(pTdC());
 strAdd(pTableTournS());
 //alert(jsonLen(id));
 
 strAdd(pTableO(0,0,'print-tour'));
 strAdd(pTrO());
 
for(did in myvar)
{
 
 if(myvar[did].value != "0" || myvar[did].value == "1") 
 {
 	if(myvar[did].value == "1")
 	{
 		myvar[did].value = 'Yes';
 	} 	
 	
  tableTrTd('<span class=font-tour-bold>' + myvar[did].name + '</span><span class=font-tour>:&nbsp;' + myvar[did].value,0,0,'print-tour' + '</span>');  
 }
 else
 {
 	tableTrTd(' ',0,0,'print-tour');
 }

 if(did == "3")
  {  	
   strAdd(pTrC());
   strAdd(pTrO());
   tableTrTd('',0,0,'print-tour');
  }
  if(did == "5")
  {	
  	strAdd(pTrC());
   strAdd(pTrO());
   tableTrTd('',0,0,'print-tour');
  }
  if(did == "7")
  {	
  	strAdd(pTrC());
   strAdd(pTrO());
   tableTrTd('',0,0,'print-tour');
  }
  if(did == "9")
  {	
  	strAdd(pTrC());
   strAdd(pTrO());
   tableTrTd('',0,0,'print-tour');
  }
}

 strAdd(pTrC());
 strAdd(pTableC());
 strAdd(pTdC());
 strAdd(pTableTournR());
 strAdd(pTdC());
 strAdd(pTrC());
 strAdd(pTrO());
 strAdd(pTableTournLB());
 strAdd(pTdC());
 strAdd(pTableTournB());
 strAdd(pTdC());
 strAdd(pTableTournRB());
 strAdd(pTdC()); 
 strAdd(pTrC());
 strAdd(pTableC());
document.getElementById('tur-view').innerHTML = content;
content = "";
 
}

function pTblBuy()
{
  return '<table cellspacing="0" cellpadding="0" width="110" border="0" id="BuyList">';
}

function pTblType()
{
  return '<table cellspacing="0" cellpadding="0" width="90" border="0" id="TypeList">';
}

function pTdType()
{
  return '<td class="tourn-left">';
}

function pTdRightType()
{
  return '<td class="tourn-right">';
}

function pTdCType()
{
  return '<td style="background-color: #f2f2f2;">';
}

function pTdTLBType()
{
  return '<td class="tourn-left-bottom-st">';
}

function pTdTBType()
{
  return '<td class="tourn-bottom">';
}

function pTdTRBType()
{
  return '<td class="tourn-right-bottom-st">';
}

function showSelectType(Tourtype)
{
	alert('showSelectType');
	var rows = document.getElementById('TournamentsList').getElementsByTagName('tbody')[0].getElementsByTagName('tr');
	for (i = 0; i < rows.length; i++)
	{	
		var inList = rows[i].getElementsByTagName('td')[2].innerHTML;			
		if(inList != Tourtype)
		{
			rows[i].removeNode(true);
		}
	}
}

function displayType()
{
	strAdd(pTblType());
		
	var rows = document.getElementById('TournamentsList').getElementsByTagName('tbody')[0].getElementsByTagName('tr');
		
	if (rows.length > 0)
	{
		var Typelist = new Array();
		
		strAdd(pTrO());
		strAdd(pTdType());
		strAdd(pTdC());
		strAdd(pTdCType());	
		
		Typelist[0] = rows[0].getElementsByTagName('td')[2].innerHTML;
		
		strAdd('<div class="tourn-select-link" onclick="showSelectType('+ Typelist[0] +')">' + Typelist[0] + '</div>');	
		strAdd(pTdC());	
		strAdd(pTdRightType());	
		strAdd(pTdC());
		strAdd(pTrC());	
		
		for (i = 1; i < rows.length; i++)
		{	
			var inList = rows[i].getElementsByTagName('td')[2].innerHTML;
			var faund = new Boolean(false);
			
			for(j = 0; j < Typelist.length; j++)
			{				
				if(inList == Typelist[j])
				{
					faund = true;							
				}
			}
			if(faund == false)
			{
				strAdd(pTrO());
				strAdd(pTdType());
				strAdd(pTdC());
				strAdd(pTdCType());
				strAdd('<div class="tourn-select-link" onclick="showSelectType('+ inList +')">' + inList + '</div>');	
				strAdd(pTdC());	
				strAdd(pTdRightType());	
				strAdd(pTdC());
				strAdd(pTrC());
			
				Typelist[Typelist.length] = inList;
			}
		}	
	}
	
	strAdd(pTrO());	
	strAdd(pTdTLBType());
	strAdd(pTdC());
	strAdd(pTdTBType());
	strAdd(pTdC());
	strAdd(pTdTRBType());
	strAdd(pTdC());
	strAdd(pTrC());
	strAdd(pTableC());
	
	document.getElementById('type-selector-tbl').innerHTML = content;
	content = "";	
}

function displayBuy()
{
	strAdd(pTblBuy());
	
	var rows = document.getElementById('TournamentsList').getElementsByTagName('tbody')[0].getElementsByTagName('tr');
		
	if (rows.length > 0)
	{
		var Typelist = new Array();
		
		strAdd(pTrO());
		strAdd(pTdType());
		strAdd(pTdC());
		strAdd(pTdCType());	
		
		Typelist[0] = rows[0].getElementsByTagName('td')[4].innerHTML;
		
		strAdd('<div class="tourn-select-link" onclick="ShowSelect('+ Typelist[0] +')">' + Typelist[0] + '</div>');	
		strAdd(pTdC());	
		strAdd(pTdRightType());	
		strAdd(pTdC());
		strAdd(pTrC());	
		
		for (i = 1; i < rows.length; i++)
		{	
			var inList = rows[i].getElementsByTagName('td')[4].innerHTML;
			var faund = new Boolean(false);
			
			for(j = 0; j < Typelist.length; j++)
			{				
				if(inList == Typelist[j])
				{
					faund = true;							
				}
			}
			if(faund == false)
			{
				strAdd(pTrO());
				strAdd(pTdType());
				strAdd(pTdC());
				strAdd(pTdCType());
				strAdd('<div class="tourn-select-link" onclick="ShowSelect('+ inList +')">' + inList + '</div>');	
				strAdd(pTdC());	
				strAdd(pTdRightType());	
				strAdd(pTdC());
				strAdd(pTrC());
			
				Typelist[Typelist.length] = inList;
			}
		}	
	}
	
	strAdd(pTrO());
	strAdd(pTdTLBType());
	strAdd(pTdC());
	strAdd(pTdTBType());
	strAdd(pTdC());
	strAdd(pTdTRBType());
	strAdd(pTdC());
	strAdd(pTrC());
	strAdd(pTableC());	
	document.getElementById('buy-selector-tbl').innerHTML = content;
	content = "";	
}

function	hideT(id)
{   
   document.getElementById(id).style.display="none";    
}
function showT(id)
{ 
   document.getElementById(id).style.display="block";   
   displayType(); 
}
function	hideB(id)
{   
   document.getElementById(id).style.display="none";     
}

function showB(id)
{ 
   document.getElementById(id).style.display="block";
   //alert(id);   
   displayBuy(); 
}

// filter 

function filterb(term, _id, cellNr){
	var suche = term.value.toLowerCase();
	var table = document.getElementById(_id);
//alert(table.rows[0].innerHTML);
	var ele;
	for (var r = 0; r < table.rows.length; r++){
		ele = table.rows[r].cells[cellNr].innerHTML.replace(/<[^>]+>/g,"");
		if (ele.toLowerCase().indexOf(suche)>=0 )
			table.rows[r].style.display = '';
		else table.rows[r].style.display = 'none';
	}
}

function BinPlus(msg)
{

	document.getElementById('my-search').typeb.value++;
	filterb(document.getElementById('my-search').typeb, 'TournamentsList', 4);
    	
}
function BinMinus(msg)
{
	if(document.getElementById('my-search').typeb.value > 0)
	{
	document.getElementById('my-search').typeb.value--;
	filterb(document.getElementById('my-search').typeb, 'TournamentsList', 4);      
   } 
}

function showMeN()
{
 document.getElementById('menmen').style.display = "block";
}
   


