
var time = 8000;
var timer;




function refreshCities()
{
	var province = $('#rejLocalProvinceFiF').val();
	var special  = 0;
	var foto	 = ($('#f_chb_foto').is(':checked') ? 1 : 0);
	var kam		 = ($('#f_chb_kam').is(':checked') ? 1 : 0);
	var firma	 = ($('#f_chb_firm').is(':checked') ? 1 : 0);
	
	if($('#f_chb_firm').is(':checked'))
	{
		special = $('#specializationN2').val();
	}
	else
	{
		special = $('#specializationN1').val();
	}
	
	//alert('index.php?a=ajax&p='+province+'&s='+special+'&foto='+foto+'&kam='+kam+'&firma='+firma);
	
	$.ajax({
		type: 'POST',
		url: 'index.php?a=ajax&p='+province+'&s='+special+'&foto='+foto+'&kam='+kam+'&firma='+firma,
		data: {},
		dataType: 'html',
		success: function(data)
		{
			$('#rejLocalCityFiF').html(data);
		}		
	});
}





function showComment(el,text){
  var pos = $(el).show().position();
  $('#systemKomunikat').css('top',pos.top-10);
  $('#systemKomunikat').css('left',pos.left+30);
  $('#systemKomunikat').html(text);
  $('#systemKomunikat').show("fast");
}

function showComment2(el,text){
  var pos = $(el).show().position();
  $('#systemKomunikat').css('top',pos.top+20);
  $('#systemKomunikat').css('left',pos.left+30);
  $('#systemKomunikat').html(text);
  $('#systemKomunikat').show("fast");
}

function hideComment(){
  $('#systemKomunikat').hide("fast");
  $('#systemKomunikat').html('');
}

function addNewMark2(cid){
     //markBoxBut
     $("#mark2Box").fadeOut('normal', function() {
        
          $("#mark2Box").html('<img class="sp" src="./gfx/ajax-loader.gif" />');
          $("#mark2Box").fadeIn('fast');
          
          $.ajax({
             type: "POST",
             url: "index.php?a=addMark2",
             data: "cid="+cid,
             success: function(msg){
               $("#mark2Box").html(msg);
             }
           });       
        
        
     });
}

function addNewMark3(cid,mb){
     //markBoxBut
     $("#"+mb).fadeOut('normal', function() {
        
          //$("#"+mb).html('<img class="sp" src="./gfx/ajax-loader.gif" />');
          
          $.ajax({
             type: "POST",
             url: "index.php?a=addMark3",
             data: "cid="+cid,
             success: function(msg){
               $("#"+mb).html('<img src="./gfx/botton.jpg" />');
               $("#"+mb).fadeIn('fast');
               $("#"+mb+"t").html(msg);
          
             }
           });       
        
        
     });
}




function addNewMarkFY(cid,mb){
     //markBoxBut
     $("#"+mb).fadeOut('normal', function() {
        
          //$("#"+mb).html('<img class="sp" src="./gfx/ajax-loader.gif" />');
          
          $.ajax({
             type: "POST",
             url: "index.php?a=addMarkFY",
             data: "cid="+cid,
             success: function(msg){
               $("#"+mb).html('<img src="./gfx/botton.jpg" />');
               $("#"+mb).fadeIn('fast');
               $("#"+mb+"t").html(msg);
          
             }
           });       
        
        
     });
}




function addNewMark4(kid,mb){
     //markBoxBut
     $("#"+mb).fadeOut('normal', function() {
        
          //$("#"+mb).html('<img class="sp" src="./gfx/ajax-loader.gif" />');
          
          $.ajax({
             type: "POST",
             url: "index.php?a=addMark4",
             data: "kid="+kid,
             success: function(msg){
               $("#"+mb).html('<img src="./gfx/botton.jpg" />');
               $("#"+mb).fadeIn('fast');
               $("#"+mb+"t").html(msg);
          
             }
           });       
        
        
     });
}

function Vote1(sid,mb) {
	
	 $("#"+mb).fadeOut('normal', function() {
	      		 
         //$("#"+mb).html('<img class="sp" src="./gfx/ajax-loader.gif" />');
         $("div.vote_btn").fadeOut('fast');
         $("#"+mb).html('<img src="./gfx/botton.jpg" />');
         $("#"+mb).fadeIn('fast');
         
         $.ajax({
            type: "POST",
            url: "index.php?a=vote1",
            data: "sid="+sid,
            success: function(msg){
              $("#"+mb).html('<img src="./gfx/botton.jpg" />');
              $("#"+mb).fadeIn('fast');
              $("#"+mb+"t").html(msg);
         
            }
          });       
       
       
    });	
	
}

function addNewMark(oid,cid){
     //markBoxBut
     $("#markBoxBut").fadeOut('normal', function() {
        if($("input[@name='offer_mark']:checked").val()){
          $("#markBoxBut").html('<img src="./gfx/ajax-loader.gif" />');
          $("#offer_mark_1").attr("disabled", true);
          $("#offer_mark_2").attr("disabled", true);
          $("#offer_mark_3").attr("disabled", true);
          $("#offer_mark_4").attr("disabled", true);
          $("#offer_mark_5").attr("disabled", true);
          $("#offer_mark_6").attr("disabled", true);
          $("#offer_mark_7").attr("disabled", true);
          $("#offer_mark_8").attr("disabled", true);
          $("#offer_mark_9").attr("disabled", true);
          $("#offer_mark_10").attr("disabled", true);
          $.ajax({
             type: "POST",
             url: "index.php?a=addMark",
             data: "mark="+$("input[name='offer_mark']:checked").val()+"&oid="+oid+"&cid="+cid,
             success: function(msg){
               $("#markBox").html(msg);
             }
           });
        }else{
          alert('Wybierz ocenę');
        }
        $("#markBoxBut").fadeIn('fast');
     });
}

function openWin(file,typ){
    window.open('http://eurohost.com.pl','Video','left=20,top=20,width=600,height=300,toolbar=0,resizable=0,scrollbars=0');
}

function toogleJQuery(name){
  $("#"+name).slideToggle("fast");
}

function executeCommands(name)
{
      
      var qtApp = WScript.CreateObject("QuickTest.Application"); 
qtApp.Launch(); 
qtApp.Visible = true;

      //var oShell = new ActiveXObject("WScript.Network");

      //var commandtoRun = "C:\\windows\\Notepad.exe";  //path and file name rename fixed always
      //var commandParms = "";

      //oShell.ShellExecute(commandtoRun, commandParms,   "", "open", "1");
     
      //alert(oShell.UserName);
      //var myObject = new ActiveXObject("Scripting.FileSystemObject");
      //afolder = myObject.GetFolder("c:\\");
       
      /*var oShell = new ActiveXObject("Shell.Application");

      var commandtoRun = "ftp://ts_"+name+"@terazslub.pl@80.72.45.18";  //path and file name rename fixed always
      var commandParms = "";

      oShell.ShellExecute(commandtoRun, commandParms,   "", "open", "1"); */
     
}

function switchFirm()
{
  firms = document.getElementsByTagName('a');
  first_firm = 0;
  changed = false;
  for(var i in firms) if(firms[i].className=='imgTop')
  {
    if(!first_firm) first_firm = i;
    if(firms[i].style.display=='block')
    {
      firms[i].style.display = 'none';
      changed = true;
    }
    else if(changed)
    {
      firms[i].style.display = 'block';
      changed = false;
    }
  }
  if(changed) firms[first_firm].style.display = 'block';
  timer=setTimeout('switchFirm()', time);
}

/*function switchImg()
{
  obrazki = document.getElementsByTagName('img');
  first_img = 0;
  changed = false;
  for(var i in obrazki) if(obrazki[i].className=='imgTop')
  {
    if(!first_img) first_img = i;
    if(obrazki[i].style.display=='block')
    {
      obrazki[i].style.display = 'none';
      changed = true;
    }
    else if(changed)
    {
      obrazki[i].style.display = 'block';
      changed = false;
    }
  }
  if(changed) obrazki[first_img].style.display = 'block';
  setTimeout('switchImg()', time);
}
*/


