
function getElement(elementID)
{
	if (document.all)
		return document.all[elementID];
	else if (document.getElementById)
		return document.getElementById(elementID);
	else
		return false;
}

function choseWordForm( value, wordform1, wordform2, wordform3 )
{
	wordform = wordform3;

	valueStr = new String( value );
	lastDigit = valueStr.substring(-1,1);

	if(value==1)
		wordform = wordform1;
	else if(value==12 || value==13 || value==14 || lastDigit==0 || lastDigit==1 || lastDigit==5 || lastDigit==6 || lastDigit==7 || lastDigit==8 || lastDigit==9)
		wordform = wordform3;
	else if(lastDigit==2 || lastDigit==3 || lastDigit==4)
		wordform = wordform2;

	return wordform;
}


function setButtonStyle(button,state,size)
{
	var isObject = typeof button == 'object';
	
  	style = isObject ? button.style : eval(button+".style");

	var imageName = size > 0 && size < 4 ? "button0" + size : "button01";
    style.backgroundImage = state=='on' ? "url(cms/images/buttons/"+imageName+"_b.gif)" : "url(cms/images/buttons/"+imageName+"_a.gif)";
}


//
// Otwiera nowe okno popup.
//
function openPopupWindow(strName, strLocation, width, height, noscrollbars)
{
	if ( strLocation.indexOf("popup=1")<0 )
	{
		// dodaj popup=1 do URL'a
		if ( strLocation.indexOf('?') >=0 )
			strLocation += "&popup=1";
		else
			strLocation += "?popup=1";
	}
	var popupWindow = window.open(strLocation, strName, 'toolbar=no, location=no, height='+height+', width='+width+', '+
		'status=no, menubar=no, scrollbars='+(noscrollbars?'no':'yes')+', resizable=yes, top=' +
		(window.screen.height/2 - height/2) + ', left=' + (window.screen.width/2 - width/2));
	//setTimeout("popupWindow.focus()", 1000);
	popupWindow.focus();
	return popupWindow;
}

//
// Otwiera nowe okno popup. Uzywane przez modul linkman.
//
function linkmanOpenPopup(windowName, location, options)
{
	if ( location.indexOf("popup=1")<0 )
	{
		// dodaj popup=1 do URL'a
		if ( location.indexOf('?') >=0 )
			location += "&popup=1";
		else
			location += "?popup=1";
	}
	var popupWindow = window.open(location, windowName, options);
	//setTimeout("popupWindow.focus()", 1000);
	popupWindow.focus();
	return popupWindow;
}

//--------------------------------------

//
// Funkcje związane z parsowaniem i formatowaniem daty.
//

//
// Dodaje dni do daty.
//
function addDaysToDate(date, numOfDays)
{
	return new Date(date.getFullYear(), date.getMonth(), date.getDate()+numOfDays);
}

//
// Zamienia string w formacie YYYY-MM-DD na obiekt typu Date.
//
function parseDate(dateString)
{
	var str = new String(dateString);
	var array = str.split('-');
	if (array.length!=3)
		return null;
	var year = array[0];
	var month = array[1].charAt(0)=='0' ? parseInt(array[1].substr(1, 1)) : parseInt(array[1]);
	var day = array[2].charAt(0)=='0' ? parseInt(array[2].substr(1, 1)) : parseInt(array[2]);
	var date = new Date(year, month-1, day);
	if (isNaN(date))
		return null;
	date.setHours(0);
	date.setMinutes(0);
	date.setSeconds(0);
	date.setMilliseconds(0);
	return date;
}

//
// Zamienia obiekt Date na string w formacie YYYY-MM-DD.
//
function formatDate(date)
{
	return date.getFullYear() + "-" + formatDatePart(date.getMonth()+1) +
		"-" + formatDatePart(date.getDate());
}

//
// Funkcja pomocnicza dla funckcji formatDate(). Dodaje znak '0' do czesci daty.
//
function formatDatePart(value)
{
	var v = String(value);
	return v.length==1 ? "0"+v : v;
}

//--------------------------------------

//
// Rozne funkcje pomocnicze.
//

/*
** AJ: Pobranie wartosci radio z formularza z grupy.
*/
function getRadio( form, grpName ) {
	var grp, rad, r = 0;
	grp = (typeof grpName == 'string') ? form[grpName] : grpName;
	if ( grp.value ) return grp.value;
	while (rad = grp[r++]) if (rad.checked) return rad.value;
	return '';
};

//
// Ustawia wartośc elementu typu select (rozwijana lista).
//
function setSelectValue( select , valueToSelect )
{
	if( !select.options )
		return;

	var count = select.options.length;

	for( var i=0; i<count; i++ )
	{
		if( select.options[i].value == valueToSelect )
		{
			select.selectedIndex = i;
			break;
		}
	}
}

function button(name, isOver, isKoszyk) {
	var side = new Array ('L', 'M', 'R');
	if (isOver) {
		over = 'over_';
		padding = 3;
	} else {
		over = '';
		padding = 2;
	}
	if (isKoszyk)
		koszyk = 'koszyk_';
	else
		koszyk = '';

	for (var i = 0; i < side.length; i++)
		document.getElementById('button_' + name + '_' + side[i]).style.backgroundImage = 'url(cms/images/buttons/button_' + koszyk + over + side[i] + '.gif)';
	document.getElementById('button_' + name + '_M_inner').style.paddingTop = padding + 'px';
}

/*
 * Zwraca wybrana wartosc dla selecta
 */
function getSelectedValue( select_field ) {
	if ( ! select_field ) return;
	return select_field.options[ select_field.selectedIndex ].value;
}
/*
 * Ustawia selekta dla na zaznaczenie dla wartosci
 */
function setSelectByValue( select_field, value ) {
	if( !select_field.options ) return;
	var count = select_field.options.length;
	var i;
	for ( i=0; i < count; i++ ) {
		if ( select_field.options[i].value != value ) continue;
		select_field.selectedIndex = i;
		break;
	}
}

/*AJ:
 * Zwraca tłumaczenie,
 * tłumaczenie powinno zostać umieszczone na stronie przy pomocy funkcji smarty __ z parametrem hide=1
 */
function getTranslation( tagname ) {
	var el = document.getElementById( tagname );
	if ( ! el ) return;
	return el.innerHTML;
}
function getText( tagname ) { return getTranslation( tagname ); }










	
/*
 * Zwraca pozycję elementu na stronie
 */
function getAbsolutePos( oElem ) {
	var oTemp = typeof oElem == 'string' ? document.getElementById( oElem ) : oElem;
	oElem = oTemp;
	var absLeft = 0, absTop = 0;
	while ( oTemp ) 
	{
		absTop += oTemp.offsetTop;
		absLeft += oTemp.offsetLeft;
		oTemp = oTemp.offsetParent;
	}
	return new Array(absLeft, absTop, absLeft + oElem.offsetWidth, absTop + oElem.offsetHeight );
}
/*
 * Otwieranie okienek popup
 */
var sbs_popup_window = false;
function sbsPopup( link, width, height  ) {
	sbs_popup_window = window.open(
		link,
		'sbs_popup_window',
		'toolbar=no, location=no, height='+height+', width='+width
		+ ', status=no, menubar=no, scrollbars=yes, resizable=yes'
		+ ', top=' + ( window.screen.height/2 - height/2)
		+ ', left=' + (window.screen.width/2 - width/2)
	);
}


