function zmien_tlo(host, obiekt, opcja){

	//obiekt = document.getElementById(id);
	
	if(opcja){
		obiekt.style.background = 'url('+host+'img/menu_tlo_hover.jpg) 0 0 repeat-x';
	}else{
		obiekt.style.background = 'none';
	}
	return true;
}

function swapImage(id, zdjecie){
	
	obj = document.getElementById(id);
	if(obj){
		obj.src = zdjecie;
	}
	return true;
}

function show_tab_waluty(host, elementId, waluta){
	
	li = document.getElementById('waluty').getElementsByTagName('li');
	for(i=0;i<li.length;i++){
		li[i].className = '';
		//alert('a');
	}
	wal = document.getElementById(waluta);
	wal.className='aktywne';
	
	document.getElementById(elementId).innerHTML='<img src="'+host+'img/loading.gif" />';
	variables = 'waluta='+waluta;
	url = host+'ajax_kurs_walut.php';
	new ajax(''+url+'', {
	postBody: ''+variables+'', update: $(elementId)});
	return false;
	
}

function show_tab_gielda(host, elementId, indeks){
	
	li = document.getElementById('gielda').getElementsByTagName('li');
	for(i=0;i<li.length;i++){
		li[i].className = '';
	}
	wal = document.getElementById(indeks);
	wal.className='aktywne';
	
	document.getElementById(elementId).innerHTML='<img src="'+host+'img/loading.gif" />';
	variables = 'gielda='+indeks;
	url = host+'ajax_notowania_gieldy.php';
	new ajax(''+url+'', {
	postBody: ''+variables+'', update: $(elementId)});
	return false;
	
}


function show_form(elementId,host){

	if(document.getElementById(elementId).style.visibility=='hidden'){
		
		document.getElementById(elementId).style.visibility='visible';
	}else{
		document.getElementById(elementId).style.visibility='hidden';
	}

}

function ustawWartosc(nazwaPola, wartosc){
	document.getElementById(nazwaPola).value = wartosc;
}

function rollover(id1, id2, ob1, ob2){
	var img1 = document.getElementById(id1);
	var img2 = document.getElementById(id2);
	img1.src=ob1;
	img2.src=ob2;
}

function PokazUkryj(id_pokaz,op){
	var kont = document.getElementById('napis');
	var a = kont.getElementsByTagName('A');
	for(i=0;i<a.length;i++){
	  a[i].style.display='none';
	}
	if(op){
		document.getElementById(id_pokaz).style.display='block';
	}
}

function ustaw_checkboxy(formularz, opcja){
	d = eval("document." + formularz + "");
	if(opcja == "select"){
		for (i = 0; i<d.elements.length; i++){
			if(d.elements[i].type == "checkbox"){
				d.elements[i].checked = true;
			}
		}
	}else if(opcja == "deselect"){
		for (i = 0; i<d.elements.length; i++){
			if(d.elements[i].type == "checkbox"){
				d.elements[i].checked = false;
			}
		}
	}else if(opcja == "invert"){
		for (i = 0; i<d.elements.length; i++){
			if(d.elements[i].type == "checkbox"){
				if(d.elements[i].checked == true){
					d.elements[i].checked = false;
				}else{
					d.elements[i].checked = true;
				}
			}
		}
	}
}

function formatuj_liczbe(n, dokladnosc){
	/*
	n = Math.round(n * 100) / 100;
	//n = (n + 0.001) + '';
	n = (n + 0.001) + '';
	n = (n - 0.001) + '';
	//alert("n: " + n);
	return n.substring(0, n.indexOf('.') + 3);
	*/
	//num = 930.9805;
	//result = n.toFixed(2);
	return n.toFixed(dokladnosc);
}

