

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://");
		alttag = prompt("Please enter a SHORT description of this image:",default_text);
		if(url && alttag ) html = " <img src=\"" + directory + url + "\" alt=\"" + alttag + "\" /> " ;
		else alert('You didnt enter all information!');
	break
	case "a":
		url = prompt("Please enter the URL for this link:\n (http://www.example.com)","http://");
		clicktext = prompt("Please enter the CLICKABLE text for this link:","");
		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) html = " <strong>" + html + "<\/strong> "
		else html ='';
	break
	case "em":
		html = prompt("Please enter the text you would like to italicize:",default_text)
		if(html) html = " <em>" + html + "<\/em> "
		else html ='';
	break
	case "p":
		html = prompt("Please enter the text in this paragraph:",default_text)
		if(html) html = "\n<p>" + html + "<\/p>\n"
		else html = '';
	break
	case "pc":
		html = prompt("Please enter the text in this paragraph:",default_text)
		if(html) html = "\n<p class=\"center\">" + html + "<\/p>\n"
		else html = '';
	break
	case "pr":
		html = prompt("Please enter the text in this paragraph:",default_text)
		if(html) html = "\n<p class=\"right\">" + html + "<\/p>\n"
		else html = '';
	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) html = "\n<h3>" + html + "<\/h3>\n"
		else html = '';
	break
	case "h4":
		html = prompt("Please enter the text in this small heading:",default_text)
		if(html) html = "\n<h4>" + html + "<\/h4>\n"
		else html = '';
	break
	case "br":
		html = "<br \/>"
	break
	case "lorem":
		html = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Proin cursus congue diam. Donec aliquet purus ut felis. Nullam ultrices condimentum nisi. Aenean tincidunt. "
	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;
	}
}

