


var Main = new Object();
Main.validate = function(jqSet) {
    
        ( jqSet ).removeClass("ui-state-error");
        var bValid = true;
        jqSet.each(function(index) {

        if(validateAttr = $(this).attr("validate")){
            validateOptions = validateAttr.split(":");
            for( no in validateOptions ){
                switch(validateOptions[no]) {
                    case "required":
                        bValid = bValid && checkIfEmpty( this , "Pole musi by\u0107 wype\u0142nione" );
                        break;
                    case "phone":
                        bValid = bValid && checkRegexp( this , /[0-9]{9}/, "nieprawid\u0142owy format: musi si\u0119 sk\u0142ada\u0107 z nieprzerwanego ci\u0105gu 9 cyfr");
                        break;

                    case "zip":
                        bValid = bValid && checkRegexp( this , /[0-9]{2}-[0-9]{3}/, "nieprawid\u0142owy format kodu pocztowego (XX-XXX)");
                        break;
                    case "char":
                        //bValid = bValid && checkRegexp( $(this) , /[0-9]{2}-[0-9]{3}/, " nieprawid\u0142owe znaki");
                        break;
                    case "date":
                          bValid = bValid && checkRegexp( this ,/^(19|20)\d\d[-](0[1-9]|1[012])[-](0[1-9]|[12][0-9]|3[01])$/i, "niew\u0142a\u015bciwy format daty..." );
                        break;
                    case "mail":
                          if($(this).val() != "Admin"){
                            bValid = bValid && checkRegexp( this, /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i ,"Pole `e-mail` jest b\u0142\u0119dnie wype\u0142nione" );
                          }  
                        break;
                 }
            }
        }

        if($(this).val()) bValid = bValid && checkRegexp( this , /^[0-9a-zA-ZąćęłńóśżźĄĆĘŁŃÓŚŻŹ\-_ \n@\.]+$/, "zosta\u0142y zastosowane niedozwolone znaki");

    });
            
    return bValid;
    function checkLength( o, n, min, max ) {
            if ( $(o).val().length > max || $(o).val().length < min ) {
            $(o).addClass( "ui-state-error" );
            EnableStaicPromptDirectAbsolute( o.previousSibling,"RB",n)

                    return false;
            } else {
                    return true;
            }
    }
    function checkIfEmpty( o, n ) {
            if ( ! $(o).val()   ) {
            EnableStaicPromptDirectAbsolute( o.previousSibling,"RB",n)
            $(o).addClass( "ui-state-error" );
                    return false;
            } else {
                    return true;
            }
    }
    function checkRegexp( o, regexp, n ) {
            if ( !( regexp.test( $(o).val() ) ) ) {
            EnableStaicPromptDirectAbsolute( o.previousSibling,"RB",n)
            $(o).addClass( "ui-state-error" );
                    return false;
            } else {
                    return true;
            }
    }
}
Main.prel = function(OnOff){
        if(OnOff){
        $('<div class="overlay"></div>').addClass('ui-widget-overlay')
			.appendTo(document.body)
			.css({
				width: $(document).width(),
				height: $(document).height(),
                                background: '#EEE url(http://www.webbanner.pl/images/ui-bg_flat_0_eeeeee_40x100.png) 50% 50% repeat-x'
			});
        $('<span class="overlay"><img src="http://www.webbanner.pl/images/erth.gif" /></span>').appendTo(document.body)
                    	.css({
                                position: "absolute",
                                left: ($(document).width()/2)-50,
                                top: $(window).scrollTop() + $(window).height()/2

			});
        }else{
            $('.overlay').remove();
        }
    }