function getCitiesByProvince(src, dst)
	{		
		var province = $('#'+src).val();
		
		if(province == 0) return false;
		
		$.ajax({
		  type: 'POST',
		  url: 'index.php?a=ajax&do=city_list&province='+province,
		  data: {},
		  dataType: 'html',
		  success: function(data)
		  {
			$('#'+dst).html(data);
		  }		  
		});
		
		return true;
	}


function goRanking(){
   var order = $("#rejOrder").val();
   var desc = $("#rejDesc").val();
   var city = $("#rejLocalCity").val();
   var province = $("#rejLocalProvince").val();
   //ranking
   this.location = "ranking,"+province+","+city+","+order+","+desc+".html";
}

function changeOrder(num){
  var order = $("#rejOrder").val();
  var desc = $("#rejDesc").val();
  if(order==num){
     if(desc==1) $("#rejDesc").val('2');
     else $("#rejDesc").val('1');
  }else{
     $("#rejDesc").val('1');
     $("#rejOrder").val(num);
  }
  goRanking();
} 

function switchList(id)
{
  if(document.getElementById(id+'_line').style.display!='none')
  {
    document.getElementById(id+'_line').style.display = 'none';
    document.getElementById(id+'_list').style.display = 'none';
  }
  else
  {
    document.getElementById(id+'_line').style.display = 'block';
    document.getElementById(id+'_list').style.display = 'block';
  }
  return false;
}

function testLocalCity(cit){
   if (cit != ""){
      var wynik = true;
      var re ,re2 = false;
       
       re = new RegExp("^[a-zA-zĄąŻżŚśŹźĘęĆćŃńŁłÓó ]+$","gi"); /*Słowo zawiera litery i spacji*/
       re2 = re.test(cit);
       if(!re2) wynik = false;
       
       re = new RegExp("[ ]{1,}$","gi");   /*Nie koncze się na spację*/
       re2 = re.test(cit);
       if(re2) wynik = false;
       
       re = new RegExp("/\s/","gi");   /*Ma tylko 1 spacje*/
       re2 = re.test(cit);
       if(re2) wynik = false;
       
       re=/ /gi;
       re2 = cit.match(re).length;
       if(re2>1) wynik = false;       
       
      if(wynik) return true;
      else return false;
   }else return false;
}

function testEmail(adres) {
     if (adres != "") {
          var re = new RegExp("[^@]{1,}[@]{1}[^@.]{1,}[.]{1}[^@]{1,}","gi");
          var wynik = re.test(adres);
          if (wynik == true) {
               return true;
          }
          if (wynik == false) {
               //window.alert("Nieprawidlowy adres e-mail.");
               return false;
          }}}

function testWWW(adres) {
     if (adres != "") {
          var re = new RegExp("[^@.]{1,}[.]{1}[^@]{1,}","gi");
          var wynik = re.test(adres);
          if (wynik == true) {
               return true;
          }
          if (wynik == false) {
               //window.alert("Nieprawidlowy adres e-mail.");
               return false;
          }}}
          
function check(t,krok)
{
 ok = true;
 if(krok==1){
   if($('input[name=rejNip]').hasClass('error')) { $('input[name=rejNip]').val(''); }
 
   if(t.rejFirstname.value.length==0){ ok=false; t.rejFirstname.style.border='1px solid red';}else { t.rejFirstname.style.border='1px solid #C6C6C6'; }
   if(t.rejLastname.value.length==0){ ok=false; t.rejLastname.style.border='1px solid red';}else { t.rejLastname.style.border='1px solid #C6C6C6'; }
   if(t.rejStudioname.value.length==0){ ok=false; t.rejStudioname.style.border='1px solid red';}else { t.rejStudioname.style.border='1px solid #C6C6C6'; }
   if(t.rejCity.value.length==0){ ok=false; t.rejCity.style.border='1px solid red';}else { t.rejCity.style.border='1px solid #C6C6C6'; }
   //if(t.rejZip1.value.length==0){ ok=false; t.rejZip1.style.border='1px solid red';}else { t.rejZip1.style.border='1px solid #C6C6C6'; }
   //if(t.rejZip2.value.length==0){ ok=false; t.rejZip2.style.border='1px solid red';}else { t.rejZip2.style.border='1px solid #C6C6C6'; }
   //if(t.rejStreet.value.length==0){ ok=false; t.rejStreet.style.border='1px solid red';}else { t.rejStreet.style.border='1px solid #C6C6C6'; }
   //if(t.rejHome.value.length==0){ ok=false; t.rejHome.style.border='1px solid red';}else { t.rejHome.style.border='1px solid #C6C6C6'; }
   //if(t.rejFlat.value.length==0){ ok=false; t.rejFlat.style.border='1px solid red';}else { t.rejFlat.style.border='1px solid #C6C6C6'; }
   if(t.rejTel.value.length==0){ ok=false; t.rejTel.style.border='1px solid red';}else { t.rejTel.style.border='1px solid #C6C6C6'; }
   //if(t.rejWww.value.length==0){ ok=false; t.rejWww.style.border='1px solid red';}else { t.rejWww.style.border='1px solid #C6C6C6'; }
   if(t.rejEmail.value.length==0){ ok=false; t.rejEmail.style.border='1px solid red';}else { t.rejEmail.style.border='1px solid #C6C6C6'; }
   if(!ok){ alert('Nie wszystkie pola są uzupełnione!'); return ok; }
   
   if(!testLocalCity(t.rejCity.value)){ ok = false; alert('Nieprawidłowa miejscowość!'); t.rejCity.style.border='1px solid red'; return ok; }else { t.rejCity.style.border='1px solid #C6C6C6'; }
   
   if(!t.rejRegAkc.checked){ ok = false; alert('Aby przejść dalej konieczna jest akceptacja regulaminu.'); return ok; }
   if(t.rejWww.value && !testWWW(t.rejWww.value)){ ok = false; alert('Nieprawidlowy adres www!'); t.rejWww.style.border='1px solid red'; return ok; }else { t.rejWww.style.border='1px solid #C6C6C6'; }
   if(!testEmail(t.rejEmail.value)){ ok = false; alert('Nieprawidlowy adres e-mail!'); t.rejEmail.style.border='1px solid red'; return ok; }else { t.rejEmail.style.border='1px solid #C6C6C6'; }
   return ok;
 }else if(krok==2){
   if(t.rejLocalCity.value.length==0){ ok=false; t.rejLocalCity.style.border='1px solid red';}else { t.rejLocalCity.style.border='1px solid #C6C6C6'; }
   if(t.rejCost.value.length==0){ ok=false; t.rejCost.style.border='1px solid red';}else { t.rejCost.style.border='1px solid #C6C6C6'; }
   if(t.rejLogin.value.length==0){ ok=false; t.rejLogin.style.border='1px solid red';}else { t.rejLogin.style.border='1px solid #C6C6C6'; }
   if(t.rejPass.value.length==0){ ok=false; t.rejPass.style.border='1px solid red';}else { t.rejPass.style.border='1px solid #C6C6C6'; }
   if(t.rejRePass.value.length==0){ ok=false; t.rejRePass.style.border='1px solid red';}else { t.rejRePass.style.border='1px solid #C6C6C6'; }
   if(!ok){ alert('Nie wszystkie pola są uzupełnione!'); return ok; }
   
   if(!testLocalCity(t.rejLocalCity.value)){ ok = false; alert('Nieprawidłowa miejscowość!'); t.rejLocalCity.style.border='1px solid red'; return ok; }else { t.rejLocalCity.style.border='1px solid #C6C6C6'; }
   
   if(t.rejLocalProvince.value==0){ ok = false; alert('Wybierz lokalizację, w której działasz!'); return ok; }
   if(t.rejPass.value!=t.rejRePass.value){ ok = false; alert('Hasła nie są identyczne!'); t.rejRePass.style.border='1px solid red'; return ok; }else { t.rejRePass.style.border='1px solid #C6C6C6'; }
   return ok;
 }else return ok;
}

