var gbLoggedIn = false;

function TABdisplayAll(ctl,bAllInit)
{
	var tbActive = document.getElementById("tbActive");
	var tbPending = document.getElementById("tbPending");
	var tbSold = document.getElementById("tbSold");
	if (ctl && ctl.className == "tab1") return;
	TABactivate(ctl);
	if (!bAllInit) {
		TABinsertTable(tbActive, 0, true);
		TABinsertTable(tbPending, 1, true);
		TABinsertTable(tbSold, 2, true);
	}
	var aTables = new Array(tbActive, tbPending, tbSold);
	for (var i = 0; i < aTables.length; i++) {
		var tbl = aTables[i]; if (!tbl) continue;
		tbl.style.display = "";
		tbl.rows[0].style.display = "";
	}
	var trOpts = document.getElementById("trOpts");
	if (trOpts) trOpts.style.display = "none";
	document.getElementById("trAll").style.display = "";
}

function TABactivate(ctl)
{
	if (!ctl) return;
	var trTabs = document.getElementById("trTabs");
	var tab = trTabs.firstChild;
	while (tab) {
		tab.className = (tab==ctl ? "tab1" : "tab0");
		tab = tab.nextSibling;
	}
}

function TABinsertTable(tbl, n, all) 
{
	if (n == 2) {
		Heads = new Array("Address", "Zip", "SP", "BR", "BA", "ESF", "SP/ESF", "Built", "Closed");
	} else {
		Heads = new Array("Address", "Zip", "LP", "BR", "BA", "ESF", "LP/ESF", "Built", "OMD");
	}
	// var i, j, k, len, len2, arr, row, cell;
	if (!tbl) return;
	var len = tbl.rows.length;
	if (len == 1) {
		var row = tbl.insertRow(-1);
		var lrc = Heads.length-(n==0?1:0);
		for (var i = 0; i < lrc; i++) {
			var cell = row.insertCell(-1);
			cell.className = "head2";
			cell.innerHTML = Heads[i];
			if (all) cell.style.borderTop = "1px solid";
		}
		len++;
	}
	var DataN = Data[n];
	if (DataN.length > len-2) {
		var len = DataN.length-(len-2), lrc = DataN[0] ? DataN[0].length : 0;
		do {
			var row = tbl.insertRow(-1);
			for (var i = 0; i < lrc; i++) {
				var cell = row.insertCell(-1);
				cell.className = (i==lrc-1 ? "" : "bod");
			}
		} while(--len);
	}	
	var len = DataN.length;
	if (all) {
		if (!gbLoggedIn) {
			tbl.rows[0].cells[0].innerHTML = (len ? "" : 
				"You need to be logged in to see the properties. <a href=\"javascript:HomeEvalLogin()\">Login here</a>.");
		} else {
			tbl.rows[0].cells[0].innerHTML = (len ? "" : "No ")+HeadNs[n]+" Properties";
		}
		tbl.rows[1].style.display = (len ? "" : "none");
	} else {
		tbl.rows[0].style.display = (len ? "" : "none");
		tbl.rows[1].style.display = (len ? "" : "none");
	}
	if (len) {		
		for (var row = tbl.rows[2], i = 0; i < len; i++) {
			row.style.display = "";
			var cell = row.cells[0];
			for (var j = 0, arr = DataN[i], lrc = arr.length;  j < lrc; j++) {
				cell.innerHTML = arr[j];
				cell = cell.nextSibling;
			}
			row = row.nextSibling;
		}
		i += 2; 
		for (var len = tbl.rows.length; i < len; i++) {
			row.style.display = "none";
			row = row.nextSibling;
		}
	} else 
	if ((len=tbl.rows.length)>2) {
		for (var i = 2, row = tbl.rows[1]; i < len; i++) {
			row.style.display = "none";
			row = row.nextSibling;
		}
	}
}

function TABdisplayStats(ctl, n) 
{
	var tbActive = document.getElementById("tbActive");
	var tbPending = document.getElementById("tbPending");
	var tbSold = document.getElementById("tbSold");
	if (ctl.className == "tab1") return;
	TABactivate(ctl);
	var aTables = new Array(tbActive, tbPending, tbSold);
	for (var i = 0; i < aTables.length; i++) {
		var tbl = aTables[i]; if (!tbl) continue;
		tbl.style.display = (n==i?"":"none");
		if (tbl.rows.length > 2) tbl.rows[0].style.display = "none";
	}
	var trOpts = document.getElementById("trOpts");
	if (trOpts) trOpts.style.display = "none";
	document.getElementById("trAll").style.display = "";
}

function TABdisplayOpts(ctl)
{
	if (ctl.className == "tab1") return;
	TABactivate(ctl);
	document.getElementById("trAll").style.display = "none";
	var trOpts = document.getElementById("trOpts");
	if (trOpts) trOpts.style.display="";
}

function TABrChange(ctl)
{
	spnSize.style.display = (ctl.value=="0" ? "none" : "inline");
}

