/* 	Copyright (c) 2002, Scott Harris
	All rights reserved.

	Redistribution and use in source and binary forms, with or without modification,
	are permitted provided that the following conditions are met:

   	 	* Redistributions of source code must retain the above copyright notice, 
	 	 this list of conditions and the following disclaimer.
    	* Redistributions in binary form must reproduce the above copyright notice, 
	 	 this list of conditions and the following disclaimer in the documentation 
	 	 and/or other materials provided with the distribution.
   		 * Neither the name of the author nor the names of its contributors 
	 	 may be used to endorse or promote products derived from this software 
	 	 without specific prior written permission.

	THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 
	ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
	WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 
	DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY 
	DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 
	(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
	LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
	ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
	(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 
	SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   */

// Define the mouse events for the buttons
function mouseover(el) {
	el.className = "raised";
	}

function mouseout(el) {
	el.className = "button";
	}

function mousedown(el) {
	el.className = "pressed";
	}

function mouseup(el) {
	el.className = "raised";
	}

// Text Format Script
function Format(tag,action) {
// if user is selecting a heading tag, get the heading size
	if (action == "heading") {
	var size = prompt('Enter size for the heading block (1: largest to 5: smallest)','3')
	tag = 'h'+size
	}
// if the user has a section highlighted, use that to format
	if (document.selection.createRange().text != '') {
	var Text = document.selection.createRange().text;
	document.AddEvent.Description.focus();
	var sel = document.selection.createRange();	
	sel.text = '<'+tag+'>'+Text+'</'+tag+'>';	
	}
//Otherwise prompt user for input to format
	else {
	var Text = prompt('Enter text to set ' + action);		
	document.AddEvent.Description.focus();
//only continue if they have entered a value to format
	if (Text != null) {
	document.AddEvent.Description.value = 	document.AddEvent.Description.value+'<'+tag+'>'+Text+'</'+tag+'>';
	}
	}
} 

// Non Breaking Space Script
function Space () {	
	document.AddEvent.Description.focus();
	document.AddEvent.Description.value = document.AddEvent.Description.value+"&nbsp;";
	} 

// Font Format Script
function FormatFont () {	
	var fontcolor = prompt('Enter font color (ALLOWED: Aqua, Blue, Fuchsia, Gray, Green, Lime, Olive, Purple, Red, Silver, Teal, White, Yellow)', 'Black');
// only continue if they have entered a color
	if (fontcolor != null) {
// if they have a selection highlighted, use it to format the font
	if (document.selection.createRange().text != '') {
	var fonttext = document.selection.createRange().text;
	var sel = document.selection.createRange();
	document.AddEvent.Description.focus();
	sel.text = '<font color="'+fontcolor+'">'+fonttext+'</font>';
	}
// otherwise, prompt user for input to format
	else {
	var fonttext = prompt('Enter text to be formatted');
//only continue  if they have entered text to format
	if (fonttext != null) {
	document.AddEvent.Description.focus();
	document.AddEvent.Description.value = document.AddEvent.Description.value+'<font color="'+fontcolor+'">'+fonttext+'</font>';
	}
	}	
	}
}

// Link Script	
function HyperlinkText () {
	var address = prompt('Enter web address for link', 'http://www.');
// only continue if they have entered an address
	if (address != null) {	
//only continue if they have entered text for the link
// if they have a selection highlighted, use it to format the font
	if (document.selection.createRange().text != '') {
	var linkedtext = document.selection.createRange().text;
	var sel = document.selection.createRange();
	document.AddEvent.Description.focus();
	sel.text = '<a href="'+address+'" target="_blank">'+linkedtext+'</a>';
	}
	else {
	var linkedtext = prompt('Enter text for the link');
	if (linkedtext != null) {	
	document.AddEvent.Description.focus();
	document.AddEvent.Description.value = document.AddEvent.Description.value+'<a href="'+address+'" target="_blank">'+linkedtext+'</a>';
	}
	}
	}
}

// Linebreak script	
function Linebreak() {
	document.AddEvent.Description.focus();
	document.AddEvent.Description.value = document.AddEvent.Description.value+'<br>';
	
	}

// List script ordered and unordered
function List(type) {
// set item dialoge box to 1 and set an array for list items
	var itemtext = new Array();
	var listitem = 1;
//establish list size & set variable to perform loop to output <li> tags
	var listsize = prompt('how many items in this list?', '1');
// only continue if they entered a size for the list
	if (listsize != null) {
	var counter = listsize;	
//loop to to define each list item in the array - loop number of times specified
	while (listsize > 0) {		
		itemtext[listitem] = prompt('Enter item'+' '+listitem);
		listsize -= 1;
		listitem += 1;
		}
//add eventlongdescriptions to textarea
	var listitem = 1;
	document.AddEvent.Description.value = document.AddEvent.Description.value+'<'+type+'>'
//loop to add each item to list code
		while (counter > 0) {
			document.AddEvent.Description.value = document.AddEvent.Description.value+'<li>'+itemtext[listitem]+'</li>';
			counter -= 1;
			listitem += 1;
			}
		document.AddEvent.Description.value = document.AddEvent.Description.value+'</'+type+'>';
		document.AddEvent.Description.focus();
	}
}
