
// 20050917: renamed textsize stylesheets to generic sm,md,lg,xl instead of 8pt,10pt, etc.
//
// 20050916: now setting the text size doesn't interfere with the "style" stylesheet.
//
// 20050406: first release.

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 submit_post_to_CMS()
{
	if( !(document.board.body.value) )
		{ alert("You'll need to type a message before you press that button."); }
	else
	{ if((!document.board.site_username.value))
		{ alert("You forgot to type your name!");  }
	else
		{ document.board.submit(); }
	}
}

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

function setScheme(s)
{
	setCookie("ndscheme", s, 30*24, "/");
	location.reload();
}

function print_vlog_iframe()
{
	document.write('<iframe name="theiframeNew" id="vlogiframe" src="about:blank" width="1" height="1" scrolling="no" frameborder="0" align="right" marginwidth="0" marginheight="0" class="nomrgnobrdnopad">Your browser does not support inline frames. Get a <a href="http://www.mozilla.org/" target="_blank">new one</a>.</iframe>');
}

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 toggleSpellcheck(newstate)
{
	var i, span;
	for(i=0; (span = document.getElementsByTagName("span")[i]); i++)
	{
		if(newstate == 'off')
		{
			if(span.className.indexOf("spellerror") != -1)
			{
				span.className = "disabledspellerror";
			}
		}
		else
		{
			if(span.className.indexOf("disabledspellerror") != -1)
			{
				span.className = "spellerror";
			}
		}
	}
}




function setTextSize(title)
{
	var i, a, main;
	for(i=0; (a = document.getElementsByTagName("link")[i]); i++)
	{
		if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title"))
		{
			a.disabled = true;
			if(a.getAttribute("title") == title   ||   a.getAttribute("title") == getCookie("style"))
			{
				a.disabled = false;
			}
		}
	}
	setCookie("textsize", title, 365*24, "/");
}

function getCurrentTextSize()
{
	var i, a;
	for(i=0; (a = document.getElementsByTagName("link")[i]); i++)
	{
		if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled)
		{
			return a.getAttribute("title");
		}
	}
	return null;
}

function getPreferredTextSize()
{
	var i, a;
	for(i=0; (a = document.getElementsByTagName("link")[i]); i++)
	{
		if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("rel").indexOf("alt") == -1 && a.getAttribute("title"))
		{
			return a.getAttribute("title");
		}
	}
	return null;
}




function setstyle(title)
{
	// This if() needs testing on various permutations of sites that have or don't
	// have a selectable stylesheet and/or a selectable text-size stylesheet.
	if(!title)
	{
		return null;
	}

	var i, a, main;
	for(i=0; (a = document.getElementsByTagName("link")[i]); i++)
	{
		if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title"))
		{
			// We need to ignore our textsm, textmd, textlg, and textxl stylesheets here, otherwise
			// this overall-stylesheet-setting function will interfere with the text-size-only-stylesheet
			// functionality.
			if(a.getAttribute("title").indexOf("textsm") == -1   &&   a.getAttribute("title").indexOf("textmd") == -1   &&   a.getAttribute("title").indexOf("textlg") == -1   &&   a.getAttribute("title").indexOf("textxl") == -1)
			{
				a.disabled = true;
				if(a.getAttribute("title") == title)
				{
					a.disabled = false;
				}
			}
		}
	}
	setCookie("style", title, 365*24, "/");
}

function getCurrentStyle()
{
	var i, a;
	for(i=0; (a = document.getElementsByTagName("link")[i]); i++)
	{
		if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled)
		{
			return a.getAttribute("title");
		}
	}
	return null;
}

function getPreferredStyle()
{
	var i, a;
	for(i=0; (a = document.getElementsByTagName("link")[i]); i++)
	{
		if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("rel").indexOf("alt") == -1 && a.getAttribute("title"))
		{
			// We need to ignore our textsm, textmd, textlg, and textxl stylesheets here, otherwise the
			// default one will get set through setstyle(), overwriting the one chosen by setTextSize().
			if(a.getAttribute("title").indexOf("textsm") == -1   &&   a.getAttribute("title").indexOf("textmd") == -1   &&   a.getAttribute("title").indexOf("textlg") == -1   &&   a.getAttribute("title").indexOf("textxl") == -1)
			{
				return a.getAttribute("title");
			}
		}
	}
	return null;
}



var cookie1 = getCookie("textsize");
var title1 = cookie1 ? cookie1 : getPreferredTextSize();
setTextSize(title1);



var cookie2 = getCookie("style");
var title2 = cookie2 ? cookie2 : getPreferredStyle();
setstyle(title2);

