

<!--
/**
 * Get the value of a cookie with the given name.
 *
 * @example $.cookie('the_cookie');
 * @desc Get the value of a cookie.
 *
 * @param String name The name of the cookie.
 * @return The value of the cookie.
 * @type String
 *
 * @name $.cookie
 * @cat Plugins/Cookie
 * @author Klaus Hartl/klaus.hartl@stilbuero.de
 */
jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options = $.extend({}, options); // clone object since it's unexpected behavior if the expired property were changed
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // NOTE Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};


var firstLoad = true;
var flashClick = false;
var menuClick = false;

$.fn.clearForm = function() {
  return this.each(function() {
 var type = this.type, tag = this.tagName.toLowerCase();
 if (tag == 'form')
   return $(':input',this).clearForm();
 if (type == 'text' || type == 'password' || tag == 'textarea')
   this.value = '';
 else if (type == 'checkbox' || type == 'radio')
   this.checked = false;
 else if (tag == 'select')
   this.selectedIndex = -1;
  });
};

jQuery.fn.formClick = function(value){
 return this.each(function(){
  var input = $(this);

  input.focus(function(){
   if ($(this).val() === value) $(this).val("");
  });
  input.blur(function(){
   if ($(this).val() === "") $(this).val(value);
  });
 });
};

$(function(){

if (window.location.hash === "#content" && firstLoad === true && $("#flash").length) {
 firstLoad = false;
 menuClick = true;
 selectSectionJStoAS(1, true);
}

 $("table.tablesorter").tablesorter({
 headers: {
  0: { sorter: false },
  1: { sorter: false },
  2: { sorter: false },
  3: { sorter: false },
  8: { sorter: false }
 }
 });

 $("form.form-kontakt :text[name=imie]").formClick("Imię");
 $("form.form-kontakt :text[name=nazwisko]").formClick("Nazwisko");
 $("form.form-kontakt :text[name=telefon]").formClick("Numer telefonu (9 cyfr)");
 $("form.form-kontakt :text[name=kod_pocztowy]").formClick("Kod pocztowy"); 
 $("form.form-kontakt :text[name=miasto]").formClick("Miasto");
 
$("div.slidelist h6").click(function(){
  $(this).toggleClass("selected");
  $(this).next("div").slideToggle("fast");
 });

function checkIt(string) {
 switch(string) {
  case "Imię":
  case "Nazwisko":
  case "Numer telefonu (9 cyfr)":
  case "Kod pocztowy":
  case "Miasto":
   return "";
   break;
  default:
   return string;
 }
 }


$("form.form-kontakt").submit(function(){
 var f = $(this);
 var url = f.attr("action");
 
 var arr = [];
 for (var x = 0; x < f.find(":text").length; x++) {
 arr[arr.length] = f.find(":text:eq(" + x + ")").attr("name") + "=" + checkIt(f.find(":text:eq(" + x + ")").val());
 }
 var d = arr.join("&") + "&zgoda=" + ( (f.find(":checkbox[name=zgoda]").is(":checked")) ? "on" : "off");
 $.ajax({
  url: url,
  data: d,
  dataType: "json",
  type: "post",
  beforeSend: function(){
   f.find(".error:text").removeClass("error");
   f.find("p.error").remove();
  },
  success: function(json){
   if (json.wynik === 0) {
    var msg;
    jQuery.each(json.bledy, function(id, val) {
     f.find(":text[name=" + val + "]").addClass("error");
     switch(val){
      case("telefon"):
       msg = "Podaj poprawny numer telefonu."
       break;;
      case("imie"):
       msg = "Podaj imię."
       break;;
      case("nazwisko"):
       msg = "Podaj nazwisko."
       break;;
      case("kod_pocztowy"):
       msg = "Podaj poprawny kod pocztowy."
       break;;
      case("miasto"):
       msg = "Podaj miasto."
       break;;
      case("zgoda"):
       msg = "Akceptacja warunk&#243;w jest wymagana."
       break;;
     }
     $("#error").append('<p class="error">' + msg + '</p>');
     f.parents("form.form-kontakt").css("padding-bottom", f.parent().outerHeight() - 195 + "px");
    });
   } else if (json.wynik === 1) {
   window.location = "http://pro.hit.gemius.pl/hitredir/id=zU.g62t3tz.Z7RXDyWmkQ7buj6MkBlsZ6ZQvmYZUNYH.Z7/url=http://plannazycie.pl/dziekujemy.php?order_id=" + json.order_id;
      
     }
  },
  error: function(){
   alert('Wystąpił błąd podczas łączenia z serwerem.');
  }
 });
 return false;
 });

/* $("#flash").children().click(function(){
  firstLoad = false;
  if (flashClick === false) {
   selectSectionJStoAS(1, true);
   flashClick = true;
  }
 });*/

});


/***********************************************
* Dynamic Ajax Content- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/
var loadedobjects=""
var rootdomain="http://"+window.location.hostname
function ajaxpage(url, containerid){
var page_request = false
if (window.XMLHttpRequest) // if Mozilla, Safari etc
page_request = new XMLHttpRequest()
else if (window.ActiveXObject){ // if IE
try {
page_request = new ActiveXObject("Msxml2.XMLHTTP")
} 
catch (e){
try{
page_request = new ActiveXObject("Microsoft.XMLHTTP")
}
catch (e){}
}
}
else
return false

page_request.onreadystatechange=function(){

loadpage(page_request, containerid)
}
page_request.open('GET', url, true)
page_request.send(null)
}

function loadpage(page_request, containerid){
if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1))
{ 
var currentTitle = document.title;
document.getElementById(containerid).innerHTML=page_request.responseText
startSifr();
document.title = currentTitle;

if (document.getElementById(containerid)) {
 var m = document.getElementById("left");
 if (m.offsetHeight < document.documentElement.clientHeight - document.getElementById('content').offsetHeight - document.getElementById('footer').offsetHeight) {
  m.style.height = (document.documentElement.clientHeight - document.getElementById('content').offsetHeight - document.getElementById('footer').offsetHeight - 97) + "px";
  document.getElementById("leftMenu").parentNode.style.height = (document.documentElement.clientHeight - document.getElementById('content').offsetHeight - document.getElementById('footer').offsetHeight - 97) + "px";
 } else {
  document.getElementById("leftMenu").parentNode.style.height = m.offsetHeight + "px";
 }
 $("#left").css("border-right", "1px dotted #767E87");
  if (menuClick === true) {
  if (!window.location.hash) {
   window.location.hash = "content";
  }
  menuClick = false;
  window.location = window.location;
 }
}

}
}
function loadobjs(){
if (!document.getElementById)
return
for (i=0; i<arguments.length; i++){
var file=arguments[i]
var fileref=""
if (loadedobjects.indexOf(file)==-1){ //Check to see if this object has not already been added to page before proceeding
if (file.indexOf(".js")!=-1){ //If object is a js file
fileref=document.createElement('script')
fileref.setAttribute("type","text/javascript");
fileref.setAttribute("src", file);
}
else if (file.indexOf(".css")!=-1){ //If object is a css file
fileref=document.createElement("link")
fileref.setAttribute("rel", "stylesheet");
fileref.setAttribute("type", "text/css");
fileref.setAttribute("href", file);
}
}
if (fileref!=""){
document.getElementsByTagName("head").item(0).appendChild(fileref)
loadedobjects+=file+" " //Remember this object as being already added to page
}
}
};
//-->

