<!--

// scroller 20091201, v1.2
var speed=4;function stepLeft(idMovable,idViewer,__id){__scrollPos(idMovable,idViewer,-(speed),__id)}function stepRight(idMovable,idViewer,__id){__scrollPos(idMovable,idViewer,speed,__id)}function slideLeft(idMovable,idViewer,__id){__startScroll(idMovable,idViewer,-(speed),__id)}function slideRight(idMovable,idViewer,__id){__startScroll(idMovable,idViewer,speed,__id)}function slideStop(__id){__stopScroll(__id)}function setMovableWidth(idMovable,idViewer,__id){if(!idMovable||!idViewer)return false;var widthMovable=__getMovableWidth(idMovable);d.getElementById(idMovable).style.width=widthMovable+'px';var dif=__isViewerWider(idMovable,idViewer);if(dif){var left=Math.floor(dif/2);d.getElementById(idMovable).style.left=left+'px';d.getElementById(arrLftId[__id]).src=arrLftB[__id];d.getElementById(arrRghId[__id]).src=arrRghB[__id]}return true}var d=document;presentOffset=new Array();presentPx=new Array();scrollTimer=new Array();arrLftId=new Array();arrRghId=new Array();arrLft=new Array();arrRgh=new Array();arrLftB=new Array();arrRghB=new Array();function __getMovableWidth(id){if(!id)return false;var widthMovable=0;var numChild=d.getElementById(id).getElementsByTagName('li').length;for(var i=0;i<numChild;i++){var widthLi=d.getElementById(id).getElementsByTagName('li').item(i).offsetWidth;widthMovable+=widthLi}return widthMovable}function __getMaxOffsetWidth(idMovable,idViewer){if(!idMovable||!idViewer)return false;var widthMovable=__getMovableWidth(idMovable);var widthViewer=__getViewerWidth(idViewer);var maxOffsetWidth=widthMovable-widthViewer;if(maxOffsetWidth<0)maxOffsetWidth=0;return maxOffsetWidth}function __getViewerWidth(id){if(!id)return false;return d.getElementById(id).offsetWidth}function __scrollPx(idMovable,idViewer,px,__id,lim){if(!idMovable||!idViewer)return false;if(!px)px=0;if(__isViewerWider(idMovable,idViewer))return false;var maxOffsetWidth=__getMaxOffsetWidth(idMovable,idViewer);if(lim){var movableOffset=__getMovableOffset(idMovable);if(px>0){if(presentPx[__id]>lim){presentPx[__id]=lim;__stopScroll(__id)}}else if(px<0){if(presentPx[__id]<lim){presentPx[__id]=lim;__stopScroll(__id)}}}if((presentPx[__id]+px)<0){presentPx[__id]=-px;d.getElementById(arrLftId[__id]).src=arrLftB[__id]}else{d.getElementById(arrLftId[__id]).src=arrLft[__id]}if(presentPx[__id]>maxOffsetWidth){presentPx[__id]=maxOffsetWidth;d.getElementById(arrRghId[__id]).src=arrRghB[__id]}else{d.getElementById(arrRghId[__id]).src=arrRgh[__id]}presentOffset[__id]=presentPx[__id]+px;if(presentOffset[__id]==0)presentOffset[__id]+=px;d.getElementById(idMovable).style.left=-(presentOffset[__id])+px+'px';presentPx[__id]=presentOffset[__id];return true}function __stopScroll(__id){if(!__id)return false;window.clearInterval(scrollTimer[__id]);return false}function __startScroll(idMovable,idViewer,px,__id,lim){if(!idMovable||!idViewer||!__id)return false;if(!px)px=0;__stopScroll(__id);scrollTimer[__id]=window.setInterval(function(){__scrollPx(idMovable,idViewer,px,__id,lim)},10);return true}function __getMovableOffset(id){if(!id)return false;var offset=d.getElementById(id).style.left;offset=offset.substr(1,(offset.length-3));if(!offset)offset=0;return offset}function __scrollPos(idMovable,idViewer,px,__id){if(!idMovable||!idViewer||!__id)return false;if(!px)px=0;var presentStep=__getPresentStep(idMovable,px);var lim=0;if(px>0){for(var i=0;i<presentStep;i++){var widthLi=d.getElementById(idMovable).getElementsByTagName('li').item(i).offsetWidth;lim+=widthLi}}else if(px<0){for(var i=0;i<(presentStep-1);i++){var widthLi=d.getElementById(idMovable).getElementsByTagName('li').item(i).offsetWidth;lim+=widthLi}}__startScroll(idMovable,idViewer,px,__id,lim);return true}function __getPresentStep(id,px){if(!id)return false;var widthMovable=0;var movableOffset=__getMovableOffset(id);var numChild=d.getElementById(id).getElementsByTagName('li').length;for(var i=0;i<numChild;i++){var widthLi=d.getElementById(id).getElementsByTagName('li').item(i).offsetWidth;widthMovable+=widthLi;if(widthMovable-px>=movableOffset)return(i+1)}return false}function __isViewerWider(idMovable,idViewer){if(!idMovable||!idViewer)return false;var widthMovable=__getMovableWidth(idMovable);var widthViewer=__getViewerWidth(idViewer);if(widthViewer>widthMovable){var dif=widthViewer-widthMovable;return dif}return false}


