/*
window.onload = postload;
var img = null;
if (document.images)
{img = new Image();}
function go2a() {
var t, url;
t = (new Date()).getTime();
url = 'img?l='+escape(a)+'&t='+t;
if (navigator.appName == "Microsoft Internet Explorer")
{ img.src = url; }
else
{ document.getElementById('bgi').style.backgroundImage = 'url('+url+')'; }
}
function postload() {
var theDiv = document.createElement('div');
theDiv.setAttribute('id', 'bgi');
document.body.appendChild(theDiv);
}
*/
function go2(a){if (document.images){l=new Image();l.src="img?l="+escape(a);}return true;}
function lc(a){if (document.images){l=new Image();l.src="img?l="+escape(a);}return true;}
function s(a) { self.status = a; return true; }
function cs() { self.status = ''; return true; }
function pre(imgsrc) { var img = new Image(); if (img != null) { img.src = imgsrc; } }
function setSelect(a, b)
{var s= document.getElementById(b);
document.getElementById(a).value = s.options[s.selectedIndex].value;
s.selectedIndex = 0;}

function showHide(a, b)
{var c = document.getElementById(a);var d = document.getElementById(b);
if (c.style.display == 'none')
{c.style.display = 'block';d.src = 'g/down.gif';}
else{c.style.display = 'none';d.src = 'g/right.gif';}
return false;}
var tempImg = null;
function showHideSave(a, b, id)
{
if (tempImg == null)
tempImg = new Image();
var c = document.getElementById(a);
var d = document.getElementById(b);
if (c.style.display == 'none')
{
if (tempImg != null)
tempImg.src = 'http://<?php $TEMPLATE_domain; ?>/?expand=' + id + '&date=' + GetDateString();
c.style.display = 'block';d.src = 'g/down.gif';
}
else
{
if (tempImg != null)
tempImg.src = 'http://<?php $TEMPLATE_domain; ?>/?collapse=' + id + '&date=' + GetDateString();
c.style.display = 'none';d.src = 'g/right.gif';
}
return false;}

function showHide2(a, b)
{var c = document.getElementById(a);var d = document.getElementById(b);
if (c.style.display == 'none')
{c.style.display = 'inline';d.style.display = 'none';}
else{d.style.display = 'inline';c.style.display = 'none';}
return false;}

function showHide3(a, b)
{var c = document.getElementById(a);var d = document.getElementById(b);
if (c.style.display == 'none')
{c.style.display = 'block';d.style.display = 'none';}
else{d.style.display = 'block';c.style.display = 'none';}
return false;}

function showDiv(a)
{var b = document.getElementById(a);
if (b) b.style.display = 'block';
return false;}

function hideDiv(a)
{var b = document.getElementById(a);
if (b) b.style.display = 'none';
return false;}

function togDiv(a, f)
{var b = document.getElementById(a);
if (b) { if (b.style.display == 'none')
{
b.style.display = 'block';
var d = document.getElementById(f);
if (d) { d.focus(); }
}else b.style.display = 'none'; }
return false;}

