window.onload = function () 
{
		var el = document.getElementById('bold'); 
		var textarea = document.getElementsByTagName('textarea')[0];
		el.onclick = function () { wrap(textarea, 'B') }
		
		var hlp = document.getElementById('help');
		hlp.onclick = getHelp;

}

function wrap(myArea, tag) 
{ 
	var txt = 'Pažymėkite tekstą';
	if( document.selection ) //IE 
	{
		var range = document.selection.createRange();
		if(range.text)
		{
			var stored_range = range.duplicate();
			stored_range.moveToElementText(myArea);
			stored_range.setEndPoint('EndToEnd', range);
			myArea.selectionStart = stored_range.text.length - range.text.length;
			myArea.selectionEnd = myArea.selectionStart + range.text.length;
		}
		else
			alert(txt)
	}

	if (typeof(myArea.selectionStart) != "undefined") 
	{ 
		
		 var begin = myArea.value.substr(0, myArea.selectionStart); 
		 var selection = myArea.value.substr(myArea.selectionStart, myArea.selectionEnd - myArea.selectionStart); 
		 var end = myArea.value.substr(myArea.selectionEnd);
		 if(selection)
		 {
			 myArea.value = begin + '[' + tag + ']' + selection + '[/' + tag + ']' + end; 
		 }
		 else
			 alert(txt)
	}
}

function getHelp()
{
	var host = location.href.match(/^http:\/\/[^\/]+/); 
	if (host)
	{
		var width = 450;
		var height = 250;

		var top = Math.floor((screen.availHeight-height)/2)-(screen.height-screen.availHeight);
	    var left = Math.floor((screen.availWidth-width)/2)-(screen.width-screen.availWidth);


		window.open(host + '/Crib/help', 'wo', 'toolbar=0, scrollbars=0, resizable=0, location=0, width='+width+', height='+height+', top='+top+', left=' + left);
	}
}

function validate()
{
	var txt = document.getElementById('text');
	if (txt.value.length > 20000)
	{
		var ans = confirm('Maksimalus leidžiamas simbolių kiekis - 20 000. Tęsti?');
		if (!ans)
		{
			return false;
		}
	}
}