function updateChart(chartId,url) {
	//Get reference to chart object using Dom ID
	var chartObj = getChartFromId(chartId);
	//Update it's XML
	chartObj.setDataURL(url);
}

/**
 * Klasa do zarzadzanie listami rozwijalnymi, powiazanymi
 */
function Optioner(form, name){
    this._name = name;
    this._form = form;
    this._counter = 0;
    this._names = new Array();
    this._values = new Array();
    this._active = 0;
    this._selSet = false;
}

Optioner.prototype._active;
Optioner.prototype._name;
Optioner.prototype._form;
Optioner.prototype._counter;
Optioner.prototype._names;
Optioner.prototype._values;
Optioner.prototype._selNames;
Optioner.prototype._selSet;
Optioner.prototype._hidNames;
Optioner.prototype._hidSet;

Optioner.prototype.addArray = function(names, values){

    this._names[this._counter] = names;
    this._values[this._counter] = values;
    this._counter++;
}

Optioner.prototype.setNameChange = function(names){
    this._selNames = names;
    this._selSet = true;
}

Optioner.prototype.setHiddenChange = function(names){
    this._hidNames = names;
    this._hidSet = true;
}

Optioner.prototype.setArray = function(id){
    //pobieram selecta do zmiany wartosci
    var select = document[this._form][this._name];
    
    //czyszcze selecta
    for (i = select.options.length; i > 0; i--) {
        select.options[i - 1] = null;
    }
    //ustawiam nowe wartosci selecta (tabela o indeksie z parametru)
    for (i = 0; i < this._names[id].length; i++) {
        select.options[i] = new Option(this._names[id][i], this._values[id][i]);
    }
    
    //jesli ustawiona zmiana nazwy selecta, zmianiam nazwe
    if (this._selSet) {
        select.name = this._selNames[id];
    }
    //jesli ustawiona zmiana nazwy pola ukrytego, zmianiam nazwe
    if (this._hidSet) {
        document[this._form][this._hidNames[this._active]].name = this._hidNames[id];
    }
    
    //zmieniam aktywne id dla obiektu
    this._active = id;
}

Optioner.prototype.switchArray = function(){
    var nr = this._active + 1;
    
    if (nr == this._counter) {
        nr = 0;
    }
    this.setArray(nr);
}

/**
 * Klasa do ukrywania/pokazywania elementow list
 */
function SHList(active){
    this._active = active;
    document.getElementById(active).style.display = 'block';
}

SHList.prototype._active;

SHList.prototype.setVisible = function(id){

    document.getElementById(this._active).style.display = 'none';
    
    document.getElementById(id).style.display = 'block';
    
    this._active = id;
    
}



function resetAllForm(){
    resetForm('form_0');
    resetForm('form_1');
		resetForm('form_1_0');
		resetForm('form_1_1');
		resetForm('form_1_2');
		resetForm('form_1_3');
    resetForm('form_2');
		resetForm('form_2_0');
		resetForm('form_2_1');
    resetForm('form_3');
		resetForm('form_3_0');
		resetForm('form_3_1');
    resetForm('form_4');
		resetForm('form_4_0');
		resetForm('form_4_1');
    resetForm('form_5');
	resetForm('form_6');
    
}

function resetForm(formName){
	if (formName != null)
    	document[formName].reset();
}

function setValue(id, select){

    var name = select[select.selectedIndex].innerHTML;
    document.getElementById(id).value = name;
}

/**
 * Ustawia wartosc pola, jako sume wartosci dwoch innych obiektow
 * @param {String} form - nazwa formularza
 * @param {String} name - nazwa obiektu
 * @param {String} obj1 - nazwa obiektu 1
 * @param {String} obj2 - nazwa obiektu 2
 */
