//inserts tags into a provided textarea/textbox
//toElement = form element as object
//tag		= tag as text, if starts with < or & tag added as literal at end of selection range
//css		= optional class
function InsertTag(toElement, tag, css)
{
	if(typeof(toElement) != 'object'){toElement = document.getElementById(toElement);}
	var range;
	var attribs;
	var val;
	var prop1;
	
	toElement.focus();
	range = document.selection.createRange();
	attribs = '';
	
					//prep certain tags
	//href
	if(tag == 'a')
	{
		val = prompt('Enter a url. Only use full addresses when leaving the site.\nFor example: \'/canoecopia/page.asp?pgid=1042\'', '');
		if(val == null) {return;}
		prop1 = confirm('Should this link open in a new window?\n- click \'OK\' if linking to page on a different site\n- click \'CANCEL\' if the link is within this site');
		attribs = ' href="' + val + '"';
		if(prop1 == true)
		{
			attribs = attribs + ' target="_blank"';
		}

	}
	//img
	else if(tag == 'img')
	{
		val = prompt('Enter your image location. this should always be a RELATIVE location.', 'images/');
		if(val == null) {return;}
		attribs = ' src="' + val + '" border="0"';
	}

	//add css
	if(css != '')
	{
		attribs = attribs + ' class=' + css;
	}
	
	
					//build tag and insert into textbox
	//literal tags or special chars
	if(tag.charCodeAt(0) < 65 || tag.charCodeAt(0) > 122 || (tag.charCodeAt(0) > 90 && tag.charCodeAt(0) < 97))
	{
		range.text = range.text + tag;
	}
	//img
	else if(tag == 'img')
	{
		range.text = range.text + '<' + tag + attribs + '>';
	}
	//all other tags
	else
	{
		range.text = '<' + tag + attribs + '>' + range.text + '</' + tag + '>';
	}
}



//highlights modified text
function Modified(obj)
{
	if(typeof(obj) != 'object'){obj = document.getElementById(obj);}
	if(obj != null)
	{
		obj.style.backgroundColor = '#ffff88';
		for(i=0; i<obj.form.elements[obj.name].length; i++)
		{
			obj.form.elements[obj.name][i].style.backgroundColor = '#ffff88';
		}
	}
}