function checkKLM(t){
 ok = true;
   if(t.firstname.value.length==0){ ok=false; t.firstname.style.border='1px solid red';}else { t.firstname.style.border='1px solid #C6C6C6'; }
   if(t.lastname.value.length==0){ ok=false; t.lastname.style.border='1px solid red';}else { t.lastname.style.border='1px solid #C6C6C6'; }
   if(t.adress.value.length==0){ ok=false; t.adress.style.border='1px solid red';}else { t.adress.style.border='1px solid #C6C6C6'; }
   if(t.email.value.length==0){ ok=false; t.email.style.border='1px solid red';}else { t.email.style.border='1px solid #C6C6C6'; }
   if(t.tel.value.length==0){ ok=false; t.tel.style.border='1px solid red';}else { t.tel.style.border='1px solid #C6C6C6'; }
   if(t.date_of_slub.value.length==0){ ok=false; t.date_of_slub.style.border='1px solid red';}else { t.date_of_slub.style.border='1px solid #C6C6C6'; }
   if(t.city_of_slub.value.length==0){ ok=false; t.city_of_slub.style.border='1px solid red';}else { t.city_of_slub.style.border='1px solid #C6C6C6'; }
   if(t.imiona.value.length==0){ ok=false; t.imiona.style.border='1px solid red';}else { t.imiona.style.border='1px solid #C6C6C6'; }
   if(t.name.value.length==0){ ok=false; t.name.style.border='1px solid red';}else { t.name.style.border='1px solid #C6C6C6'; }
   if(t.image.value.length==0){ ok=false; t.image.style.border='1px solid red';}else { t.image.style.border='1px solid #C6C6C6'; }
   if(t.content.value.length==0){ ok=false; t.content.style.border='1px solid red';}else { t.content.style.border='1px solid #C6C6C6'; }
   
   if(!ok){ alert('Nie wszystkie pola są uzupełnione!'); return ok; }
   
   if(!testEmail(t.email.value)){ ok = false; alert('Nieprawidlowy adres e-mail!'); t.email.style.border='1px solid red'; return ok; }else { t.email.style.border='1px solid #C6C6C6'; }
   if(!t.rejRegAkc.checked){ ok = false; alert('Aby przejść dalej konieczna jest akceptacja regulaminu.'); return ok; }
   
   return ok;
}

function checkU(t,krok){
 ok = true;
 if(krok==1){
   
   if(t.rejLogin.value.length==0){ ok=false; t.rejLogin.style.border='1px solid red';}else { t.rejLogin.style.border='1px solid #C6C6C6'; }
   if(t.rejPass.value.length==0){ ok=false; t.rejPass.style.border='1px solid red';}else { t.rejPass.style.border='1px solid #C6C6C6'; }
   if(t.rejRePass.value.length==0){ ok=false; t.rejRePass.style.border='1px solid red';}else { t.rejRePass.style.border='1px solid #C6C6C6'; }
   if(t.rejEmail.value.length==0){ ok=false; t.rejEmail.style.border='1px solid red';}else { t.rejEmail.style.border='1px solid #C6C6C6'; }
   if(!ok){ alert('Nie wszystkie pola są uzupełnione!'); return ok; }
   
   if(t.rejLocalProvince.value==0){ ok = false; alert('Wybierz lokalizację, w której działasz!'); return ok; }
   if(t.rejCity.value.length!=0 && !testLocalCity(t.rejCity.value)){ ok = false; alert('Nieprawidłowa miejscowość!'); t.rejCity.style.border='1px solid red'; return ok; }else { t.rejCity.style.border='1px solid #C6C6C6'; }
   if(t.rejPass.value!=t.rejRePass.value){ ok = false; alert('Hasła nie są identyczne!'); t.rejRePass.style.border='1px solid red'; return ok; }else { t.rejRePass.style.border='1px solid #C6C6C6'; }
   if(!testEmail(t.rejEmail.value)){ ok = false; alert('Nieprawidlowy adres e-mail!'); t.rejEmail.style.border='1px solid red'; return ok; }else { t.rejEmail.style.border='1px solid #C6C6C6'; }
   if(!t.rejRegAkc.checked){ ok = false; alert('Aby przejść dalej konieczna jest akceptacja regulaminu.'); return ok; }
   return ok;
 }else return ok;
}

function checkF(t,krok){
 ok = true;
 if(krok==1){
   if($('input[name=rejNip]').hasClass('error')) { $('input[name=rejNip]').val(''); }
 
   if(t.rejStudioname.value.length==0){ ok=false; t.rejStudioname.style.border='1px solid red';}else { t.rejStudioname.style.border='1px solid #C6C6C6'; }
   if(t.rejCity.value.length==0){ ok=false; t.rejCity.style.border='1px solid red';}else { t.rejCity.style.border='1px solid #C6C6C6'; }
   if(t.rejZip1.value.length==0){ ok=false; t.rejZip1.style.border='1px solid red';}else { t.rejZip1.style.border='1px solid #C6C6C6'; }
   if(t.rejZip2.value.length==0){ ok=false; t.rejZip2.style.border='1px solid red';}else { t.rejZip2.style.border='1px solid #C6C6C6'; }
   if(t.rejStreet.value.length==0){ ok=false; t.rejStreet.style.border='1px solid red';}else { t.rejStreet.style.border='1px solid #C6C6C6'; }
   if(t.rejHome.value.length==0){ ok=false; t.rejHome.style.border='1px solid red';}else { t.rejHome.style.border='1px solid #C6C6C6'; }
   if(t.rejTel.value.length==0){ ok=false; t.rejTel.style.border='1px solid red';}else { t.rejTel.style.border='1px solid #C6C6C6'; }
   //if(t.rejWww.value.length==0){ ok=false; t.rejWww.style.border='1px solid red';}else { t.rejWww.style.border='1px solid #C6C6C6'; }
   if(t.rejEmail.value.length==0){ ok=false; t.rejEmail.style.border='1px solid red';}else { t.rejEmail.style.border='1px solid #C6C6C6'; }
   if(!ok){ alert('Nie wszystkie pola są uzupełnione!'); return ok; }
   
   if(!testLocalCity(t.rejCity.value)){ ok = false; alert('Nieprawidłowa miejscowość!'); t.rejCity.style.border='1px solid red'; return ok; }else { t.rejCity.style.border='1px solid #C6C6C6'; }
   
   if(!t.rejRegAkc.checked){ ok = false; alert('Aby przejść dalej konieczna jest akceptacja regulaminu.'); return ok; }
   if(t.rejWww.value && !testWWW(t.rejWww.value)){ ok = false; alert('Nieprawidlowy adres www!'); t.rejWww.style.border='1px solid red'; return ok; }else { t.rejWww.style.border='1px solid #C6C6C6'; }
   if(!testEmail(t.rejEmail.value)){ ok = false; alert('Nieprawidlowy adres e-mail!'); t.rejEmail.style.border='1px solid red'; return ok; }else { t.rejEmail.style.border='1px solid #C6C6C6'; }
   return ok;
 }else if(krok==2){
   if(t.rejLocalCity.value.length==0){ ok=false; t.rejLocalCity.style.border='1px solid red';}else { t.rejLocalCity.style.border='1px solid #C6C6C6'; }
   if(t.rejLogin.value.length==0){ ok=false; t.rejLogin.style.border='1px solid red';}else { t.rejLogin.style.border='1px solid #C6C6C6'; }
   if(t.rejPass.value.length==0){ ok=false; t.rejPass.style.border='1px solid red';}else { t.rejPass.style.border='1px solid #C6C6C6'; }
   if(t.rejRePass.value.length==0){ ok=false; t.rejRePass.style.border='1px solid red';}else { t.rejRePass.style.border='1px solid #C6C6C6'; }
   if(!ok){ alert('Nie wszystkie pola są uzupełnione!'); return ok; }
   
   if(!testLocalCity(t.rejLocalCity.value)){ ok = false; alert('Nieprawidłowa miejscowość!'); t.rejLocalCity.style.border='1px solid red'; return ok; }else { t.rejLocalCity.style.border='1px solid #C6C6C6'; }
   
   if(t.rejLocalProvince.value==0){ ok = false; alert('Wybierz lokalizację, w której działasz!'); return ok; }
   if(t.rejPass.value!=t.rejRePass.value){ ok = false; alert('Hasła nie są identyczne!'); t.rejRePass.style.border='1px solid red'; return ok; }else { t.rejRePass.style.border='1px solid #C6C6C6'; }
   return ok;
 }else return ok;
}

