$(document).ready(function() {
    var docH = $('#content').height() + 300;
    var windowH = screen.height;
    if (docH > windowH) {
      $('#backToTop').html('<p><a href="#wrapper">powrót na górę</a></p>');
    }  
});

$(document).ready(function(){
  $('a[href*=#]').click(function() {
	if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')
	&& location.hostname == this.hostname) {
	  var $target = $(this.hash);
	  $target = $target.length && $target
	  || $('[name=' + this.hash.slice(1) +']');
	  if ($target.length) {
		var targetOffset = $target.offset().top;
		$('html,body')
		.animate({scrollTop: targetOffset}, 1000);
	   return false;
	  }
	}
  });
  
  // for map selector
  if ($('#haveSelectedRegion').val() > 0)
  {
	GetCitiesForRegionAndType();
  }
  
  
});


function confirmSubmit(pName) {
var agree=confirm("Czy na pewno usunąć " + pName + "?");
if (agree)
	return true ;
else
	return false ;
}


function GetCitiesForRegion(){
	 var r = $('#regionSel').attr("value");
	 if (r > 0) {
       $.ajax({
         type: "POST",
         dataType: "html",
         url: "ajax_helper/engine.php",
         data: "GetCitiesForRegion=1&RegionId=" + r,
         success: function(msg){
          $('#citiesSelect').html(msg);
          $('#citiesSelect').children('option:first').attr('selected', 'selected');
          GetMainContentForCity();

        }      
       });
    } else {
      $('#citiesSelect').html('<option value="0">najpierw wybierz miasto</option>');
    }
}

function GetCitiesForRegionAndType(){
	 var r = $('#regionSel').attr("value");
	 var t = $('#type').attr("value");
	 if (r > 0) {
       $.ajax({
         type: "POST",
         dataType: "html",
         url: "ajax_helper/engine.php",
         data: "GetCitiesForRegionAndType=1&Type=" + t + "&RegionId=" + r,
         beforeSend: function(){
            $('#loader').css("visibility", "");
         },
         success: function(msg){
          $('#citiesSelect').html(msg);
          $('#citiesSelect').children('option:first').attr('selected', 'selected');
          $('#loader').css("visibility", "hidden");
          GetMainContentForCity();

        }      
       });
    } else {
      $('#citiesSelect').html('<option value="0">najpierw wybierz miasto</option>');
    }
}


function GetMainContentForCity(){
	var r = $('#citiesSelect').attr("value");
	var t = $('#type').attr("value");
	 if (r > 0 && t != "") {
       $.ajax({
         type: "POST",
         dataType: "html",
         url: "ajax_helper/engine.php",
         data: "GetContentForCity=1&CityId=" + r + "&Type=" + t,
          beforeSend: function(){
              $('#loaderCit').css("visibility", "");
           },         
         success: function(msg){
          $('#ajaxContent').html(msg);
          $('#loaderCit').css("visibility", "hidden");
          }      
       });
    } else {
      $('#ajaxContent').html("");
    }
}

function ToggleLinks() {
  var q = $("#showLinks").attr("checked");
  if (q)
    $("#links").css("display", "");
  else
    $("#links").css("display", "none");
}

function SetAsLink() {
  $('#file').css('display', 'none');
  $('#link').css('display', '');
}

function SetAsFile() {
  $('#file').css('display', '');
  $('#link').css('display', 'none');
}

function setFocus(){
	document.login.usernameTxt.focus();
}

function enableField()
{
	document.edycja.titleTxt.disabled=false;
	document.edycja.dateTxt.disabled=false;
	document.edycja.shortContentTxt.disabled=false;
}

function setText(a, b)
{
    x = document.getElementById(a);
    if (x)
      x.innerHTML = b.options[b.selectedIndex].value;
}
  
function clearText(thefield){
	if (thefield.defaultValue==thefield.value)
		thefield.value = "";
}

function setText(thefield){
	if (thefield.value == "")
		thefield.value = thefield.defaultValue;
}

$(document).ready(function() {
		$('div.faq:eq(0)> div').hide();
		$('div.faq:eq(0)> h4').click(function() {
			$(this).next().slideToggle('fast');
		});
/* ---------------- */

  var q= $("#content").find(".image").each(function() {
      var v = $(this).attr('src');
	  v = v.replace('thumbs/', '');
		$(this).click(function() {
          popImage(v, "powiększenie...")});

    });
	
	$('.openImg').bind('click', function() {
		var v = $(this).attr('open');
		
	  v = v.replace('thumbs/', '');
		popImage(v, "powiększenie...");
	});
  
  $('a').each(function(){
		var url = $(this).attr('href');
		if(url != undefined && url.match("^http://.+"))
		{
			$(this).attr('target', '_blank');
		}
	});
  
  		$('#mainmenu li').hover(function(){
			$(this).css('background-position', '0 0').children('ul').toggle();
		}, function(){
			$(this).css('background-position', '0 -24px').children('ul').toggle();
		});
  
});
						   
