

function addhtml(object,tag,directory)
{
	var html = "";
	var url = "";
	var alttag = "";
	var default_text = "Your text goes here";
	
	if(!directory) directory = '';
	
	switch (tag) {
	case "ol":
		var num = prompt("Please enter the number of list items you want to create.","1")
		if ( isNaN(num) || num < 1 ) { return false; }
		var list = new Array()
		for ( var i = 1; i <= num; i++ ) {
			list[i] = prompt("Please enter a list item:",default_text)
			html = html + "\t<li>" + list[i] + "<\/li>\n"
		}
		html = "\n<ol>\n" + html + "<\/ol>\n"
	break
	case "ul":
		var num = prompt("Please enter the number of list items you want to create.","1")
		if ( isNaN(num) || num < 1 ) { return false; }
		var list = new Array()
		for ( var i = 1; i <= num; i++ ) {
			list[i] = prompt("Please enter a list item:",default_text)
			html = html + "\t<li>" + list[i] + "<\/li>\n"
		}
		html = "\n<ul>\n" + html + "<\/ul>\n"
	break
	case "img":
		url = prompt("Please enter the full URL of this image, including the http:// for best results:","http://");
		if(!url) return false;
		alttag = prompt("Please enter a SHORT description of this image:",default_text);
		if(!alttag) return false;
		html = " <img src=\"" + directory + url + "\" alt=\"" + alttag + "\" /> " ;
	break
	case "a":
		url = prompt("Please enter the URL for this link:\n (http://www.example.com)","http://");
		if(!url) return false;
		clicktext = prompt("Please enter the CLICKABLE text for this link:","");
		if(!clicktext) return false;
		alttag = prompt("Please enter a SHORT description of this link:",default_text);
		if( url && clicktext && alttag ) html = " <a href=\"" + url + "\" title=\"" + alttag + "\">" + clicktext + "<\/a> ";
		else alert('You didnt enter all information!');
	break
	case "strong":
		html = prompt("Please enter the text you would like bold:",default_text)
		if(!html) return false;
		html = " <strong>" + html + "<\/strong> "
	break
	case "em":
		html = prompt("Please enter the text you would like to italicize:",default_text)
		if(!html) return false;
		html = " <em>" + html + "<\/em> "
	break
	case "p":
		html = prompt("Please enter the text in this paragraph:",default_text)
		if(!html) return false;
		html = "\n<p>" + html + "<\/p>\n"
	break
	case "pc":
		html = prompt("Please enter the text in this paragraph:",default_text)
		if(!html) return false;
		html = "\n<p class=\"center\">" + html + "<\/p>\n"
	break
	case "pr":
		html = prompt("Please enter the text in this paragraph:",default_text)
		if(!html) return false;
		html = "\n<p class=\"right\">" + html + "<\/p>\n"
	break
	case "h2":
		html = prompt("Please enter the text in this large heading:",default_text)
		if(html) html = "\n<h2>" + html + "<\/h2>\n"
		else html = '';
	break
	case "h3":
		html = prompt("Please enter the text in this medium heading:",default_text)
		if(!html) return false;
		html = "\n<h3>" + html + "<\/h3>\n"
	break
	case "h4":
		html = prompt("Please enter the text in this small heading:",default_text)
		if(!html) return false;
		html = "\n<h4>" + html + "<\/h4>\n"
	break
	case "br":
		html = "<br \/>"
	break
	case "lorem":
		html = "<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Proin cursus congue diam. Donec aliquet purus ut felis. Nullam ultrices condimentum nisi. Aenean tincidunt. Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Proin cursus congue diam. Donec aliquet purus ut felis. Nullam ultrices condimentum nisi. Aenean tincidunt. Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Proin cursus congue diam. Donec aliquet purus ut felis. Nullam ultrices condimentum nisi. Aenean tincidunt.<\/p>\n"
	break
	}	

	insertAtCursor( document.getElementById(object) , html )
	return false;
	
}


function insertAtCursor(myField, myValue) 
{
	//IE support
	if (document.selection) 
	{
		myField.focus();
		sel = document.selection.createRange();
		sel.text = myValue;
	}
	//MOZILLA/NETSCAPE support
	else if (myField.selectionStart || myField.selectionStart == '0') 
	{
		var startPos = myField.selectionStart;
		var endPos = myField.selectionEnd;
		myField.value = myField.value.substring(0, startPos)
		+ myValue
		+ myField.value.substring(endPos, myField.value.length);
	} else {
		myField.value += myValue;
	}
}


function replaceSelection(myField, val1 , val2 ) 
{
	//IE support
	if (document.selection) 
	{
		myField.focus();
		sel = document.selection.createRange();
		sel.text = val1 + sel.text + val2;
	}
	//MOZILLA/NETSCAPE support
	else if (myField.selectionStart || myField.selectionStart == '0') 
	{
		var startPos = myField.selectionStart;
		var endPos = myField.selectionEnd;
		myField.value = myField.value.substring(0, startPos)
		+ myValue
		+ myField.value.substring(endPos, myField.value.length);
	} else {
		myField.value += myValue;
	}
}

