function showContent(vThis)
{
// http://www.javascriptjunkie.com
// alert(vSibling.className + " " + vDef_Key);
vParent = vThis.parentNode;
vSibling = vParent.nextSibling;
while (vSibling.nodeType==3) { // Fix for Mozilla/FireFox Empty Space becomes a TextNode or Something
vSibling = vSibling.nextSibling;
}
if(vSibling.style.display == "none")
{
vThis.src="/images/collapse.gif";
vThis.alt = "Hide Div";
vSibling.style.display = "block";
} else {
vSibling.style.display = "none";
vThis.src="/images/expand.gif";
vThis.alt = "Show Div";
}
return;
}

function returnObjById( id ) 
{ 
    if (document.getElementById) 
        var returnVar = document.getElementById(id); 
    else if (document.all) 
        var returnVar = document.all[id]; 
    else if (document.layers) 
        var returnVar = document.layers[id]; 
    return returnVar; 
}

function changeClass(id,classname) {
var item = returnObjById(id);
item.setAttribute("class",classname);
item.setAttribute("className",classname);
}

function changeBackground(id,bgimage) {
var item = returnObjById(id);
var item2 = returnObjById(id+"2");
item.setAttribute("background","../images/"+bgimage);
item.setAttribute("backgroundImage","../images/"+bgimage);
item2.setAttribute("background","../images/"+bgimage);
item2.setAttribute("backgroundImage","../images/"+bgimage);
}

function changeContent(id,content) {
var item = returnObjById(id);
if (content=='')
{
	item.style.display = "none";
	if (id.substr(0,2)=='eb')
	{
		loop=id.substr(2);
		returnObjById("expimg"+loop).style.display = "none";
	}
}
else
{
	item.style.display = "inline";
	if (id.substr(0,2)=='eb')
	{
		loop=id.substr(2);
		returnObjById("expimg"+loop).style.display = "inline";
	}
}
item.innerHTML = content;
}

function changeItem(loop) {
var item1 = returnObjById("ibox1"+loop);
var item2 = returnObjById("ibox2"+loop);
var item3 = returnObjById("ibox3"+loop);
item1.style.display = "none";
item2.style.display = "none";
item3.style.display = "none";
var typebox = returnObjById("itemtype"+loop);
var posbox = returnObjById("itempos"+loop);
var namebox = returnObjById("item"+loop);
var type = typebox.value;
var itempos = posbox.value;
var itemname = namebox.value;
var item = returnObjById("ibox"+itempos+loop);
if (itempos != "0")
{
	item.style.display = "block";
	item.innerHTML = jsCreateItem(type,itemname);
}
}

function changeItem2(loop) {
var item = returnObjById("ibox"+loop);
var typebox = returnObjById("itemtype"+loop);
var namebox = returnObjById("item"+loop);
var type = typebox.value;
var itemname = namebox.value;
item.innerHTML = jsCreateItem(type,itemname);
}

function changeItem3(row,cell) {
var item = returnObjById("r"+row+"c"+cell);
var typebox = returnObjById("itemtype"+"r"+row+"c"+cell);
var namebox = returnObjById("item"+"r"+row+"c"+cell);
var type = typebox.value;
var itemname = namebox.value;
item.innerHTML = jsCreateItem(type,itemname);
}

function changeState(state) {
if (state.substr(0,4)=='out:') {
window.location=state.substr(4);
} else {
var item = returnObjById("statebox");
item.innerHTML = jsCreateItem("state",state);
}
}

function Inint_AJAX() {
try { return new ActiveXObject("Msxml2.XMLHTTP");  } catch(e) {} //IE
try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) {} //IE
try { return new XMLHttpRequest();          } catch(e) {} //Native Javascript
alert("XMLHttpRequest not supported");
return null;
}

function jsBrand(string) {
var req = Inint_AJAX();
req.open("POST", "../items/jsbrand.php",false); //make connection
req.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
var encoded = "";
encoded = "string=" + string;
req.send(encoded);
if (req.status != 200) {
  alert("There was a communications error: " +
    req.responseText);
  return;
} else {
	return req.responseText;
}
}

