var POST = 0;
var MODIFY = 1;

function modify_check()
{
	if(title_check() && contributor_check() && description_check() && folder_check() && document_check() && set_icon(MODIFY))
		return true;
	else
		return false;
}
function submit_check()
{
	if(title_check() && contributor_check() && description_check() && folder_check() && document_check() && set_icon(POST))
		return true;
	else { 
		return false;
	}
}
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 Title for the document.");
		return false;
	}
	else
		return true;
}

function contributor_check()
{
	// check that a title has been added
	if (this.document.forms[0].contributor.value == "" || (document.forms[0].contributor.value == document.forms[0]._wb_placeholder_contributor.value))
	{
		alert("You must enter a Contributor for the document.");
		return false;
	}
	else
		return true;
}

// If no content has been added, change the form's action and store value
function description_check()
{
	if (document.forms[0].description.value == "" || (document.forms[0].description.value == document.forms[0]._wb_placeholder_description.value))
	{
		alert("Please enter a Description");
		return false;
	}
	return true;
}

function link_check()
{
	if(document.forms[0].link.value == '' || document.forms[0].link.value == 'http://')
	{
		alert("Please enter a Link")
		return false;
	}
	else
		return true;
}

function folder_check(action)
{
	var status = 0;
	// change the action of form depending on whether folder is Public or Member
	if(document.forms[0].folder.options[document.forms[0].folder.selectedIndex].value == "")
	{
		alert("Please select a Folder.");
		return false;
	}
	return true;
}
function document_check()
{
	if(document.forms[0].isDocument.value != "")
		return true;
		
	// determine if this is a link or a file being submitted
	if (this.document.forms[0].document.value != "")
	{	
		this.document.forms[0].type.value = "none";
		return true;
	}
	else if ((this.document.forms[0].link.value != "") && (this.document.forms[0].link.value != "http://"))
	{	
		this.document.forms[0].type.value = "Link";
		return true;
	}
	else
	{	
		alert("You have not uploaded a document or specified a link.");
		return false;
	}
}

function set_icon(action)
{ 
	var thefile;
	var splitstr;
	var xten;
	var thefile;
	
	thefile = this.document.forms[0].document.value;
	
	if(this.document.forms[0].type.value == "Link") // Item is a link, set icon to html.gif
	{
		this.document.forms[0].icon.value = "/ixa/images/icons/html.gif";
		return true;
	}
	else if(thefile == "") // No (new) document, return true
	{
		return true;
	}
	else // New document, reset icon
	{
		if(thefile[thefile.length-1] == "/") 
		{ 
			thefile += "index.html"; 
		} 
		splitstr = thefile.split(".");
		xten = splitstr[splitstr.length - 1];
		xten = xten.toLowerCase();
		if(xten=="htm")  
		{ 
			xten = "html";
		} 
		if(xten=="jpeg")  
		{ 
			xten = "jpg"; 
		} 
		if(xten=="rtf")  
		{ 
			xten = "doc"; 
		} 
		if ((xten=="doc") || 
				(xten=="html") || 
				(xten=="pdf") || 
				(xten=="jpg") || 
				(xten=="gif") ||  
				(xten=="ppt") || 
				(xten=="pub") ||  
				(xten=="xls") || 
				(xten=="zip"))  
		{  
			this.document.forms[0].icon.value = '/ixa/images/icons/' + xten + '.gif'; 
			return true; 
		} 
		else 
		{ 
			alert('Sorry, files with extensions, .'+xten+', cannot be accepted\nAcceptable types are htm, html, doc, xls, pdf, jpeg, jpg, gif, rtf, ppt, pub or zip');
			thefile="";
			return false; 
		}
	}
}

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 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();
}