function opinionInitForm(c){var e=$(c);var b=e.getElementById("opinionsUserSubmit");initField(e.getElementById("opinionsUserNick"),"msg",{sizeMin:0,mail:false});initField(e.getElementById("opinionsUserEmail"),"msg",{sizeMin:0,mail:true});initField(e.getElementById("opinionsUserOpinion"),"msg",{sizeMin:20,mail:false});var d=new Fx.Slide($("opinionsFormHideBlock")).hide();var f=function(i){i.preventDefault();var h=new Fx.Slide($("opinionsFormHideBlock"),{onComplete:function(){var k={theme:"white",callback:Recaptcha.focus_response_field,custom_translations:{visual_challenge:"Wybierz wyzwanie wizualne",audio_challenge:"Wybierz wyzwanie audio",refresh_btn:"Nowe wyzwanie",instructions_visual:"Wpisz dwa słowa:",instructions_audio:"Wpisz co usłyszałeś(-aś):",help_btn:"Pomoc",play_again:"Odtwórz jeszcze raz",cant_hear_this:"Ściągnij jako MP3",incorrect_try_again:"Nieprawidłowy. Spróbuj jeszcze raz."}};Recaptcha.create("6LfPdQwAAAAAALLB-5-UA715iTrFUZM2b8LFsww2 ",e.getElementById("opinionsCaptcha"),k);e.removeEvent("submit",f);e.addEvent("submit",a);b.set("value","Dodaj komentarz");var j=new Fx.Scroll(window).toElement("opinionsForm")}}).slideIn()};var g=function(){var h=new Fx.Slide($("opinionsFormHideBlock"),{duration:1000,onComplete:function(){e.removeEvent("submit",a);e.addEvent("submit",f)}}).slideOut().chain(function(){Recaptcha.destroy()})};e.addEvent("submit",f);var a=function(i){i.preventDefault();var h=true;e.getElements("input[type=text]").each(function(k){if(null!=k.opinionValidate){if(!k.opinionValidate()){h=false}}else{if(0==k.getProperty("value").length){h=false}}});e.getElements("textarea").each(function(k){if(null!=k.opinionValidate){if(!k.opinionValidate()){h=false}}});if(!h){b.set("value","Wypełnij poprawnie formularz...");return}b.set("value","Dodawanie komentarza...");b.setProperty("disabled","disabled");sendItemParams={name:$("opinionsUserNick").getProperty("value"),mail:$("opinionsUserEmail").getProperty("value"),comment:$("opinionsUserOpinion").getProperty("value"),rc_challenge:Recaptcha.get_challenge(),rc_respone:Recaptcha.get_response()};sendItem={action:"addComment",params:sendItemParams};var j=new Request.JSON({url:"/comments.php",onSuccess:function(k,m){if(null!=k){if(null==k.data){b.set("value",k.error.msg+"("+k.error.code+")")}else{b.set("value","Komentarz został dodany! Dodaj kolejny...");addComment(k.data,"bottom",$("opinionsList"));e.getElements("input[type=text]").each(function(n){n.setProperty("value",n.getProperty("msg"))});e.getElements("textarea").each(function(n){n.setProperty("value",n.getProperty("msg"))});g();var l=new Fx.Scroll(window).toElement("opItem#"+k.data.id)}}Recaptcha.reload();b.removeProperty("disabled")}}).send(JSON.encode(sendItem))}}function addComment(e,f,b){var h=new Element("li",{"class":"opinionItem",id:"opItem#"+e.id});h.addEvent("mouseover",function(){this.addClass("opinionItemMouseOver")});h.addEvent("mouseout",function(){this.removeClass("opinionItemMouseOver")});var d=new Element("div",{"class":"opinionsItemContenerLeft"});var i=new Element("span",{"class":"opinionsItemName",html:e.name});var a=new Element("div",{"class":"opinionsItemNote",html:e.date});var c=new Element("div",{"class":"opinionsItemNote",html:e.time});d.adopt([i,a,c]);var g=new Element("div",{"class":"opinionsItemComment",html:e.comment});h.adopt(d,g);h.inject(b,f)}function initField(a,d,c){var b=a.getProperty(d);a.value=b;a.addEvent("focus",function(){if(a.value==b){a.value=""}});a.opinionValidate=function(){if(this.value!=this.getProperty(d)){if(c.sizeMin>0){if(this.value.length<c.sizeMin){showError(this,"Wymagane jest minimum "+c.sizeMin+" znaków.");return false}}if(c.mail){if(!(/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i).test(this.get("value"))){showError(this,"Wymagany jest poprawny E-mail.");return false}}showError(this,null);return true}};a.addEvent("blur",function(){if(a.value==""){a.value=b;showError(a,"To pole jest wymagane.")}else{a.opinionValidate()}})}function showError(a,b){var d=a.id+"msg";var c=a.getNext();if((null==b)&&(null!=c)){if(c.get("tag")=="div"){c.destroy();a.setStyle("border-color","#ACACAC");return}}if(null!=b){if((null==c)||(c.get("tag")!="div")){c=new Element("div");c.inject(a,"after")}c.set("text",b);c.addClass("opinionsValidityFails");a.setStyle("border-color","red")}}function loadOpinions(){sendItem={action:"getComments",params:null};var a=new Request.JSON({url:"/comments.php",onSuccess:function(b,c){if(null!=b){if(null!=b.data){b.data.each(function(d){addComment(d,"bottom",$("opinionsList"))})}}$("opinionsLoadWaiting").destroy()}}).send(JSON.encode(sendItem))}window.addEvent("domready",function(){var a=new Fx.SmoothScroll({links:".opinionsSmoothAnchors",wheelStops:false});opinionInitForm("opinionsForm");loadOpinions()});