function jsCreateItem(type,item) {
var req = Inint_AJAX();
req.open("POST", "../items/jscreateitem.php",false); //make connection
req.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
var encoded = "";
encoded = "item=" + item + "&type=" + type;
req.send(encoded);
if (req.status != 200) {
  alert("There was a communications error: " +
    req.responseText);
  return;
} else {
	return req.responseText;
}
}

  function addRow(id,col1,col2,rowid){
    var tbody = document.getElementById
(id).getElementsByTagName("TBODY")[0];
    var row = document.createElement("TR")
    var td1 = document.createElement("TD")
    td1.appendChild(document.createTextNode(col1))
    var td2 = document.createElement("TD")
    td2.appendChild (document.createTextNode(col2))
    row.appendChild(td1);
    row.appendChild(td2);
    tbody.appendChild(row);
	row.id = rowid;
	changeClass(rowid,'black-normal-txt');
	td1.innerHTML=col1;
	td2.innerHTML=col2;
  }

var numGames=new Array();
numGames[1]=1;
numMonths=1;

function newGame(month) {
var item = returnObjById("m"+month+"games");
numGames[month]++;
item.innerHTML+="<span id='m"+month+"g"+numGames[month]+"'><br><br><select name='bigblindm"+month+"[]' class='black-normal-txt' id='bigblindm"+month+"g"+numGames[month]+"'><option value=''>Select the betting structure</option><option value='NL/0.04'>NL $0.02/0.04</option><option value='NL/0.10'>NL $0.05/0.10</option><option value='FL/0.10'>FL $0.10/0.20</option><option value='NL/0.20'>NL $0.10/0.20</option><option value='FL/0.25'>FL $0.25/0.50</option><option value='NL/0.50'>NL $0.25/0.50</option><option value='FL/0.50'>FL $0.50/1.00</option><option value='NL/1.00'>NL $0.50/1.00</option><option value='FL/1.00'>FL $1.00/2.00</option><option value='NL/2.00'>NL $1.00/2.00</option><option value='FL/2.00'>FL $2.00/4.00</option><option value='FL/3.00'>FL $3.00/6.00</option><option value='NL/4.00'>NL $2.00/4.00</option><option value='FL/5.00'>FL $5.00/10.00</option><option value='NL/6.00'>NL $3.00/6.00</option><option value='NL/10.00'>NL $5.00/10.00</option><option value='FL/10.00'>FL $10.00/20.00</option><option value='NL/20.00'>NL $10.00/20.00</option><option value='FL/20.00'>FL $20.00/40.00</option><option value='FL/30.00'>FL $30.00/60.00</option><option value='NL/50.00'>NL $25.00/50.00</option><option value='FL/50.00'>FL $50.00/100.00</option></select><br><select name='tablem"+month+"[]' class='black-normal-txt' id='tablem"+month+"g"+numGames[month]+"'><option value=''>Select the table type</option><option value='6max'>Short Handed (6max)</option><option value='10max'>Full Ring (10max)</option><option value='hu'>Heads Up (2max)</option></select><br>Number of hands: <input type='text' name='handsm"+month+"[]' class='black-normal-txt' value='0' id='handsm"+month+"g"+numGames[month]+"'></span>";
}

