function insertTag(przed, po)
{
  	pole = document.getElementById("tresc");
  
		if (document.selection) // IE/Opera
		{ 
			pole.focus();
			obszar = document.selection.createRange();
			obszar.text = przed+obszar.text+po;
			obszar.select();
		} 
		else if (pole.selectionStart>-1)  // FireFox
		{
			start = pole.selectionStart;
			tekst = przed+pole.value.substring(start,pole.selectionEnd)+po;
			pole.value = pole.value.substring(0, start)
			+ tekst + pole.value.substring(pole.selectionEnd, pole.value.length);
			pole.selectionStart = start+tekst.length;
			pole.selectionEnd   = pole.selectionStart;
		}

}


function selectCheck(v) {
	i=0;
	while (pole = document.getElementById("id"+i))
	{
		pole.checked = v.checked;
		i++;
	}
}


//oddanie głosu na sondzie typu yes/no
function sondaGlosuj(glos, id) 
{
	document.getElementById('sonda_odp'+id).value = glos;
	document.getElementById('sonda_odp'+id).form.submit();
}

//podświetla linie w sondzie typu yes/no
function sondaOver(glos, id) 
{
	document.getElementById('sonda_wynik'+glos+'_'+id).style.background = (glos==1?"#ff9494":"#9494FF");
}
//odświetla linie w sondzie typu yes/no
function sondaOut(glos, id)  
{
	document.getElementById('sonda_wynik'+glos+'_'+id).style.background = (glos==1?"#FF0000":"#0000FF");
} 

//sprawdzanie ilosci zaznaczen w sondzie typu checkbox
function sondaCheckbox(k, count, id) 
{
	i=0;
	zaz=0;
	while (a = document.getElementById('sonda_odp'+i+'_'+id))
	{
		if (a.checked) zaz++;
		i++;
	}

	if (count<zaz)
	{
		k.checked = false;
		alert('Możesz zaznaczyć maksymalnie '+count+' odpowiedzi!')
	}
}



//edycja tekstu
function editText(v, typ)
{
	document.getElementById('edit_'+v+'_tekst').value = (typ==1?document.getElementById('show_'+v).innerHTML:'');
	
	e = document.getElementById('edit_'+v+'_tekst').value;
	if (e.replace(/ć/g, "c")=='Kliknij aby dodac tekst!') e='';
	e = e.replace(/<BR>/g, "");
	e = e.replace(/<br>/g, "");
	document.getElementById('edit_'+v+'_tekst').value = e;
	
	//document.getElementById('edit_motto_tekst').value = e.replace(/ć/g, "c");
	document.getElementById('show_'+v).style.display = (typ==1?'none':'block');
	document.getElementById('edit_'+v).style.display = (typ==1?'block':'none');
}

jQuery(document).ready(function($) {

	// tip na herbach
	$('a.herb').cluetip({
		splitTitle: '|',
		positionBy: 'bottomTop',
		topOffset: 20,
		leftOffset: -80,
		tracking: true,
		width: 120,
		cluetipClass: 'herb'
	});
	
	// tip na tabelach
	$('span[title], td[title]').cluetip({
		splitTitle: '|',
		positionBy: 'bottomTop',
		topOffset: 20,
		leftOffset: -80,
		tracking: true,
		width: 120,
		cluetipClass: 'herb'
	});
	
	
	// powiększenie obrazków
	$('a[rel*=facebox]').facebox() 


});