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.guestname.value))
		{ alert("You forgot to type your name!");  }
	else
		{ document.board.submit(); }
	}
}

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";
	//		}
	//	}
	//}

	setCookie('spellcheck', newstate, 99999);
	location.reload();
}

function ebtextbold()
{
	document.getElementById("ebbody").value += ' [b]your text here[/b]';
}

function ebtextitalic()
{
	document.getElementById("ebbody").value += ' [i]your text here[/i]';
}

function ebtextunderline()
{
	document.getElementById("ebbody").value += ' [u]your text here[/u]';
}

function ebtextquote()
{
	document.getElementById("ebbody").value += "\n[blockquote=\"Author of Quote\"]\nyour text here\n[/blockquote]\n";
}

function ebinslink()
{
	var text = document.getElementById("ebbody");
	var linkURL = prompt("Enter the URL (address) for the link:", "http://");
	var linktext = prompt("Enter the text that should be linkified:", "your text here");
	var num = 1;
	while(text.value.indexOf('][' + num + ']') != -1)
		num++;
	if(linktext && linkURL)
		text.value += ' [' + linktext + '][' + num + '] ' + "\n\n" + '[' + num + ']: ' + linkURL + "\n";
}

function ebinsimage()
{
	var text = document.getElementById("ebbody");
	var tag = '[image1here]';
	var num = 1;
	var showed_warning = 0;
	while(text.value.indexOf(tag) != -1)
	{
		tag = '[image' + (++num) + 'here]';
		showed_warning = 1;
	}
	text.value += "\n" + tag + "\n";
	if(!showed_warning)
		alert("Inserting the image tag now; you will be prompted to upload your image at the end of the posting process.");
}

