function tylkoJeden(linkp,komunikat)
{
	var dane = document.getElementsByName('id_tab[]');
	var zaznaczone = 0;
	var zaznaczone_id = '';
	var ilosc = dane.length;


	for(i=0;i<ilosc;i++)
	{
		if(dane[i].checked)
		{
			zaznaczone++;
			zaznaczone_id = dane[i].value;
		}
	}

	if(zaznaczone==1)
	{
		location.href=linkp+"&id_nr="+zaznaczone_id;
	}
	else
		alert(komunikat);
}

function changeSrc(el,img){
	if(el!=null){
		el.src=img;
	}
}

function changeTlo(el,tlo){
	if(el!=null){
		el.className=tlo;
	}
}

function czy_usun2(linkp,komunikat)
{
	if(confirm(komunikat))
	{
		var dane = document.getElementsByName('id_tab[]');
		var zaznaczone = 0;
		var zaznaczone_id = '';
		var ilosc = dane.length;
		var linkp2 = '';
		var j=0;

		for(i=0;i<ilosc;i++)
		{
			if(dane[i].checked)
			{
				linkp2+= "&id_tab["+j+"]="+dane[i].value;
				j++;
			}
		}


		//alert(linkp+linkp2);
		location.href=linkp+linkp2
	}
}
function conajmniejJeden(linkp,komunikat)
{
	var dane = document.getElementsByName('id_tab[]');
	var zaznaczone = 0;
	var zaznaczone_id = '';
	var ilosc = dane.length;
	var linkp2 = '';
	var j=0;

	for(i=0;i<ilosc;i++)
	{
		if(dane[i].checked)
		{
			linkp2+= "&id_tab["+j+"]="+dane[i].value;
			j++;
		}
	}

	if(j>=1)
	{
		location.href=linkp+linkp2
	}
	else alert(komunikat);
}

function czy_usun(linkp,komunikat){
	if(confirm(komunikat)){
		location.href=linkp;
	}
}

function sprawdzNip(id,id_nr)
{
	nip = $("#firma_nip").val();

	link = '';
	if(id_nr!='')
		link+= "&id_nr="+id_nr;

	if(nip!='')
	{
		$.ajax(
		{
			  type: "POST",
			  url: "nip.php",
			  data: "nip="+nip+"&u_id="+id+link,
			  cache: false,
			  success: function(html)
			  {
				  $("#informacja_o_nip").html(html);
			  	  document.getElementById('informacja_o_nip').style.display='block';
			  }
		});
	}
}

function ajax_filtrujCertyfikaty()
{
	form_elements = document.getElementById("wyszukiwarka").elements;
	ilosc_elementow = document.getElementById("wyszukiwarka").elements.length;

	link = '';
	for(i=0;i<ilosc_elementow;i++)
		if(form_elements[i].name!="akcja")
		{
			if(link=="")
				link+=form_elements[i].name+"="+form_elements[i].value;
			else
				link+="&"+form_elements[i].name+"="+form_elements[i].value;
		}

	$.ajax(
		{
			  type: "POST",
			  url: "ajax_filtrujCertyfikaty.php",
			  data: link,
			  cache: false,
			  success: function(html)
			  {
				  $("#lista_certyfikatow").html(html);
			  }
		});
}

function sprawdzNip3(id,id_nr)
{
	nip = $("#nip").val();

	link = '';
	if(id_nr!='')
		link+= "&id_nr="+id_nr;

	if(nip!='')
	{
		$.ajax(
		{
			  type: "POST",
			  url: "nip3.php",
			  data: "nip="+nip+"&u_id="+id+link,
			  cache: false,
			  success: function(html)
			  {
				  $("#informacja_o_nip").html(html);
			  	  document.getElementById('informacja_o_nip').style.display='block';
			  }
		});
	}
}

function sprawdzNip2(id,id_nr)
{
	nip = $("#szuk_firma_nip").val();

	if(nip!='')
	{
		$.ajax(
		{
			  type: "POST",
			  url: "nip2.php",
			  data: "nip="+nip+"&u_id="+id+"&id_nr="+id_nr,
			  cache: false,
			  success: function(html)
			  {
				  $("#informacja_o_nip").html(html);
			  	  document.getElementById('informacja_o_nip').style.display='block';
			  }
		});
	}
}

