﻿function wstawCiag(ciag1,ciag2)
{
	var textarea=document.edytor.stronka;
	
	microsoft=false;
	theSelection = false;
	
	// wykrywamy czy to jest I4
	if(navigator.appName.indexOf("Explorer")>0) 
	{
		theSelection = document.selection.createRange().text; // Get text selection
		microsoft=true;
	}
		//confirm(navigator.appName);
	
	if(theSelection)
	{	// 4 IE
		document.selection.createRange().text=ciag1+theSelection+ciag2;
		//confirm(theSelection);
	}
	else
	{
	 	if(microsoft) textarea.value=textarea.value+ciag1+ciag2;
	}
	
	if(!microsoft)
	{	// 4 Mozilla
		starcik=textarea.selectionStart;
		koncik=textarea.selectionEnd;
		dlugosc=textarea.value.length;
		
		// Jest zaznaczenie
		textarea.selectionStart=3;
		textarea.selectionEnd=3;
		textcik='';

		s1=textarea.value.substring(0,starcik);
		s2=textarea.value.substring(starcik,koncik);
		s3=textarea.value.substring(koncik,dlugosc);
		
		textcik=s1+ciag1+s2+ciag2+s3;

		textarea.value=textcik;
	}
	textarea.focus();
}

function bolduj() 
{
	wstawCiag('[b]','[/b]');
}
			
function kursywuj() 
{
	wstawCiag('[k]','[/k]');
}
			
function podkresl() 
{
	wstawCiag('[p]','[/p]');
}

function linkuj() 
{
	wstawCiag('[link:"",1,""]','[/link]');
}

function grafikuj() 
{
	wstawCiag('[graf:kod,LOK,rozmX,rozmY]','');
}

function dokumentuj() 
{	
	wstawCiag('[dok:kod,1]','[/dok]');
}

function enduj()
{
	wstawCiag('[br]','');
}

// Czysci formularz edycyjny w edycji stronki
function czyscTextarea() 
{	
	var textarea=document.edytor.stronka;
	textarea.value="";
	textarea.focus();
}
// Otwiera w nowym oknie
function displayGraphicsWindow(url, width, height) 
{	
	//'width=' + width + ',height=' + height + ',resizable=yes,scrollbars=yes,menubar=no'
	//url
	//var Win = window.open("index.php","Elkom Sp. z.o.o.", "width=100,height=100");
	var Win = window.open(url,"displayWindow",'width=' + width + ',height=' + height + ',resizable=1,scrollbars=1,menubar=off' );
}

function potwierdzenie(what)
{

	//confirm("Jesteś pewny?");
	//document.edytor.reset();
	//what
	if(confirm(what)) 
	{
		//click();
		return true;
	} 
	else 
	{ 
		return false;
	} 
}
