// Function to check data and manipulate necessary fields before posting
function post_check()
{
	document.forms[1].action = "/odd_jobs/output.chtml";
  	if(document.forms[1].link.value!="")
	{
	  	window.location = "/odd_jobs/index.shtml";
    		return false;
	}
	if(title_check() && category_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() && category_check() && description_check() && content_modify_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[1].title.value == "")
	{
		alert("You must enter a title.");
		return false;
	}
	else
		return true;
}

// Function to ensure that something has been entered in the category field
function category_check()
{
	// check that a title has been added
	if (this.document.forms[1].category.value == "")
	{
		alert("You must select a category.");
		return false;
	}
	else
		return true;
}

// Function to ensure that something has been entered in the description field
function description_check()
{
	// check that a brief description has been added
	if (this.document.forms[1].content.value == "")
	{
		alert("Please enter a long description.");
		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[1].content.value == "")
        {
                alert("Please enter a Long Description.");
                return false;
        }
        else
                return true;
}


// Same as content_check(), but for modifying items
function content_modify_check()
{
	if (this.document.forms[1].content.value == "")
        {
                alert("Please enter a Long Description.");
                return false;
        }
        else
                return true;
}

// Function to ensure that something has been entered in the description field
function source_check()
{
        // check that a brief description has been added
        if (this.document.forms[1].contact_name.value == "")
        {
                alert("Please enter a Contact name.");
                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[1].url.value == "http://")
		this.document.forms[1].url.value ="";
	return true;
}

// Allows return spaces in textfield 
function replace(String) {

  var re = /\n/g
return String.replace(re,"<br>");
}


