//adds tag to end of the text in text_area
function AppendTag(tag){
form_object = window.document.forms[form_name].elements[text_area];
form_object.value = form_object.value + "<" + tag + ">" + "</" + tag + ">";
form_object.focus();
}

//if supported surrounds selection with tag, otherwise just appends
function InsertTag(tag) {
form_object = window.document.forms[form_name].elements[text_area];

if(document.selection){ //testing for support
	strSelection = document.selection.createRange().text
	if (strSelection == "") {
		AppendTag(tag);
	}	
	else {
	document.selection.createRange().text = "<" + tag + ">" + strSelection + "</" + tag + ">";
	form_object.focus();
	}
	return;
	}
else{	
AppendTag(tag);
	}
}

//appends a string (presumably a tag) to the text_area text
function AddTag(tag){
form_object = window.document.forms[form_name].elements[text_area];
form_object.value = form_object.value + tag
form_object.focus();
}

//if supported surrounds selection with given strings
function SurroundTags(tag1,tag2) {
form_object = window.document.forms[form_name].elements[text_area];

if(document.selection){
	strSelection = document.selection.createRange().text
	if (strSelection == "") {
		AddTag(tag1+tag2);
	}	
	else {
	document.selection.createRange().text = tag1 + strSelection + tag2;
	form_object.focus();
	}
	return;
	}
else{	
AddTag(tag1+tag2);
	}
}

//if supported + have selected something surrounds selection with link
//otherwise runs link wizard
function InsertLink() {
form_object = window.document.forms[form_name].elements[text_area];

if(document.selection){ //testing for support
	strSelection = document.selection.createRange().text
	if (strSelection == "") {
		popup('http://www.rakehell.net/divineditor_light/link.html','link','status=yes,scrollbars=yes,resizable=yes,width=420,height=340');
		form_object.focus();
	}	
	else {
	var url = prompt("What's the URL?","http://");
	document.selection.createRange().text = '<a href="' + url + '">' + strSelection + '</a>';
	form_object.focus();
	}
	return;
	}
else{	
popup('http://www.rakehell.net/divineditor_light/link.html','link','status=yes,scrollbars=yes,resizable=yes,width=420,height=340');
	}
}

//gets rid of annoying thing that surrounds image links in IE
function ExplorerFix()
  {
   for (a in document.links) document.links[a].onfocus =
   document.links[a].blur;
  }
 if (document.all)
  {
   document.onmousedown = ExplorerFix;
  }
 
function popup(theURL,winName,features)
{ 
 window.open(theURL,winName,features);
}

function preloadImages(the_images_array) {

	for(loop = 0; loop < the_images_array.length; loop++)
	{
   		var an_image = new Image();
		an_image.src = the_images_array[loop];
	}
}

var the_images = new Array('divineditor_light/img/paragraph_on.gif','divineditor_light/img/paragraph_click.gif','divineditor_light/img/bold_on.gif','divineditor_light/img/bold_click.gif','divineditor_light/img/help_on.gif','divineditor_light/img/help_click.gif','divineditor_light/img/italic_on.gif','divineditor_light/img/italic_click.gif','divineditor_light/img/link_on.gif','divineditor_light/img/link_click.gif','divineditor_light/img/whatis_on.gif','divineditor_light/img/center_click.gif','divineditor_light/img/right_click.gif','divineditor_light/img/mail_click.gif','divineditor_light/img/br_click.gif','divineditor_light/img/image_click.gif','divineditor_light/img/bulleted_click.gif','divineditor_light/img/numbered_click.gif','divineditor_light/img/sub_click.gif','divineditor_light/img/super_click.gif','divineditor_light/img/under_click.gif');


//sample implementation:
//<a href="" onMouseOver="Swap('name','img/src2.gif');" onMouseOut="Swap('name','img/src1.gif');">
function Swap(image_name,new_src)
{
	if(document.images){window.document.images[image_name].src = new_src;}
}

//sample implementation:
//<a href="" onMouseOver="SwapOn('name');" onMouseOut="SwapOff('name');" onclick="SwapClick('name');">
//requires standardized image naming (of files and code)
// <img name="car"> 
// initial image: car.gif 
// rollover image: car_on.gif

function SwapOn(image_name)
{
	if(document.images){
	window.document.images[image_name].src = image_path + image_name + "_on" + image_type;
	}
}

function SwapOff(image_name)
{
	if(document.images){
	window.document.images[image_name].src = image_path + image_name + image_type;
	}
}

function SwapClick(image_name)
{
	if(document.images){
	window.document.images[image_name].src = image_path + image_name + "_click" + image_type;
	}
}

