/* 
	Funkcje javascript
	Wersja: 2.1.2

  * o------------------------------------------------------------------------------o
  * | Biblioteki te zostały dołączone do oprogramowania tej strony na licencji     | 
  * | IT4Business i bez pisemnej zgody IT4Business nie mogą zostać użyte na        |
  * | żadnej innej stronie oraz w żadnej innej aplikacji. Po więcej szczegółów     |
  * | zapraszmy pod adres:                                                         |
  * |                                                                              |
  * |       http://it4business.pl/license.txt                                      |
  * |                                                                              |
  * o------------------------------------------------------------------------------o
  * 
  * o------------------------------------------------------------------------------o
  * | This package is licensed under the IT4Business license. A quick summary is   |
  * | that it is attached to this site as library and can not be used on other     |
  * | sites or application without permission of IT4Business. For more details     |
  * | please look at:                                                            |
  * |                                                                              |
  * |       http://it4business.pl/license.txt                                      |
  * |                                                                              |
  * o------------------------------------------------------------------------------o
  *
  * © Copyright IT4Business

*/

var ns6=document.getElementById&&!document.all?1:0;

// wysyła formularz pod zadany url
function submitForm(name, url)
{
  if(url != '' && typeof(url) != 'undefined')
   document.getElementById(name).action = url;
  
   document.getElementById(name).submit();
}


// dodaje zdarzenie do obiektu
function addEvent( obj, type, fn )
{
  if (obj.addEventListener)
    obj.addEventListener( type, fn, false );
  else if (obj.attachEvent)
  {
    obj["e"+type+fn] = fn;
    obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
    obj.attachEvent( "on"+type, obj[type+fn] );
  }
}

// zwraca element o podanym id
function getelem(name) {
if(ns6)
 return document.getElementById(name);
else
 return document.all[name];
};

// detekcja IE6
function detectIE6() {
 var is_ie6 = (
  window.external &&
  typeof window.XMLHttpRequest == "undefined"
 );

 return is_ie6;
}

// przekierowanie
function link(location)
{
	window.location = location;
}

// potwierdzenie klinięcia na URL
function sureURL()
{
 str = 'Jesteś pewien?';
 link = arguments[0];
 if(arguments.length == 2)
  str = arguments[1];
  
 if(confirm(str))
  document.location = link;
}

// potwierdzenie klinięcia na submit
function sureForm()
{
 str = 'Jesteś pewien?';
 if(arguments.length == 1)
  str = arguments[0];
  
 if(confirm(str))
  return true;
 else return false;
}

// zostawienie ciasteczka
function createCookie(name,value,days) 
{
		if (days) {
			var date = new Date();
			date.setTime(date.getTime()+(days*24*60*60*1000));
			var expires = "; expires="+date.toGMTString();
		}
		else var expires = "";
		document.cookie = name+"="+value+expires+"; path=/";
}

// odczytanie ciasteczka
function readCookie(name) 
{
		var nameEQ = name + "=";
		var ca = document.cookie.split(';');
		for(var i=0;i < ca.length;i++) {
			var c = ca[i];
			while (c.charAt(0)==' ') c = c.substring(1,c.length);
			if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
			}
		return null;
}

// wymazanie ciasteczka
function eraseCookie(name) 
{
		createCookie(name,"",-1);
}

// sortuje tablice assocjacyjną
function asort(aInput)
{
	var aTemp = [];
	for (var sKey in aInput)
	aTemp.push([sKey, aInput[sKey]]);
	aTemp.sort(function () {return arguments[0][1] < arguments[1][1]});

	var aOutput = [];
	for (var nIndex = aTemp.length-1; nIndex >=0; nIndex--)
	aOutput[aTemp[nIndex][0]] = aTemp[nIndex][1];

	return aOutput;
}

// otwiera popup'a
function popup(link, width, height)
{
 arg = 'height=' + height + ',width=' + width + ',toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0';
 newwindow = window.open(link, "popupwindow", arg);
 if(window.focus) 
    newwindow.focus();
}

// ładuje jquery
function loadJQuery()
{
  if (!jQuery) {  
        var fileref=document.createElement("script");
        fileref.setAttribute("type","text/javascript");
        fileref.setAttribute("src", "lib/js/jquery.min.js");
  }
}

// odpowiednik funkcjo PHP urlencode
function urlencode (str) {
  str = (str + '').toString();

  return encodeURIComponent(str).replace(/!/g, '%21').replace(/'/g, '%27').replace(/\(/g, '%28').
  replace(/\)/g, '%29').replace(/\*/g, '%2A').replace(/%20/g, '+').replace(/~/g, '%7E');
}
