function BackPage()
	{
	document.href=window.history.go(-1);
	return false;
	}



function CancelEntry()
	{
	BeSure=confirm("Are you sure you wish to cancel what you are doing?");
	if (BeSure)
		{
		document.href=window.history.go(-1);
		return false;
		}
		else
			{return false;}
	return false;
	}



function EffectCode(Code,Action,Field)
	{
	var RTEditor;
	if (document.all) 
		{RTEditor=frames[Field];}
		else 
			{RTEditor=document.getElementById(Field).contentWindow;}

	RTEditor.focus();
	switch (Action)
		{
		case "insert":
			{
			if (document.all) 
				{RTEditor.document.selection.createRange().pasteHTML(Code);}
				else 
					{RTEditor.document.execCommand("insertHTML",false,Code);}
			break;
			}
		case "link":
			{
			RTEditor.document.execCommand("unlink",false,false);
			RTEditor.document.execCommand("createlink",false,Code);
			break;
			}
		case "mail":
			{
			RTEditor.document.execCommand("unlink",false,false);
			RTEditor.document.execCommand("createlink",false,"mailto:"+Code);
			break;
			}
		case "table":
			{
			var Rows=parseInt(Code.substr(0,Code.indexOf(",")));
			var Cols=parseInt(Code.substr(Code.indexOf(",")+1));
			var TableDims="<table class='entrytable entrytablesize'>";
			for (x=0;x<Rows;x++)
				{
				TableDims+="<tr>";
				for (y=0;y<Cols;y++)
					{TableDims+="<td class=entrytable>";}
				}
			TableDims+="</table>";
			if (document.all) 
				{RTEditor.document.selection.createRange().pasteHTML(TableDims);}
				else {RTEditor.document.execCommand("insertHTML",false,TableDims);}
			break;
			}
		case "image":
			{
			RTEditor.document.execCommand("insertimage",false,Code);
			break;
			}
		default:
			{RTEditor.document.execCommand(Code,false,false);}
		}

	RTEditor.focus();
	return false;
	}



function EM(name,domain,type,subject,display)
	{
	if (name && domain && type && display)
		{document.write('<a href=mailto:'+name+'@'+domain+'.'+type+'?subject='+subject+'>'+display+'</a>');}
	return true;
	} 




function EMBrief(name,domain,type)
	{
	if (name && domain && type)
		{document.write('<a href=mailto:'+name+'@'+domain+'.'+type+'>');}
	return true;
	}



function EntryFormCode(Code,Field)
	{
	if (Code=="bold")
		{EffectCode("bold","",Field);}
	if (Code=="italics")
		{EffectCode("italic","",Field);}
	if (Code=="underline")
		{EffectCode("underline","",Field);}
	if (Code=="character" && document.forms["EntryForm"].elements["charfocus"])
		{
		var CharNum=document.forms["EntryForm"].elements["charfocus"].value;
		EffectCode(document.getElementById("Char"+CharNum).innerHTML,"insert",Field);
		}
	if (Code=="indent")
		{EffectCode("indent","",Field);}
	if (Code=="outdent")
		{EffectCode("outdent","",Field);}
	if (Code=="justify")
		{EffectCode("justifyfull","",Field);}
	if (Code=="center")
		{EffectCode("justifycenter","",Field);}
	if (Code=="right")
		{EffectCode("justifyright","",Field);}
	if (Code=="numlist")
		{EffectCode("insertorderedlist","",Field);}
	if (Code=="unordlist")
		{EffectCode("insertunorderedlist","",Field);}
	if (Code=="link")
		{
		WebAddress=VerifiedWebAddress();
		EffectCode(WebAddress,"link",Field);
		}
	if (Code=="mail")
		{
		var MailOK=false;
		var MailAddress=true;
		while (!MailOK && MailAddress)
			{
			MailAddress=prompt("Enter recipient address for selected text: ","");
			if (MailAddress.indexOf("@")>0 && MailAddress.indexOf(".")>(MailAddress.indexOf("@")+1) && MailAddress.indexOf(".")<(MailAddress.length-1))
				{MailOK=true;}
			}
		EffectCode(MailAddress,"mail",Field);
		}
	if (Code=="image")
		{
		LinkAddress=prompt("Enter Web address for rights-cleared image: ","");
		EffectCode(LinkAddress,"image",Field);
		}
	if (Code=="table")
		{
		TableDimensions=prompt("Rows, Columns (e.g. 2,3) (Format fixed when entry submitted): ",",");
		EffectCode(TableDimensions,"table",Field);
		}
	if (Code=="coding")
		{EffectCode("","coding",Field);}
	return false;
	}



