// Function to check data and manipulate necessary fields before posting
function post_check()
{
	if(title_check() && description_check() && content_check() && source_check() && url_check())
		return true;
	else
		return false;
}

// Function to check data and manipulate necessary fields before modifying
function modify_check()
{
	if(title_check() && description_check() && content_check() && source_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 == "" || (document.forms[0].title.value == document.forms[0]._wb_placeholder_title.value))
	{
		alert("You must enter a Posting Title.");
		return false;
	}
	else
		return true;
}

// Function to ensure that something has been entered in the description field
function description_check()
{
        // check that a content has been added
        if (this.document.forms[0].description.value == "" || (document.forms[0].description.value == document.forms[0]._wb_placeholder_description.value))
        {
                alert("You must enter a Short Description.");
                return false;
        }
        else
                return true;
}

// Function to ensure that something has been entered in the content field
function content_check()
{
        // check that a content has been added
        if (this.document.forms[0].content.value == "" || (document.forms[0].content.value == document.forms[0]._wb_placeholder_content.value))
        {
                alert("You must enter a Main Message.");
                return false;
        }
        else
                return true;
}

// Function to ensure that something has been entered in the source field
function source_check()
{
        // check that a source has been added
        if (this.document.forms[0].source.value == "" || (document.forms[0].source.value == document.forms[0]._wb_placeholder_source.value))
        {
                alert("You must enter a Source.");
                return false;
        }
        else
                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://" || (document.forms[0].url.value == document.forms[0]._wb_placeholder_url.value))
		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>");
}

function related_check() {
	var theform = document.forms[0];
	if (theform.dol_article_title_01.value != "" ||
			theform.dol_article_title_02.value != "" ||
			theform.dol_article_title_03.value != "" ||
			theform.dol_article_url_01.value != "" ||
			theform.dol_article_url_02.value != "" ||
			theform.dol_article_url_03.value != "" ||
			theform.dol_links_title_01.value != "" ||
			theform.dol_links_title_02.value != "" ||
			theform.dol_links_title_03.value != "" ||
			theform.dol_links_url_01.value != "" ||
			theform.dol_links_url_02.value != "" ||
			theform.dol_links_url_03.value != "") {
		theform.nothing_related.value = 0;
	}
}

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;
}


function isDateValid(name)
{
        var doThis = eval("document.forms[0]." + name + ".value");
        if (doThis != '')
        {
                if (name == "expires")
                        return isFutureDate(doThis,'Date to Remove from News');
                else if (name == "calendar")
                        return isFutureDate(doThis,'Calendar');
        }
        placeholderBack(name)
}


function placeholderBack(name)
{
        var placeholder = eval("document.form1." + name);
        var defaultPlace = eval("document.form1._wb_placeholder_" + name + ".value");
                if(placeholder.value == '')
                        placeholder.value = defaultPlace;
}

function remove_select(name)
{
        var placeholder = eval("document.form1." + name);
        var defaultPlace = eval("document.form1._wb_placeholder_" + name + ".value");

        if(placeholder.value == defaultPlace)
                placeholder.value = '';
        else
                placeholder.select();
}