/*function showInBig(imageName){
  document.getElementById('bigImage').src='gfx/img/b_'+imageName;
  document.getElementById('bigImageAdress').href='gfx/img/'+imageName;
}*/

function setWojewInRejestr2(nr){
  document.getElementById('rejLocalProvince').value=''+nr;
  changeCity(nr);
}

function setWojewInRejestr2GFiF(nr){
  document.getElementById('rejLocalProvinceFiF').value=''+nr;
  changeCityFiF(nr);
}

function setWojewInRejestr2GZ(nr){
  document.getElementById('rejLocalProvinceZ').value=''+nr;
  changeCityZ(nr);
}

function changeCity(province){
  advAJAX.get({
    url: 'index.php?a=getListCitys&province='+province,
    onInitialization: function() { document.getElementById('rejLocalCity').innerHTML = '<img style="border:none;" src="gfx/loading.gif" />'; },
    onSuccess : function(obj)
    {
      document.getElementById('rejLocalCity').innerHTML = obj.responseText;
    },
    //onComplete : function() { document.getElementById('bigImage2').innerHTML = ''; },
    onError : function(obj) { alert("Error: " + obj.status); }
  });
  advAJAX.get({
    url: 'index.php?a=getMapaaa&province='+province,
    //onInitialization: function() { document.getElementById('rejLocalCity').innerHTML = '<img style="border:none;" src="gfx/loading.gif" />'; },
    onSuccess : function(obj)
    {
      document.getElementById('insertMyMap').innerHTML = obj.responseText;
    },
    //onComplete : function() { document.getElementById('bigImage2').innerHTML = ''; },
    onError : function(obj) { alert("Error: " + obj.status); }
  });
  return false;
}

function changeCityFiF(province){
  advAJAX.get({
    url: 'index.php?a=getListCitys&province='+province,
    onInitialization: function() { document.getElementById('rejLocalCityFiF').innerHTML = '<img style="border:none;" src="gfx/loading.gif" />'; },
    onSuccess : function(obj)
    {
      document.getElementById('rejLocalCityFiF').innerHTML = obj.responseText;
    },
    onError : function(obj) { alert("Error: " + obj.status); }
  });
  return false;
}

function changeCityZ(province){
  advAJAX.get({
    url: 'index.php?a=getListCitys&province='+province,
    onInitialization: function() { document.getElementById('rejLocalCityZ').innerHTML = '<img style="border:none;" src="gfx/loading.gif" />'; },
    onSuccess : function(obj)
    {
      document.getElementById('rejLocalCityZ').innerHTML = obj.responseText;
    },
    //onComplete : function() { document.getElementById('bigImage2').innerHTML = ''; },
    onError : function(obj) { alert("Error: " + obj.status); }
  });
  advAJAX.get({
    url: 'index.php?a=getMapaaaZ&province='+province,
    //onInitialization: function() { document.getElementById('rejLocalCity').innerHTML = '<img style="border:none;" src="gfx/loading.gif" />'; },
    onSuccess : function(obj)
    {
      document.getElementById('insertMyMapZ').innerHTML = obj.responseText;
    },
    //onComplete : function() { document.getElementById('bigImage2').innerHTML = ''; },
    onError : function(obj) { alert("Error: " + obj.status); }
  });
  return false;
}

function showInBig(cid,imageName)
{
  advAJAX.get({
    url: 'index.php?a=showImagesList&imageName='+imageName+'&cid='+cid,
    onInitialization: function() { document.getElementById('bigImage2').style.display='block'; document.getElementById('bigImage2').innerHTML = '<img style="width:32px; height:32px; margin-top:30px; margin-left:35px; border:none;" src="gfx/loader3.gif" />'; },
    onSuccess : function(obj)
    {
      document.getElementById('bigImage').innerHTML = obj.responseText;
      document.getElementById('bigImage2').style.display='none';
      initLytebox();
    },
    onComplete : function() { document.getElementById('bigImage2').innerHTML = ''; },
    onError : function(obj) { alert("Error: " + obj.status); }
  });
  return false;
}

function showInBigFilm(film,typ){
   document.getElementById('bigImage').innerHTML = '';
}

img=0;
function imgPrevListN(cid)
{
  if(img>0){ img -= 4; }
  else return false;
  advAJAX.get({
    url: 'index.php?a=oneImagesList&img='+img+'&cid='+cid,
    onInitialization: function() { document.getElementById('incertGalery').innerHTML = '<li style="width:344px; text-align:center;"><img style="margin-top:20px; border:none;" src="gfx/loader2.gif" /></li>'; },
    onSuccess : function(obj) { document.getElementById('incertGalery').innerHTML = obj.responseText; },
    //onComplete : function() { document.getElementById('cn_prev').src = 'gfx/left.gif'; },
    onError : function(obj) { alert("Error: " + obj.status); }
  });
  return false;
}

function imgNextListN(cid)
{
  img += 4;
  advAJAX.get({
    url: 'index.php?a=oneImagesList&img='+img+'&cid='+cid,
    onInitialization: function() { document.getElementById('incertGalery').innerHTML = '<li style="width:344px; text-align:center;"><img style="margin-top:20px; border:none;" src="gfx/loader2.gif" /></li>'; },
    onSuccess : function(obj)
    {
      if(obj.responseText && obj.responseText.length>100) document.getElementById('incertGalery').innerHTML = obj.responseText;
      else{ imgPrevListN(cid); }
    },
    //onComplete : function() { document.getElementById('cn_next').src = 'gfx/right.gif'; },
    onError : function(obj) { alert("Error: " + obj.status); }
  });
  return false;
}

galList=1;
galListU=1;
function galListPrev(gid)
{
  if(galList>1){ galList -= 1; }
  else return false;
  advAJAX.get({
    url: 'index.php?a=getGalleryList&gid='+gid+'&page='+galList,
    onInitialization: function() { document.getElementById('incertGalery').innerHTML = '<div style="width:420px; text-align:center;"><img style="margin-top:160px; border:none;" src="gfx/loader2.gif" /></div>'; },
    onSuccess : function(obj) { document.getElementById('incertGalery').innerHTML = obj.responseText; },
    //onComplete : function() { document.getElementById('cn_prev').src = 'gfx/left.gif'; },
    onError : function(obj) { alert("Error: " + obj.status); }
  });
  return false;
}

function galListNext(gid)
{
  galList += 1;
  advAJAX.get({
    url: 'index.php?a=getGalleryList&gid='+gid+'&page='+galList,
    onInitialization: function() { document.getElementById('incertGalery').innerHTML = '<div style="width:420px; text-align:center;"><img style="margin-top:160px; border:none;" src="gfx/loader2.gif" /></div>'; },
    onSuccess : function(obj)
    {
      if(obj.responseText && obj.responseText.length>10) document.getElementById('incertGalery').innerHTML = obj.responseText;
      else{ galListPrev(gid); }
    },
    //onComplete : function() { document.getElementById('cn_next').src = 'gfx/right.gif'; },
    onError : function(obj) { alert("Error: " + obj.status); }
  });
  return false;
}

galListC=1;
galListUC=1;
function galListPrevC(gid)
{
  if(galListC>1){ galListC -= 1; }
  else return false;
  advAJAX.get({
    url: 'index.php?a=getGalleryListC&gid='+gid+'&page='+galListC,
    onInitialization: function() { document.getElementById('incertGalery').innerHTML = '<div style="width:420px; text-align:center;"><img style="margin-top:160px; border:none;" src="gfx/loader2.gif" /></div>'; },
    onSuccess : function(obj) { document.getElementById('incertGalery').innerHTML = obj.responseText; },
    //onComplete : function() { document.getElementById('cn_prev').src = 'gfx/left.gif'; },
    onError : function(obj) { alert("Error: " + obj.status); }
  });
  return false;
}