function setValueObject(form, name, obj1, obj2){
    var o1 = document[form][obj1];
    var o2 = document[form][obj2];
    
    for (var i = 0; i < o2.length; i++) {
        if (o2[i].checked) {
            var val = o2[i].value;
        }
    }
   
    document[form][name].value = parseInt(o1.value) + parseInt(val);

}

function switchFormHeader() {
	var form = document['form_4_1'];
	
	if (form.method == 'post' && form['P[id]'].selectedIndex != 0) {
		form.method = 'get';
		form.action = 'http://gielda.wp.pl/POD,2,domy_maklerskie.html';					
	} else if (document['form_4_1'].method == 'get' && form['P[id]'].selectedIndex == 0) {
		form.method = 'post';	
		form.action = 'http://gielda.wp.pl/domy_maklerskie.html';					
	}
}

function tscGetFlashVersion(){
	var tscFV=0;
	if(navigator.plugins && navigator.plugins.length){
		PWAx=navigator.plugins["Shockwave Flash"];
		if(PWAx){
			if(PWAx.description){
				PWAy=PWAx.description;
				tscFV=PWAy.charAt(PWAy.indexOf('.')-1);
			}
		}else if(navigator.plugins["Shockwave Flash 2.0"]){
			tscFV=2;
		}
	}else{
		for(var PWAi=10;PWAi>0;PWAi--){
			tscFV=0;
			try{
				var flash=new ActiveXObject("ShockwaveFlash.ShockwaveFlash."+PWAi);
				tscFV=PWAi;
				break;
			}catch(e){}
		}
	}
	return tscFV;
}

licz=0;
function otworz(nazwa,szer,wys) {
config='left=100,top=100,width='+szer+',height='+wys+',innerheight='+wys+',innerwidth='+szer+',toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no';
kitekSC='okno' + licz;
stadion=window.open('',kitekSC,config)
stadion.document.write('<HTML><HEAD>');
stadion.document.write('<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-2">');
stadion.document.write('<TITLE>Wirtualna Polska - Foto-Galeria</title>');
stadion.document.write('<script language="javascript">');
stadion.document.write('setTimeout(');
stadion.document.write('"self.close()');
stadion.document.write(';",70000)');stadion.document.write('</');
stadion.document.write('script>');
stadion.document.write('</HEAD>');
stadion.document.write('<body bgcolor=white leftmargin=0 topmargin=0 marginheight=0 marginwidth=0>');
stadion.document.write('<DIV align=center><a href=# onclick="javascript:self.close();"><img src='+nazwa+' border=0></A></DIV>');
stadion.document.write('</body></html>');
stadion.focus();
licz+=1;
}

function ch_bx(id, n, a) { //change boxes(id, num of boxes, actual)
  if (!id) id = 't';
  if (!n) return(false);
  if (!a) a = 1;
  
  for (var i = 1; i <= n; i++) {   
    document.getElementById(id + i).style.display = 'none';
  }
  document.getElementById(id + a).style.display = 'block';
}

//kalkulator walutowy
function zmiana_sel2() {
	document.form_calc_0.sel3.selectedIndex = document.form_calc_0.sel2.selectedIndex;
	return;
}

function zmiana_sel3() {
	document.form_calc_0.sel2.selectedIndex = document.form_calc_0.sel3.selectedIndex;
	return;
}

function kasuj_waluty() {
 	document.form_calc_0.ilosc.value='';
        document.form_calc_0.wynik.value='';
	return;
}

function zamien_waluty() {
	var s1, s2;

	s1 = document.form_calc_0.sel1.selectedIndex;
	s2 = document.form_calc_0.sel2.selectedIndex;
	document.form_calc_0.sel1.selectedIndex = s2;
	document.form_calc_0.sel2.selectedIndex = s1;

	return;
}

function Numer(fieldName) {
	var txtNumber = '' + fieldName.value;
	fieldName.value = txtNumber.replace(',','.');
	txtNumber = '' + fieldName.value;
	if (isNaN(txtNumber) || txtNumber == "" || txtNumber.indexOf('-')!=-1)
	{
		alert("Wpisano nieprawidłową wartość!");
		fieldName.select();
		fieldName.focus();
		return false;
	}else 
	{ 
		fieldName.value= parseFloat(fieldName.value);
		return true;
	}
}

// kalkulator wynagrodzen

function delFormW() {
  document.getElementById('zarobki').value='';
  document.getElementById('rok_zarobki').selectedIndex=0;
}

