var MENU_TAB_ID = '';

toggleList = function(tree_id) {
  $("#parent"+tree_id).slideToggle("medium");
}

$(document).ready(function(){
    $("#boxLoginForm").submit(function(){
        if($("#box_authorize_login").val().length==0)
        {
            alert("Podaj swoją nazwę użytkownika!");
            $("#box_authorize_login").focus();
            return false;
        }
        if(!/^[a-zA-Z0-9\._-]+$/.test($("#box_authorize_login").val()))
        {
            alert("Podałeś nieprawidłową nazwę użytkownika. Upewnij się, że wpisałeś poprawnie swój login!");
            $("#box_authorize_login").focus();
            return false;
        }
        if($("#box_authorize_password").val().length==0)
        {
            alert("Wpisz hasło, które służy Ci do logowania się na konto w serwisie!");
            $("#box_authorize_password").focus();
            return false;
        }
        return true;
    });
    
    $("#loginForm").submit(function(){
        if($("#authorize_login").val().length==0)
        {
            alert("Podaj swoją nazwę użytkownika!");
            $("#authorize_login").focus();
            return false;
        }
        if(!/^[a-zA-Z0-9\._-]+$/.test($("#authorize_login").val()))
        {
            alert("Podałeś nieprawidłową nazwę użytkownika. Upewnij się, że wpisałeś poprawnie swój login!");
            $("#authorize_login").focus();
            return false;
        }
        if($("#authorize_password").val().length==0)
        {
            alert("Wpisz hasło, które służy Ci do logowania się na konto w serwisie!");
            $("#authorize_password").focus();
            return false;
        }
        return true;
    });
    
    
    $("#boxResetPasswordForm").submit(function(){
        if($("#box_reset_login").val().length==0 && $("#box_reset_email").val().length==0)
        {
            alert("Podaj nazwę użytkownika lub adres e-mail, użyty podczas rejestracji!");
            $("#box_reset_login").focus();
            return false;
        }
        return true;
    });
    
	$("#boxSearchForm").submit(function(){
        if($("#box_qs").val().length==0)
        {
            alert("Wpisz nazwę produktu, którego szukasz!");
            $("#box_qs").focus();
            return false;
        }
        return true;
    });
	
	
	/*
    $("#lostPasswordLink").click(function(){
        $("#loginPanelBox").fadeOut("medium", function(){
            $("#lostPasswordPanelBox").fadeIn("medium", function(){
                $("#box_reset_login").focus();
            });
        });
        return false;
    });
    $("#lostPasswordBackLogin").click(function(){
        $("#lostPasswordPanelBox").fadeOut("medium", function(){
            $("#loginPanelBox").fadeIn("medium", function(){
                $("#box_authorize_login").focus();
            });
        });
        return false;
    });
    
    $("#mailThisPageForm").submit(function(){
        if (!/^[a-zA-Z0-9\-_\.]+?@[a-zA-Z0-9\-_\.]+?\.[a-zA-Z]{2,4}$/.test($("#mail_this_od").val()))
        {
            alert("Podaj swój adres e-mail!");
            $("#mail_this_od").focus();
            return false;
        }
        if (!/^[a-zA-Z0-9\-_\.]+?@[a-zA-Z0-9\-_\.]+?\.[a-zA-Z]{2,4}$/.test($("#mail_this_do").val()))
        {
            alert("Podaj adres e-mail osoby, do której chcesz przesłać wiadomość!");
            $("#mail_this_do").focus();
            return false;
        }
        return true;
    });
    
    $("#commentForm").submit(function(){
       if($("#comment").val().length==0 || $("#comment").val()=="Tutaj wpisz swój komentarz...")
        {
            alert("Wpisz treść komentarza, który chcesz dodać!");
            $("#comment").focus();
            return false;
        }
       return true; 
    });*/
    
    
    $('#linkToLoginBox').click(function(){
        $.scrollTo('#boxLoginForm', 800, {onAfter:function(){
            $('#box_authorize_login').focus();
        }});
        return false;
    });
	
    
    $('#muzycy_slide').slideshow();
	
    
    
    $('ul#cardMenu li a').click(function()
    {
        if(MENU_TAB_ID==""){
            $('ul#cardMenu li').each(function(){
                if($(this).hasClass('selected')){
                    MENU_TAB_ID=$(this).attr("id");
                }
            });
        }
        var id = $(this).parent().attr("id");
        if (MENU_TAB_ID!=id)
        {
            $('#'+id+'_content').show();
            $('#'+MENU_TAB_ID+'_content').hide();
            
            $('#'+id).addClass('selected');
            $('#'+MENU_TAB_ID).removeClass('selected');
            
            MENU_TAB_ID=id;
        }
        return false;
    });
    
    
    $('.cartDropItem').click(function(){
        if(confirm("Usunąć produkt?"))
        {
            return true;
        }
        return false;
    });
    
    
    $.fancybox.cyclic = true;
    
    $('a[rel*=lightbox]').fancybox({
                                   'cyclic' : true
    });
    $('a[rel*=fancybox]').fancybox({
                                   'cyclic' : true
    });
	//$('a#prev_th_a[@rel*=fancybox]').lightBox();
	var lph = ''
	$('.prev_photoTh').click(function(){
	  var t_=$('#first_photon').find('a').attr('id');
	  
	  
	  $('#prev_th_a').attr('href', this.href)
	  $('#prev_th_img').attr('src', this.href)
	  $('#prev_th_a').attr('title', this.title)
	  
	  var h = this.href.replace('http://www.handbox.pl/upload/sklep/', '');
	  h = h.replace('.','');
	  
	  $('#'+h).attr('rel', 'brak');
	  
	  if ( lph && lph!=h )
	  {
		$('#'+lph).attr('rel', 'fancybox[galeria]');
	  }
	  
	  lph = h;
	  
	  return false;
	});
    
    
	$('#StronaDrukuj').click(function()
    {
        window.open($(this).attr("href"), "printWindow", "width=760,height=680,toolbar=0,locationbar=1,directories=0,status=1,menubar=0,scrollbars=1,resizable=1,copyhistory=0");
        return false;
    });
    
    $('a.productLists').click(function()
    {
        $.cookie('ProductListsViewType', $(this).attr("rel"), { expires: 31, path: "/" });
        location.reload(true);
        return false;
    });
	
    
	$(".newsletterForm").submit(function(){
        var id = (this.name=="box") ? "#box_" : "#";
        if($(id+"newsletter_imie").val().length==0)
        {
            alert("Podaj swoje imię!");
            $(id+"newsletter_imie").focus();
            return false;
        }
        if (!/^[a-zA-Z0-9\-_\.]+?@[a-zA-Z0-9\-_\.]+?\.[a-zA-Z]{2,4}$/.test($(id+"newsletter_email").val()))
        {
            alert("Podaj prawidłowy adres e-mail!");
            $(id+"newsletter_email").focus();
            return false;
        }
        return true;
    });
    
    
});