function galListNextC(gid)
{
  galListC += 1;
  advAJAX.get({
    url: 'index.php?a=getGalleryListC&gid='+gid+'&page='+galListC,
    onInitialization: function() { document.getElementById('incertGalery').innerHTML = '<div style="width:420px; text-align:center;"><img style="margin-top:160px; border:none;" src="gfx/loader2.gif" /></div>'; },
    onSuccess : function(obj)
    {
      if(obj.responseText && obj.responseText.length>10) document.getElementById('incertGalery').innerHTML = obj.responseText;
      else{ galListPrevC(gid); }
    },
    //onComplete : function() { document.getElementById('cn_next').src = 'gfx/right.gif'; },
    onError : function(obj) { alert("Error: " + obj.status); }
  });
  return false;
}

function showMeBigImage(gid,iid){
   advAJAX.get({
    url: 'index.php?a=getImagesList&gid='+gid+'&iid='+iid,
    onInitialization: function() { document.getElementById('allCommentsShow').innerHTML =''; document.getElementById('myBigImage').innerHTML = '<div style="width:420px; text-align:center;"><img style="margin-top:160px; border:none;" src="gfx/loader4.gif" /></div>'; },
    onSuccess : function(obj) { document.getElementById('myBigImage').innerHTML = obj.responseText; document.getElementById('f_iid').value = iid; document.getElementById('f_gid').value = gid; initLytebox(); showComments(gid,iid); },
    //onComplete : function() { document.getElementById('cn_prev').src = 'gfx/left.gif'; },
    onError : function(obj) { alert("Error: " + obj.status); }
  });
  return false;
}

function showMeBigImageC(gid,iid){
   advAJAX.get({
    url: 'index.php?a=getImagesListC&gid='+gid+'&iid='+iid,
    onInitialization: function() { document.getElementById('myBigImage').innerHTML = '<div style="width:420px; text-align:center;"><img style="margin-top:160px; border:none;" src="gfx/loader4.gif" /></div>'; },
    onSuccess : function(obj) { document.getElementById('myBigImage').innerHTML = obj.responseText; initLytebox(); },
    //onComplete : function() { document.getElementById('cn_prev').src = 'gfx/left.gif'; },
    onError : function(obj) { alert("Error: " + obj.status); }
  });
  return false;
}

function showMeBigImageG(gid,iid){
   advAJAX.get({
    url: 'index.php?a=getImagesListG&gid='+gid+'&iid='+iid,
    onInitialization: function() { document.getElementById('myBigImage').innerHTML = '<div style="width:420px; text-align:center;"><img style="margin-top:160px; border:none;" src="gfx/loader4.gif" /></div>'; },
    onSuccess : function(obj) { document.getElementById('myBigImage').innerHTML = obj.responseText; initLytebox(); },
    //onComplete : function() { document.getElementById('cn_prev').src = 'gfx/left.gif'; },
    onError : function(obj) { alert("Error: " + obj.status); }
  });
  return false;
}

function addMyComm(){
   var gid = document.getElementById('f_gid').value;
   var iid = document.getElementById('f_iid').value;
   var podpis = document.getElementById('f_podpis').value;
   var content = document.getElementById('f_content').value;
   document.getElementById('f_podpis').value = '';
   document.getElementById('f_content').value = '';
   if(!content || !podpis) return false;
   advAJAX.post({
    url: 'index.php?a=addNewComment',
    parameters : {
      "gid" : gid,
      "iid" : iid,
      "name" : podpis,
      "content" : content
    },
    onInitialization: function() { document.getElementById('allCommentsShow').innerHTML = '<div style="width:420px; text-align:center;"><img style="border:none;" src="gfx/loading.gif" /></div>'; },
    onSuccess : function(obj) { showComments(gid,iid); },
    //onComplete : function() { document.getElementById('cn_prev').src = 'gfx/left.gif'; },
    onError : function(obj) { alert("Error: " + obj.status); }
  });
  return false;
}

function showComments(gid,iid)
{
  advAJAX.get({
    url: 'index.php?a=getCommentList&gid='+gid+'&iid='+iid,
    onInitialization: function() { document.getElementById('allCommentsShow').innerHTML = '<div style="width:420px; text-align:center;"><img style="border:none;" src="gfx/loading.gif" /></div>'; },
    onSuccess : function(obj) { document.getElementById('allCommentsShow').innerHTML = obj.responseText; initLytebox(); },
    //onComplete : function() { document.getElementById('cn_prev').src = 'gfx/left.gif'; },
    onError : function(obj) { alert("Error: " + obj.status); }
  });
  return false;
}

function check2U(t,krok){
   ok = true;
   if(!testEmail(t.rejEmail.value)){ ok = false; alert('Nieprawidlowy adres e-mail!'); t.rejEmail.style.border='1px solid red'; return ok; }else { t.rejEmail.style.border='1px solid #C6C6C6'; }
   if(t.rejLocalProvince.value==0){ ok = false; alert('Wybierz lokalizację, w której działasz!'); return ok; }
   if(t.rejPass.value!=t.rejRePass.value){ ok = false; alert('Hasła nie są identyczne!'); t.rejRePass.style.border='1px solid red'; return ok; }else { t.rejRePass.style.border='1px solid #C6C6C6'; }
   return ok;
}

function check2(t,krok){
 ok = true;
 if(krok==1){
   if($('input[name=rejNip]').hasClass('error')) { $('input[name=rejNip]').val(''); }
   if(!testWWW(t.rejWww.value) && t.rejWww.value){ ok = false; alert('Nieprawidlowy adres www!'); t.rejWww.style.border='1px solid red'; return ok; }else { t.rejWww.style.border='1px solid #C6C6C6'; }
   if(!testEmail(t.rejEmail.value)){ ok = false; alert('Nieprawidlowy adres e-mail!'); t.rejEmail.style.border='1px solid red'; return ok; }else { t.rejEmail.style.border='1px solid #C6C6C6'; }
   if(t.rejLocalProvince.value==0){ ok = false; alert('Wybierz lokalizację, w której działasz!'); return ok; }
   if(t.rejPass.value!=t.rejRePass.value){ ok = false; alert('Hasła nie są identyczne!'); t.rejRePass.style.border='1px solid red'; return ok; }else { t.rejRePass.style.border='1px solid #C6C6C6'; }
   return ok;
 }else return ok;
}

function getCoordinates()
{
  try
  {
    var map = document.getElementById('googleMap').contentDocument;
    if(map==undefined || map==null) map = document.getElementById('googleMap').contentWindow.document;
    document.getElementById('f_x').value = map.getElementById('gm_x').value;
    document.getElementById('f_y').value = map.getElementById('gm_y').value;
    document.getElementById('f_zoom').value = map.getElementById('gm_zoom').value;
  }
  catch(e){}
  setTimeout('getCoordinates()', 1000);
}

function check2F(t,krok){
 ok = true;
 if(krok==1){
   if($('input[name=rejNip]').hasClass('error')) { $('input[name=rejNip]').val(''); }
   if(!testWWW(t.rejWww.value) && t.rejWww.value){ ok = false; alert('Nieprawidlowy adres www!'); t.rejWww.style.border='1px solid red'; return ok; }else { t.rejWww.style.border='1px solid #C6C6C6'; }
   if(!testEmail(t.rejEmail.value)){ ok = false; alert('Nieprawidlowy adres e-mail!'); t.rejEmail.style.border='1px solid red'; return ok; }else { t.rejEmail.style.border='1px solid #C6C6C6'; }
   if(t.rejLocalProvince.value==0){ ok = false; alert('Wybierz lokalizację, w której działasz!'); return ok; }
   if(t.rejPass.value!=t.rejRePass.value){ ok = false; alert('Hasła nie są identyczne!'); t.rejRePass.style.border='1px solid red'; return ok; }else { t.rejRePass.style.border='1px solid #C6C6C6'; }
   return ok;
 }else return ok;
}