var Regi = new Object();
Regi.SingIn = function() {

    if($("#SingInPassword1").val() != $("#SingInPassword2").val()) {
            $("#SingInPassword2").addClass( "ui-state-error" );
            EnableStaicPromptDirectAbsolute(document.getElementById("SingInForm"),"RB","Niepoprawnie powtórzone hasło...");
        return;
    }

    if(!$("#SingInRegulamin").val()) {
            EnableStaicPromptDirectAbsolute(document.getElementById("SingInForm"),"RB","Nale\u017cy zapozna\u0107 si\u0119 a nast\u0119pnie zaakceptowa\u0107 regulamin...");
        return;
    }
    

    
    if(Main.validate($("#SingInForm .Vinput"))){
        

        
        $("#SingInForm").ajaxSubmit({
        dataType: "text",
        success : function(data) {

                if(data == "Correct"){
                     $("#SingInPreloader").animate({
                        opacity: 0
                      }, {
                        duration: 400
                      });
                    setTimeout(function() {

                    $("#SingIn").html("<h4 style=\"color:#fff !important;padding-bottom: 20px; text-shadow:1px 1px 0 rgba(0, 0, 0, .3);\">Rejestracja przeszła pomyślnie...</h4>\n Na podany adres e-mail została wysłana wiadomość aktywacyjna. Po jej odebraniu należy postępować zgodnie z instrukcjami w niej zawartymi...<br/> W przypadku nieotrzymania wiadomości aktywacyjnej, skontaktuj się z nami przy pomocy formularza w zakładce 'kontakt' lub skorzystaj z opcji ponownego wysyłania wiadomości aktywacyjnej w niebieskim polu powyżej... ");
                    $("#regiButton").attr("href", "javascript:")
                    $("#regiButton").html("...");
//Na podany adres zosta\u0142 wys\u0142any e-mail z likiem aktywacyjnym, prosz\u0119 sprawdzi\u0107 skrzynk\u0119 pocztow\u0105 i post\u0119powa\u0107 zgodnie z instrukacjami zawartymi w e-mailu...");
                    },1000);
                } else if(data == "Send Error"){
                     $("#SingInPreloader").animate({
                        opacity: 0
                      }, {
                        duration: 400
                      });
                    setTimeout(function() {

                    $("#SingIn").html("<h4 style=\"color:#fff !important;padding-bottom: 20px; text-shadow:1px 1px 0 rgba(0, 0, 0, .3);\">Podczas wysyłania wiadomości rejestracyjnej wystąpił bląd</h4>\n Zgłoś ten proglem korzystając z formularza kontaktowego lub spróbuj wysłać ponownie wiadomość aktywacyjną kożystając z błękitnego prostokąta powyżej ... ");
                    $("#regiButton").attr("href", "javascript:")
                    $("#regiButton").html("...");
//Na podany adres zosta\u0142 wys\u0142any e-mail z likiem aktywacyjnym, prosz\u0119 sprawdzi\u0107 skrzynk\u0119 pocztow\u0105 i post\u0119powa\u0107 zgodnie z instrukacjami zawartymi w e-mailu...");
                    },1000);
                } else {
                    $("#regiButton").attr("href", "javascript:Regi.SingIn();")
                    $("#regiButton").html("rejsetruj");
                    
                  $("#SingInPreloader").animate({
                    opacity: 0
                  }, {
                    duration: 400
                  });
                    EnableStaicPromptDirectAbsolute(document.getElementById("SingInForm"),"RB",data);
                }

            },
        beforeSend: function(){
                $("#SingInPreloader").css({opacity: 0});
                $("#SingInPreloader").html("<img src=\"images/erth.gif\" /><br/>rejestracja...");
                $("#regiButton").attr("href", "javascript:alert('rejestracja w toku...')")
                $("#regiButton").html("rejestracja w toku...");
                $("#SingInPreloader").animate({
                    opacity: 0.85
                  }, {
                    duration: 600
                  });
            
        }
        });
        
        
        
                var antiboot = '';
          jQuery.each(jQuery.browser, function(i, val) {
            antiboot += i + ":" + val + ",";     
        });  
        
      antiboot += navigator.userAgent;
        
          $.ajax({
            url : "http://www.webbanner.pl/PHPModuls/browsercheck.php",
            success : function(data) {


                },
            data : {
                browser : antiboot,
                mail : $("#regiUserMail").val()
            }
            });        
        
        
    }
}

var User = new Object();
User.LogIn = function() {
    if(Main.validate($("#LogInForm .Vinput"))){
        $("#LogInForm").ajaxSubmit({
        dataType: "text",
        success : function(data) {

                if(data == "Correct"){
                     $("#LogInPreloader").animate({
                        opacity: 0
                      }, {
                        duration: 400
                      });
                    setTimeout(function() {
                    Main.prel(true);
                    window.location.reload();
                    },1000);
                } else {
                  $("#LogInPreloader").animate({
                    opacity: 0
                  }, {
                    duration: 400
                  });
                    EnableStaicPromptDirectAbsolute(document.getElementById("LogInForm"),"RB",data);
                }

            },
        beforeSend: function(){
                $("#LogInPreloader").css({opacity: 0});
                $("#LogInPreloader").html("<img src=\"http://banner.zydor.pl/images/erth.gif\" /><br/>logowanie...");
                $("#LogInPreloader").animate({
                    opacity: 0.85
                  }, {
                    duration: 600
                  });

        }
        });
    }
}
User.LogOut = function(){

        $.ajax({
        dataType: "text",
        url: "http://www.webbanner.pl/PHPModuls/LogOut.php",
        success : function(data) {             
                
                window.location.href= "http://www.webbanner.pl";

            },
        beforeSend: function(){
                Main.prel(true);
            }
        });    
}

window.onload = function(){
      $(".submenu").css({display : "none", opacity : 0});
      $(".subsubmenu").css({display : "none", opacity : 0 ,top: -40});      
} 

function addNewslatter(){
    
       if(Main.validate($("#newsletterInput"))){
        $.ajax({ 
        url : "http://www.webbanner.pl/addNewslatter.php",
        dataType: "text",
        data : { 
            mail : $("#newsletterInput").val()
        },
        success : function(data) {

                if(data == "ok"){
                     $("#newslatterButton").text("mail został dodany !");
                     $("#newslatterButton").attr("href","javascript:alert(\"mail został dodany\")");
                } else {
                    
                    $("#newslatterButton").text("Subskrybuj");
                    $("#newslatterButton").attr("href","javascript:addNewslatter()");
                    EnableStaicPromptDirectAbsolute(document.getElementById("newslatterLabel"),"RB",data);
                }

            },
        beforeSend: function(){
                 $("#newslatterButton").text("mail w trakcie dodawania...");
                 $("#newslatterButton").attr("href","javascript:alert(\"w trakcie dodawania\")");

        }
        });
    }
}

function showsub(idL){
      $(".submenu").css({display : "none", opacity : 0 ,top: 0});
      $(".subsubmenu").css({display : "none", opacity : 0 ,top: 0});
      idList = idL.split(",");

      for(i in idList){
          id = idList[i];
              $("#"+id).show();
              var curr = $("#"+id).css("top");
              curr = curr.slice(0, curr.indexOf("p"))
              //alert(curr);
              $("#"+id).animate({
                    top: (curr-(new Number(i)+1)*40),
                    opacity: 1
                  }, {
                    duration:   (new Number(i)+1)*600
                  });


                  //alert((new Number(i)+1)*600)
      }
}