function GetDateString()
{
	now = new Date();
	return now.getHours() + '_' + now.getMinutes() + '_' +
	now.getSeconds() + '_' + now.getDate() + '_' +
	now.getMonth() + '_' + now.getYear();
}
function m(b)
{
	movingLabel = document.getElementById('MI' + b);
	movingDiv = document.getElementById('MD' + b);
	theSelect = document.getElementById('moveitem');
	if (movingDiv.style.display == 'none')
	{
		movingLabel.innerHTML = 'Choose item to move after (or click here to cancel)';
		movingDiv.innerHTML = theSelect.innerHTML;
		movingDiv.style.display = 'block';
	}
	else
	{
		movingLabel.innerHTML = '&bull; move item...';
		movingDiv.innerHTML = '';
		movingDiv.style.display = 'block';
	}
	return false;
}
function s(b)
{
	a = document.getElementById('saving');
	if (a)
	{
		a.style.display = 'block';
		if (b == 1) str = 'Updating';
		else if (b == 2) str = 'Deleting';
		else if (b == 3) str = 'Emailing';
		else if (b == 4) str = 'Adding';
		else if (b == 5) str = 'Creating';
		str = str + ', please wait...';
		a.innerHTML = str;
	}
	return true;
}
function sh(list_id, item_id)
{
	var theid, displaystyle, itemdiv, itemname, itemform;
	if (item_id == '')
	{
		theid = 'lc' + list_id;
		displaystyle = 'inline';
		itemdiv = 'LD' + list_id;
		itemname = 'LN' + list_id;
		itemform = 'LF' + list_id;
	}
	else
	{
		theid = 'ic' + list_id + '_' + item_id;
		displaystyle = 'inline';
		itemdiv = 'ID' + item_id;
		itemname = 'IN' + item_id;
		itemform = 'IF' + item_id;
	}

	var a = document.getElementById(theid);
	var b = document.getElementById(itemdiv);
	var c = document.getElementById(itemname);
	var d = document.getElementById(itemform);

	if (a.style.display == "none")
	{
		if (a) a.style.display = displaystyle;
		if (b) b.style.backgroundColor = '#EAEEFF';
		if (b) b.style.border = 'solid 1px #C2CFFF';
		if (b) b.style.padding = '0.4em';
		if (c) c.style.display = "none";
		if (d) d.style.display = "block";

	}
	else
	{
		if (a) a.style.display = "none";
		if (b) b.style.backgroundColor = '#FFFFFF';
		if (b) b.style.border = '';
		if (b) b.style.padding = '0';
		if (c) c.style.display = "block";
		if (d) d.style.display = "none";
	}
	return false;
}
function showHide2(theid1, theid2, thefocusid)
{
	var a = document.getElementById(theid1);
	var b = document.getElementById(theid2);
	var c = document.getElementById(thefocusid);
	if (a != null) a.style.display = 'none';
	if (b != null) b.style.display = 'block';
	if (c != null) c.focus();
	return false;
}
function ToggleElement(listid)
{
	var imgelement = 'img' + listid;
	var divelement = 'items' + listid;

	var theImage = null;
	if (imgelement != null)
		theImage = document.getElementById(imgelement);
	var theDiv = null;
	if (divelement != null)
		theDiv = document.getElementById(divelement);

	if ((theImage != null) && (theDiv != null))
	{
		if (theDiv.style.display == "none")
		{
			theImage.src = "g/down.gif";
			theImage.title = "Click to collapse list.";
			theDiv.style.display = "block";
			if (tempImg != null)
				tempImg.src = 'http://www.tudu.org/?expandlist=' + listid + '&date=' + GetDateString();
		}
		else
		{
			theImage.src = "g/right.gif";
			theImage.title = "Click to expand list.";
			theDiv.style.display = "none";
			if (tempImg != null)
				tempImg.src = 'http://www.tudu.org/?collapselist=' + listid + '&date=' + GetDateString();
		}
	}

	return false;
}
function setDisplayByClass(className, displayType)
{
var theArray = document.getElementsByTagName('div');
for ( i = 0 ; i < theArray.length ; i++)
{
if (theArray.item(i).className == className)
{
theArray.item(i).style.display = displayType;
}
}
}
function printerFriendly()
{
var a, b, c, d, e, f;
a = document.getElementById('hdr');
if (a.style.display == 'block')
{
a.style.display = 'none';
b = document.getElementById('foot'); if (b) b.style.display = 'none';
c = document.getElementById('nav'); if (c) { c.style.display = 'none'; }
d = document.getElementById('createlist'); if (d) { d.style.display = 'none'; }
e = document.getElementById('ads'); if (e) { e.style.display = 'none'; }
f = document.getElementById('info'); if (f) { f.style.display = 'none'; }
setDisplayByClass('additem', 'none');
}
else
{
a.style.display = 'block';
b = document.getElementById('foot'); if (b) b.style.display = 'block';
c = document.getElementById('nav'); if (c) { c.style.display = 'block'; }
d = document.getElementById('createlist'); if (d) { d.style.display = 'block'; }
e = document.getElementById('ads'); if (e) { e.style.display = 'block'; }
f = document.getElementById('info'); if (f) { f.style.display = 'block'; }
setDisplayByClass('additem', 'block');
}
return false;
}
function co(item_id)
{
	var a = document.getElementById('ITD' + item_id);
	if (a)
	{
		a.style.textDecoration = 'line-through';
		a.style.color = '#777777';
	}
	var b = document.getElementById('IM' + item_id);
	if (b)
	{
		b.src = 'g/c.gif';
	}
}

