
// konfiguracja
var g_LiveEditReaction = false; // zmienna odpowiadajaca za wartosc zwracana przez liveEditora
var g_allowLiveEditNodesEvents = false; // czy zezwalac na reakcje wezly liveEdita
var g_LiveEditLastCtrl = null;
// == koniec ==


function flashButton(name, dir, width, height, flashParams){
	if (AC_FL_RunContent == 0) {
		alert("Blad podczas wczytywania AC_RunActiveContent.js.");//lub jego brak
	} else {
	 AC_FL_RunContent(
	  'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0',
	  'width', width,
	  'height', height,
	  'src', dir+name,
	  'quality', 'high',
	  'pluginspage', 'http://www.macromedia.com/go/getflashplayer',
	  'align', 'middle',
	  'play', 'true',
	  'loop', 'true',
	  'scale', 'showall',
	  'wmode', 'transparent',
	  'devicefont', 'false',
	  'id', 'swf_'+name,
	  'bgcolor', '#ff99cc',
	  'name', name,
	  'menu', 'true',
	  'allowFullScreen', 'false',
	  'allowScriptAccess','always',
	  'movie', dir+name,
	  'flashvars', flashParams,
	  'salign', ''
	  );
	}
}

function liveEdit(ob, givenId)
{
	//alert('dzialam se');
	/*if(g_LiveEditLastCtrl != null)
	{
		g_LiveEditLastCtrl.getElementsByTagName('input').item(2).click(); # do dopracowania
	}
	g_LiveEditLastCtrl = ob;*/
	ob.ondblclick = function(){ return true; }
	
	//alert(ob.parentNode.offsetWidth);
	//ob.style.width = ob.parentNode.offsetWidth;
	//ob.style.border = '1px solid #f00';
	
	var bufforek = ob.innerHTML;
	ob.innerHTML = '';
	var poleEdytorki = document.createElement('input');
	poleEdytorki.setAttribute('type', 'text');
	
	if(givenId == null)
		poleEdytorki.setAttribute('name', 'aureliusLiveEdit_ctrl_'+givenId);
	else
		poleEdytorki.setAttribute('name', 'aureliusLiveEdit_ctrl_'+givenId);
	
	poleEdytorki.value = bufforek;
	poleEdytorki.className = 'liveEditCtrl';
	//poleEdytorki.style.width = ob.style.width - 24;
	
	var submitEdytorki = document.createElement('input');
	submitEdytorki.setAttribute('type', 'submit');
	submitEdytorki.setAttribute('name', 'aureliusLiveEdit_content');
	submitEdytorki.setAttribute('value', 's');
	
	var submitEdytorkaZamykajaca = document.createElement('input');
	submitEdytorkaZamykajaca.setAttribute('type', 'submit');
	submitEdytorkaZamykajaca.setAttribute('name', 'aureliusLiveEdit_content_close');
	submitEdytorkaZamykajaca.setAttribute('value', 'x');
	
	submitEdytorki.className = 'liveEditSub';
	submitEdytorkaZamykajaca.className = 'liveEditSub';
	
	submitEdytorki.onclick = function()
	{
		// dosc dlugo rozpisana funkcja ajaxu
		var tgetLink = ("admin/dict_guardian.php?action=updateValue&dic_id="+givenId+'&newVal='+poleEdytorki.value);
		
		var polaczenie = ajaxFunction();
		polaczenie.open("GET", tgetLink, true);
		polaczenie.send(null);
		
		polaczenie.onreadystatechange=function()
		{
		if(polaczenie.readyState==4)
		  {
			var odpowiedz = polaczenie.responseText;
			window.status = 'Odpowiedz powloki: '+odpowiedz;
			
			
			return true;
		  }
		}
		
		ob.innerHTML = poleEdytorki.value;
		ob.ondblclick = function(){ liveEdit(ob, givenId); }
	}
	
	submitEdytorkaZamykajaca.onclick = function()
	{
		ob.innerHTML = bufforek;
		ob.ondblclick = function(){ liveEdit(ob, givenId); }
	}
	//znacznik.className = 'upload';
	//var kontener = document.getElementById(kontener);
	ob.appendChild(poleEdytorki);
	ob.appendChild(submitEdytorki);
	ob.appendChild(submitEdytorkaZamykajaca);
	
	return g_LiveEditReaction; // reaguj zdefiniowana reakcja - jesli uzytkownik chce przeskakiwac musi byc true, jesli edytowac musi byc false
}

function getInternetExplorerVersion()
	// Returns the version of Internet Explorer or a -1
	// (indicating the use of another browser).
	{
	  var rv = -1; // Return value assumes failure.
	  if (navigator.appName == 'Microsoft Internet Explorer')
	  {
		var ua = navigator.userAgent;
		var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
		if (re.exec(ua) != null)
		  rv = parseFloat( RegExp.$1 );
	  }
	  return rv;
	}
	function wysrodkuj(img)
	{
		if(img == null) return false;
		
		img.style.position = 'absolute';
		
		img.style.margin = ''+(img.height/2)+'px -'+(img.width/2)+' 0px';
	}
