//
// Copyright (c) 2007, Tomek Gubala (http://www.vgtworld.pl, vgt@pro.wp.pl)
// Copying forbidden without permission of the author. / Kopiowanie bez zgody autora zabronione.
//
/**
*
*
*@author VGT
*@copyright Copyright (c) 2007, Tomek Gubala (http://www.vgtworld.pl, vgt@pro.wp.pl)
*@package Framework
*@version 7.8.11
*/
/**
* funkcja ukrywa / wyswietla element o danym id
*
*@param String id elementu do ukrycia / wyswietlenia
*@since 1.1
*@return Boolean
*/
function hideToggle(sId)
	{
	var element = document.getElementById(sId);
	if (element != null)
		{
		if (element.style.display != '')
			element.style.display = '';
		else
			element.style.display = 'none';
		return true;
		}
	else
		return false;
	}
function ajaxLoading(iStatus)
	{
	switch (iStatus)
		{
		case 1:
			iPrzesuniecie = document.documentElement.scrollTop | document.body.scrollTop;
			if (document.all)
				iWys = document.body.clientHeight;
			else
				iWys = document.documentElement.clientHeight;
			iWspX = Math.round((document.body.clientWidth - 100) / 2);;
			iWspY = Math.round((iWys / 2) + iPrzesuniecie );
			var oKomunikatDiv = document.createElement("div");
			oKomunikatDiv.style.backgroundColor = "#FFFFFF";
			oKomunikatDiv.style.border = "solid 2px #000";
			oKomunikatDiv.style.position = "absolute";
			oKomunikatDiv.style.textAlign = "center";
			oKomunikatDiv.style.fontWeight = "bold";
			oKomunikatDiv.style.fontSize = "10px";
			oKomunikatDiv.style.width = "100px";
			oKomunikatDiv.style.height = "100px";
			oKomunikatDiv.style.left = iWspX + "px";
			oKomunikatDiv.style.top = iWspY + "px";
			oKomunikatDiv.id = "ajax_loading";
			var oKomunikatImg = document.createElement("img");
			oKomunikatImg.src = "/images/loading.gif";
			oKomunikatImg.style.display = "block";
			oKomunikatImg.style.margin = "25px auto";
			oKomunikatDiv.appendChild(oKomunikatImg);
			oKomunikatDiv.appendChild(document.createTextNode("Proszę czekać"));
			document.body.appendChild(oKomunikatDiv);
			break;
		case 0:
			if (document.getElementById('ajax_loading') != null)
				{
				el = document.getElementById('ajax_loading');
				el.parentNode.removeChild(el);
				}
			break;
		}
	}
/**
* funkcja sprawdza, czy zawartosc pola formularza nie przekracza okreslonej dlugosci
* jesli tak - skraca wprowadzony tekst
*
* funkcja zwraca ilosc dostepnych znakow, ktore mozna jeszcze wpisac
*
*@return Integer
*@param String id pola, ktorego zawartosc jest sprawdzana
*@param Integer maksymalna dozwolona dlugosc tekstu w polu formularza
*/
function formFieldMaxLength(sIdElement, iMaxDlugosc)
	{
	var rElement = document.getElementById(sIdElement);
	if (rElement != null)
		{
		if (rElement.value.length > iMaxDlugosc)
			{
			rElement.value = rElement.value.substring(0, iMaxDlugosc);
			return 0;
			}
		else
			{
			return iMaxDlugosc - rElement.value.length;
			}
		}
	else
		return iMaxDlugosc;
	}
/**
* funkcja sprwdza ilosc pozostalych znakow do wprowadzenia w polu sIdFormField za pomoca funkcji formFieldMaxLength()
*  zapisuje ja w poli sIdLiniczk
*
*@return void
*@param String id elementu licznika
*@param String id pola, ktorego zawartosc jest sprawdzana
*@param String maksymalna dozwolona dlugosc tekstu w polu formularza
*/
function formLicznik(sIdLicznik, sIdFormField, iMaxDlugosc)
	{
	var rElement = document.getElementById(sIdLicznik);
	var iZnakowDoWpisania = formFieldMaxLength(sIdFormField, iMaxDlugosc);
	if (rElement != null)
		rElement.value = iZnakowDoWpisania;
	}