// 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 insertCode(text) {
	text = '' + text + '';
	if (document.chapter_input.paragraph_text.createTextRange && document.chapter_input.paragraph_text.caretPos) {
		var caretPos = document.chapter_input.paragraph_text.caretPos;
		caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == '' ? text + '' : text;
		document.chapter_input.paragraph_text.focus();
	} else {
	document.chapter_input.paragraph_text.value  += text;
	document.chapter_input.paragraph_text.focus();
	}
}

function storeCaret(textEl) {
	if (textEl.createTextRange) textEl.caretPos = document.selection.createRange().duplicate();
}