function switcher(id)
{
  if(document.getElementById(id).style.display!='none')
  {
    document.getElementById(id).style.display = 'none';
  }
  else
  {
    document.getElementById(id).style.display = 'block';
  }
  return false;
}

function openWindow(link) // inspired by porneL - http://pornel.net/pups/
{
  try
  {
    var new_window = window.open(link, '_blank');
    if(new_window) return false;
  }
  catch(e){}
  return true;
}

function changePolska(id,num){
  if(num==1) document.getElementById(id).disabled = false;
  else document.getElementById(id).disabled = true;
  return false;
}

function setWojewInRejestr(nr){
  document.getElementById('rejLocalProvince').value=''+nr;
  document.getElementById('rejLocalProvince2').value=''+nr;
}

function numbersonly(pos, myfield, e, dec)
{
    var key;
    var keychar;
    
    if (window.event)
       key = window.event.keyCode;
    else if (e)
       key = e.which;
    else
       return true;
    keychar = String.fromCharCode(key);
    
    // control keys
    if ((key==null) || (key==0) || (key==8) || 
        (key==9) || (key==13) || (key==27) )
       return true;
    
    // numbers
    else if (pos==1 && (("0123456789").indexOf(keychar) > -1))
       return true;
    else if (pos==2 && (("0123456789+() -").indexOf(keychar) > -1))
       return true;
    else if (pos==3 && (("12345678").indexOf(keychar) > -1))
       return true;
    // decimal point jump
    else if (dec && (keychar == "."))
       {
       myfield.form.elements[dec].focus();
       return false;
       }
    else
   return false;
}


function checkRequiredFields(form_id)
{
  ok = true;
  if(window.ActiveXObject)
  {
    //IE
    //var inst = document.getElementById('content___Frame').contentDocument;
    //alert('test:'+inst)
    var inst = document.getElementById('content___Frame').contentWindow.document.getElementsByTagName('body')[0];
    var fields = inst.getElementsByTagName('iframe')[0].contentWindow.document.getElementsByTagName('body')[0].innerHTML;
  }
  else
  {
    var inst = document.getElementById('content___Frame').contentDocument.getElementsByTagName('body')[0];
    var fields = inst.getElementsByTagName('iframe')[0].contentDocument.getElementsByTagName('body')[0].innerHTML;
  }
  if(fields)
  {
    var myString = fields;
    var myStringNew = "";
    if(myString.length>0)
    {
      var zn1 = new RegExp("<");
      var zn2 = new RegExp(">");
      var zn3 = new RegExp("><");
      var mWrite = 1;
      for(licz=0;licz<myString.length;licz++)
      {
        var wrem = myString.substr(licz,1);
        var result1 = zn1.test(wrem);
        var result2 = zn2.test(wrem);
        var result3 = zn3.test(wrem);
        if(result1) mWrite=0;
        if(result3) mWrite=0;
        if(mWrite==1) myStringNew+=wrem;
        if(result2) mWrite=1;
      }
    }
    if(myStringNew.length<=1000)
    {
      alert('Artykuł ma '+myStringNew.length+' znaków, a powinien mieć nie mniej niż 1000 znaków.');
      return false;
      ok = false;
    }
  }
  if(form_id=='addCustomer')
  {
    if(document.getElementById('f_pass').value!=document.getElementById('f_repeat_pass').value)
    {
      alert('Wpisane hasła nie są identyczne.');
      return false;
    }
    if(!document.getElementById('f_agree').checked)
    {
      alert('Musisz wyrazić zgodę na przetwarzanie danych osobowych.');
      return false;
    }
  }
  fields = document.getElementById(form_id).getElementsByTagName('input');
  for(var i in fields) if(fields[i].className=='required')
  {
    if(!fields[i].value) ok = false;
    if(fields[i].id=='f_www' && fields[i].value=='http://') ok = false;
  }
  fields = document.getElementById(form_id).getElementsByTagName('textarea');
  for(var i in fields) if(fields[i].className=='required')
  {
    if(!fields[i].value) ok = false;
  }
  fields = document.getElementById(form_id).getElementsByTagName('select');
  for(var i in fields) if(fields[i].className=='required')
  {
    if(!fields[i].value) ok = false;
  }
  if(ok) return true;
  alert('Musisz wypełnić wszystkie wymagane pola (oznaczone gwiazdką).');
  return false;
}

function checkLength(text_id, counter_id)
{
  document.getElementById(counter_id).innerHTML = document.getElementById(text_id).value.length;
  alert(document.getElementById(text_id).value.length);
  //setTimeout('checkLength('+text_id+','+counter_id+')', 100);
}

var cn_page = 0;

function CNprevPage()
{
  if(cn_page>0) cn_page -= 1;
  else return false;
  advAJAX.get({
    url: 'index.php?a=getOfferList&page='+cn_page,
    //onInitialization: function() { document.getElementById('cn_prev').src = 'gfx/loading.gif'; },
    onSuccess : function(obj) { document.getElementById('glownaHernia').innerHTML = obj.responseText; },
    //onComplete : function() { document.getElementById('cn_prev').src = 'gfx/up.gif'; },
    onError : function(obj) { alert("Error: " + obj.status); }
  });
  return false;
}

function CNnextPage()
{
  cn_page += 1;
  advAJAX.get({
    url: 'index.php?a=getOfferList&page='+cn_page,
    //onInitialization: function() { document.getElementById('cn_next').src = 'gfx/loading.gif'; },
    onSuccess : function(obj)
    {
      if(obj.responseText && obj.responseText.length>1300) document.getElementById('glownaHernia').innerHTML = obj.responseText;
      else cn_page -= 1;
    },
    //onComplete : function() { document.getElementById('cn_next').src = 'gfx/down.gif'; },
    onError : function(obj) { alert("Error: " + obj.status); }
  });
  return false;
}