function createMonth(month) {
var item = returnObjById("months");
var col1 = "<span id='month"+month+"'><b>Month "+month+":</b><br><span id='m"+month+"games'><span id='m"+month+"g1'><select name='bigblindm"+month+"[]' class='black-normal-txt' id='bigblindm"+month+"g1'><option value=''>Select the betting structure</option><option value='NL/0.04'>NL $0.02/0.04</option><option value='NL/0.10'>NL $0.05/0.10</option><option value='FL/0.10'>FL $0.10/0.20</option><option value='NL/0.20'>NL $0.10/0.20</option><option value='FL/0.25'>FL $0.25/0.50</option><option value='NL/0.50'>NL $0.25/0.50</option><option value='FL/0.50'>FL $0.50/1.00</option><option value='NL/1.00'>NL $0.50/1.00</option><option value='FL/1.00'>FL $1.00/2.00</option><option value='NL/2.00'>NL $1.00/2.00</option><option value='FL/2.00'>FL $2.00/4.00</option><option value='FL/3.00'>FL $3.00/6.00</option><option value='NL/4.00'>NL $2.00/4.00</option><option value='FL/5.00'>FL $5.00/10.00</option><option value='NL/6.00'>NL $3.00/6.00</option><option value='NL/10.00'>NL $5.00/10.00</option><option value='FL/10.00'>FL $10.00/20.00</option><option value='NL/20.00'>NL $10.00/20.00</option><option value='FL/20.00'>FL $20.00/40.00</option><option value='FL/30.00'>FL $30.00/60.00</option><option value='NL/50.00'>NL $25.00/50.00</option><option value='FL/50.00'>FL $50.00/100.00</option></select><br><select name='tablem"+month+"[]' class='black-normal-txt' id='tablem"+month+"g1'><option value=''>Select the table type</option><option value='6max'>Short Handed (6max)</option><option value='10max'>Full Ring (10max)</option><option value='hu'>Heads Up (2max)</option></select><br>Number of hands: <input type='text' name='handsm"+month+"[]' class='black-normal-txt' value='0' id='handsm"+month+"g1'></span></span><br>Tournament fees: <input type='text' name='tfees[]' id='tfees"+month+"' class='black-normal-txt' value='0'></span>";
var col2 = "<a href='#' onclick='destroyGame("+month+"); return false'>Remove last game</a><br><a href='#' onclick='newGame("+month+"); return false'>Add a new game type</a><br><a href='#' onclick='fillMonths("+month+"); return false'>Fill future months with these settings</a>";
rowid="row"+month;
addRow('calctable',col1,col2,rowid);
//item.innerHTML+="<tr class='black-normal-txt' id='row"+month+"'><td align='left'><span id='month"+month+"'><b>Month "+month+":</b><br><span id='m"+month+"games'><span id='m"+month+"g1'><select name='bigblindm"+month+"[]' class='black-normal-txt' id='bigblindm"+month+"g1'><option value=''>Select the betting structure</option><option value='NL/0.02'>NL $0.01/0.02</option><option value='NL/0.04'>NL $0.02/0.04</option><option value='NL/0.10'>NL $0.05/0.10</option><option value='FL/0.10'>FL $0.10/0.20</option><option value='NL/0.20'>NL $0.10/0.20</option><option value='FL/0.25'>FL $0.25/0.50</option><option value='NL/0.50'>NL $0.25/0.50</option><option value='FL/0.50'>FL $0.50/1.00</option><option value='NL/1.00'>NL $0.50/1.00</option><option value='FL/1.00'>FL $1.00/2.00</option><option value='NL/2.00'>NL $1.00/2.00</option><option value='FL/2.00'>FL $2.00/4.00</option><option value='FL/3.00'>FL $3.00/6.00</option><option value='NL/4.00'>NL $2.00/4.00</option><option value='FL/5.00'>FL $5.00/10.00</option><option value='NL/6.00'>NL $3.00/6.00</option><option value='NL/10.00'>NL $5.00/10.00</option><option value='FL/10.00'>FL $10.00/20.00</option><option value='NL/20.00'>NL $10.00/20.00</option><option value='FL/20.00'>FL $20.00/40.00</option><option value='FL/30.00'>FL $30.00/60.00</option><option value='NL/50.00'>NL $25.00/50.00</option><option value='FL/50.00'>FL $50.00/100.00</option></select><br><select name='tablem"+month+"[]' class='black-normal-txt' id='tablem"+month+"g1'><option value=''>Select the table type</option><option value='6max'>Short Handed (6max)</option><option value='10max'>Full Ring (10max)</option><option value='hu'>Heads Up (2max)</option></select><br>Number of hands: <input type='text' name='handsm"+month+"[]' class='black-normal-txt' value='0' id='handsm"+month+"g1'></span></span><br>Tournament fees: <input type='text' name='tfees[]' id='tfees"+month+"' class='black-normal-txt' value='0'></span></td><td align='left'><a href='#' onclick='destroyGame("+month+"); return false'>Remove last game</a><br><a href='#' onclick='newGame("+month+"); return false'>Add a new game type</a><br><a href='#' onclick='fillMonths("+month+"); return false'>Fill future months with these settings</a></td></tr>";
numGames[month]=1;
}

