// Function to check data and manipulate necessary fields before posting
function post_check()
{
	if(title_check() && content_check() && url_check() && expires() && calendar())
		return true;
	else
		return false;
}

// Function to check data and manipulate necessary fields before modifying
function modify_check()
{
	if(title_check() && content_modify_check() && url_check() && expires() && calendar())
		return true;
	else
		return false;
}

// The following functions relate to specific fields within the posting/modfiying form
// Function to ensure that something has been entered in the title field
function title_check()
{
	// check that a title has been added
	if (this.document.forms[0].title.value == "")
	{
		alert("You must enter a title.");
		return false;
	}
	else
		return true;
}

// If no content has been added, change the form's action and store value
function content_check()
{
	if (this.document.forms[0].content.value == "")
	{
		this.document.forms[0].store.value = "none"
		this.document.forms[0].action = "/news/output-nostore.chtml"
	}
	return true
}

// Same as content_check(), but for modifying items
function content_modify_check()
{
	if (this.document.forms[0].content.value == "")
	{
		this.document.forms[0].store.value = "none"
		this.document.forms[0].action = "/news/modify-output-nostore.chtml"
	}
	return true
}

// If url is just "http://" (the value given as a default when the form loads) reset it to ""
function url_check()
{
	if (this.document.forms[0].url.value == "http://")
		this.document.forms[0].url.value ="";
	return true;
}

// Allows return spaces in textfield 
function replace(String) {

  var re = /\n/g
return String.replace(re,"<br>");
}

//check expiry date
function expires()
{
	if(this.document.forms[0].expires.value != "")
	{
		return isFutureDate(this.document.forms[0].expires.value, "Expiry Date");
	}
	return true;
}

//check calendar date
function calendar()
{
	if(this.document.forms[0].calendar.value != "")
	{
		return isFutureDate(this.document.forms[0].calendar.value, "Date of event");
	}
	return true;
}


function expiry()
{
	if (document.forms[0].expires.value == '')
	{
		if (document.forms[0].calendar.value != '')
			document.forms[0].expires.value = document.forms[0].calendar.value;
	}
	return true;
}