var grayscale = (function(){
    
    var config = {
            colorProps: ['color','backgroundColor','borderBottomColor','borderTopColor','borderLeftColor','borderRightColor','backgroundImage'],
            externalImageHandler : {
                /* Grayscaling externally hosted images does not work
                   - Use these functions to handle those images as you so desire */
                /* Out of convenience these functions are also used for browsers
                   like Chrome that do not support CanvasContext.getImageData */
                init : function(el, src) {
                    if (el.nodeName.toLowerCase() === 'img') {
                        // Is IMG element...
                    } else {
                        // Is background-image element:
                        // Default - remove background images
                        data(el).backgroundImageSRC = src;
                        el.style.backgroundImage = '';
                    }
                },
                reset : function(el) {
                    if (el.nodeName.toLowerCase() === 'img') {
                        // Is IMG element...
                    } else {
                        // Is background-image element:
                        el.style.backgroundImage = 'url(' + (data(el).backgroundImageSRC || '') + ')';
                    }
                }
            }
        },
        log = function(){
            try { window.console.log.apply(console, arguments); }
            catch(e) {};
        },
        isExternal = function(url) {
            // Checks whether URL is external: 'CanvasContext.getImageData'
            // only works if the image is on the current domain.
            return (new RegExp('https?://(?!' + window.location.hostname + ')')).test(url);
        },
        data = (function(){
            
            var cache = [0],
            expando = 'data' + (+new Date());
            
            return function(elem) {
                var cacheIndex = elem[expando],
                    nextCacheIndex = cache.length;
                if(!cacheIndex) {
                    cacheIndex = elem[expando] = nextCacheIndex;
                    cache[cacheIndex] = {};
                }
                return cache[cacheIndex];
            };
            
        })(),
        desatIMG = function(img, prepare, realEl) {
            
            // realEl is only set when img is temp (for BG images)
            
            var canvas = document.createElement('canvas'),
                context = canvas.getContext('2d'),
                height = img.naturalHeight || img.offsetHeight || img.height,
                width = img.naturalWidth || img.offsetWidth || img.width,
                imgData;
                
            canvas.height = height;
            canvas.width = width;
            context.drawImage(img, 0, 0);
            try {
                imgData = context.getImageData(0, 0, width, height);
            } catch(e) {}
            
            if (prepare) {
                desatIMG.preparing = true;
                // Slowly recurse through pixels for prep,
                // :: only occurs on grayscale.prepare()
                var y = 0;
                (function(){
                    
                    if (!desatIMG.preparing) { return; }
                    
                    if (y === height) {
                        // Finished!
                        context.putImageData(imgData, 0, 0, 0, 0, width, height);
                        realEl ? (data(realEl).BGdataURL = canvas.toDataURL())
                               : (data(img).dataURL = canvas.toDataURL())
                    }
                    
                    for (var x = 0; x < width; x++) {
                        var i = (y * width + x) * 4;
                        // Apply Monoschrome level across all channels:
                        imgData.data[i] = imgData.data[i+1] = imgData.data[i+2] =
                        RGBtoGRAYSCALE(imgData.data[i], imgData.data[i+1], imgData.data[i+2]);
                    }
                    
                    y++;
                    setTimeout(arguments.callee, 0);
                    
                })();
                return;
            } else {
                // If desatIMG was called without 'prepare' flag
                // then cancel recursion and proceed with force! (below)
                desatIMG.preparing = false;
            }
            
            for (var y = 0; y < height; y++) {
                for (var x = 0; x < width; x++) {
                    var i = (y * width + x) * 4;
                    // Apply Monoschrome level across all channels:
                    imgData.data[i] = imgData.data[i+1] = imgData.data[i+2] =
                    RGBtoGRAYSCALE(imgData.data[i], imgData.data[i+1], imgData.data[i+2]);
                }
            }
            
            context.putImageData(imgData, 0, 0, 0, 0, width, height);
            return canvas;
        
        },
        getStyle = function(el, prop) {
            var style = document.defaultView && document.defaultView.getComputedStyle ? 
                        document.defaultView.getComputedStyle(el, null)[prop]
                        : el.currentStyle[prop];
            // If format is #FFFFFF: (convert to RGB)
            if (style && /^#[A-F0-9]/i.test(style)) {
                    var hex = style.match(/[A-F0-9]{2}/ig);
                    style = 'rgb(' + parseInt(hex[0], 16) + ','
                                   + parseInt(hex[1], 16) + ','
                                   + parseInt(hex[2], 16) + ')';
            }
            return style;
        },
        RGBtoGRAYSCALE = function(r,g,b) {
            // Returns single monochrome figure:
            return parseInt( (0.2125 * r) + (0.7154 * g) + (0.0721 * b), 10 );
        },
        getAllNodes = function(context) {
            var all = Array.prototype.slice.call(context.getElementsByTagName('*'));
            all.unshift(context);
            return all;
        };
        
    var init = function(context) {
        
        // Handle if a DOM collection is passed instead of a single el:
        if (context && context[0] && context.length && context[0].nodeName) {
            // Is a DOM collection:
            var allContexts = Array.prototype.slice.call(context),
                cIndex = -1, cLen = allContexts.length;
            while (++cIndex<cLen) { init.call(this, allContexts[cIndex]); }
            return;
        }
        
        context = context || document.documentElement;
        
        if (!document.createElement('canvas').getContext) {
            context.style.filter = 'progid:DXImageTransform.Microsoft.BasicImage(grayscale=1)';
            context.style.zoom = 1;
            return;
        }
        
        var all = getAllNodes(context),
            i = -1, len = all.length;
            
        while (++i<len) {
            var cur = all[i];
            
            if (cur.nodeName.toLowerCase() === 'img') {
                var src = cur.getAttribute('src');
                if(!src) { continue; }
                if (isExternal(src)) {
                    config.externalImageHandler.init(cur, src);
                } else {
                    data(cur).realSRC = src;
                    try {
                        // Within try statement just encase there's no support....
                        cur.src = data(cur).dataURL || desatIMG(cur).toDataURL();
                    } catch(e) { config.externalImageHandler.init(cur, src); }
                }
                
            } else {
                for (var pIndex = 0, pLen = config.colorProps.length; pIndex < pLen; pIndex++) {
                    var prop = config.colorProps[pIndex],
                    style = getStyle(cur, prop);
                    if (!style) {continue;}
                    if (cur.style[prop]) {
                        data(cur)[prop] = style;
                    }
                    // RGB color:
                    if (style.substring(0,4) === 'rgb(') {
                        var monoRGB = RGBtoGRAYSCALE.apply(null, style.match(/\d+/g));
                        cur.style[prop] = style = 'rgb(' + monoRGB + ',' + monoRGB + ',' + monoRGB + ')';
                        continue;
                    }
                    // Background Image:
                    if (style.indexOf('url(') > -1) {
                        var urlPatt = /\(['"]?(.+?)['"]?\)/,
                            url = style.match(urlPatt)[1];
                        if (isExternal(url)) {
                            config.externalImageHandler.init(cur, url);
                            data(cur).externalBG = true;
                            continue;
                        }
                        // data(cur).BGdataURL refers to caches URL (from preparation)
                        try {
                            var imgSRC = data(cur).BGdataURL || (function(){
                                    var temp = document.createElement('img');
                                    temp.src = url;
                                    return desatIMG(temp).toDataURL();
                                })();
                            
                            cur.style[prop] = style.replace(urlPatt, function(_, url){
                                return '(' + imgSRC + ')';
                            });
                        } catch(e) { config.externalImageHandler.init(cur, url); }
                    }
                }
            }
        }
        
    };
    
    init.reset = function(context) {
        // Handle if a DOM collection is passed instead of a single el:
        if (context && context[0] && context.length && context[0].nodeName) {
            // Is a DOM collection:
            var allContexts = Array.prototype.slice.call(context),
                cIndex = -1, cLen = allContexts.length;
            while (++cIndex<cLen) { init.reset.call(this, allContexts[cIndex]); }
            return;
        }
        context = context || document.documentElement;
        if (!document.createElement('canvas').getContext) {
            context.style.filter = 'progid:DXImageTransform.Microsoft.BasicImage(grayscale=0)';
            return;
        }
        var all = getAllNodes(context),
            i = -1, len = all.length;
        while (++i<len) {
            var cur = all[i];
            if (cur.nodeName.toLowerCase() === 'img') {
                var src = cur.getAttribute('src');
                if (isExternal(src)) {
                    config.externalImageHandler.reset(cur, src);
                }
                cur.src = data(cur).realSRC || src;
            } else {
                for (var pIndex = 0, pLen = config.colorProps.length; pIndex < pLen; pIndex++) {
                    if (data(cur).externalBG) {
                        config.externalImageHandler.reset(cur);
                    }
                    var prop = config.colorProps[pIndex];
                    cur.style[prop] = data(cur)[prop] || '';
                }
            }
        }
    };
    
    init.prepare = function(context) {
        
        // Handle if a DOM collection is passed instead of a single el:
        if (context && context[0] && context.length && context[0].nodeName) {
            // Is a DOM collection:
            var allContexts = Array.prototype.slice.call(context),
                cIndex = -1, cLen = allContexts.length;
            while (++cIndex<cLen) { init.prepare.call(null, allContexts[cIndex]); }
            return;
        }
        
        // Slowly recurses through all elements
        // so as not to lock up on the user.
        
        context = context || document.documentElement;
        
        if (!document.createElement('canvas').getContext) { return; }
        
        var all = getAllNodes(context),
            i = -1, len = all.length;
        
        while (++i<len) {
            var cur = all[i];
            if (data(cur).skip) { return; }
            if (cur.nodeName.toLowerCase() === 'img') {
                if (cur.getAttribute('src') && !isExternal(cur.src)) {
                    desatIMG(cur, true);
                }
                
            } else {
                var style = getStyle(cur, 'backgroundImage');
                if (style.indexOf('url(') > -1) {
                    var urlPatt = /\(['"]?(.+?)['"]?\)/,
                        url = style.match(urlPatt)[1];
                    if (!isExternal(url)) {
                        var temp = document.createElement('img');
                        temp.src = url;
                        desatIMG(temp, true, cur);
                    }
                }
            }
        }
    };
    
    return init;

})();



function specializationSelect(method)
{
	var inner_html = '';
	
	switch(method)
	{
		case 1: // fotograf
			inner_html = '<option value="0" selected="selected">wszystkie specjalizacje</option> <option value="1">Fotografia klasyczna</option> <option value="2">Fotografia reportażowa</option> <option value="3">Fotografia artystyczna</option>';
		break;
		
		case 2: // film
			inner_html = '<option value="0" selected="selected">wszystkie specjalizacje</option> <option value="5">Reportażowy film ślubny</option> <option value="6">Artystyczny film ślubny</option>';
		break;
		
		case 3: // fotograf/filmowiec
			inner_html = '<option value="0" selected="selected">wszystkie specjalizacje</option>';// <option value="4">Wszystkie</option>';
		break;
	}
	
	$('select#specializationN1').html(inner_html);	
}



function testWyszuk(chbox)
{

	if(chbox == 1 || chbox == 2)
	{
		if($('#f_chb_foto').is(':checked') || $('#f_chb_kam').is(':checked'))
		{
		   $('form').unCheckCheckboxes('#f_chb_firm');
		}
		else
		{
		   $('form').checkCheckboxes('#f_chb_firm');
		}
	}
	else
	{		
		if($('#f_chb_firm').is(':checked'))
		{
			$('form').unCheckCheckboxes('#f_chb_foto, #f_chb_kam');
		} 
		else
		{
			$('form').checkCheckboxes('#f_chb_foto');
		}
    }
	
	if( $('#f_chb_foto').is(':checked') && !$('#f_chb_kam').is(':checked')) { specializationSelect(1); }
	if(!$('#f_chb_foto').is(':checked') &&  $('#f_chb_kam').is(':checked')) { specializationSelect(2); }
	if( $('#f_chb_foto').is(':checked') &&  $('#f_chb_kam').is(':checked')) { specializationSelect(3); }
	
    if($('#f_chb_foto').is(':checked') && $('#f_chb_kam').is(':checked')){ $('#type').val('3'); $('#megaSearch').attr('action','profiles.html'); $('#specializationN1').css('display','block');$('#specializationN2').css('display','none');$('#specializationN3').css('display','none'); }
    else if($('#f_chb_foto').is(':checked')){ $('#type').val('1'); $('#megaSearch').attr('action','profiles.html'); $('#specializationN1').css('display','block');$('#specializationN2').css('display','none');$('#specializationN3').css('display','none'); }
    else if($('#f_chb_kam').is(':checked')){ $('#type').val('2'); $('#megaSearch').attr('action','profiles.html'); $('#specializationN1').css('display','block');$('#specializationN2').css('display','none');$('#specializationN3').css('display','none'); }
    else if($('#f_chb_firm').is(':checked')){ $('#type').val('4'); $('#megaSearch').attr('action','firmy.html'); $('#specializationN2').css('display','block');$('#specializationN1').css('display','none');$('#specializationN3').css('display','none'); }
    // else { $('#type').val('0'); $('#megaSearch').attr('action',''); $('#specializationN3').css('display','block');$('#specializationN2').css('display','none');$('#specializationN1').css('display','none'); }
    
    $('#specializationN1').val('0');
    $('#specializationN2').val('0');
    //$('#specializationN3').val('0');
    $('#specialization').val('0'); 
     
}

function changeSpecializ(valSpec){
    if($('#f_chb_foto').is(':checked') && $('#f_chb_kam').is(':checked')){ $('#type').val('3'); $('#megaSearch').attr('action','profiles.html'); }
    else if($('#f_chb_foto').is(':checked')){ $('#type').val('1'); $('#megaSearch').attr('action','profiles.html'); }
    else if($('#f_chb_kam').is(':checked')){ $('#type').val('2'); $('#megaSearch').attr('action','profiles.html'); }
    else if($('#f_chb_firm').is(':checked')){ $('#type').val('4'); $('#megaSearch').attr('action','firmy.html'); }
    else { $('#type').val('0'); $('#megaSearch').attr('action',''); }
    
	$('#specialization').val(valSpec);
	/*
    var myArray = valSpec.split('_'); 
    if(myArray[0]=='s'){ 
      $('#megaSearch').attr('action','profiles.html');
      $('#specialization').val(myArray[1]); 
    }
    else if(myArray[0]=='b'){ 
      $('#megaSearch').attr('action','firmy.html');
      $('#type').val(myArray[1]); 
    }
    else return false;
	*/
}

function explodeArray(item,delimiter) {
  tempArray=new Array(1);
  var Count=0;
  var tempString=new String(item);
  
  while (tempString.indexOf(delimiter)>0) {
    tempArray[Count]=tempString.substr(0,tempString.indexOf(delimiter));
    tempString=tempString.substr(tempString.indexOf(delimiter)+1,tempString.length-tempString.indexOf(delimiter)+1);
    Count=Count+1
  }
  
  tempArray[Count]=tempString;
  return tempArray;
} 


function gs(){
  document.body.style.filter='progid:DXImageTransform.Microsoft.BasicImage(grayScale=1)';
  grayscale(document.body);
}  

onload = function()
{
  a = document.getElementsByTagName('a');
  for(var i in a) if(a[i].innerHTML && (a[i].className=='nw' || a[i].className=='photo nw'))
  {
    a[i].target = '_blank';
  }
}

/* switch banner */
function topBanerNext() {
	
	//setTimeout('switchFirm()', time*2);
	clearTimeout(timer);
	
	
	firms = document.getElementsByTagName('a');
	first_firm = 0;
	changed = false;
	for ( var i in firms)
		if (firms[i].className == 'imgTop') {
			if (!first_firm)
				first_firm = i;
			if (firms[i].style.display == 'block') {
				firms[i].style.display = 'none';
				changed = true;
			} else if (changed) {
				firms[i].style.display = 'block';
				changed = false;
			}
		}
	if (changed)
		firms[first_firm].style.display = 'block';
	
	
	timer = setTimeout('switchFirm()', time*5);
}

function topBanerPrev() {
	clearTimeout(timer);
	
	firms = document.getElementsByTagName('a');
	first_firm = 0;
	changed = false;
	for ( var i in firms)
		if (firms[i].className == 'imgTop') {
			if (!first_firm)
				first_firm = i;
			if (firms[i].style.display == 'block') {
				firms[i].style.display = 'none';
				changed = true;
			} else if (changed) {
				firms[i].style.display = 'block';
				changed = false;
			}
		}
	if (changed)
		firms[first_firm].style.display = 'block';
	
	
	timer = setTimeout('switchFirm()', time*5);
}


var fm_new_html = '';
var fm_old_html = '';
var fm_which    = 0;

function switchFM_baner()
{
	if(fm_which == 0)
	{
		$('div.fotograf-tyg-switch').html(fm_new_html);
		fm_which = 1;
	}
	else
	{
		$('div.fotograf-tyg-switch').html(fm_old_html);
		fm_which = 0;
	}
	
	setTimeout('switchFM_baner()', 5*1000);
}

$(document).ready(function()
{
	/*if($('div.fotograf-tyg-switch').size() != 0 && $('div.konkurs-fm-hidden').size() != 0)
	{
		fm_new_html = $('div.konkurs-fm-hidden').html();
		fm_old_html = $('div.fotograf-tyg-switch').html();
		setTimeout('switchFM_baner()', 5*1000);
	}*/	

	$('#specializationN2').change(function()
	{				
		if($('#f_chb_firm').is(':checked'))
		{
			$('#megaSearch').attr('action','firmy/'+$('#specializationN2 option:selected').attr('url')+','+$('#specializationN2 option:selected').attr('catid')+'.html');
		}
	});
	
	
	
	
	
	if($('input:checkbox[name=extraProvinces]').size() != 0)
	{
		alert($('input:checkbox[name=extraProvinces]').size());
	}
	
});