function findPosY(obj)
  {
    var curtop = 0;
    if(obj.offsetParent)
        while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
    return curtop;
  }
  
  function findPosX(obj)
  {
    var curleft = 0;
    if(obj.offsetParent)
        while(1) 
        {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    return curleft;
  }


function showhide_events(elementId,id,data,akcja,powiaty,lang,event){
    
	var mouseX = 0;
	var mouseY = 0;
	
	var IE = (document.all && document.getElementById && !window.opera );
	var FF = (!document.all && document.getElementById && !window.opera);
	
	if(!event){
		var event = window.event;
	}
	
	if(akcja){
		
		div = document.createElement('div');
		div.setAttribute('id', elementId);
		mouseX = findPosX(document.getElementById(id))-320;
		mouseY = findPosY(document.getElementById(id));
		
		img = document.createElement('img');
		img.setAttribute('src', 'img/loader.gif');
		img.setAttribute('width', '16');
		img.setAttribute('height', '16');
		img.setAttribute('alt', '');
		div.appendChild(img);
		div.style.width = '300px';
		div.style.position = 'absolute';
		div.style.display = 'block';
		div.style.top = mouseY+'px';
		div.style.left = mouseX+'px';
		div.style.zIndex = 1000;
		div.style.backgroundColor = '#FFFFFF';
		div.style.padding = '10px';
		div.style.border = '1px solid #666666';
		document.body.appendChild(div);
		
		variables='data='+data+'&lang='+lang+'&powiaty='+powiaty+'';
		url = site_host+'ajax_kalendarz.php';
		new Ajax.Request(url, {
			method: 'post',
			parameters: variables, 
			asynchronous: true,
				onComplete:function(request){
					jQuery('#'+elementId+'').html(request.responseText);	
				}
	    });
		
		
	}else{
		div = document.getElementById(elementId);
		if(div){
		   document.body.removeChild(div);
		}
	}
	return false;
}



function ajaxZaladujKalendarz(kontener, powiaty, lang){
	
	jQuery('#'+kontener+'').html('<img src="'+site_host+'img/loader.gif" width="16" height="16" alt="" align="center" />');
	new Ajax.Updater(kontener,site_host+'calendar/calendar.php', {
		method: 'get',
		parameters: 'powiaty='+powiaty+'&lang='+lang+'&kontener='+kontener+'', 
		asynchronous: true
		});
	return true;
}

function limit_dla_pola(limit, pole, span_pole){
	if (document.getElementById(pole).value.length > limit){
		document.getElementById(pole).value = document.getElementById(pole).value.substring(0, limit);
	}
	if(span_pole.length > 0){
		txt = "";
		ile_pozostalo = limit - document.getElementById(pole).value.length;
		txt = "<br>Pozostało/Remaining " + ile_pozostalo + " z/from " + limit + " znaków/chars.";
		document.getElementById(span_pole).innerHTML = txt;
	}
}

function migajacy_text(id, k1, t1, k2, t2){
  if (document.getElementById){
    document.getElementById(id).style.color = k1;
	setTimeout('migajacy_text("' +  id + '","' + k2 + '",' + t2 + ',"' + k1 + '",' + t1 + ')', t1);
  }else if (document.all){
    document.all[id].style.color = k1;
	setTimeout('migajacy_text("' +  id + '","' + k2 + '",' + t2 + ',"' + k1 + '",' + t1 + ')', t1);
  }
}

function popraw_telefon(nazwa_pola, max_znakow) {
    document.getElementById(nazwa_pola).value = document.getElementById(nazwa_pola).value.replace(/[^0-9\(\)\ ]/g,"");
	if(max_znakow.length > 0){
		document.getElementById(nazwa_pola).value = przytnij_text(document.getElementById(nazwa_pola).value, max_znakow);
	}
}

function sprawdz_mail(email_pole) {
	if (document.getElementById(email_pole).value.length>0){
		Wzor = /^[0-9a-zA-Z.-_\-]+\@[0-9a-zA-Z.-_\-]+\.[0-9a-zA-Z.]{2,4}$/;
	   	if (Wzor.test(document.getElementById(email_pole).value) == false){
    		alert("Niewłaściwy format adresu e-mail!");
	    	return false;
	    }  
   		return true; 
    }
  	return true;
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function MM_swapImgRestore(){ //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages(){ //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d){ //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage(){ //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function pop_new_window(nazwa_pliku, zmienna, id, qs){
	var plik = nazwa_pliku + "?" + zmienna + "=" + id + qs;
	var Win = window.open(plik, "text","menubar=0,location=0,status=0,toolbar=0,directories=0,alwaysRaised=1,scrollbars=1,titlebar=1,resizable=1");
}

function pop_zdjecie(nazwa_zdjecia_big, nazwa_podkatalogu){
	var plik = "pop_zdjecie.php?foto=" + nazwa_zdjecia_big + "&podkatalog=" + nazwa_podkatalogu;
	var Win = window.open(plik, "big_foto","width=100,height=100,menubar=0,location=0,status=0,toolbar=0,directories=0,alwaysRaised=1,scrollbars=1,titlebar=1,resizable=1");
}

function przytnij_text(text, max_znakow){
	if (text.length > max_znakow){
		text = text.substring(0, max_znakow);
	}
	return text;
}

function tylko_cyfry(nazwa_pola, max_znakow) {
    document.getElementById(nazwa_pola).value = document.getElementById(nazwa_pola).value.replace(/[^0-9]/g,"");
	if(max_znakow.length > 0){
		document.getElementById(nazwa_pola).value = przytnij_text(document.getElementById(nazwa_pola).value, max_znakow);
	}
}

function tylko_litery(nazwa_pola, max_znakow) {
    document.getElementById(nazwa_pola).value = document.getElementById(nazwa_pola).value.replace(/[^a-z]/g,"");
	if(max_znakow.length > 0){
		document.getElementById(nazwa_pola).value = przytnij_text(document.getElementById(nazwa_pola).value, max_znakow);
	}
}

function usun_biale_znaki(ciag){
	ciag = ciag.replace(/\r/g, " ");
  	ciag = ciag.replace(/[^ A-Za-z0-9`~!@#\$%\^&\*\(\)-_=\+\\\|\]\[\}\{'";:\?\/\.>,<]/g, "");
	ciag = ciag.replace(/'/g, "");
	ciag = ciag.replace(/ +/g, " ");  
	ciag = ciag.replace(/^\s/g, "");
	ciag = ciag.replace(/\s$/g, "");	
	return ciag;
}

function wylicz_wartosc(licznik, pole_baza, pole_zmiana, pole_vat, opcja){
	if(opcja == 'brutto'){
		document.getElementById(pole_zmiana).value = formatuj_liczbe(document.getElementById(pole_baza).value * (1 + usun_biale_znaki(document.getElementById(pole_vat).value) / 100), 3);
	}else if(opcja == 'netto'){
		document.getElementById(pole_zmiana).value = formatuj_liczbe(document.getElementById(pole_baza).value / (1 + usun_biale_znaki(document.getElementById(pole_vat).value) / 100), 3);
		//netto=(brutto*100)/(100+VAT)
		//alert("baza: " + document.getElementById(pole_baza).value * 100);
		//alert("vat: " + usun_biale_znaki(document.getElementById(pole_vat).value);
		//document.getElementById(pole_zmiana).value = formatuj_liczbe( (document.getElementById(pole_baza).value * 100) / (100 + usun_biale_znaki(document.getElementById(pole_vat).value)) );
		
	}
	document.getElementById("oszczedzasz_"+licznik).value = formatuj_liczbe((1*document.getElementById("cena_"+licznik).value) - (1*document.getElementById("cenaspecjalna_"+licznik).value),3);
	document.getElementById("oszczedzaszbrutto_"+licznik).value = formatuj_liczbe((1*document.getElementById("cenabrutto_"+licznik).value) - (1*document.getElementById("cenaspecjalnabrutto_"+licznik).value),3);
}
function cien(id,ok,ile){
	if(ok){
	   for(i=0;i<ile;i++){	
	     if(i!=id){
	   	 	document.getElementById('kto'+i).style.opacity=0.3;
			document.getElementById('kto'+i).style.filter='alpha(opacity=30)';
		 }
	   }
	}else{
		for(i=0;i<ile;i++){	
	    
     	 	document.getElementById('kto'+i).style.opacity=1;
			document.getElementById('kto'+i).style.filter='alpha(opacity=100)';
		
	   }
	}
}
function addbookmark(pole) { 
	var tytul = document.title; 
	var adres = document.location; 
	if (window.sidebar){ 
		window.sidebar.addPanel(tytul, adres, ""); 
	}else if (window.external) { 
		window.external.AddFavorite(adres, tytul); 
	}else if (window.opera && window.print) {
		var a = document.getElementById(pole); 
		a.setAttribute('href', adres); 
		a.setAttribute('title', tytul); 
		a.setAttribute('rel','sidebar'); 
		a.click(); 
	} 
} 

function loadRegisterForm(id, id_elementu){

    jQuery('#'+id_elementu+'').html('<img src="'+site_host+'img/loader.gif" width="16" height="16" alt="" />');
	new Ajax.Updater(id_elementu,site_host+'ajax_load_register_form.php', {
			method: 'post',
			parameters: 'id='+id+'',
			asynchronous: true
	});
	
	return true;
}

function loadNewsForm(id_elementu){

    jQuery('#'+id_elementu+'').html('<img src="'+site_host+'img/loader.gif" width="16" height="16" alt="" />');
	new Ajax.Updater(id_elementu,site_host+'ajax_load_add_news_form.php', {
			method: 'post',
			evalScripts: true,
			asynchronous: true
	});
	
	return true;
}

function drawPoint2(wsp, zoom, text, url, mapa){
         
		pom = wsp.split(',');
		latlng = new GLatLng(pom[0], pom[1]);
	    marker = new GMarker(latlng,{draggable:false, autoPan:true});
		marker.setImage("http://maps.google.com/mapfiles/marker.png");
		
		if(text){
			GEvent.addListener(marker, "mouseover", function(point) {
				 marker.openInfoWindowHtml(text);
			});
		}
		
		if(url){
			GEvent.addListener(marker, "click", function(point) {
                document.location.href = url;
            });
		}
		
		var latlngbounds = new GLatLngBounds();
		latlngbounds.extend(latlng);
        eval(mapa+".addOverlay(marker);");
		eval(mapa+".setCenter( latlngbounds.getCenter( ), "+zoom+" );");
		   
  
}

function loadGoogleMaps(id_elementu, id, tytul){

   jQuery('#'+id_elementu+'').html('');
   jQuery('#'+id_elementu+'').html('<img src="'+site_host+'img/loader.gif" width="16" height="16" alt="" />');
	new Ajax.Updater(id_elementu,site_host+'ajax_load_google_maps.php', {
			method: 'post',
			parameters: 'id='+id+'',
			onComplete: function(request){
				jQuery('#'+id_elementu+'').dialog({width: 600, height: 540, modal: true, title: tytul, buttons: {}});
			},
			evalScripts: true,
			asynchronous: true
	});
	
	return true;
	
}


function loadEditNewsForm(id_elementu, id, tytul){

   jQuery('#dodaj').html('');
   jQuery('#'+id_elementu+'').html('<img src="'+site_host+'img/loader.gif" width="16" height="16" alt="" />');
	new Ajax.Updater(id_elementu,site_host+'ajax_load_edit_news_form.php', {
			method: 'post',
			parameters: 'id='+id+'',
			onComplete: function(request){
				jQuery('#'+id_elementu+'').dialog({width: 700, height: 680, modal: true, title: tytul, buttons: {}});
			},
			evalScripts: true,
			asynchronous: true
	});
	
	return true;
}

function loadOffers(id_elementu){

   jQuery('#'+id_elementu+'').html('<img src="'+site_host+'img/loader.gif" width="16" height="16" alt="" />');
   new Ajax.Updater(id_elementu,site_host+'ajax_load_offers.php', {
			method: 'post',
			evalScripts: true,
			asynchronous: true
	});
	
	return true;
}

function loadNews(id_elementu){

   jQuery('#'+id_elementu+'').html('<img src="'+site_host+'img/loader.gif" width="16" height="16" alt="" />');
   new Ajax.Updater(id_elementu,site_host+'ajax_load_news.php', {
			method: 'post',
			evalScripts: true,
			asynchronous: true
	});
	
	return true;
}

function deleteNoticeForm(id_elementu, id, tresc, tytul){

   jQuery('#dodaj').html('');
   jQuery('#'+id_elementu+'').html(tresc);
   jQuery('#'+id_elementu+'').dialog({width: 400, height: 200, modal: true, title: tytul, buttons: {"NO": function(){jQuery('#'+id_elementu+'').dialog('close');},"OK": function(){deleteNotice(id, id_elementu, tytul);}}});
		
	return true;
	
}

function logIn(id_elementu, formId){
   
	new Ajax.Request(site_host+'ajax_login.php', {
			method: 'post',
			parameters: jQuery('#'+formId+'').serialize(),
			onComplete: function(request){
				
				var xmlResponse = request.responseXML.documentElement;
				if(xmlResponse.hasChildNodes()){
						//var rekord = xmlResponse.firstChild;
						message = xmlResponse.childNodes.item(0).childNodes.length ? xmlResponse.childNodes.item(0).firstChild.data : '';
						result = xmlResponse.childNodes.item(1).childNodes.length ? parseInt(xmlResponse.childNodes.item(1).firstChild.data) : 0;
				        if(!result){
						  jQuery('#'+id_elementu+'').html(message);
						}else{
							document.location = message;
						}
				       /* jQuery('#'+id_elementu+'').tooltip({ 
							delay: 0, 
							showURL: false, 
							showBody: " - ", 
							bodyHandler: function() { 
								return message; 
							} 
						});*/
						  
						xmlResponse.removeChild(xmlResponse.firstChild);
				}
				
				
			},
			evalScripts: true,
			asynchronous: true
	});
	
	return true;
	
}

function deleteNotice(id, id_elementu, tytul){
   
   jQuery('#dodaj').html('');
   jQuery('#'+id_elementu+'').dialog('close');
	new Ajax.Request(site_host+'ajax_delete_notice.php', {
			method: 'post',
			parameters: 'id='+id+'',
			onComplete: function(request){
				
				var xmlResponse = request.responseXML.documentElement;
				if(xmlResponse.hasChildNodes()){
						//var rekord = xmlResponse.firstChild;
						message = xmlResponse.childNodes.item(0).childNodes.length ? xmlResponse.childNodes.item(0).firstChild.data : '';
						result = xmlResponse.childNodes.item(1).childNodes.length ? parseInt(xmlResponse.childNodes.item(1).firstChild.data) : 0;
				 
						jQuery('#'+id_elementu+'').html(message);
				        jQuery('#'+id_elementu+'').dialog({width: 400, height: 200, modal: true, title: tytul, buttons: {"OK": function(){jQuery('#'+id_elementu+'').dialog('close');}}});
				        loadOffers('offers');
						  
						xmlResponse.removeChild(xmlResponse.firstChild);
				}
				
				
			},
			evalScripts: true,
			asynchronous: true
	});
	
	return true;
	
}

function deleteNewsForm(id_elementu, id, tresc, tytul){

   jQuery('#dodaj').html('');
   jQuery('#'+id_elementu+'').html(tresc);
   jQuery('#'+id_elementu+'').dialog({width: 400, height: 200, modal: true, title: tytul, buttons: {"NO": function(){jQuery('#'+id_elementu+'').dialog('close');},"OK": function(){deleteNews(id, id_elementu, tytul);}}});
		
	return true;
	
}

function deleteNews(id, id_elementu, tytul){
   
   jQuery('#dodaj').html('');
   jQuery('#'+id_elementu+'').dialog('close');
	new Ajax.Request(site_host+'ajax_delete_news.php', {
			method: 'post',
			parameters: 'id='+id+'',
			onComplete: function(request){
				
				var xmlResponse = request.responseXML.documentElement;
				if(xmlResponse.hasChildNodes()){
						//var rekord = xmlResponse.firstChild;
						message = xmlResponse.childNodes.item(0).childNodes.length ? xmlResponse.childNodes.item(0).firstChild.data : '';
						result = xmlResponse.childNodes.item(1).childNodes.length ? parseInt(xmlResponse.childNodes.item(1).firstChild.data) : 0;
				 
						jQuery('#'+id_elementu+'').html(message);
				        jQuery('#'+id_elementu+'').dialog({width: 400, height: 200, modal: true, title: tytul, buttons: {"OK": function(){jQuery('#'+id_elementu+'').dialog('close');}}});
				        loadNews('offers');
						  
						xmlResponse.removeChild(xmlResponse.firstChild);
				}
				
				
			},
			evalScripts: true,
			asynchronous: true
	});
	
	return true;
	
}

function loadNoticeForm(id_elementu){

    jQuery('#'+id_elementu+'').html('<img src="'+site_host+'img/loader.gif" width="16" height="16" alt="" />');
	new Ajax.Updater(id_elementu,site_host+'ajax_load_add_notice_form.php', {
			method: 'post',
			evalScripts: true,
			asynchronous: true
	});
	
	return true;
}

function addslashes(str) {
	str=str.replace(/\\/g,'\\\\');
	str=str.replace(/\'/g,'\\\'');
	str=str.replace(/\"/g,'\\"');
	str=str.replace(/\0/g,'\\0');
	return str;
}
function stripslashes(str) {
	str=str.replace(/\\'/g,'\'');
	str=str.replace(/\\"/g,'"');
	str=str.replace(/\\0/g,'\0');
	str=str.replace(/\\\\/g,'\\');
	return str;
}

function upload(id_elementu, file, folder){
	
	jQuery('#'+id_elementu+'').uploadify({
				'uploader': site_host+'fileupload/uploadify.swf',
				'script': site_host+file,
				'folder': site_host+folder,
				'cancelImg': site_host+'fileupload/cancel.png',
				'onAllComplete'  : function(event, ID, fileObj, response, data) {
				    jQuery('#okienko').dialog('close');
				},
	});
	
}

function selectObj(id_elementu){
	jQuery().ready(function() {
		jQuery('#'+id_elementu+'').multiselect2side({moveOptions: false});
	});
}

function date(id_elementu){
	jQuery().ready(function() {
		jQuery('#'+id_elementu+'').datepicker({dateFormat: 'yy-mm-dd'});
	});
}

function loadEditNoticeForm(id_elementu, id, tytul){

   jQuery('#dodaj').html('');
   jQuery('#'+id_elementu+'').html('<img src="'+site_host+'img/loader.gif" width="16" height="16" alt="" />');
	new Ajax.Updater(id_elementu,site_host+'ajax_load_edit_notice_form.php', {
			method: 'post',
			parameters: 'id='+id+'',
			onComplete: function(request){
				jQuery('#'+id_elementu+'').dialog({width: 600, height: 570, modal: true, title: tytul, buttons: {}});
			},
			close: function() {
				jQuery('#'+id_elementu+'').css('display','none'); 
			},
			evalScripts: true,
			asynchronous: true
	});
	
	return true;
}

function addNotice(formId, id_elementu){
	
	jQuery('#'+id_elementu+'').html('<img src="'+site_host+'img/loader.gif" width="16" height="16" alt="" />');
	new Ajax.Request(site_host+'ajax_load_add_notice_form.php', {
			method: 'post',
			parameters: jQuery('#'+formId+'').serialize(),
			onComplete: function(request){
				var xmlResponse = request.responseXML.documentElement;
				if(xmlResponse.hasChildNodes()){
						//var rekord = xmlResponse.firstChild;
						message = xmlResponse.childNodes.item(0).childNodes.length ? xmlResponse.childNodes.item(0).firstChild.data : '';
						result = xmlResponse.childNodes.item(1).childNodes.length ? parseInt(xmlResponse.childNodes.item(1).firstChild.data) : 0;
				
						jQuery('#'+id_elementu+'').html(message);
						if(result){
							jQuery('#foto1').uploadifySettings('scriptData', {'id' : result});
						    jQuery('#foto1').uploadifyUpload();
							loadOffers('offers');
						    clearForm(formId);
						   
				        }
						xmlResponse.removeChild(xmlResponse.firstChild);
				}
			},
			asynchronous: true
	});
	
	return true;
}

function sendPassword(formId, id_elementu){
	
	jQuery('#'+id_elementu+'').html('<img src="'+site_host+'img/loader.gif" width="16" height="16" alt="" />');
	new Ajax.Request(site_host+'ajax_send_password.php', {
			method: 'post',
			parameters: document.getElementById(formId).serialize(),
			onComplete: function(request){
				var xmlResponse = request.responseXML.documentElement;
				if(xmlResponse.hasChildNodes()){
						//var rekord = xmlResponse.firstChild;
						message = xmlResponse.childNodes.item(0).childNodes.length ? xmlResponse.childNodes.item(0).firstChild.data : '';
						result = xmlResponse.childNodes.item(1).childNodes.length ? parseInt(xmlResponse.childNodes.item(1).firstChild.data) : 0;
				
						document.getElementById(id_elementu).innerHTML = message;
						if(result){
							
						   clearForm(formId);
						   
						  
				        }
						xmlResponse.removeChild(xmlResponse.firstChild);
				}
			},
			asynchronous: true
	});
	
	return true;
}


function addNews(formId, id_elementu){
	
	jQuery('#'+id_elementu+'').html('<img src="'+site_host+'img/loader.gif" width="16" height="16" alt="" />');
	new Ajax.Request(site_host+'ajax_load_add_news_form.php', {
			method: 'post',
			parameters: jQuery('#'+formId+'').serialize()+'&tresc_fck='+escape(FCKeditorAPI.GetInstance('tresc').GetXHTML()),
			onComplete: function(request){
				var xmlResponse = request.responseXML.documentElement;
				if(xmlResponse.hasChildNodes()){
						//var rekord = xmlResponse.firstChild;
						message = xmlResponse.childNodes.item(0).childNodes.length ? xmlResponse.childNodes.item(0).firstChild.data : '';
						result = xmlResponse.childNodes.item(1).childNodes.length ? parseInt(xmlResponse.childNodes.item(1).firstChild.data) : 0;
				        jQuery('#'+id_elementu+'').html(message);
						
						if(result){
						  
						  jQuery('#foto1').uploadifySettings('scriptData', {'id' : result});
						  jQuery('#foto1').uploadifyUpload();
						  clearForm(formId);
						  loadNews('offers');
						  FCKeditorAPI.GetInstance('tresc').SetHTML('');
						   //loadNews('offers');
						   //clearForm(formId);
						   
						  
				        }
						xmlResponse.removeChild(xmlResponse.firstChild);
				}
			},
			asynchronous: true
	});
	
	return true;
}


function saveNotice(formId, id_elementu){
	
	jQuery('#'+id_elementu+'').html('<img src="'+site_host+'img/loader.gif" width="16" height="16" alt="" />');
	new Ajax.Request(site_host+'ajax_load_edit_notice_form.php', {
			method: 'post',
			parameters: jQuery('#'+formId+'').serialize(),
			onComplete: function(request){
				var xmlResponse = request.responseXML.documentElement;
				if(xmlResponse.hasChildNodes()){
						//var rekord = xmlResponse.firstChild;
						message = xmlResponse.childNodes.item(0).childNodes.length ? xmlResponse.childNodes.item(0).firstChild.data : '';
						result = xmlResponse.childNodes.item(1).childNodes.length ? parseInt(xmlResponse.childNodes.item(1).firstChild.data) : 0;
				
						
						if(result){
						
						   jQuery('#foto1').uploadifySettings('scriptData', {'id' : result});
						   jQuery('#foto1').uploadifyUpload();
						   
						    //jQuery('#okienko').dialog('close');
							jQuery('#myfrmkom').html(message);
							//jQuery('#okienko').append(message);
							//jQuery('#okienko').dialog({width: 400, height: 200, modal: true, buttons: {"OK": function(){jQuery('#okienko').dialog('close');}}});
						
						   loadOffers('offers');
						  
				        }else{
						   jQuery('#'+id_elementu+'').html(message);
						}
						
						xmlResponse.removeChild(xmlResponse.firstChild);
				}
			},
			asynchronous: true
	});
	
	return true;
}

function saveNews(formId, id_elementu){
	
	jQuery('#'+id_elementu+'').html('<img src="'+site_host+'img/loader.gif" width="16" height="16" alt="" />');
	new Ajax.Request(site_host+'ajax_load_edit_news_form.php', {
			method: 'post',
			parameters: jQuery('#'+formId+'').serialize()+'&tresc_fck='+escape(FCKeditorAPI.GetInstance('tresc').GetXHTML()),
			onComplete: function(request){
				var xmlResponse = request.responseXML.documentElement;
				if(xmlResponse.hasChildNodes()){
						//var rekord = xmlResponse.firstChild;
						message = xmlResponse.childNodes.item(0).childNodes.length ? xmlResponse.childNodes.item(0).firstChild.data : '';
						result = xmlResponse.childNodes.item(1).childNodes.length ? parseInt(xmlResponse.childNodes.item(1).firstChild.data) : 0;
				        
						if(result){
							 
						     jQuery('#foto1').uploadifySettings('scriptData', {'id' : result});
						  jQuery('#foto1').uploadifyUpload();
						  jQuery('#okienko').dialog('close');
						   jQuery('#okienko').html('');
						   jQuery('#okienko').append(message);
						   jQuery('#okienko').dialog({width: 400, height: 200, modal: true, buttons: {"OK": function(){jQuery('#okienko').dialog('close');}}});
						   loadNews('offers');
				        }else{
							jQuery('#'+id_elementu+'').html(message);
						}
						
						xmlResponse.removeChild(xmlResponse.firstChild);
				}
			},
			asynchronous: true
	});
	
	return true;
}

function changePassword(formId, id_elementu){

   jQuery('#'+id_elementu+'').html('<img src="'+site_host+'img/loader.gif" width="16" height="16" alt="" />');
	new Ajax.Request(site_host+'ajax_load_change_password_form.php', {
			method: 'post',
			parameters: jQuery('#'+formId+'').serialize(),
			onComplete: function(request){
				var xmlResponse = request.responseXML.documentElement;
				if(xmlResponse.hasChildNodes()){
						//var rekord = xmlResponse.firstChild;
						message = xmlResponse.childNodes.item(0).childNodes.length ? xmlResponse.childNodes.item(0).firstChild.data : '';
						result = xmlResponse.childNodes.item(1).childNodes.length ? parseInt(xmlResponse.childNodes.item(1).firstChild.data) : 0;
				
						jQuery('#'+id_elementu+'').html(message);
						if(result){
							 
						   clearForm(formId);
						  
						   /*if(captchaId){
						      refresh_captcha(captchaId);
						   }*/
				        }
						xmlResponse.removeChild(xmlResponse.firstChild);
						//scroll_top(elementId);
				}
			},
			asynchronous: true
	});
	
	return true;
}

function loadChangePasswordForm(id_elementu){

   jQuery('#'+id_elementu+'').html('<img src="'+site_host+'img/loader.gif" width="16" height="16" alt="" />');
	new Ajax.Updater(id_elementu,site_host+'ajax_load_change_password_form.php', {
			method: 'post',
			asynchronous: true
	});
	
	return true;
}

function unLoadChangePasswordForm(id_elementu){

    jQuery('#'+id_elementu+'').html('<a href="javascript:void(0);" onclick="loadChangePasswordForm(\'edycja\')" class="ziel">zmiana hasła &raquo;</a>');
	return true;
}

function clearForm(form){
	  
	  var elts = document.getElementById(form).elements;
	  for(i=0;i<elts.length;i++){	
		   if(elts[i].type=='radio' && elts[i].checked){
		      elts[i].checked = false;
		   }else if(elts[i].type=='checkbox' && elts[i].checked){
		       elts[i].checked = false;
		   }else if(elts[i].tagName=='SELECT'){
			   elts[i].options[elts[i].selectedIndex].selected = false;
			   elts[i].options[0].selected = true;
		   }else if(elts[i].type!='radio' && elts[i].type!='checkbox' && elts[i].type!='hidden' && elts[i].type!='button'){
		       elts[i].value = '';
		   }
		}    
	  return true;	
  }

function register(form, id_elementu){
	
	jQuery('#'+id_elementu+'').html('<img src="'+site_host+'img/loader.gif" width="16" height="16" alt="" />');
	new Ajax.Request(site_host+'ajax_register.php', {
			method: 'post',
			parameters: jQuery('#'+form+'').serialize(),
			asynchronous: true,
			onComplete: function(request){
				var xmlResponse = request.responseXML.documentElement;
				if(xmlResponse.hasChildNodes()){
						//var rekord = xmlResponse.firstChild;
						message = xmlResponse.childNodes.item(0).childNodes.length ? xmlResponse.childNodes.item(0).firstChild.data : '';
						result = xmlResponse.childNodes.item(1).childNodes.length ? parseInt(xmlResponse.childNodes.item(1).firstChild.data) : 0;
				
						jQuery('#'+id_elementu+'').html(message);
						if(result){
							 
						   clearForm(form);
						  
						   /*if(captchaId){
						      refresh_captcha(captchaId);
						   }*/
				        }
						xmlResponse.removeChild(xmlResponse.firstChild);
						//scroll_top(elementId);
				}
			}
	});
	return true;
}

function sendEmail(contact_id, contactkom_id){
	
	jQuery('#'+contactkom_id+'').html('<img src="'+site_host+'img/loader.gif" width="16" height="16" alt="" />');
	new Ajax.Request(site_host+'ajax_send_message.php', {
			method: 'post',
			parameters: jQuery('#'+contact_id+'').serialize(),
			asynchronous: true,
			onComplete: function(request){
				var xmlResponse = request.responseXML.documentElement;
				if(xmlResponse.hasChildNodes()){
						//var rekord = xmlResponse.firstChild;
						message = xmlResponse.childNodes.item(0).childNodes.length ? xmlResponse.childNodes.item(0).firstChild.data : '';
						result = xmlResponse.childNodes.item(1).childNodes.length ? parseInt(xmlResponse.childNodes.item(1).firstChild.data) : 0;
				
						jQuery('#'+contactkom_id+'').html(message);
						
						if(result){
							 
						   clearForm(contact_id);
						  
						   /*if(captchaId){
						      refresh_captcha(captchaId);
						   }*/
				        }
						xmlResponse.removeChild(xmlResponse.firstChild);
						//scroll_top(elementId);
				}
			}
	});
	return true;
	
}

function sendEmail2(contact_id, contactkom_id){
	
	jQuery('#'+contactkom_id+'').html('<img src="'+site_host+'img/loader.gif" width="16" height="16" alt="" />');
	new Ajax.Request(site_host+'ajax_send_message2.php', {
			method: 'post',
			parameters: jQuery('#'+contact_id+'').serialize(),
			asynchronous: true,
			onComplete: function(request){
				var xmlResponse = request.responseXML.documentElement;
				if(xmlResponse.hasChildNodes()){
						//var rekord = xmlResponse.firstChild;
						message = xmlResponse.childNodes.item(0).childNodes.length ? xmlResponse.childNodes.item(0).firstChild.data : '';
						result = xmlResponse.childNodes.item(1).childNodes.length ? parseInt(xmlResponse.childNodes.item(1).firstChild.data) : 0;
				
						jQuery('#'+contactkom_id+'').html(message);
						
						if(result){
							 
						   clearForm(contact_id);
						  
						   /*if(captchaId){
						      refresh_captcha(captchaId);
						   }*/
				        }
						xmlResponse.removeChild(xmlResponse.firstChild);
						//scroll_top(elementId);
				}
			}
	});
	return true;
	
}

function sendEmail3(contact_id, contactkom_id){
	
	jQuery('#'+contactkom_id+'').html('<img src="'+site_host+'img/loader.gif" width="16" height="16" alt="" />');
	new Ajax.Request(site_host+'ajax_send_message3.php', {
			method: 'post',
			parameters: jQuery('#'+contact_id+'').serialize(),
			asynchronous: true,
			onComplete: function(request){
				var xmlResponse = request.responseXML.documentElement;
				if(xmlResponse.hasChildNodes()){
						//var rekord = xmlResponse.firstChild;
						message = xmlResponse.childNodes.item(0).childNodes.length ? xmlResponse.childNodes.item(0).firstChild.data : '';
						result = xmlResponse.childNodes.item(1).childNodes.length ? parseInt(xmlResponse.childNodes.item(1).firstChild.data) : 0;
				
						jQuery('#'+contactkom_id+'').html(message);
						
						if(result){
							 
						   clearForm(contact_id);
						  
						   /*if(captchaId){
						      refresh_captcha(captchaId);
						   }*/
				        }
						xmlResponse.removeChild(xmlResponse.firstChild);
						//scroll_top(elementId);
				}
			}
	});
	return true;
	
}

