var checkedFields = 0;

$(document).ready(function() {
	$('.slideshow').cycle({
		fx: 'turnLeft',
		timeout:  10000 ,
		pager:  '#nav div'

});
});
	
	

$(document).ready(function(){
    $("a[rel^='prettyPhoto']").prettyPhoto();
    
    $("#registerForm").validate({
     rules: {
        username: {
            required: true,
            minlength: 5
        },
        password: {
            required: true,
            minlength: 5
        },
        fname: {
            required: true,
            minlength: 3
        },
        lname: {
            required: true,
            minlength: 3
        },
        email: {
            required: true,
            email: true       
        },
        phone: {
            required: true,
            minlength: 9
        },
        address1: {
            required: true,
            minlength: 6       
        },
        postcode: {
            required: true,
            rangelength: [6, 6]       
        },
        city: {
            required: true,
            minlength: 3       
        },
        birth: {
            required: true,
            dateISO: true       
        }    
      },
      messages: {
        username:{
            required: "Prosze podać swój login",
            minlength: "Minimalna długość loginu to 5 znaków"
        },
        password:{
            required: "Prosze podać swoje hasło",
            minlength: "Minimalna długość hasła to 5 znaków"
        },
        fname:{
            required: "Prosze podać imię",
            minlength: "Minimalna długość imienia to 3 znaki"
        },
        lname:{
            required: "Prosze podać nazwisko",
            minlength: "Minimalna długość nazwiska to 3 znaki"
        },
        email:{
            required: "Prosze podać e-mail",
            email: "Proszę podać prawidłowy adres email"
        },
        phone:{
            required: "Prosze podać telefon",
            minlength: "Minimalna długość telefonu to 9 znaków"
        },
        address1:{
            required: "Prosze podać adres",
            minlength: "Minimalna długość adresu to 6 znaków"
        },
        postcode:{
            required: "Prosze podać kod-pocztowy",
            rangelength: "Długosc kodu to 6 znaków"
        },
        city:{
            required: "Prosze podać miasto",
            minlength: "Minimalna długość miasta to 3 znaki"
        },
        birth:{
            required: "Prosze podać datę urodzenia",
            dateISO: "Poprawny format daty: YYYY-MM-DD"
        }    
      },
       success: function() {
       }
      });

    
  });
  
  function submitForm(){
     return false;
  }
  
  
function sendForm(){
    
    if(!$("#regulamin").is(':checked')){
        alert('Musisz zaakceptować regulamin');
        return false;
    }
    $.post("/promocje/register.html", { 
            username: $('input#username').attr("value"),
            password: $('input#password').attr("value"),
            fname: $('#fname').attr("value"),
            lname: $('#lname').attr("value"),
            email: $('#email').attr("value"),
            address1: $('#address1').attr("value"),
            address2: $('#address2').attr("value"),
            postcode: $('#postcode').attr("value"),
            city: $('#city').attr("value"),
            birth: $('#birth').attr("value"),
            phone: $('#phone').attr("value")
        },

        function(response){
            if(response.success=='true'){
                $('#register').toggle('slow');
                $('#form-login').toggle('slow');
                $('#ajaxInfoRegister').html(response.info);
            }
            else{
                $('#ajaxInfoRegister').html(response.info);
            }
        }, "json");        
 
}


function resetPassword(){
    $.post("/promocje/reset.html", { 
            email: $('input#reset-email').attr("value")
        },

        function(response){          
            if(response.success=='true'){
                $('#form-forget').hide('slow');
                $('#ajaxInfo').html(response.info);
            }
            else{
                $('#ajaxInfo').html(response.info);
            }
        }, "json");
        
        return false;
 
}