function submitFormCalc1() {

  if(document.pressed == 'Oblicz') {
     document.form_calc_1.action ="http://podatki.wp.pl/kalkulator_wynagrodzen_wyniki.html";
  } else {
     document.form_calc_1.action ="http://podatki.wp.pl/kalkulator_wynagrodzen.html";
  }

	var obj1 = document.getElementById('zarobki');

	if (null == obj1) {
		return;
	}
	
        for (i = 1; i <=12; i++) {
		var obj2 = document.getElementById('zarobki' + i);

		if (null == obj2) {
			continue;
		}

		obj2.value = obj1.value;
	}
}
//kalkulator odsetek
function formReset() {
	document.getElementById("form_calc_2Body").reset();
}



function usun_zobowiazanie() {
	if (row_count > 1) {
		document.getElementById('form_calc_2Body').deleteRow(row_count--);
		document.getElementById('form_calc_2Body').deleteRow(row_count--);
		document.getElementById('form_calc_2Body').deleteRow(row_count--);
		document.getElementById('form_calc_2Body').deleteRow(row_count--);
		document.getElementById('form_calc_2Body').deleteRow(row_count--);
		document.getElementById('form_calc_2Body').deleteRow(row_count--);
		z_count--;
		ar.pop();
		ar.pop();
		ar.pop();
	}
}

function dodaj_zobowiazanie() {
	z_count++;
	var table_body = document.getElementById("form_calc_2Body");

	f01_row = document.createElement("tr");
	f01_row.setAttribute('class', 'r2');
	f01_row.setAttribute('id', 'row' + ++row_count);

	label_cell = document.createElement("td");
	label_cell.setAttribute('class', 'left');
	label_text = document.createTextNode("kwota zobowiązania:");
	label_cell.appendChild(label_text);
	f01_row.appendChild(label_cell);

	f02_row = document.createElement("tr");
	f02_row.setAttribute('class', 'r2');
	f02_row.setAttribute('id', 'row' + ++row_count);

	input_cell = document.createElement("td");
	input_cell.setAttribute('class', 'left');
	kwota_label = 'kwota' + z_count;
	myinput = document.createElement("input");
	myinput.setAttribute('type', 'text');
	myinput.setAttribute('class', 'val');
	myinput.setAttribute('id', kwota_label);
	myinput.setAttribute('name', kwota_label);
	myinput.setAttribute('size', '18');
	input_cell.appendChild(myinput);
	f02_row.appendChild(input_cell);

	f03_row = document.createElement("tr");
	f03_row.setAttribute('class', 'r2');
	f03_row.setAttribute('id', 'row' + ++row_count);

	label_cell = document.createElement("td");
	label_cell.setAttribute('class', 'left');
	label_text = document.createTextNode("data powstania:");
	label_cell.appendChild(label_text);
	f03_row.appendChild(label_cell);

	f04_row = document.createElement("tr");
	f04_row.setAttribute('class', 'r2');
	f04_row.setAttribute('id', 'row' + ++row_count);

	input_cell = document.createElement("td");
	input_cell.setAttribute('class', 'right');
	data_start_label = 'data_start' + z_count;
	myinput = document.createElement("input");
	myinput.setAttribute('type', 'text');
	myinput.setAttribute('class', 'val');
	myinput.setAttribute('id', data_start_label);
	myinput.setAttribute('name', data_start_label);
	myinput.setAttribute('size', '18');
	input_cell.appendChild(myinput);
	f04_row.appendChild(input_cell);

	calendar_cell = document.createElement("td");
	calendar = document.createElement('img');
	calendar.setAttribute('src', 'http://i.wp.pl/a/i/waluty/layout/cal_ico.gif');
	calendar.setAttribute('onclick', "rysuj2(document.getElementById('" + data_start_label + "'), event);");
	calendar.setAttribute('alt', 'Wybierz datę z kalendarza');
	calendar.setAttribute('border', '0');
	calendar.setAttribute('style', '""');
	calendar_cell.appendChild(calendar);
	f04_row.appendChild(calendar_cell);

	f05_row = document.createElement("tr");
	f05_row.setAttribute('class', 'r2');
	f05_row.setAttribute('id', 'row' + ++row_count);

	label_cell = document.createElement("td");
	label_cell.setAttribute('class', 'left');
	label_text = document.createTextNode("data ustania:");
	label_cell.appendChild(label_text);
	f05_row.appendChild(label_cell);

	f06_row = document.createElement("tr");
	f06_row.setAttribute('class', 'r2');
	f06_row.setAttribute('id', 'row' + ++row_count);

	input_cell = document.createElement("td");
	input_cell.setAttribute('class', 'right');
	data_end_label = 'data_end' + z_count;
	myinput = document.createElement("input");
	myinput.setAttribute('type', 'text');
	myinput.setAttribute('class', 'val');
	myinput.setAttribute('id', data_end_label);
	myinput.setAttribute('name', data_end_label);
	myinput.setAttribute('size', '18');
	input_cell.appendChild(myinput);
	f06_row.appendChild(input_cell);

	calendar_cell = document.createElement("td");
	calendar = document.createElement('img');
	calendar.setAttribute('src', 'http://i.wp.pl/a/i/waluty/layout/cal_ico.gif');
	calendar.setAttribute('onclick', "rysuj2(document.getElementById('" + data_end_label + "'), event);");
	calendar.setAttribute('alt', 'Wybierz datę z kalendarza');
	calendar.setAttribute('border', '0');
	calendar.setAttribute('style', '""');
	calendar_cell.appendChild(calendar);
	f06_row.appendChild(calendar_cell);

	table_body.appendChild(f01_row);
	table_body.appendChild(f02_row);
	table_body.appendChild(f03_row);
	table_body.appendChild(f04_row);
	table_body.appendChild(f05_row);
	table_body.appendChild(f06_row);

	ar.push(new Array('kwota zobowiązania:',  kwota_label, 'float', 0, 100000000, true));
	ar.push(new Array('data powstania:',  data_start_label, 'date', 0, 0, true));
	ar.push(new Array('data ustania:',  data_end_label, 'date', 0, 0, true));
}

