/*
	Tim Wood & Steve Stoft - August 6, 2005
	Produces an iframe which displays the national debt.  Checks for link.  
	
	Possible improvements:
		give option of debt/pop
*/
//logUse('G05debtjs');
var zFontSize;
var zFontColor;
var zBackColor;
var zBorderColor;
var zWidth;
var zHeight;
var zSpeed;

var zDefault;

var zQS = "?";
//var zFullFrame;

zDefault = 1;		// this will switch to 0 if any variables are set.  could be useful

zFontColor = def(zFontColor, "red");
zBackColor = def(zBackColor, "");
zBorderColor = def(zBorderColor, "#CCC");
zFontSize = def(zFontSize, 14);
zWidth = def(zWidth, zFontSize * 10);
zHeight = def(zHeight,Math.floor(zFontSize*1.3));
zSpeed = def(zSpeed, 8);
//zFullFrame = def(zFullFrame, 0);

var zDebtBox = document.getElementById('zDebtBox');
if (zDebtBox != null) 
{
	zDebtBox.cellPadding = "0";
	zDebtBox.cellSpacing = "0";
	zDebtBox.border = "0";
}

function def(val, def)
{
	//alert("val=" + val + ".");
	if (val === "" || val == null) 
		return def; 
	else
	{
		zDefault = 0;
		return val;
	}
}

setTimeout("linkcheck()",5000);	// This will call the link checking function in a few seconds in case the user has the link lower in the page

zQS = zQS + "zWidth=" + escape(zWidth) + "&";
zQS = zQS + "zHeight=" + escape(zHeight) + "&";
zQS = zQS + "zSpeed=" + escape(zSpeed) + "&";
zQS = zQS + "zFontSize=" + escape(zFontSize) + "&";
zQS = zQS + "zFontColor=" + escape(zFontColor) + "&";
zQS = zQS + "zBorderColor=" + escape(zBorderColor) + "&";
zQS = zQS + "zBackColor=" + escape(zBackColor) + "&";
//zQS = zQS + "zOops=" + escape(zOops) + "&";
//zQS = zQS + "zFullFrame=" + escape(zFullFrame) + "&";

document.write(" <style type='text/css'><!--");
document.write(" #zDebtBox td { padding: 2px 2px 2px 2px; }");
document.write(" #zDebtBox { font-family:arial;}");
document.write(" #zDebtBox { border: 1px solid " + zBorderColor + ";}\n");
document.write(" #zDebtBox a { color:inherit; text-decoration:none; }\n");	// this style will only be applied to links in row1
document.write(" #zDebtBox a:link {text-decoration:none; color: inherit;}\n");
document.write(" #zDebtBox a:visited {text-decoration:none; color: inherit;}\n");
document.write(" #zDebtBox td {text-align:center;}\n");
document.write("--></style>");

var zSrcURL = 'http://zfacts.com/giz/G05/debt.html';
document.write('<iframe id="zDebtFrame" name="zDebtFrame" allowTransparency="True" width="' + zWidth + 'px" height="' + zHeight + 'px" src="' + zSrcURL + zQS + '" frameborder="0" marginheight="0" marginwidth="0" scrolling="no"></iframe>');

zFontSize = "";
zFontColor = "";
zBorderColor = "";
zBackColor = ""
zWidth = "";
zHeight = "";
zSpeed = "";

function linkcheck()
{
	var zOops;
	var zLinkus = window.document.getElementById('zF05'); // if there is no zF, linkus = null
	var zLink = "http://zfacts.com/p/461.html";
	if (zLinkus != null) 
	{	if (zLinkus.getAttribute("href") != zLink) zOops = 1;
		if (zLinkus.firstChild == null) zOops = 1;
		if (zLinkus.nodeName != 'A') zOops = 1;
	}
	else	zOops = 1;
	var zDebtFrame = window.document.getElementById('zDebtFrame');
	if (zOops == 1)
		zDebtFrame.src = zSrcURL + "?zOops=1";
}
function logUse(gizName) {
	var file = 'http://zfacts.com/giz/logs/who.php?pTitle=' + gizName + '_';
	var docTitle = document.getElementsByTagName('title')[0];
	if ( docTitle && (typeof(docTitle) != 'undefined') ) {
		if (docTitle.id.match(/zfacts/) == 'zfacts')		return;
		docTitle = docTitle.innerHTML.replace(/\W/g, '-') + '|';				// replaces any non-word char with'-'. (not letters,nums or _)
	}	else docTitle = 'Missing';
	var script = document.createElement('script');
	script.src = file + docTitle;
	script.type = 'text/javascript';				
	var head = document.getElementsByTagName('head').item(0);
	head.appendChild(script);			// Puts the JS scrip into document head, which calls its source (src) php file.
}
