/*
        Expand Code Area
*/
function expandIt(whichEl){
    whichEl.style.display = (whichEl.style.display == "none" ) ? "" : "none";
}

/*
	Smiley Face List
*/
function smiley_list() {
	window.open('smilies.html','Smilies','width=250,height=500,resizable=yes,scrollbars=yes'); 
}

/*
	Help bar messages
*/
var help_center = "(alt + c) Text will appear centered";
var help_bold = "(alt + b) Text will appear Bold";
var help_italic = "(alt + i) Text will appear in Italics";
var help_underline = "(alt + u) Text will appear Under-lined";
var help_close = "Close all open tags";
var help_href = "(alt + h) Create a hyperlink [href]http://www.domain.com[/href]";
var help_img = "(alt + p) Display an image [img]http://www.domain.com/picture.gif[/img]";
var help_email = "(alt + m) Create a mailto link";
var help_quote = "(alt + q) Quoted text";
var help_code = "(alt + s) Text will be formatted as source code";
var help_click_close = "Click button again to close this tag";

/*
	Tag Insert Code
	Hybrid InvisionBoard, Apollo and Mozilla.org JavaScript
	IB Mod by Volker Puttrich
*/

var B_open = 0;
var I_open = 0;
var U_open = 0;
var quote_open = 0;
var code_open = 0;
var href_open = 0;
var center_open = 0;
var img_open = 0;
var email_open = 0;

var bbtags = new Array();

// From http://www.mozilla.org/docs/web-developer/sniffer/browser_type.html
var myAgent   = navigator.userAgent.toLowerCase();
var myVersion = parseInt(navigator.appVersion);

var is_ie   = ((myAgent.indexOf("msie") != -1)  && (myAgent.indexOf("opera") == -1));
var is_nav  = ((myAgent.indexOf('mozilla')!=-1) && (myAgent.indexOf('spoofer')==-1)
                && (myAgent.indexOf('compatible') == -1) && (myAgent.indexOf('opera')==-1)
                && (myAgent.indexOf('webtv') ==-1)       && (myAgent.indexOf('hotjava')==-1));

var is_win   =  ((myAgent.indexOf("win")!=-1) || (myAgent.indexOf("16bit")!=-1));
var is_mac    = (myAgent.indexOf("mac")!=-1);

/*
	Help form field box text
*/
function hstat(msg)
{
	document.ApolloForm.helpbox.value = eval( "help_" + msg );
}

/*
	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 the Stack
*/
function popstack(thearray)
{
	arraysize = stacksize(thearray);
	theval = thearray[arraysize - 1];
	delete thearray[arraysize - 1];
	return theval;
}

/*
	Close all open tags
*/
function closeall()
{
	if (bbtags[0]) {
		while (bbtags[0]) {
			tagRemove = popstack(bbtags)
			document.ApolloForm.msgBody.value += "[/" + tagRemove + "]";
			// Change the button status
			eval("document.ApolloForm." + tagRemove + ".value = ' " + tagRemove + " '");
			eval(tagRemove + "_open = 0");
		}
	}
	
	// Check we got them all
	bbtags = new Array();
	document.ApolloForm.msgBody.focus();
}

/*
	Smiley Face
*/
function smiley(theSmilie)
{
	doInsert(" " + theSmilie + " ", "", false);
}

/*
	Add Code
*/
function add_code(NewCode)
{
    document.ApolloForm.msgBody.value += NewCode;
    document.ApolloForm.msgBody.focus();
}

/*
	Tag Insert
*/
function insertTag(thetag) {

	var tagOpen = eval(thetag + "_open");
	
	if (tagOpen == 0) {

		if (doInsert("[" + thetag + "]", "[/" + thetag + "]", true)) {
			eval(thetag + "_open = 1");
			eval("document.ApolloForm." + thetag + ".value += '*'");
			pushstack(bbtags, thetag);
			hstat('click_close');
		}

	} else {

		// Find the last occurance of the opened tag
		lastindex = 0;
	
		for (i = 0 ; i < bbtags.length; i++ ) {
			if (bbtags[i] == thetag) {
				lastindex = i;
			}
		}
	
		// Close all tags opened up to that tag was opened
		while (bbtags[lastindex]) {
			tagRemove = popstack(bbtags);
			doInsert("[/" + tagRemove + "]", "", false)
			
			// Change the button status
			eval("document.ApolloForm." + tagRemove + ".value = ' " + tagRemove + " '");
			eval(tagRemove + "_open = 0");
		}
	
	}

}

function doInsert(ibTag, ibClsTag, isSingle)
{
	var ibTag = ibTag.toLowerCase();
	var ibClsTag = ibClsTag.toLowerCase();

	var isClose = false;
	var obj_ta = document.ApolloForm.msgBody;

	if ( (myVersion >= 4) && is_ie && is_win) // Ensure it works for IE4up / Win only
	{
		if(obj_ta.isTextEdit){ // this doesn't work for NS, but it works for IE 4+ and compatible browsers
			obj_ta.focus();
			var sel = document.selection;
			var rng = sel.createRange();
			rng.colapse;
			if((sel.type == "Text" || sel.type == "None") && rng != null){
				if(ibClsTag != "" && rng.text.length > 0)
					ibTag += rng.text + ibClsTag;
				else if(isSingle)
					isClose = true;
	
				rng.text = ibTag;
			}
		}
		else{
			if(isSingle)
				isClose = true;
	
			obj_ta.value += ibTag;
		}
	}
	else
	{
		if(isSingle)
			isClose = true;

		obj_ta.value += ibTag;
	}

	obj_ta.focus();
	
	return isClose;
}

/*
	End of File
*/
