// Start the subroutines.
var text_enter_url      = "Enter the complete URL for the hyperlink";
var text_enter_url_name = "Enter the title of the webpage";
var text_enter_email    = "Enter the email address";
var error_no_url        = "You must enter a URL";
var error_no_title      = "You must enter a title";
var error_no_email      = "You must enter an email address";


function contentWrite(NewCode) {
    document.theform.blog_comment.value+=NewCode;
    document.theform.blog_comment.focus();
    return;
}

function Modbold() {
	add = "<strong></strong>";
	contentWrite(add);
}

function Moditalic() {
	add = "<em></em>";
	contentWrite(add);
}

function Modunder() {
	add = "<u></u>";
	contentWrite(add);
}

function Modstrike() {
	add = "<s></s>";
	contentWrite(add);
}

function ModInsImg(enterIMG,enterIMGw,enterIMGh)
{
	var ToAdd = "<img src='"+enterIMG+"' width='"+enterIMGw+"' height='"+enterIMGh+"' />";
	window.opener.document.theform.blog_comment.value+=ToAdd;
	window.close();
};

function ModInsFile(enterFile,enterFileDesc)
{
	var ToAdd = "<a href='"+enterFile+"'>"+enterFileDesc+"</a>";
	window.opener.document.theform.blog_comment.value+=ToAdd;
	window.close();
};

function ModInsMovie(enterFile,enterFileDesc)
{
	var ToAdd = "<a href='"+enterFile+"'>"+enterFileDesc+"</a>";
	window.opener.document.theform.blog_comment.value+=ToAdd;
	window.close();
};

function ModInsChar(character)
{
	var ToAdd = character; 
	window.opener.document.theform.blog_comment.value+=ToAdd;
};

function ModInsLink(enterLink,enterLinkTitle)
{
	if (document.theformselect.selectType.value == '1') {
	    var ToAdd = "<a href='"+enterLink+"'>"+enterLinkTitle+"</a>"; 
		};
	if (document.theformselect.selectType.value == '2') {
	    var ToAdd = "<a href='mailto:"+enterLink+"'>"+enterLinkTitle+"</a>";
		};
		window.opener.document.theform.blog_comment.value+=ToAdd;
		window.close();
};

function ModSysLink(sysLink)
{
	var ToAdd = sysLink; 
	window.opener.document.theform.blog_comment.value+=ToAdd;
	window.close();
};


function ModTable()
{
	var width = document.theformselect.width.value;
	var rows = document.theformselect.rows.value;
	var cols = document.theformselect.cols.value;
	var cells = document.theformselect.cells.value;
	var cellp = document.theformselect.cellp.value;
	var align = document.theformselect.align.options[document.theformselect.align.selectedIndex].value;
	var border = document.theformselect.border.value;
	var ToAdd = "";
	ToAdd = ToAdd + "<table width='"+width+"' cellspacing='"+cells+"' cellpadding='"+cellp+"' align='"+align+"' border='"+border+"'>\r\n";
	for(i = 0; i < rows; i++)
	{
	ToAdd = ToAdd + "<tr>\r\n";
	for(j = 0; j < cols; j++)
	{
	"></td>\r\n"; 
	ToAdd = ToAdd + "<td valign='top' align='left'>&nbsp;</td>\r\n";
	};
	ToAdd = ToAdd + "</tr>\r\n";
	};
	ToAdd = ToAdd + "</table>";
	window.opener.document.theform.blog_comment.value+=ToAdd;
	window.close();
};

function ModList()
{
	var type = document.theformselect.type.options[document.theformselect.type.selectedIndex].value;
	var rows = document.theformselect.rows.value;
	var ToAdd = "";
	ToAdd = ToAdd + "<"+type+">\r\n";
	for(i = 0; i < rows; i++)
	{
	ToAdd = ToAdd + "<li>&nbsp;</li>\r\n";
	};
	ToAdd = ToAdd + "</"+type+">";
	window.opener.document.theform.blog_comment.value+=ToAdd;
	window.close();
};


function ModStyles()
{
	var style = document.theform.modstyle.options[document.theform.modstyle.selectedIndex].value;
	var ToAdd = ""+style+"";
	contentWrite(ToAdd);
}


function tag_url()
{
	var FoundErrors = '';
	var enterURL   = prompt(text_enter_url, "http://");
	var enterTITLE = prompt(text_enter_url_name, "My Webpage");
	
	if (!enterURL) {
		FoundErrors += " " + error_no_url;
	}
	if (!enterTITLE) {
		FoundErrors += " " + error_no_title;
	}

	if (FoundErrors) {
		alert("Error!"+FoundErrors);
		return;
	}

	ToAdd = "<a href='"+enterURL+"'>"+enterTITLE+"</a>";
	contentWrite(ToAdd);
}



function tag_email()
{
	var emailAddress = prompt(text_enter_email, "");
	var emailNAME = prompt('Enter an email name', "");

	if (!emailAddress) { 
		alert(error_no_email); 
		return; 
	}

	ToAdd = "<a mailto='"+emailAddress+"'>"+emailNAME+"</a>";
	contentWrite(ToAdd);
}