function message(data, location, button) {
	if (typeof(data) == "object") {
		msg = data.msg;
		location = data.location;
		button = data.button;
	} else
		msg = data;
	
	var div = $("<div>"+msg+"</div>").dialog({
		show: "blind",
		hide: "explode"
	});
	
	if (button) {
		div.dialog({
			modal: true,
			buttons: {
				Ok: function() {
					if (location)
						window.location = location;
					else
						div.dialog( "close" );
				}
			},
			minWidth: 400
		});
	} else {
		setTimeout(function(){
			if (location)
				window.location = location;
			else
				div.dialog( "close" );
		}, 2000);
	}
}

function myConfirm(data, location) {
	if (typeof(data) == "object") {
		msg = data.msg;
		location = data.location;
	} else
		msg = data;

	var div = $("<div>"+msg+"</div>").dialog({
		show: "blind",
		hide: "explode",
		modal: true,
		buttons: {
			"Tak" : function() {
				window.location = location;
			},
			"Nie" : function() {
				$( this ).dialog( "close" );
			}
		},
		minWidth: 400
	});

	return false;
}

function getURLParam(strParamName){
  var strReturn = "";
  var strHref = window.location.href;
  if ( strHref.indexOf("?") > -1 ) {
    var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
    var aQueryString = strQueryString.split("&");
    for ( var iParam = 0; iParam < aQueryString.length; iParam++ ) {
      if ( aQueryString[iParam].indexOf(strParamName + "=") > -1 ) {
        var aParam = aQueryString[iParam].split("=");
        strReturn = aParam[1];
        break;
      }
    }
  }
  return strReturn;
}

function setCookie(name, value, expires) {
	  var cookieStr = escape(name) +"=";
	  if (typeof value != "undefined") {
	    cookieStr += escape(value);
	  }
	  if (!expires) {
	    expires = new Date();
	    expires.setTime(expires.getTime()+365*24*60*60*1000);
	  }
	  cookieStr += "; expires="+ expires.toGMTString() +";";
	  document.cookie = cookieStr;
	}

function getCookie(name){
	  var str = '; '+ document.cookie +';';
	  var index = str.indexOf('; '+ escape(name) +'=');
	  if (index != -1) {
	    index += name.length+3;
	    var value = str.slice(index, str.indexOf(';', index));
	    return unescape(value);
	  }
	  return '';
	}

function deleteCookie(name){
	  var past = new Date();
	  past.setTime(0); // 1970-01-01
	  setCookie(name, null, past);
	}

$(document).ready(function() {

//walidacja pól formularzy
	if ($(".validate").length) {
		$(".validate").validate({
			errorElement: "em"
		});
		$(".validate").submit(function(e){
			console.log(e);
			if (!$(e.currentTarget).valid()) {
				message({msg: 'Należy poprawnie wypełnić pola obowiązkowe', button: true});
				return false;
			}
		});
	}

//fancybox
	if ($("a.fancybox").length) $("a.fancybox").fancybox({
		'transitionIn'	:	'easing',
		'transitionOut'	:	'easing',
		'speedIn'		:	600,
		'speedOut'		:	200,
		'overlayShow'	:	true
	});
});