function ToggleEdit() {
  var q = $("#toggleEdit").attr("checked");
  if (q) {
    $("#edit_div").css("visibility", "visible");
    $("#edit_div").css("position", "relative");
    $("#edit_prv").css("visibility", "hidden");
	$("#edit_prv").css("position", "absolute");
  } else {
    $("#edit_div").css("visibility", "hidden");
	$("#edit_div").css("position", "absolute");
    $("#edit_prv").css("visibility", "visible");
	$("#edit_prv").css("position", "relative");
  }
}

/* ------------------------------- */

// Script Source: CodeLifter.com
// Copyright 2003
// Do not remove this notice.

// SETUPS:
// ===============================

// Set the horizontal and vertical position for the popup

PositionX = 100;
PositionY = 100;

// Set these value approximately 20 pixels greater than the
// size of the largest image to be used (needed for Netscape)

defaultWidth  = 500;
defaultHeight = 500;

// Set autoclose true to have the window close automatically
// Set autoclose false to allow multiple popup windows

var AutoClose = true;

// Do not edit below this line...
// ================================
if (parseInt(navigator.appVersion.charAt(0))>=4){
var isNN=(navigator.appName=="Netscape")?1:0;
var isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}
var optNN='scrollbars=yes,width='+defaultWidth+',height='+defaultHeight+',left='+PositionX+',top='+PositionY;
var optIE='scrollbars=yes,width=150,height=100,left='+PositionX+',top='+PositionY;
function popImage(imageURL,imageTitle){
if (isNN){imgWin=window.open('about:blank','',optNN);}
if (isIE){imgWin=window.open('about:blank','',optIE);}
with (imgWin.document){
writeln('<html><head><title>Loading...</title><style>body{margin:0px;}</style>');writeln('<sc'+'ript>');
writeln('var isNN,isIE;');writeln('if (parseInt(navigator.appVersion.charAt(0))>=4){');
writeln('isNN=(navigator.appName=="Netscape")?1:0;');writeln('isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}');
writeln('function reSizeToImage(){');writeln('if (isIE){');writeln('window.resizeTo(300,300);');
writeln('width=300-(document.body.clientWidth-document.images[0].width);');
writeln('height=300-(document.body.clientHeight-document.images[0].height);'); 
writeln('if (height > 600){');
writeln('height=599;width+=18;}');
writeln('window.resizeTo(width,height);}');writeln('if (isNN){');       
writeln('window.innerWidth=document.images["George"].width;');
writeln('window.innerHeight=document.images["George"].height;}');
writeln('if (document.images["George"].height > 600){');
writeln('window.innerHeight=599;window.innerWidth+=18;}');
writeln('}');

writeln('function doTitle(){document.title="'+imageTitle+'";}');writeln('</sc'+'ript>');
if (!AutoClose) writeln('</head><body bgcolor=FFFFFF scroll="yes" onload="reSizeToImage();doTitle();self.focus()">')
else writeln('</head><body bgcolor=FFFFFF scroll="yes" onload="reSizeToImage();doTitle();self.focus()" onblur="self.close()">');
writeln('<img name="George" src="'+imageURL+'" style="display:block; cursor: pointer;" onclick="self.close();"></body></html>');
close();		
}}


/***** OLDIES 
function AddNextDocument() {
  var q = $('.fileOrLink');
  var par = q.length;

  var inputer = '<div class="fileOrLink">';
      inputer += 'typ:<input type="radio" name="type_'+par+'" value="1" checked="checked" onchange="SetAsFile('+par+')" /> plik  <input type="radio" name="type_'+par+'" value="2" onclick="SetAsLink('+par+')" /> link<br />';
      inputer += 'nazwa: <input type="text" name="title_'+par+'" value="" /><br />';
      inputer += 'opis: <input type="text" name="content_'+par+'" value="" />';
      inputer += '<div id="file_'+par+'">';
      inputer += 'plik: <input type="file" name="file_'+par+'" />';
      inputer += '</div>';
      inputer += '<div id="link_'+par+'"  style="display:none;">';
      inputer += 'link: <input type="text" value="http://" name="link_'+par+'" />';
      inputer += '</div>';
      inputer += '</div>';
  $('#fileAndLinks').append(inputer);
}

function SetAsLink(pId) {
  $('#file_' + pId).css('display', 'none');
  $('#link_' + pId).css('display', '');
}

function SetAsFile(pId) {
  $('#file_' + pId).css('display', '');
  $('#link_' + pId).css('display', 'none');
}
*****/

