// Function to check data and manipulate necessary fields before posting
function post_check()
{
	if(title_check() && content_check() && url_check())
		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())
		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;
}

function replace(String) {

  var re = /\n/g
return String.replace(re,"<br>");
}


function fieldCheck()

{
var msg = "";
var error = "0";
        // check that a fields have been added
if (this.document.requestinfo.title.value == "")
        {
                msg = msg + "Please provide a Title.\n";
                error= "1";
        }

if (this.document.requestinfo.contributor.value == "")
        {
                msg = msg + "Please provide a Contributor.\n";
                error= "1";
        }

if (this.document.requestinfo.source.value == "")
        {
                msg = msg + "Please provide a Source.\n";
                error= "1";
        }

if (this.document.requestinfo.content.value == "")
        {
                msg = msg + "Please enter a Long Description.\n";
                error= "1";
        }

if (this.document.requestinfo.expires.value == "")
        {
                msg = msg + "Please enter a Expiry Date.\n";
                error= "1";
        }

        if (error == "1")
        {
                alert(msg);
                return false;
        }
        else
                return true;
}

function spw(url) {
  var NewWin = window.open(url,"NewWin","toolbar=no,location=no,directories=no,menubar=no,status=yes,scrollbars=yes,resizable=yes,width=680,height=465");
  NewWin.moveTo("10", "10");
  NewWin.focus();
}
function spwc(url) {
  openthis = opener;
  if(openthis == null)  {
      openthis = self;
  }  else  {
      self.close();
  }
  openthis.location.href = url;
}