function ajax_faktura()
{
		$.ajax(
		{
			  type: "POST",
			  url: "ajax_faktura.php",
			  data: "szuk_numer="+$("#szuk_numer").val(),
			  cache: false,
			  success: function(html)
			  {
			  	$("#select_faktura").html(html);
			  }
		});

}
function ajax_firma(pole)
{
	link = '';

	if(document.getElementById("szuk_firma_nip")!=null && document.getElementById("szuk_firma_nip").value!="")
		link+= "&szuk_firma_nip="+$("#szuk_firma_nip").val();
	if(document.getElementById("szuk_nazwa_firmy")!=null && document.getElementById("szuk_nazwa_firmy").value!= '')
		link+= "&szuk_nazwa_firmy="+$("#szuk_nazwa_firmy").val();

	link = "pole_w_bazie="+pole+link;

	$.ajax(
	{
		  type: "POST",
		  url: "ajax_firma.php",
		  data: link,
		  cache: false,
		  success: function(html)
		  {
		  	$("#select_firma").html(html);
		  }
	});

}


function ajaxpobierz(typ,id,firma_id,id_u)
{
		if(typ=="2")
		{
			if($("#posrednik_szukaj").val()!='')
				{
					$.ajax(
						{
						  type: "POST",
						  url: "ajax_posrednik.php",
						  data: "posrednik_id="+firma_id+"&id_nr="+id+"&szuk="+$("#posrednik_szukaj").val(),
						  cache: false,
						  success: function(html){
						    $("#results_po").html(html);
						  }
					});
				}
				else
				{
					alert('Podaj wartość do wyszukania!');
				}
		}
		else
		{
			if($("#komis_szukaj").val()!='')
				{

					if(id_u=='')
						dodatek='';
					else
						dodatek= "&id_user="+id_u;


					$.ajax(
						{
						  type: "POST",
						  url: "ajax_komis.php",
						  data: "firma_id="+firma_id+dodatek+"&id_nr="+id+"&szuk="+$("#komis_szukaj").val(),
						  cache: false,
						  success: function(html){
						    $("#results_ko").html(html);
						  }
					});
				}
				else
				{
					alert('Podaj wartość do wyszukania!');
				}
		}
}


function zaznacz_checkboxy(formularz,tablica,statusel) {
	var elts=(typeof(formularz.elements[tablica+'[]'])!= 'undefined') ? formularz.elements[tablica+'[]'] : '';
	var elts_cnt = (typeof(elts.length) != 'undefined') ? elts.length : 0;
	if (elts_cnt){
		for (var i = 0; i < elts_cnt; i++){
		 	elts[i].checked=statusel;
		}
  } else {
		elts.checked = statusel;
	}
}


function dodajtag(FormName,FieldName,tag,prompttext) {
	if (tag=='b'){ tag_prompt='bold'; }
	if (tag=='i'){ tag_prompt='italic'; }
	inserttext = prompt(prompttext+'\n<'+tag+'>xxx</'+tag+'>','');
	if ((inserttext != null) && (inserttext != '')) {
		document.forms[FormName].elements[FieldName].value += '<'+tag+'>'+inserttext+'</'+tag+'>';
	}
	document.forms[FormName].elements[FieldName].focus();
}

function emotikony_obrazek(pole,znaczek) {
  emotikony_pole=document.getElementById(pole);
  emotikony_pole.value=emotikony_pole.value+znaczek;
  emotikony_pole.focus();
}


function popup_image(okno,imageURL,imageTitle,w,h,margines){

	if(margines==''){
		$margines=0;
	}

	w=w+(2*margines);
	h=h+(2*margines);

	PositionY=(screen.height-h)/2;
	if (PositionY<0){
		PositionY=0;
	}

	PositionX=(screen.width-w)/2;
	if (PositionY<0){
		PositionY=0;
	}


  var imgWin = window.open('',okno,'scrollbars=no,resizable=1,width='+w+',height='+h+',left='+PositionX+',top='+PositionY);
	//popup blockers should not cause errors
  if( !imgWin ) {
		return true;
	}

	imgWin.moveTo(PositionX,PositionY);
	imgWin.resizeTo(w,h);
  imgWin.document.write('<html><head><title>'+imageTitle+'<\/title><\/head><body style="margin:0px; padding:0px; text-align:center"><div style="padding:'+margines+'px">'+'<img src="'+imageURL+'" alt=\"\" style=\"cursor:pointer\" onclick=\"window.close();\" />'+'<\/div><\/body><\/html>');

	imgWin.document.close();

  if( imgWin.focus ) {
		imgWin.focus();
	}

}