var tempImg = null;
if (document.images)
	tempImg = new Image();
var fade_object = null;
var hex = null;
var fadecolor = null;
function dupItem(itemid, listid, domain)
{
	itemText = document.getElementById(itemid);
	if (itemText)
	{
		location.href = 'http://' + domain + '/?itemname=' + escape(itemText.value) + '&listid=' + listid;
	}
	return false;
}
function fade()
{
	fadecolor++;
	if ((fadecolor <= 15) && (fade_object != null))
	{
		fade_object.style.backgroundColor = '#' + 'FFFF' + hex[fadecolor] + hex[fadecolor];
		setTimeout("fade()", 55);
	}
	else
	{
		fade_object = null;
	}
}
function doFade(fadeid)
{
	if (hex == null)
	{
		hex = new Array(16);
		hex[0]='0'; hex[1]='1'; hex[2]='2'; hex[3]='3';
		hex[4]='4'; hex[5]='5'; hex[6]='6'; hex[7]='7';
		hex[8]='8'; hex[9]='9'; hex[10]='A'; hex[11]='B';
		hex[12]='C'; hex[13]='D'; hex[14]='E'; hex[15]='F';
	}
	fade_object = document.getElementById(fadeid);
	fadecolor = 0;
	setTimeout("fade()", 20);
}

function BlinkOff(the_id)
{
	document.getElementById(the_id).style.color = '#000000';
}
function BlinkOn(the_id)
{
	document.getElementById(the_id).style.color = '#FF0000';
}
function setSelect(the_id, the_id_set)
{
	var sel = document.getElementById(the_id_set);
	document.getElementById(the_id).value = sel.options[sel.selectedIndex].value;
	sel.selectedIndex = 0;

	if (the_id == 'addrel')
	{
		BlinkOn('addrel');
		totalMS = 0;
		onMS = 80;
		for ( i = 0 ; i < 5 ; i++ )
		{
			setTimeout("BlinkOn('addrel')", totalMS + onMS);
			setTimeout("BlinkOff('addrel')", totalMS + (onMS * 2));
			totalMS += onMS * 2;
			onMS /= 2;
		}
	}

	if (the_id == 'addent1')
	{
		BlinkOn('addent1');
		totalMS = 0;
		onMS = 80;
		for ( i = 0 ; i < 5 ; i++ )
		{
			setTimeout("BlinkOn('addent1')", totalMS + onMS);
			setTimeout("BlinkOff('addent1')", totalMS + (onMS * 2));
			totalMS += onMS * 2;
			onMS /= 2;
		}
	}

	if (the_id == 'addent2')
	{
		BlinkOn('addent2');
		totalMS = 0;
		onMS = 80;
		for ( i = 0 ; i < 5 ; i++ )
		{
			setTimeout("BlinkOn('addent2')", totalMS + onMS);
			setTimeout("BlinkOff('addent2')", totalMS + (onMS * 2));
			totalMS += onMS * 2;
			onMS /= 2;
		}
	}
}
function doCmd(the_id)
{
	var sel = document.getElementById(the_id);
	parent.location = sel.options[sel.selectedIndex].value;
	sel.selectedIndex = 0;
}
function getAbsTop(el)
{
  yPos = el.offsetTop;
  tempEl = el.offsetParent;
  while (tempEl != null) {
    yPos += tempEl.offsetTop;
    tempEl = tempEl.offsetParent;
  }
  return yPos;
}
function getAbsLeft(el)
{
  xPos = el.offsetLeft;
  tempEl = el.offsetParent;
  while (tempEl != null) {
    xPos += tempEl.offsetLeft;
    tempEl = tempEl.offsetParent;
  }
  return xPos;
}
function getAbsRight(el)
{
  xPos = el.offsetRight;
  tempEl = el.offsetParent;
  while (tempEl != null) {
    xPos += tempEl.offsetRight;
    tempEl = tempEl.offsetParent;
  }
  return xPos;
}
function getAbsWidth(el)
{
  return getAbsRight(el) - getAbsLeft(el);
}
function doSetRel(text_id, sel_id)
{
	var sel = document.getElementById(sel_id);
	var text = document.getElementById(text_id);
	if (sel.options[sel.selectedIndex].value == "[new]")
{
	//sel.style.display = 'none';
	text.style.display = 'block';
	text.style.position = 'absolute';
	text.style.top = getAbsTop(sel);
	text.style.left = getAbsLeft(sel);
	//sel.style.display.top = text.style.display.top;
	//sel.style.display.left = text.style.display.left;
	sel.selectedIndex = 0;
	//text.style.zIndex = 50;
	text.focus();
	}
	else if (sel.options[sel.selectedIndex].value == "")
	{
	}
	else
	{
		text.value = sel.options[sel.selectedIndex].value;
	}

}

