var selText;
var selStart;
var selEnd;
var MozBegText = '';
var MozEndText = '';
var textObj;
var curBlog = '';

//handles text selection
function getActiveText(e) 
{ 
	if (document.all)
	{
		selText = (document.all) ? document.selection.createRange().text : document.getSelection();
	}
	else
	{
		if (document.getElementById)
		{
			textObj = 'none';
			
			if (document.CreateBlogForm.blogtext.selectionStart < document.CreateBlogForm.blogtext.selectionEnd)
				textObj = document.CreateBlogForm.blogtext;
			else
			{
				if (document.CreateBlogForm.blogname.selectionStart < document.CreateBlogForm.blogname.selectionEnd)
					textObj = document.CreateBlogForm.blogname;
			}
			
			if (textObj != 'none')
			{
				selStart = textObj.selectionStart;
				selEnd = textObj.selectionEnd;
				selText = textObj.value.substring(selStart,selEnd);
				MozBegText = textObj.value.substring(0,selStart);
				MozEndText = textObj.value.substring(selEnd,document.CreateBlogForm.blogtext.value.length);
			}
			else
			{	
				selText = '';
			}
		}
	}
}


function formatText(w)
{
	
	
	var nText = '';
	var pText = '';
	try
	{
		switch(w.name)
		{
			case 'imageselect':
				var pImg = prompt('Copy this code and insert into requested location of image:','<img src="obj/'+w.value+'" align=left border=0>');
				w.selectedIndex= 0;
				return(false);
				break;	
		}
		
	}
	catch (e) {}
	
	if (selText != '')
	{
		switch (w)
		{
			case 'b':
				nText = "<b>"+selText+"</b>";
				break;
			case 'i':
				nText = "<i>"+selText+"</i>";	
				break;
			case 'u':
				nText = "<u>"+selText+"</u>";
				break;
			case 'l':
				nText = selText;
				pText = prompt("Enter address to link:","http://");
				if (pText)
				{
					if (pText != "http://")
						nText = '<a href="'+pText+'" target=__blank>'+selText+'</a>';
				}
				break;
			default:
				if (w.name == "fontsize")
					nText = "<font size="+w.value+">"+selText+"</font>";
				else
					nText = "<font color="+w.value+">"+selText+"</font>";
				
				w.selectedIndex= 0;
				break;	
		}
	
		if (nText != '')
		{
			if (document.all)
			{
				document.selection.createRange().text = nText;
			}
			else
			{
				 textObj.value = MozBegText + nText + MozEndText;
			}
		}
	}
	else
	{
		alert('Please select text first.');
	}
}

document.onmouseup = getActiveText;
if (!document.all) document.captureEvents(Event.MOUSEUP);

function GoToBlog(bdate,blgrid,id)
{
	try
	{
		document.location.hash = id;
		var gotou = -1;
		
		
		for (var x=0;x<document.anchors.length;x++)
		{
			if (document.anchors[x].name == id)
			{
				document.location.hash = id;
				gotou = x;
			}
		}
		
		
		if (gotou == -1)
			document.location.href =  "/blogger/archive.cfm?docinfo="+blgrid+"|"+unescape(bdate)+"|"+id; 
		
	}
	catch (e) {
		//
	}
	
}




function showDiv(x)
{
	if (curBlog != '')
	{
		try
		{	
			
			curBlog.innerHTML = '';
			
		}
		catch (e) {}
	}
	
	
	curBlog = getDocObj(x+"BlogTable");
	curBlog.innerHTML = getDocObj(x+"BlogArchive").innerHTML;
	
}
