var POST = 0;
var MODIFY = 1;

function title_check()
{
	// check that a title has been added
	if (document.linkForm.title.value == "")
	{
		alert("You must enter a title for the document.");
		return false;
	}
	else
		return true;
}
function modify_link()
{
	if(title_check() && valid_link(MODIFY) && folder_check(MODIFY))
		return true;
	else
		return false;
}
function link_check()
{
	if(title_check() && valid_link(POST) && folder_check(POST))
		return true;
	else
		return false;
}
function valid_link(action)
{
	if (action == POST)
		document.linkForm.action = "/links/output.chtml"; 
	else if (action == MODIFY)
		document.linkForm.action = "/links/modify-output.chtml"; 
				
	if ((document.linkForm.document.value != "") && (document.linkForm.document.value != "http://"))
	{
		document.linkForm.type.value = "Link";
		return true;
	}
	else
	{
		alert("Please enter a link");
		return false;
	}
}
	
function folder_check(action)
{
	this_value = document.linkForm.folder.options[document.linkForm.folder.selectedIndex].value;
	// check that a valid folder has been selected
	if (this_value == "")
	{
		alert("You have not selected a valid folder. Please select another.");
		return false;
	}
	else
	{
	
		// change the action of form depending on whether folder is Public or Member
		if ((this_value == "Top") ||		// public folders
				(this_value == "Personal_Development") ||
				(this_value == "Sexuality") ||
				(this_value == "Family") ||
				(this_value == "Employment_Training") ||
				(this_value == "Education") ||
				(this_value == "CALD") ||
				(this_value == "Health"))
		{
			if (action == POST)
				document.linkForm.action = "/links/output.chtml"; //public
			else if (action == MODIFY)
				document.linkForm.action = "/links/modify-output.chtml"; //public
		return true;
		}
		else
		{
			alert("Please select a valid links folder");
			return false;
		}
	}
}
function replace(String) {

  var re = /\n/g
return String.replace(re,"<br>");
}
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;
}