function zlicz_zobowiazania() {
	form = document.getElementById('form_calc_2');
	input_hidden = document.createElement("input");
	input_hidden.setAttribute('type', 'hidden');
	input_hidden.setAttribute('name', 'count');
	input_hidden.setAttribute('value', z_count);
	form.appendChild(input_hidden);
	return true;
}


function submitFormCalc2() {

  if(document.pressed == 'Oblicz' && document.getElementById('form_calc_2U').checked==true) {
     document.form_calc_2.action = "http://podatki.wp.pl/kalkulator_odsetek_ustawowych_wyniki.html";
     document.form_calc_2._action.value = "CalculatorDataStatutoryInterest";
  } else if(document.pressed == 'Oblicz' && document.getElementById('form_calc_2P').checked==true) {
     document.form_calc_2.action = "http://podatki.wp.pl/kalkulator_odsetek_podatkowych_wyniki.html";
     document.form_calc_2._action.value = "CalculatorDataTaxInterest";
  }

}

function KasujFormCalc2() {
  document.getElementById('kwota1').value='';
  document.getElementById('data_start1').value='';
  document.getElementById('data_end1').value='';
}

// kalkulator kredytowy
function KasujFormCalc3() {
  document.getElementById('miesiecznyDochodRodziny').value='';
  document.getElementById('oprocentowanieKredytu').value='';
  document.getElementById('okresKredytowania').value='';
}

//kalkulator rat
function KasujFormCalc4_0() {
  document.getElementById('waluta4_0').selectedIndex=0;
  document.getElementById('kwotaKredytu').value='';
  document.getElementById('okresKredytowania4_0').value='';
  document.getElementById('oprocentowanieKredytu4_0').value='';
}
function KasujFormCalc4_1() {
  document.getElementById('waluta1_4_1').selectedIndex=0;
  document.getElementById('waluta2_4_1').selectedIndex=0;
  document.getElementById('kwotaKredytu1').value='';
  document.getElementById('okresKredytowania1').value='';
  document.getElementById('oprocentowanieKredytu1').value='';
  document.getElementById('okresKredytowania2').value='';
  document.getElementById('oprocentowanieKredytu2').value='';
}

//-->



// forum
// bbCode control by
// subBlue design
// www.subBlue.com

// Startup variables
var imageTag = false;
var theSelection = false;

// Check for Browser & Platform for PC & IE specific bits
// More details from: http://www.mozilla.org/docs/web-developer/sniffer/browser_type.html
var clientPC = navigator.userAgent.toLowerCase(); // Get client info
var clientVer = parseInt(navigator.appVersion); // Get browser version

var is_ie = ((clientPC.indexOf("msie") != -1) && (clientPC.indexOf("opera") == -1));
var is_nav = ((clientPC.indexOf('mozilla')!=-1) && (clientPC.indexOf('spoofer')==-1)
                && (clientPC.indexOf('compatible') == -1) && (clientPC.indexOf('opera')==-1)
                && (clientPC.indexOf('webtv')==-1) && (clientPC.indexOf('hotjava')==-1));
var is_moz = 0;