function GetElementsByClass(classname)
{
	var thearray = new Array();
	var inc = 0
	var alltags = document.all ? document.all : document.getElementsByTagName("*")
	for (i=0; i<alltags.length; i++)
	{
		if (alltags[i].className==classname)
			thearray[inc++]=alltags[i]
	}
	return thearray;
}


function showHideClassByCheckbox(thecheckbox, theclass)
{
	var showIt = thecheckbox.checked;
	var elements = GetElementsByClass(theclass);
	for (var i = 0; i < elements.length; i++)
	{
		if (showIt)
			elements[i].style.display = 'inline';
		else
			elements[i].style.display = 'none';
	}
	return false;
}


function HideElementsByClass(theclass)
{
	var elements = GetElementsByClass(theclass);
	for (var i = 0; i < elements.length; i++)
	{
		elements[i].style.display = 'none';
	}
	return false;
}

function ToggleDisplayOfElementsWithName(name, showdisplay)
{
	if (showdisplay == '')
		showdisplay = 'block';
	var elements = GetElementsByClass('editlink');
	for (var i = 0; i < elements.length; i++)
	{
		if (elements[i].style.display == 'none')
			elements[i].style.display = showdisplay;
		else
			elements[i].style.display = 'none';
	}
	return false;
}

function TogEdit(element)
{
	if (element.style.backgroundColor == 'transparent')
	{ element.style.backgroundColor = '#FFFF00'; }
	else
	{
		// no longer editing
		HideElementsByClass('editfact');
		element.style.backgroundColor = 'transparent';
	}
	return ToggleDisplayOfElementsWithName('editlink','inline');
}

function SVBC(theclass, newvalue)
{
	var elements = GetElementsByClass(theclass);
	for (var i = 0; i < elements.length; i++)
	{
		elements[i].value = newvalue;
	}
	return false;
}

function SABC(theclass, theattribute, newvalue)
{
	var elements = GetElementsByClass(theclass);
	for (var i = 0; i < elements.length; i++)
	{
		eval( 'elements[i].' + theattribute + ' = newvalue;' );
	}
	return false;
}

function CheckAll(theclass, checkit)
{
	var alltags = document.all ? document.all : document.getElementsByTagName("input");
	for (i=0; i<alltags.length; i++)
	{
		if (alltags[i].className == theclass)
			alltags[i].checked = checkit;
	}
	return false;
}

function BoxesChecked(theclass)
{
	var alltags = document.all ? document.all : document.getElementsByTagName("input");
	for (i=0; i<alltags.length; i++)
	{
		if (alltags[i].className == theclass)
			if (alltags[i].checked)
				return true;
	}
	alert('Please select one or more items.');
	return false;
}

function SetRelationship(therelationship,thevisibility)
{
	var setrel = document.getElementById('setrel');

	for ( i = 0 ; i < setrel.options.length ; i++ )
	{
		if (setrel.options[i].value == therelationship)
		{
			setrel.selectedIndex = i;
			break;
		}
	}

	document.getElementById('rel').value = therelationship;
	var vis = document.getElementById('private');
	for ( i = 0 ; i < vis.options.length ; i++ )
	{
		if (vis.options[i].innerHTML == thevisibility)
		{
			vis.selectedIndex = i;
			break;
		}
	}
	return false;
}