// JavaScript Document
var fileCounter = 1;
var maxCounter = 15;

var defaultQuestionContent = '';  // Validacja Formularza
var defaultQuestionTitle = '';	 // Validacja Formularza
$(document).ready(function(){
    defaultQuestionContent = $("#questionContent").val();
    defaultQuestionTitle = $("#questionTitle").val();
    $("#addFile").click(
        function(){
            if(fileCounter < maxCounter){
                fileCounter ++;
                $(this).before('<div class="browse"><span class="zal">Załącznik ' 
                    + fileCounter + ':</span><input  class="file" type="file" name="zalacznik_' + fileCounter + 
                    '" id="zalacznik_' + fileCounter +'" size="23"></div>');

                if(fileCounter == maxCounter){
                    $(this).remove();
                }
                $('input#zalacznik_' +fileCounter).filestyle({
                    image: "images/form/add_file.png",
                    imageheight : 33,
                    imagewidth : 130,
                    width : 248
                });
            }
            return false;
        }
        );
		
    $("input.file[type=file]").filestyle({ 
        image: "images/form/add_file.png",
        imageheight : 33,
        imagewidth : 130,
        width : 248
    });
    $('#questionContent').blur(function(){
        if (this.value.replace(/\s/g,'')=='') 
            this.value=this.defaultValue;
        this.style.color='#777';
    })
    $('#questionContent').focus(function(){
        if (this.value==this.defaultValue) this.value='';
        this.style.color='#444';
    })
    $('#questionTitle').focus(function(){
        if (this.value==this.defaultValue) this.value='';
        this.style.color='#444';
    })
    $('#questionTitle').blur(function(){
        this.style.color='#777';
    })
		
		
    $('#confirm_mail').focus(function(){
        if (this.value==this.defaultValue) this.value='';
        this.style.color='#444';
    })
    $('#confirm_mail').blur(function(){
        this.style.color='#777';
    })
		
		
    /* ***********************  Left Menu Slide *************************** */
    //$('.sub-menu').hide();
    $('.slide').click(function(){
        if( $(this).next().is(':hidden') ) {
            $('.slide').next().slideUp();
            //$(this).next().toggleClass('active').slideDown();
            $(this).next().slideDown();
        }else{
            $(this).next().slideUp();
        }
        return false;
    });
    /* ***********************  / Left Menu Slide *************************** */


	/* ***********************  Simply Scroll *************************** */	
       
	$("#scroller").simplyScroll({
		className: 'vert',
		horizontal: false,
		frameRate: 24,
		autoMode: 'loop',
		pauseOnHover: false,
		speed: 1
	});
    /* ***********************  Simply Scroll *************************** */           

		
    /* ***********************  Validacja Formularza *************************** */
    jQuery.validator.addMethod("domyslnewartosci", function(value, element) {
        if( value==defaultQuestionContent || value==defaultQuestionTitle ){
            return false;
        }
        return true;
    }, "Proszę wpisać treść pytania");
    
    $("#send-question-form").validate({  
        focusCleanup: true,
        rules: {
            tytul: {
                domyslnewartosci:true,        
                required:true,
                minlength: 5
            },		
            tresc:{
                domyslnewartosci:true,
                required: true,
                minlength: 5
            },	
            imie: {
                required: true,
                minlength: 3
            },
            email: {
                required: true,
                email: true
            },
            regulamin: {
                required: true
            }
        },
			
        messages: {
            tytul:{
				domyslnewartosci:"Proszę wpisać tytuł pytania",
                required: "Proszę wpisać tytuł pytania",
                minlength: "Minimalna długość to 5 znaków"
            },
            tresc: {
                required: "Proszę wpisać treść pytania",
                minlength: "Proszę wpisać treść pytania"
            },
            imie:{
                required: "Proszę wpisać swoje Imię",
                minlength: "Minimalna długość to 3 znaki"
            },
            email:{
                required: "Wprowadź adres e-mail",
                email: "Wprowadź poprawny adres e-mail"
            },
            regulamin:{
                required: "Ważne! ->"
            }
        },
        success: function(label) {
            var id=label.attr('for');
            $("#"+id+"_info").addClass("ok"); 
            $("#"+id+"_info").removeClass("error");
        },
        errorPlacement: function(error, element) {
				
            if(element.attr('id')=="questionContent"){
                element.parent().before(error);
            }else{
                element.before(error);
            }
			$("#"+element.attr('id')+"_info").removeClass("ok");
            $("#"+element.attr('id')+"_info").addClass("error");
            /* Tutaj trzeba usunąć klasę "ok", aby znaczek też się zmienił na błąd */
        }
        ,
        debug:false
    });
/* ***********************  / Validacja Formularza *************************** */
  

});