var is_win = ((clientPC.indexOf("win")!=-1) || (clientPC.indexOf("16bit") != -1));
var is_mac = (clientPC.indexOf("mac")!=-1);

// Define the bbCode tags
bbcode = new Array();
bbtags = new Array('[b]','[/b]','[i]','[/i]','[u]','[/u]','[quote]','[/quote]','[code]','[/code]','[list]','[/list]','[list=]','[/list]','[img]','[/img]','[url]','[/url]');
imageTag = false;

// Shows the help messages in the helpline window
function helpline(help) {
	document.post.helpbox.value = eval(help + "_help");
}


// Replacement for arrayname.length property
function getarraysize(thearray) {
	for (i = 0; i < thearray.length; i++) {
		if ((thearray[i] == "undefined") || (thearray[i] == "") || (thearray[i] == null))
			return i;
		}
	return thearray.length;
}

// Replacement for arrayname.push(value) not implemented in IE until version 5.5
// Appends element to the array
function arraypush(thearray,value) {
	thearray[ getarraysize(thearray) ] = value;
}

// Replacement for arrayname.pop() not implemented in IE until version 5.5
// Removes and returns the last element of an array
function arraypop(thearray) {
	thearraysize = getarraysize(thearray);
	retval = thearray[thearraysize - 1];
	delete thearray[thearraysize - 1];
	return retval;
}

function emoticon(text) {
	var txtarea = document.post.message;
	text = ' ' + text + ' ';
	if (txtarea.createTextRange && txtarea.caretPos) {
		var caretPos = txtarea.caretPos;
		caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text + ' ' : text;
		txtarea.focus();
	} else {
		txtarea.value  += text;
		txtarea.focus();
	}
}

function bbfontstyle(bbopen, bbclose) {
	var txtarea = document.post.message;

	if ((clientVer >= 4) && is_ie && is_win) {
		theSelection = document.selection.createRange().text;
		if (!theSelection) {
			txtarea.value += bbopen + bbclose;
			txtarea.focus();
			return;
		}
		document.selection.createRange().text = bbopen + theSelection + bbclose;
		txtarea.focus();
		return;
	}
	else if (txtarea.selectionEnd && (txtarea.selectionEnd - txtarea.selectionStart > 0))
	{
		mozWrap(txtarea, bbopen, bbclose);
		return;
	}
	else
	{
		txtarea.value += bbopen + bbclose;
		txtarea.focus();
	}
	storeCaret(txtarea);
}


function bbstyle(bbnumber) {
	var txtarea = document.post.message;

	donotinsert = false;
	theSelection = false;
	bblast = 0;

	if (bbnumber == -1) { // Close all open tags & default button names
		while (bbcode[0]) {
			butnumber = arraypop(bbcode) - 1;
			txtarea.value += bbtags[butnumber + 1];
			buttext = eval('document.post.addbbcode' + butnumber + '.value');
			eval('document.post.addbbcode' + butnumber + '.value ="' + buttext.substr(0,(buttext.length - 1)) + '"');
		}
		imageTag = false; // All tags are closed including image tags :D
		txtarea.focus();
		return;
	}

	if ((clientVer >= 4) && is_ie && is_win)
	{
		theSelection = document.selection.createRange().text; // Get text selection
		if (theSelection) {
			// Add tags around selection
			document.selection.createRange().text = bbtags[bbnumber] + theSelection + bbtags[bbnumber+1];
			txtarea.focus();
			theSelection = '';
			return;
		}
	}
	else if (txtarea.selectionEnd && (txtarea.selectionEnd - txtarea.selectionStart > 0))
	{
		mozWrap(txtarea, bbtags[bbnumber], bbtags[bbnumber+1]);
		return;
	}
	
	// Find last occurance of an open tag the same as the one just clicked
	for (i = 0; i < bbcode.length; i++) {
		if (bbcode[i] == bbnumber+1) {
			bblast = i;
			donotinsert = true;
		}
	}

	if (donotinsert) {		// Close all open tags up to the one just clicked & default button names
		while (bbcode[bblast]) {
				butnumber = arraypop(bbcode) - 1;
				txtarea.value += bbtags[butnumber + 1];
				buttext = eval('document.post.addbbcode' + butnumber + '.value');
				eval('document.post.addbbcode' + butnumber + '.value ="' + buttext.substr(0,(buttext.length - 1)) + '"');
				imageTag = false;
			}
		txtarea.focus();
		return;
	} else { // Open tags
	
		if (imageTag && (bbnumber != 14)) {		// Close image tag before adding another
			txtarea.value += bbtags[15];
			lastValue = arraypop(bbcode) - 1;	// Remove the close image tag from the list
			document.post.addbbcode14.value = "Img";	// Return button back to normal state
			imageTag = false;
		}
		
		// Open tag
		txtarea.value += bbtags[bbnumber];
		if ((bbnumber == 14) && (imageTag == false)) imageTag = 1; // Check to stop additional tags after an unclosed image tag
		arraypush(bbcode,bbnumber+1);
		eval('document.post.addbbcode'+bbnumber+'.value += "*"');
		txtarea.focus();
		return;
	}
	storeCaret(txtarea);
}

