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)
{
	setCookie('spellcheck', newstate, 99999);
	location.reload();
}

function ebtextbold()
{
	var input = prompt("Enter the text that should be bolded:", "your text here");
	if(input)
		document.getElementById("ebbody").value += ' [b]' + input + '[/b]';
}

function ebtextitalic()
{
	var input = prompt("Enter the text that should be italicized:", "your text here");
	if(input)
		document.getElementById("ebbody").value += ' [i]' + input + '[/i]';
}

function ebtextunderline()
{
	var input = prompt("Enter the text that should be underlined:", "your text here");
	if(input)
		document.getElementById("ebbody").value += ' [u]' + input + '[/u]';
}

function ebtextquote()
{
	document.getElementById("ebbody").value += "\n[quote=\"name of author goes here\"]\ntext of quote goes here\n[/quote]\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 for the link:", "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 ebinsobject(obtype)
{
	var text = document.getElementById("ebbody");
	var input = '';
	var tag = '';
	if(obtype == 'file')
	{
		input = prompt("Enter the text for the link to the file:", "your text here");
		tag = '[[file="' + input + '"]]';
	}
	else
	{
		// we use double-brackets only during the posting process, not during storage.
		tag = "[[" + obtype + "]]";
	}
	var showed_warning = 0;
	if(text.value.indexOf("[" + obtype) != -1)
		showed_warning = 1;
	text.value += "\n" + tag + "\n";
	if(!showed_warning)
		alert("Inserting the " + obtype + " tag now; you will be prompted to upload your " + obtype + " at the end of the posting process.");
}

