var POST = 0;
var MODIFY = 1;

function submit_check()
{
	if(document_check() && set_icon(POST))
		return true;
	else { 
		return false;
	}
}

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].attachment.value != "")
	{	
		this.document.forms[0].type.value = "none";
		return true;
	}
	else if ((this.document.forms[0].url.value != "") && (this.document.forms[0].url.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].attachment.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; 
		}
	}
}