// From http://www.massless.org/mozedit/
function mozWrap(txtarea, open, close)
{
	var selLength = txtarea.textLength;
	var selStart = txtarea.selectionStart;
	var selEnd = txtarea.selectionEnd;
	if (selEnd == 1 || selEnd == 2) 
		selEnd = selLength;

	var s1 = (txtarea.value).substring(0,selStart);
	var s2 = (txtarea.value).substring(selStart, selEnd)
	var s3 = (txtarea.value).substring(selEnd, selLength);
	txtarea.value = s1 + open + s2 + close + s3;
	return;
}

// Insert at Claret position. Code from
// http://www.faqts.com/knowledge_base/view.phtml/aid/1052/fid/130
function storeCaret(textEl) {
	if (textEl.createTextRange) textEl.caretPos = document.selection.createRange().duplicate();
}

// On Document Ready

WP.$(function($){



/* horizontal scroll */



function runSlider() {



	var currentPosition = 0;

	var jump = 1;

	var slideWidth = 136;

	var maxElement = (Math.round(parseFloat($('#sliderCnt .slideshow').css('width'))/slideWidth));

	var slides = $('#sliderCnt .slide');

	var numberOfSlides = slides.length;

	

	

	bindScrollEvents = function() {

		

		currentPosition = ($(this).attr('id')=='sliderButtonNext') ? currentPosition+jump : currentPosition-jump;

		currentPosition = Math.max(Math.min(currentPosition, numberOfSlides-maxElement), 0);

		manageControls(currentPosition);

		updatePos(350);

	}

	

	

	updatePos = function (time){

		$('#sliderCnt .slidesContainer').stop();

		$('#sliderCnt .slidesContainer').animate({

			'left' : (slideWidth)*(-currentPosition)

		}, time);

	}

	



	manageControls = function(position) {



		if (position == 0) {

			$('#sliderButtonPrev').removeClass('active').unbind('click')

		} else {

			$('#sliderButtonPrev').addClass('active').unbind('click').bind('click', bindScrollEvents);

		}



		if (position == numberOfSlides - maxElement) {

			$('#sliderButtonNext').removeClass('active').unbind('click')

		} else {

			$('#sliderButtonNext').addClass('active').unbind('click').bind('click', bindScrollEvents);

		}

	}



	// Update slides container width

	$('#sliderCnt .slidesContainer').css({

		'width' : slideWidth * numberOfSlides

	});





	manageControls(currentPosition);

	updatePos(0);

	



	$('#sliderCnt .slide').each(function(){

		$(this).hover(function () {

			$(this).css('opacity','0.9');

		},

		function () {

			$(this).css('opacity','1');

		});

	});



	$('#sliderCnt .nav').noSelect();

	$('#sliderCnt .nav').removeClass('inactive');



}



$.fn.noSelect = function() {

	return this.each(function() {

		if ($.browser.mozilla) {

			$(this).css('MozUserSelect','none');

		} else if ($.browser.msie) {

			$(this).bind('selectstart', function() {

				return false;

			});

		} else {

			$(this).mousedown(function() {

				return false;

			});

		}

	});

}



	/* run slider */

	runSlider();

});
// On Document Ready


/* horizontal scroll */

