var zaawansstatus = 1;
var oldNotesBox = new Array();
$(document).ready(function(){	
	if( $("div.extend") )
	{
     $("div.extend").hide();
     $("#zaawansa").empty().prepend(" zaawansowane >");
     zaawansstatus = 0;
    }        
   });
   
$(document).ready(function() {
  $('#oferty tr').hover(function(){
  		$(this).addClass('tr-hover');
	},function(){
  		$(this).removeClass('tr-hover');
	});
	/*$('#hover-demo2 p').hover(function() {
    $(this).addClass('pretty-hover');
  }, function() {
    $(this).removeClass('pretty-hover');
  });*/
});
$(function() {
	$('#lightgallery a').lightBox({
	//fixedNavigation:true
	//overlayBgColor: '#FFF',
	overlayOpacity: 0.6,	
	//containerResizeSpeed: 350,
	txtImage: 'Zdjecie',
	txtOf: 'z'	
	});
	$('a.lightbox').lightBox({
	//fixedNavigation:true
	//overlayBgColor: '#FFF',
	overlayOpacity: 0.6,	
	//containerResizeSpeed: 350,
	txtImage: 'Zdjecie',
	txtOf: 'z'	
	});
});
function zaawans()
{
	if( zaawansstatus == 1)
	{
		$("div.extend").slideUp("slow");
		$("#zaawansa").empty().prepend(" zaawansowane >");
		zaawansstatus = 0;
	}
	else
	{
		$("div.extend").slideDown("slow");
		$("#zaawansa").empty().prepend("< zaawansowane ");
		zaawansstatus = 1;
	}
} 
function ajaxLoadingImg()
{
	topa = $("#notesBox").height()/2 + 40;
	$("#ajaxLoading").css("top",-topa);
	$("#ajaxLoading").show();
}
function saveMainNote()
{
	msgHide();
	ajaxLoadingImg();
	$.post("welcome.php",
        {notatkaGlowna:$("#notatkaGlowna").val()},function(data){
                $("#ajaxLoading").hide();
                eval(data);
        });
}
function addNote()
{
	msgHide();
	ajaxLoadingImg();
	$.post("nba.php",
        {notatka:$("#notatka").val(),informEmail:$("#informEmail").attr("checked"),ofertaId:$("#ofertaId").val()},function(data){
                $("#ajaxLoading").hide();
                eval(data);
        });
}
function removeNote()
{
	msgHide();
	ajaxLoadingImg();
	$.post("nba.php",
        {del:1,notatka:$("#notatka").val(),informEmail:$("#informEmail").attr("checked"),ofertaId:$("#ofertaId").val()},function(data){
                $("#ajaxLoading").hide();
                eval(data);
        });
}
function updateNote()
{
	msgHide();
	ajaxLoadingImg();
	$.post("nba.php",
        {update:1,notatka:$("#notatka").val(),informEmail:$("#informEmail").attr("checked"),ofertaId:$("#ofertaId").val()},function(data){
                $("#ajaxLoading").hide();
                eval(data);
        });
}
function getContent(site)
{
	ajaxLoadingImg();
	$.get(site, function(datab){
  		notesBoxContent(datab);
  		$("#ajaxLoading").hide();
	});
}

function login()
{
	msgHide();
	ajaxLoadingImg();
	$.post("login.php",
        {userEmail:$("#userEmail").val(),password:$("#userPassword").val()},function(data){
                $("#ajaxLoading").hide();
                eval(data);
        });	
}

function notesBoxContent(data, b)
{	
	msgHide();
	if( b != -1 )
	{
		i = oldNotesBox.length;
		oldNotesBox[i] = $("#notesBox").html();
	}
	$("#notesBox").empty().html(data);
}
function notesBack(ii)
{
	msgHide();
	if( ii > 0 )
	{
		v = oldNotesBox[ii-1];
		oldNotesBox.splice(ii-1,99);
		notesBoxContent(v,-1);
	}
	else
	{
		i = oldNotesBox.length;
		v = oldNotesBox[i-1];
		oldNotesBox.splice(i-1,99);
		notesBoxContent(v,-1);
	}
}

function passwordRemainder()
{
	msgHide();
	if( $("#userEmail").val() == '' )
	{
		notesError('Pole email musi byc wypelnione');
	}
	else if( !checkMail($("#userEmail").val()) )
	{
		notesError('Bledy adres email');
	}
	else
	{
		ajaxLoadingImg();
		$.post("passwordRemainder.php",
        {userEmail:$("#userEmail").val(),password:$("#userPassword").val()},function(data){
                $("#ajaxLoading").hide();
                eval(data);
        });
    }
}
function checkMail(x)
{	
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (filter.test(x)) return true;
	return false;
}
function register()
{
	msgHide();
	if( $("#userName").val() == '' )
	{
		notesError('Pole nazwa musi byc wypelnione');
	}
	else if( $("#userEmail").val() == '' )
	{
		notesError('Pole email musi byc wypelnione');
	}
	else if( $("#userPassword").val() == '' || $("#userPasswordRepeat").val() == '' )
	{
		notesError('Pola Haslo i Powtorz Haslo musza byc wypelnione');
	}
	else if($("#userPassword").val() != $("#userPasswordRepeat").val())
	{
		notesError('Para hasel nie jest zgodna.');
	}
	else if( !checkMail($("#userEmail").val()) )
	{
		notesError('Bledy adres email');
	}
	else
	{
		ajaxLoadingImg();
		$.post("register.php",
        {userName:$("#userName").val(),userEmail:$("#userEmail").val(),password:$("#userPassword").val()},function(data){
                $("#ajaxLoading").hide();
                eval(data);
        });
	}
}
function reloadNotes()
{
	if( $("#loginToWelcome").val() == 1 )
	{
		/*getContent('welcome.php');*/
		window.location.href = 'notes.html';
	}
	else
	{
	ajaxLoadingImg();
		$.post("notesBox.php",
        {id:$("#ofertaId").val()},function(data){
                $("#ajaxLoading").hide();
                notesBoxContent(data);
        });
   }
}
function notesError(r)
{
	$("#notesBoxInfoMsg").hide();
	$("#notesBoxErrorMsg").show();
	$("#notesBoxErrorMsg").empty().html(r);
}
function notesInfo(r)
{
	$("#notesBoxErrorMsg").hide();
	$("#notesBoxInfoMsg").show();
	$("#notesBoxInfoMsg").empty().html(r);
}
function msgHide()
{
	$("#notesBoxErrorMsg").hide();
	$("#notesBoxInfoMsg").hide();
}
