/*
 * Style Functions
 *
 */

// Remember the current position.
function storeCaret(text)
{
	// Only bother if it will be useful.
	if (typeof(text.createTextRange) != 'undefined')
		text.caretPos = document.selection.createRange().duplicate();
}

// Surrounds the selected text with text1 and text2.
function surroundText(text1, text2, textarea)
{
	// Can a text range be created?
	if (textarea.createTextRange && textarea.caretPos)
	{
		var caretPos = textarea.caretPos;

		caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text1 + caretPos.text + text2 + ' ' : text1 + caretPos.text + text2;
		caretPos.select();
	}
	// Mozilla text range wrap.
	else if (textarea.selectionStart)
	{
		var begin = textarea.value.substr(0, textarea.selectionStart);
		var selection = textarea.value.substr(textarea.selectionStart, textarea.selectionEnd - textarea.selectionStart);
		var end = textarea.value.substr(textarea.selectionEnd);

		textarea.value = begin + text1 + selection + text2 + end;
		if (textarea.setSelectionRange)
		{
			var newCursorPos = textarea.selectionEnd + text1.length + text2.length;
			textarea.focus();
			textarea.setSelectionRange(newCursorPos, newCursorPos);
		}
	}
	// Just put them on the end, then.
	else
	{
		textarea.value += text1 + text2;
		textarea.focus(textarea.value.length - 1);
	}
}
/*
function SAP_encode_b64(Str)
{
	var encStr = "";

	var base64 = [
	'A','B','C','D','E','F','G','H','I','J','K','L','M',
	'N','O','P','Q','R','S','T','U','V','W','X','Y','Z',
	'a','b','c','d','e','f','g','h','i','j','k','l','m',
	'n','o','p','q','r','s','t','u','v','w','x','y','z',
	'0','1','2','3','4','5','6','7','8','9','+','/' ];

	for (var i = 0; i < Str.length; i += 3)
	{
		encStr += base64[(Str.charCodeAt(i) >>> 2)];
		if(!Str.charAt(i+1)) {encStr += '=='; break;}
		encStr += base64[(((Str.charCodeAt(i) & 0x03) << 4) | Str.charCodeAt(i+1) >>> 4)];
		if(!Str.charAt(i+2)) {encStr += '='; break;}
		encStr += base64[(((Str.charCodeAt(i+1) & 0x0F) << 2) | Str.charCodeAt(i+2) >>> 6)];
		encStr += base64[(Str.charCodeAt(i+2) & 0x3F)];
	}

	return encStr;
}
*/