//this is a series of functions that some, but not all pages use, must be implicitly included
var expanded_item = '';

//functions for highlighting text and putting in links
function addLink(name){
	//get the selection
	 var selection = get_selection($(name)); 

	//get the url
	var response = prompt('Enter Link URL','');  
    if(response != null)  
	{
         replace_selection($(name),'<a href=\'' + response + '\'>' + selection + '</a>');
	}
}

function replace_selection(itemId,replaceString){
	if(!!document.selection){
			itemId.focus();
			var old = document.selection.createRange().text;
			var range = document.selection.createRange();
			if(old == '')
				itemId.innerHTML += replaceString;
			else{
				range.text = replaceString;
				range -= old.length - replaceString.length;
			}
		}else if(!!itemId.setSelectionRange){
			var selection_start = itemId.selectionStart;
			itemId.value = itemId.value.substring(0,selection_start) + replaceString + itemId.value.substring(itemId.selectionEnd);
			itemId.setSelectionRange(selection_start + replaceString.length,selection_start + replaceString.length);
		}

}

function get_selection(itemId){
	if(!!document.selection)
	{
		return document.selection.createRange().text;
	}
	else if(!!itemId.setSelectionRange)
	{
		return itemId.value.substring(itemId.selectionStart,itemId.selectionEnd);
	}
	else
	{
		return false;
	}
}

function checkLength(titleInput,size){
	
	if(titleInput.value.length + 1 >= size)
	{	
		//if there are more than 25 characters, limit the title to the size specified
		titleInput.value = titleInput.value.substring(0,size);
	}
}

function expandList(commaList){
	var listArray = commaList.split(',');
	
	for(i = 0; i < listArray.length; i ++)
	{
		expandItem(listArray[i]);
	}
}

function expandItem(name){
	
	if(expanded_item != name)
	{
		//close the already expanded item
		if(expanded_item != '')
		{
			Effect.SlideUp(expanded_item);
		}
		
		expanded_item = name;
		
		//expand the new item
		Effect.SlideDown(name);
	}
}