bbtags   = new Array();

	// IBC Code stuff
	var text_enter_url      = "Enter the complete URL for the hyperlink";
	var text_enter_url_name = "Enter the title of the webpage";
	var text_enter_image    = "Enter the complete URL for the image";
	var text_enter_alt		= "Enter a Title for the image";
	var text_enter_email    = "Enter the email address";
	var text_enter_flash    = "Enter the URL to the Flash movie.";
	var text_code           = "Usage: [CODE] Your Code Here.. [/CODE]";
	var text_quote          = "Usage: [QUOTE] Your Quote Here.. [/QUOTE]";
	var error_no_url        = "You must enter a URL";
	var error_no_title      = "You must enter a title";
	var error_no_email      = "You must enter an email address";
	var error_no_width      = "You must enter a width";
	var error_no_height     = "You must enter a height";
	//-->
//--------------------------------------------
// Get stack size
//--------------------------------------------
function stacksize(thearray)
{
	for (i = 0 ; i < thearray.length; i++ )
	{
		if ( (thearray[i] == "") || (thearray[i] == null) || (thearray == 'undefined') )
		{
			return i;
		}
	}
	return thearray.length;
}
//--------------------------------------------
// Push stack
//--------------------------------------------
function pushstack(thearray, newval)
{
	arraysize = stacksize(thearray);
	thearray[arraysize] = newval;
}
//--------------------------------------------
// Pop stack
//--------------------------------------------
function popstack(thearray)
{
	arraysize = stacksize(thearray);
	theval = thearray[arraysize - 1];
	delete thearray[arraysize - 1];
	return theval;
}
//--------------------------------------------
// Close current open tag
//--------------------------------------------
function closelast(thename)
{
	if (bbtags[0])
	{
		var el;
		var els = document.getElementsByName(thename);
		
		el = els[0];
		el.value+='[/'+popstack(bbtags)+']';
//		document.form3.Post.value += "[/" + popstack(bbtags) + "]";
	}
	el.focus();
//	document.form3.Post.focus();
}
//--------------------------------------------
// Close all tags
//--------------------------------------------
function closeall(thename)
{
	if (bbtags[0])
	{
		while (bbtags[0])
		{
			var el;
			var els = document.getElementsByName(thename);
			
			el = els[0];
			el.value+='[/'+popstack(bbtags)+']';
//			document.form3.Post.value += "[/" + popstack(bbtags) + "]";
		}
		
		el.value+=' ';
//		document.form3.Post.value += " ";
	}
	el.focus();
//	document.form3.Post.focus();
}
//--------------------------------------------
// ALTER FONT
//--------------------------------------------
function alterfont(theval, thetag, thename)
{
    if (theval == 0)
    {
    	return;
    }
    else
    {
		var el; 
		var els = document.getElementsByName(thename); 
	
		if(!els.length) 
		{ 
			return; 
		} 
	
		el = els[0]; 

		el.value += '[' + thetag + '=' + theval + ']'; 
//    	document.form3.Post.value += "[" + thetag + "=" + theval + "]";
    	pushstack(bbtags, thetag);
    }
//    document.Load.ffont.selectedIndex  = 0;
//    document.Load.fsize.selectedIndex  = 0;
//    document.Load.fcolor.selectedIndex = 0;
    el.selectedIndex = 0;
    el.focus();
}
//--------------------------------------------
// SIMPLE TAGS (such as B, I U, etc)
//--------------------------------------------

function simpletag(thetag, thename) 
{ 
    var el; 
    var els = document.getElementsByName(thename); 

    if(!els.length) 
    { 
        return; 
    } 

    el = els[0]; 
    el.value += '[' + thetag + ']'; 

    pushstack(bbtags, thetag); 

    el.focus(); 
}
function tag_url(thename)
{
    var el; 
    var els = document.getElementsByName(thename); 
    var FoundErrors = '';
    var enterURL   = prompt('text_enter_url', "http://");
    var enterTITLE = prompt('text_enter_url_name', "My Webpage");
	
	el = els[0];

    if(!els.length) 
    { 
        return; 
    } 

    if (!enterURL)
    {
        FoundErrors += " " + error_no_url;
    }
    if (!enterTITLE)
    {
        FoundErrors += " " + error_no_title;
    }
    if (FoundErrors)
    {
        alert("Error!"+FoundErrors);
        return;
    }
    var ToAdd = "[URL="+enterURL+"]"+enterTITLE+"[/URL]";
	
	el.value+=ToAdd;
	el.focus();
}

function tag_image(thename)
{
    var el; 
    var els = document.getElementsByName(thename); 
    var FoundErrors = '';
    var enterURL   = prompt(text_enter_image, "http://");
	var enterALT   = prompt(text_enter_alt, "Enter a Title for the Image");
	
	el = els[0];
    if (!enterURL) {
        FoundErrors += " " + error_no_url;
    }
    if (FoundErrors) {
        alert("Error!"+FoundErrors);
        return;
    }
	if ( !enterALT )
	{
		var ToAdd = "[IMG]"+enterURL+"[/IMG]";
	}
	else
	{
		var ToAdd = "[IMG]"+enterURL+" [alt]"+enterALT+"[/alt][/IMG]";
	}
    el.value+=ToAdd;
	el.focus();
}
function tag_email(thename)
{
    var el; 
    var els = document.getElementsByName(thename); 
    var emailAddress = prompt(text_enter_email,"");
	
	el = els[0];
	
    if (!emailAddress) { alert(error_no_email); return; }
    var ToAdd = "[EMAIL]"+emailAddress+"[/EMAIL]";
    el.value+=ToAdd;
	el.focus();
}