function createMonthByPreset(month,games,bblabel,bigblind,table,hands,tfees) {
var item = returnObjById("months");
//var newhtml="<tr class='black-normal-txt' id='row"+month+"'><td align='left'><span id='month"+month+"'><b>Month "+month+":</b><br><span id='m"+month+"games'>";
var col1="<span id='month"+month+"'><b>Month "+month+":</b><br><span id='m"+month+"games'>";
var i=0;
while (i < games)
{
i++;
//newhtml+="<span id='m"+month+"g"+i+"'><select name='bigblindm"+month+"[]' class='black-normal-txt' id='bigblindm"+month+"g"+i+"'><option value='"+bigblind[i]+"'>"+bblabel[i]+"</option><option value=''>Select the betting structure</option><option value='NL/0.02'>NL $0.01/0.02</option><option value='NL/0.04'>NL $0.02/0.04</option><option value='NL/0.10'>NL $0.05/0.10</option><option value='FL/0.10'>FL $0.10/0.20</option><option value='NL/0.20'>NL $0.10/0.20</option><option value='FL/0.25'>FL $0.25/0.50</option><option value='NL/0.50'>NL $0.25/0.50</option><option value='FL/0.50'>FL $0.50/1.00</option><option value='NL/1.00'>NL $0.50/1.00</option><option value='FL/1.00'>FL $1.00/2.00</option><option value='NL/2.00'>NL $1.00/2.00</option><option value='FL/2.00'>FL $2.00/4.00</option><option value='FL/3.00'>FL $3.00/6.00</option><option value='NL/4.00'>NL $2.00/4.00</option><option value='FL/5.00'>FL $5.00/10.00</option><option value='NL/6.00'>NL $3.00/6.00</option><option value='NL/10.00'>NL $5.00/10.00</option><option value='FL/10.00'>FL $10.00/20.00</option><option value='NL/20.00'>NL $10.00/20.00</option><option value='FL/20.00'>FL $20.00/40.00</option><option value='FL/30.00'>FL $30.00/60.00</option><option value='NL/50.00'>NL $25.00/50.00</option><option value='FL/50.00'>FL $50.00/100.00</option></select><br><select name='tablem"+month+"[]' class='black-normal-txt' id='tablem"+month+"g"+i+"'><option value='"+table[i]+"'>"+table[i]+"</option><option value=''>Select the table type</option><option value='6max'>Short Handed (6max)</option><option value='10max'>Full Ring (10max)</option><option value='hu'>Heads Up (2max)</option></select><br>Number of hands: <input type='text' name='handsm"+month+"[]' class='black-normal-txt' value='"+hands[i]+"' id='handsm"+month+"g"+i+"'><br><br></span>";
col1+="<span id='m"+month+"g"+i+"'><select name='bigblindm"+month+"[]' class='black-normal-txt' id='bigblindm"+month+"g"+i+"'><option value='"+bigblind[i]+"'>"+bblabel[i]+"</option><option value=''>Select the betting structure</option><option value='NL/0.04'>NL $0.02/0.04</option><option value='NL/0.10'>NL $0.05/0.10</option><option value='FL/0.10'>FL $0.10/0.20</option><option value='NL/0.20'>NL $0.10/0.20</option><option value='FL/0.25'>FL $0.25/0.50</option><option value='NL/0.50'>NL $0.25/0.50</option><option value='FL/0.50'>FL $0.50/1.00</option><option value='NL/1.00'>NL $0.50/1.00</option><option value='FL/1.00'>FL $1.00/2.00</option><option value='NL/2.00'>NL $1.00/2.00</option><option value='FL/2.00'>FL $2.00/4.00</option><option value='FL/3.00'>FL $3.00/6.00</option><option value='NL/4.00'>NL $2.00/4.00</option><option value='FL/5.00'>FL $5.00/10.00</option><option value='NL/6.00'>NL $3.00/6.00</option><option value='NL/10.00'>NL $5.00/10.00</option><option value='FL/10.00'>FL $10.00/20.00</option><option value='NL/20.00'>NL $10.00/20.00</option><option value='FL/20.00'>FL $20.00/40.00</option><option value='FL/30.00'>FL $30.00/60.00</option><option value='NL/50.00'>NL $25.00/50.00</option><option value='FL/50.00'>FL $50.00/100.00</option></select><br><select name='tablem"+month+"[]' class='black-normal-txt' id='tablem"+month+"g"+i+"'><option value='"+table[i]+"'>"+table[i]+"</option><option value=''>Select the table type</option><option value='6max'>Short Handed (6max)</option><option value='10max'>Full Ring (10max)</option><option value='hu'>Heads Up (2max)</option></select><br>Number of hands: <input type='text' name='handsm"+month+"[]' class='black-normal-txt' value='"+hands[i]+"' id='handsm"+month+"g"+i+"'><br><br></span>";
}
//newhtml+="</span><br>Tournament fees: <input type='text' name='tfees[]' id='tfees"+month+"' class='black-normal-txt' value='"+tfees+"'></span></td><td align='left'><a href='#' onclick='destroyGame("+month+")'>Remove last game</a><br><a href='#' onclick='newGame("+month+"); return false'>Add a new game type</a><br><a href='#' onclick='fillMonths("+month+"); return false'>Fill future months with these settings</a></td></tr>";
col1+="</span><br>Tournament fees: <input type='text' name='tfees[]' id='tfees"+month+"' class='black-normal-txt' value='"+tfees+"'></span>";
col2="<a href='#' onclick='destroyGame("+month+")'>Remove last game</a><br><a href='#' onclick='newGame("+month+"); return false'>Add a new game type</a><br><a href='#' onclick='fillMonths("+month+"); return false'>Fill future months with these settings</a>"
//item.innerHTML+=newhtml;
rowid="row"+month;
addRow('calctable',col1,col2,rowid);
numGames[month]=games;
}