function ExtraChars()
	{
	var MasterList="&Aacute;|&aacute;|&Agrave;|&agrave;|&Acirc;|&acirc;|&Auml;|&auml;|&Aring;|&aring;|&Atilde;|&atilde;|&AElig;|&aelig;|&Ccedil;|&ccedil;|&Eacute;|&eacute;|&Egrave;|&egrave;|&Ecirc;|&ecirc;|&Euml;|&euml;|&#286;|&#287;|&Iacute;|&iacute;|&Igrave;|&igrave;|&Icirc;|&icirc;|&Iuml;|&iuml;|&#304;|&#305;|&Ntilde;|&ntilde;|&Oacute;|&oacute;|&Ograve;|&ograve;|&Ocirc;|&ocirc;|&Ouml;|&ouml;|&Oslash;|&oslash;|&Otilde;|&otilde;|&#350;|&#351;|&Uacute;|&uacute;|&Ugrave;|&ugrave;|&Ucirc;|&ucirc;|&Uuml;|&uuml;|&Yacute;|&yacute;|&yuml;|&szlig;|&ETH;|&eth;|&THORN;|&thorn;|&ndash;|&mdash;|&iquest;|&iexcl;|&laquo;|&raquo;|&sect;|&para;|&cent;|&frac14;|&frac12;|&frac34;|&pound;|&#8364;|&yen;|&plusmn;|&deg;";
	var Char=MasterList.split("|");

	document.write("<table>");
	var ListLength=Char.length;
	var RowStep=1;
	for (x=0;x<ListLength;x++)
		{
		if (RowStep==1)
			{document.write("<tr>");}
		document.write ("<td class=excharpadround id='Char"+x+"' onclick='SelectChar("+x+")'>"+Char[x]);
		RowStep++;
		if (RowStep>5)
			{RowStep=1;}
		}
	document.write("</table>");
	return true; 
	}




function FormSubmit(Action,DocID)
	{
	var Flds=document.forms["EntryForm"].elements["Fields"].value.split(",");
	var WarnFlds=document.forms["EntryForm"].elements["WarnFields"].value.split(",");
	var ReqFlds=document.forms["EntryForm"].elements["ReqFields"].value.split(",");
	var RTEFlds=document.forms["EntryForm"].elements["RTEFields"].value.split(",");
	for (x=0;x<Flds.length;x++)
		{
		var RTEditor;
		var RFldLoc;
		if (RTEFlds[x]=="Yes")
			{
			if (document.all) 
				{RTEditor=frames[Flds[x]];}
				else 
					{RTEditor=document.getElementById(Flds[x]).contentWindow;}
			RFldItem=RTEditor.document.body.innerHTML;
			}
			else
				{RFldItem=document.forms["EntryForm"].elements[Flds[x]].value;}
		if ((ReqFlds[x]=="Yes" || ReqFlds[x]=="Link") && RFldItem.replace("<br>","").length<1)
			{
			alert ("Please provide the "+WarnFlds[x]+".");
			return false;
			}
		if (ReqFlds[x]=="Link")
			{
			LinkValid=LinkVerify(RFldItem);
			if (!LinkValid)
				{
				alert ("Please provide a correctly formatted Web address.");
				return false;
				}
			}
		}

	BeSure=confirm("Please confirm that entry meets all site standards.","");	
	if (BeSure)
		{
		var RTEditor;
		for (x=0;x<Flds.length;x++)
			{
			if (RTEFlds[x]=="Yes")
				{
				if (document.all) 
					{RTEditor=frames[Flds[x]];}
					else 
						{RTEditor=document.getElementById(Flds[x]).contentWindow;}
				RTEItem=document.createElement("input");				
				RTEItem.name=Flds[x];
				RTEItem.type="textarea";
				RTEItem.style.display="none";
				RTEItem.value=RTEditor.document.body.innerHTML;
				document.forms["EntryForm"].appendChild(RTEItem);
				}
			}

		StageItem=document.createElement("input");				
		StageItem.name="Stage";
		StageItem.type="hidden";
		var Secondary="Submit";
		if (DocID)
			{
			Secondary="Submit.Edit";
			EditOne=document.createElement("input");				
			EditOne.name="ItemID";
			EditOne.type="hidden";
			EditOne.value=DocID;			
			document.forms["EntryForm"].appendChild(EditOne);
			}
		StageItem.value="Entry."+Secondary;
		document.forms["EntryForm"].appendChild(StageItem);
		document.forms["EntryForm"].submit();
		}
	return true;
	}





function ImageRestore(ImgAddress)
	{
	document.write("<img src='"+ImgAddress+"'>");
	return true;
	}



function LinkVerify(WebAddress)
	{
	var WebOK=false;
	var WebHead=false;
	var WebAddRemnant=WebAddress;
	var Headers="http://|https://|www.|wwww.";
	var Prefix=Headers.split("|");
	for (x=0;x<Prefix.length;x++)
		{
		if (WebAddRemnant.substr(0,Prefix[x].length)==Prefix[x])
			{
			WebHead=true;
			WebAddRemnant=WebAddRemnant.substr(Prefix[x].length);
			}
		}
	if (WebAddRemnant.indexOf(".")>0 && WebAddRemnant.lastIndexOf(".")<WebAddRemnant.length-2)
		{WebOK=true;}
	return WebOK;
	}



