function setCookie(name, value, hours_to_live, path, domain, secure) {
  var expireDate = "";
  if(hours_to_live)
  {
    expireDate = (new Date((new Date()).getTime() + hours_to_live*3600000)).toGMTString();
  }

  var curCookie = name + "=" + escape(value) +
	((hours_to_live) ? "; expires=" + expireDate : "") +
	((path) ? "; path=" + path : "") +
	((domain) ? "; domain=" + domain : "") +
	((secure) ? "; secure" : "");
	document.cookie = curCookie;
}

function getCookie(name) {
	var dc = document.cookie;
	var prefix = name + "=";
	var begin = dc.indexOf("; " + prefix);
	if (begin == -1) {
		begin = dc.indexOf(prefix);
		if (begin != 0) return null;
	} else
		begin += 2;
	var end = document.cookie.indexOf(";", begin);
	if (end == -1)
		end = dc.length;
	return unescape(dc.substring(begin + prefix.length, end));
}

function deleteCookie(name, path, domain) {
  if (getCookie(name)) {
    document.cookie = name + "=" + 
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}

function fixDate(date) {
  var base = new Date(0);
  var skew = base.getTime();
  if (skew > 0)
    date.setTime(date.getTime() - skew);
}

function setdelay(num_seconds)
{
 	setCookie("nodiv_slideshow_delay", num_seconds, 365 * 24, "/");
	alert("Display time set to " + num_seconds + " seconds, starting with the next image.");
	return false;
}
function setsize(set)
{
 	setCookie("nd_photos_big", set, 365 * 24, "/");
	if(getCookie("nd_photopage_mode") == "framed")
	{
		parent.ndphotoframe.location.reload();
	}
	else
	{
		location.reload();
	}
}
function play()
{
 	setCookie("nd_slideshow_paused", 0, 365*24, "/");
	location.reload();
}
function pause()
{
 	setCookie("nd_slideshow_paused", 1, 365*24, "/");
	location.reload();
}
function setphotopagemode(set)
{
 	setCookie("nd_photopage_mode", set, 365*24, "/");
	parent.location.reload();
}
function setphotoframelayout(set)
{
 	setCookie("nd_photoframe_layout", set, 365*24, "/");
	parent.location.reload();
}

function addclass(element,newclass)
{
	if(!element.className)
		element.className = '';

	if(!element.className.match(RegExp("\\b" + newclass + "\\b")))
		element.className = element.className.replace(/(\S$)/,'$1 ') + newclass;
}

function removeclass(element,oldclass)
{
	if(!element.className)
		element.className = '';

	element.className = element.className.replace(   RegExp("(\\s*\\b" + oldclass + "\\b(\\s*))*", "g"), '$2'   );
}

function toggletagcb()
{
	if(this.checked)
		addclass(this.parentNode,'tagcbon');
	else
		removeclass(this.parentNode,'tagcbon');
}

function style_edititems_checkboxes()
{
	var container = document.getElementById('edititems') ? document.getElementById('edititems') : document.getElementById('edititems-wide');
	if(container)
	{
		var inputs = container.getElementsByTagName('input');
		for(i=0; i<inputs.length; i++)
		{
			if(inputs[i].name.indexOf('tagcb_') != -1)
			{
				inputs[i].onchange = toggletagcb;
				inputs[i].onclick = toggletagcb; // IE is garbage.

				// make the text label clickable:
				inputs[i].nextSibling.onclick = function () { this.previousSibling.checked=!this.previousSibling.checked;this.previousSibling.onchange(); }
			}
		}
	}
}

function schedule_onload_action(newfunc)
{
	var already_scheduled = window.onload;
	if(typeof window.onload != 'function')
	{
		window.onload = newfunc;
	}
	else
	{
		window.onload = function()
		{
			already_scheduled();
			newfunc();
		}
	}
}



schedule_onload_action(style_edititems_checkboxes);