function destroyMonth(month) {
var item = returnObjById("row"+month);
item.parentNode.removeChild(item);
}

function changeMonths(num) {
if (num > numMonths)
{
	while (num > numMonths)
	{
		numMonths++;
		createMonth(numMonths);
	}
} else if (num < numMonths) {
	while (num < numMonths)
	{
		destroyMonth(numMonths);
		numMonths--;
	}
}
}

function destroyGame(month) {
var item = returnObjById("m"+month+"g"+numGames[month]);
numGames[month]--;
item.parentNode.removeChild(item);
}

function fillMonths(month) {
var bblabel = new Array();
var bigblind = new Array();
var table = new Array();
var hands = new Array();
var bbarr = new Array();
var seltfees = returnObjById("tfees"+month);
var tfees = seltfees.value;
var i=0;
while (i < numGames[month])
{
i++;
var selbigblind = returnObjById("bigblindm"+month+"g"+i);
var seltable = returnObjById("tablem"+month+"g"+i);
var selhands = returnObjById("handsm"+month+"g"+i);
bigblind[i] = selbigblind.value;
table[i] = seltable.value;
hands[i] = selhands.value;
bbarr = bigblind[i].split("/");
if (bbarr[0]=="NL") {
var sb=bbarr[1]/2;
bblabel[i]="NL $"+sb+"/"+bbarr[1];
} else {
var bigbet=bbarr[1]*2;
bblabel[i]="FL $"+bbarr[1]+"/"+bigbet;
}
}
i = month;
while (i <= numMonths)
{
destroyMonth(i);
i++;
}
i = month;
while (i <= numMonths)
{
createMonthByPreset(i,numGames[month],bblabel,bigblind,table,hands,tfees);
i++;
}
}

function openLog(site,month) {
var item = returnObjById("logs"+site+"m"+month);
item.style.display = "";
}

function closeLog(site,month) {
var item = returnObjById("logs"+site+"m"+month);
item.style.display = "none";
}

function addOrderCriterium() {
var item = returnObjById("orderbody");
item.innerHTML+="<tr class='black-normal-txt'><td><select name='order[]' class='black-normal-txt'><option value='ignore'>Select a category to sort by</option><option value='dealtype'>Deal type</option><option value='sitename'>Site name</option><option value='affiliate'>Affiliate</option><option value='networkid'>Network ID</option><option value='dealid'>Specific deal</option></select> <select name='ascdesc[]' class='black-normal-txt'><option value='ASC'>Ascending</option><option value='DESC'>Descending</option></select></td></tr>";
var table = document.getElementById('order');
var tableDnD = new TableDnD();
tableDnD.init(table);
}

function refillTable(oldcat,newcat,cellid) {
var item = returnObjById("orderspan"+oldcat);
item.parentNode.removeChild(item);
var cell = returnObjById("cell"+cellid);
cell.innerHTML+="<span id='orderspan"+newcat+"'><table id='ordertable"+newcat+"'><tr><td><select name='ordervalues"+newcat+"[]' class='black-normal-txt'><option value='ignore'>Select a value to sort by</option></select></td></tr></table><br><a href='#' onclick='addOrderValue("+newcat+")'>Add value to sort by</a></span>";
}

function addOrderValue(cat) {
var item = returnObjById("ordertable"+cat);
item.innerHTML+="<tr><td><select name='ordervalues"+cat+"[]' class='black-normal-txt'><option value='ignore'>Select a value to sort by</option></select></td></tr>";
}