function LTCookie(Action)											/* Handles long-term cookies */
	{
	var Stage;
	var LTCookie;
	if (Action=="Add")
		{
		Stage="LTAdd";
		LTCookie=confirm("Are you sure you wish to add a long-term cookie to this computer? The cookie contains the filename of your personal page so that you can log in easily from other pages. Please only add this cookie if you keep this computer private.");
		}
	if (Action=="Remove")
		{
		Stage="LTRemove";
		LTCookie=confirm("Are you sure you wish to remove the long-term cookie from this computer? The cookie merely contains the filename of your personal page. It should be removed if your computer will no longer be private.");
		}
	
	if (LTCookie)
		{
		LTCookieForm=document.createElement("Form");
		LTCookieForm.action=top.location.href;
		LTCookieForm.target="_top";
		LTCookieForm.method="post";

		InputOne=document.createElement("input");				
		InputOne.name="Stage";
		InputOne.type="hidden";
		InputOne.value=Stage;			
		LTCookieForm.appendChild(InputOne);

		document.body.appendChild(LTCookieForm);
		LTCookieForm.submit();

		return true;
		}
	}





function LogOut()													/* To log out writers */
	{
	var LogOut=confirm("Are you sure you wish to log out?");
	if (LogOut)
		{
		RemoveForm=document.createElement("Form");
		RemoveForm.action=top.location.href;
		RemoveForm.target="_top";
		RemoveForm.method="post";

		InputOne=document.createElement("input");				
		InputOne.name="Stage";
		InputOne.type="hidden";
		InputOne.value="Remove";			
		RemoveForm.appendChild(InputOne);

		document.body.appendChild(RemoveForm);
		RemoveForm.submit();

		return true;
		}
	}




function MailAddress(name,domain,type)
	{document.write(name+'@'+domain+'.'+type);} 




function PostItem(Page,Stage,ItemID)
	{
	var PostForm=document.createElement("Form");

	PostForm.action="/Forms/"+Page+".html";
	PostForm.target="_top";
	PostForm.method="post";

	InputOne=document.createElement("input");				
	InputOne.name="Stage";
	InputOne.type="hidden";
	InputOne.value=Stage;			
	PostForm.appendChild(InputOne);

	InputTwo=document.createElement("input");				
	InputTwo.name="ItemID";
	InputTwo.type="hidden";
	InputTwo.value=ItemID;			
	PostForm.appendChild(InputTwo);

	document.body.appendChild(PostForm);
	PostForm.submit();
	return true;
	}



function RequestSubmit()
	{
	var RequestForm=document.forms["RequestForm"];
	
	InputOne=document.createElement("input");				
	InputOne.name="BoxItem";
	InputOne.type="hidden";
	
	var BoxName=document.getElementById("ImageBox").src;
	BoxName=BoxName.substr(BoxName.lastIndexOf("/")+1);
	BoxName=BoxName.substr(0,BoxName.length-BoxName.substr(BoxName.lastIndexOf(".")).length);
	
	InputOne.value=BoxName;
	RequestForm.appendChild(InputOne);

	InputTwo=document.createElement("input");				
	InputTwo.name="Stage";
	InputTwo.type="hidden";
	InputTwo.value="Request.Submit";			
	RequestForm.appendChild(InputTwo);

	RequestForm.submit();
	return true;
	}



function SelectChar(CharNum)
	{
	if (!document.forms["EntryForm"].elements["charfocus"])
		{
		var CF;
		if (document.all) 
			{CF=document.createElement("<input name='charfocus'>");}
			else 
				{
				CF=document.createElement("input");
				CF.name="charfocus";
				}
		CF.type="hidden";
		CF.value=CharNum;
		document.forms["EntryForm"].appendChild(CF);
		}
		else
			{
			var CurrChar=document.forms["EntryForm"].elements["charfocus"].value;
			document.getElementById("Char"+CurrChar).className="extrachardeselected excharpadround";
			}
	document.forms["EntryForm"].elements["charfocus"].value=CharNum;
	document.getElementById("Char"+CharNum).className="extracharselected excharpadround";
	return false;
	}




function StageChange(Stage)											/* For use only when Stage is only POST variable */
	{
	var StageForm=document.createElement("Form");

	StageForm.name="StageChange";
	StageForm.action=top.location.href;
	StageForm.target="_top";
	StageForm.method="post";

	InputOne=document.createElement("input");				
	InputOne.name="Stage";
	InputOne.type="hidden";
	InputOne.value=Stage;			
	StageForm.appendChild(InputOne);

	document.body.appendChild(StageForm);
	StageForm.submit();

	return true;
	}



function VerifiedWebAddress()
	{
	var WebOK=false;
	var WebAddress=true;
	while (!WebOK && WebAddress)
		{
		WebAddress=prompt("Enter Web address for selected text: ","");
		WebOK=LinkVerify(WebAddress);
		}
	if (!WebOK)
		{WebAddress=false;}
	return WebAddress;
	}




function WidthEnsure()
	{
	document.write("<div class=whitetext>");
	for (x=0;x<75;x++)
		{document.write("&#32;X");}
	document.write("</div>");
	return false;
	}