function popup_open(okno,adres,w,h,margines) {

	if(margines==''||!margines||margines=='undefined'||isNaN(margines)){
		margines=0;
	}

	w=w+margines;
	h=h+margines;

	top_okno=(screen.height-h)/2;
	if (top_okno<0){
		top_okno=0;
	}
	left_okno=(screen.width-w)/2;

	if (left_okno<0){
		left_okno=0;
	}

	imgWin=window.open(adres,okno,'top='+top_okno+',left='+left_okno+',width='+w+',height='+h+',toolbar=no,menubar=no,location=no,directories=no,alwaysRaised=no,status=no,scrollbars=no,resizable=yes,fullscreen=0');

	imgWin.moveTo(left_okno,top_okno);
	imgWin.resizeTo(w,h);

	//popup blockers should not cause errors
  if( !imgWin ) {
		return true;
	}

  if( imgWin.focus ) {
		imgWin.focus();
	}

}

function spr_email(email){
	var forma_email=/^(?:(?:\w\-*)+\.?)*\w+@(?:(?:\w\-*)+\.)+\w{1,4}$/;
	return forma_email.test(email);
}

String.prototype.trim=function(){
	return this.replace(/^\s*|\s*$/g,"");
}



var div_id = 'flash_div';    //nazwa przesuwanego menu

var top_offset = 0;   //pozycja po przesunieciu
var absolute_top = 500; //pozycja startowa
var offset_ie=0;

var xstep = .4;        //im wiecej tym szybciej porusza sie menu - dlugosc kroku
var delay_time = 50;   //im wiecej tym wolniejszy ruch - opoznienie pomiedzy krokami

//rozpoznanie przegladarki
var ie=document.all?1:0;
var ns4=document.layers?1:0;
var w3c=document.getElementById?1:0;
var mac_ie=ie&&((navigator.appVersion.indexOf("Mac")!=-1)&&(navigator.appVersion.substring(0,3)>=4.5)&&(navigator.appVersion.substring(0,1)<=5))?1:0;

var ie6=ie&&(navigator.appVersion.indexOf("MSIE 6")!=-1);


//uruchomienie ruchu
function onloader(){

	div_idel=document.getElementById(div_id);

	if(mac_ie)window.onscroll=loopfunc;
	else setInterval('loopfunc()',delay_time);


}
//funkcja ruchu
function loopfunc(){

	if(!div_idel.style.top){
		div_idel.style.top="0px";
	}

	if(mac_ie){
		if(document.body.scrollTop<absolute_top)
			div_idel.style.pixelTop=absolute_top;
		else
			div_idel.style.pixelTop=document.body.scrollTop+top_offset;
	}else if(ie){
		if(document.body.scrollTop<absolute_top){
			var dif=parseInt((absolute_top-div_idel.offsetTop)*xstep);
		} else {
			if(offset_ie==0){
				offset_ie=parseInt(div_idel.style.top);
			}
			if(ie6){
				var dif=parseInt((parseInt(document.body.scrollTop)-parseInt(div_idel.style.top))*xstep);
			} else {
				var dif=parseInt((parseInt((document.documentElement||document.body).scrollTop)-parseInt(div_idel.style.top))*xstep);
			}
		}

		if(dif!=0){
			div_idel.style.top=(parseInt(div_idel.style.top)+dif)+"px";
		}

	}else if(ns4){
		if (window.pageYOffset<absolute_top){
			var dif=parseInt((absolute_top-eval('document.'+div_id+'.top'))*xstep);
		} else {
			var dif=parseInt((window.pageYOffset+top_offset-eval('document.'+div_id+'.top'))*xstep);
		}
		if(!isNaN(dif)&&(dif!=0))eval('document.'+div_id+'.pageY+='+dif);
	}else if(w3c){
		if (window.pageYOffset<absolute_top){
			var dif=parseInt((absolute_top-parseInt(div_idel.style.top))*xstep);
		} else {
			var dif=parseInt((window.pageYOffset+top_offset-parseInt(div_idel.style.top))*xstep);
		}

		if(dif&&(dif!=0)) {
			div_idel.style.top=(parseInt(div_idel.style.top)+dif)+"px";
		}

	}
}

function adv_close() {
	adv=document.getElementById('adv_layer');
  adv.style.display='none';
}

