/*
Main script file for the courier


Under no circumstances is this file to be
modified by anyone but Kevin Cuzner
...since it is probably going to be written
in speghetti code (a.k.a. uncommented)
*/

stack = new Array();

// Replacement for arrayname.length property
function getarraysize(thearray) {
	for (i = 0; i < thearray.length; i++) {
		if ((thearray[i] == "undefined") || (thearray[i] == "") || (thearray[i] == null))
			return i;
		}
	return thearray.length;
}

// Replacement for arrayname.push(value) not implemented in IE until version 5.5
// Appends element to the array
function arraypush(thearray,value) {
	thearray[ getarraysize(thearray) ] = value;
}

// Replacement for arrayname.pop() not implemented in IE until version 5.5
// Removes and returns the last element of an array
function arraypop(thearray) {
	thearraysize = getarraysize(thearray);
	retval = thearray[thearraysize - 1];
	delete thearray[thearraysize - 1];
	return retval;
}

function DoInsert(beg,mid,end,finish) {
	var theplace = document.theform.thetext;
	theplace.value+=beg+mid;
	
	if (finish == true) {
		theplace.value+=end;
	}
	else {
		arraypush(stack,end);
	}
}

function bold() {
	DoInsert('[b]','','[/b]',false);
}

function italic() {
	DoInsert('[i]','','[/i]',false);
}

function underline() {
	DoInsert('[i]','','[/i]',false);
}

function orient(pos) {
	/*
	0: center
	1: left
	2: right
	*/
	DoInsert('[b]','','[/b]',false);
}

function closeAll() {
	var size = getarraysize(stack);
	var theplace = document.theform.thetext;
	
	alart(size);
	for(i=0;i<size;i++) {
		theplace.value+=arraypop(stack);
	}
}