var Slider = function (pars) {

	var sliderCntID = pars.sliderCntID;
	var slideWidth = pars.slideWidth || 150;	
	var currentPosition = pars.currentPosition || 0;
	var visible = pars.visible || 3;
	var	speed = pars.speed || 150;
	var loop = pars.loop || false;
	var jump = pars.jump || 1;
	
	if (sliderCntID) {
		var slider = WP.$('#' + sliderCntID);
		if (!slider) {
			throw("Nie istnieje slider o podanym ID!");	
			return;
		}		
	} else {
		throw("Brakuje ID slidera!");	
		return;
	}
	
	var sliderHolder = slider.find('.slideshow');	
	var slidesContainer = slider.find('.slidesContainer');
	
	var sliderButtons = slider.find('.nav');
	var sliderButtonPrev = slider.find('#sliderButtonPrev');
	var sliderButtonNext = slider.find('#sliderButtonNext');

	

	var slides = slider.find('.slide');	

	var numberOfSlides = slides.length;	

	var maxElement = (Math.round(parseFloat(sliderHolder.css('width'))/slideWidth));

	

	var dir = '';	

	var queue = new Array();

	var queueLimit = Math.floor((numberOfSlides - visible)/2);

	var started = false;

			

	var bindScrollEvents = function(e) {

		//console.log("bindScrollEvents");

		if (queue.length < queueLimit) {

			queue.push( WP.$(e.target).attr('id') );						 	

			if (!started) onComplete("CLICK");	

		}

	}	

	

	var slide = function (time){

		//console.log("slide");

		upadePosition();

		//slidesContainer.stop();			

		slidesContainer.animate({

			'left' : (slideWidth)*(-currentPosition)

		}, time, onComplete);

	}

	

	var upadePosition = function () 

	{

		if (dir == 'sliderButtonNext') {

			appendSlide(slidesContainer.find('.slide').first());

		} 

		if (dir == 'sliderButtonPrev') {

			prependSlide(slidesContainer.find('.slide').last());

		}

	}

	

	var appendSlide = function (itemSlide , left) {

		var	pos = parseInt(itemSlide.css('left'));

		itemSlide.remove();

		if (left) itemSlide.css('left', left);

		else itemSlide.css('left', pos + slideWidth * numberOfSlides);

		slidesContainer.append(itemSlide);

	}

	

	var prependSlide = function (itemSlide , left) {

		var	pos = parseInt(itemSlide.css('left'));

		itemSlide.remove();

		if (left) itemSlide.css('left', left);

		else itemSlide.css('left', pos - slideWidth * numberOfSlides);

		slidesContainer.prepend(itemSlide);

	}

	

	var rangePosition = function () {

		if (!loop) currentPosition = Math.max(Math.min(currentPosition, numberOfSlides-maxElement), 0);

	}

	

	var onComplete = function (e){

		//console.log("onComplete = " + (e ? e.toString() : ''));

		manageControls();

		if (queue.length)

		{

			started = true;

			dir = queue.pop();

			if (dir == 'sliderButtonNext') {

				currentPosition = currentPosition+jump;

				rangePosition();

				slide(speed);

			} 

			if (dir == 'sliderButtonPrev')  

			{

				currentPosition = currentPosition-jump;

				rangePosition();

				slide(speed);

			}			

		} else {

			started = false;

			dir = '';	

		}

	}

	

	var manageControls = function() {

		//console.log("manageControls");

		if (!loop) {

			if (currentPosition == 0) {

				sliderButtonPrev.removeClass('active').unbind('click')

			} else {

				sliderButtonPrev.addClass('active').unbind('click').bind('click', bindScrollEvents);

			}



			if (currentPosition == numberOfSlides - maxElement) {

				sliderButtonNext.removeClass('active').unbind('click')

			} else {

				sliderButtonNext.addClass('active').unbind('click').bind('click', bindScrollEvents);

			}

		}																

	}

	

	var init = function () {

		

		var slideItem;

		var offset = numberOfSlides - queueLimit;

		

		slides.each( function (i, v) 

		{ 	

			slideItem = WP.$(v);

			slideItem.css('left', i * slideWidth) ;									

			slideItem.hover( 

				function () { WP.$(v).css('opacity','0.9'); },

				function () { WP.$(v).css('opacity','1'); }

			);

		});

		

		for (var j = 0 ; j < queueLimit; j++) {

			prependSlide(slides.eq(numberOfSlides - j - 1) , -(j+1) * slideWidth);

		} 

		

		sliderHolder.css('width', slideWidth * visible );

		slidesContainer.css('width' , slideWidth * numberOfSlides );	

		sliderButtons.noSelect();

		sliderButtons.removeClass('inactive');

		sliderButtonPrev.addClass('active').click(bindScrollEvents);

		sliderButtonNext.addClass('active').click(bindScrollEvents);

	}	



	this.run = function () {

		init ();

		manageControls ();	

	}

}



WP.$.fn.noSelect = function() {

	return this.each(function() {

		if (WP.$.browser.mozilla) {

			WP.$(this).css('MozUserSelect','none');

		} else if (WP.$.browser.msie) {

			WP.$(this).bind('selectstart', function() {

				return false;

			});

		} else {

			WP.$(this).mousedown(function() {

				return false;

			});

		}

	});

}



function setCaption(caption,a) {
	document.getElementById(caption).innerHTML = a;
}

