/* charset "utf-8"; */
/* Pieces: rettiwt-formCommon-questionPage-questionListPage-formAddAnswer-for_AddAnswer-formAddQuestionModule-for_AddQuestion-cutter-homePageAnswers */
/* base_path_placeholder */
/* @JAVASCRIPT rettiwt */
var Rettiwt_classes={prefix:"prefix",sufix:"sufix",counter:"counter",counterspan:"counterspan",check:"check"};var Rettiwt_texts={idCounterSpan:"counter_span",prefixCounter:Namespace.utilities.i18n.getText("Please write at least"),separator:"&nbsp;",sufixCounter:Namespace.utilities.i18n.getText("characters")};var Rettiwt=function(a){this.oApplyTo=null;this.oCounterSpan=null;this.oClasses=Rettiwt_classes;this.oTexts=Rettiwt_texts;this.nCharacters=0;this.nMinChars=0;this.oCounterLayer=null;this.oCheckLayer=null;this.oParentApplyTo=null;this.nWidth=0;this.bInsertBefore=true;this.sInstance=a||"_default"};Rettiwt.prototype.applyTo=function(a){this.oApplyTo=a;return this};Rettiwt.prototype.setWidth=function(a){this.nWidth=a;return this};Rettiwt.prototype.setMinCharacters=function(a){this.nMinChars=a;return this};Rettiwt.prototype.setClasses=function(a){this.oClasses=a;return this};Rettiwt.prototype.setInsertBefore=function(a){this.bInsertBefore=a;return this};Rettiwt.prototype.setTexts=function(a){this.oTexts=a;return this};Rettiwt.prototype.setCharactersLength=function(){this.nCharacters=this.oApplyTo.value.length;return this};Rettiwt.prototype.putLengthOnCounterSpan=function(){this.setCharactersLength();this.oCounterSpan.innerHTML=this.nMinChars-this.nCharacters;return this};Rettiwt.prototype.removeContentCounterLayer=function(){this.oCounterLayer.innerHTML="";return this};Rettiwt.prototype.wrapApplyToOnDiv=function(){var a=document.createElement("div");if(this.nWidth){a.style.width=this.nWidth+"px"}this.insertBeforeApplyTo(a);a.appendChild(this.oApplyTo);this._setParentApplyTo(false)};Rettiwt.prototype.createCounterLayer=function(){var a=document.createElement("div");a.className=this.oClasses.counter;this.oCounterLayer=a;return a};Rettiwt.prototype.createSeparatorSpan=function(){var a=document.createElement("span");a.innerHTML=this.oTexts.separator;return a};Rettiwt.prototype._appendSeparator={};Rettiwt.prototype._appendSeparator._default=function(){this.oCounterLayer.appendChild(this.createSeparatorSpan())};Rettiwt.prototype._appendSeparator.jp=function(){};Rettiwt.prototype.createDomLessThanMinChars=function(){var b=document.createElement("span");b.className=this.oClasses.prefix;b.innerHTML=this.oTexts.prefixCounter;var a=document.createElement("span");a.id=this.oTexts.idCounterSpan;a.className=this.oClasses.counterspan;this.oCounterSpan=a;var c=document.createElement("span");c.className=this.oClasses.sufix;c.innerHTML=this.oTexts.sufixCounter;this.oCounterLayer.appendChild(b);this.oCounterLayer.appendChild(this.createSeparatorSpan());this.oCounterLayer.appendChild(a);this._appendSeparator[this.sInstance].call(this);this.oCounterLayer.appendChild(c);this.insertBeforeApplyTo(this.oCounterLayer)};Rettiwt.prototype._setParentApplyTo=function(b){if(!b){var a=this.oApplyTo.parentNode;if(a){this.oParentApplyTo=a}else{this.oParentApplyTo=document.body}}};Rettiwt.prototype.insertBeforeApplyTo=function(a){this._setParentApplyTo(this.oParentApplyTo);if(this.bInsertBefore){this.oParentApplyTo.insertBefore(a,this.oApplyTo)}else{this.oParentApplyTo.appendChild(a)}};Rettiwt.prototype.createDomEqualsOrMoreThanMinChars=function(){var a=document.createElement("div");a.className=this.oClasses.check;this.oCheckLayer=a;this.oCounterLayer.appendChild(a);this.insertBeforeApplyTo(this.oCounterLayer)};Rettiwt.prototype.setBehaviour=function(){var a=this;$(this.oApplyTo).keyup(function(){a.decideWhatDomToCreate()})};Rettiwt.prototype.decideWhatDomToCreate=function(){var a=this.nCharacters;this.setCharactersLength();if(this.nCharacters<this.nMinChars){if(!document.getElementById(this.oTexts.idCounterSpan)){this.removeContentCounterLayer();this.createDomLessThanMinChars()}this.putLengthOnCounterSpan()}else{this.removeContentCounterLayer();this.createDomEqualsOrMoreThanMinChars()}};Rettiwt.prototype.createDom=function(){this.wrapApplyToOnDiv();this.setCharactersLength();var a=this.createCounterLayer();this.decideWhatDomToCreate()};Rettiwt.prototype.init=function(){this.createDom();this.setBehaviour()};
/* @end JAVASCRIPT rettiwt */

/* @JAVASCRIPT formCommon */
Namespace.formValidation={};Namespace.formValidation.utilities={};Namespace.formValidation.rules={};Namespace.formValidation.messages={};Namespace._getText_=Namespace.utilities.i18n.getText;Namespace.formValidation.utilities.getRemoteUrl=function(f,a,e){var b=[];var d=$("input.ajax_form_controller",document.getElementById(f))[0];if(d){b.push("http://");b.push(window.document.domain);b.push(d.value);b.push("?");b.push("action="+a);if(typeof e!="undefined"){b.push("&");b.push($(e).serialize())}}try{return b.join("")}catch(c){alert(c)}finally{b=d=null}};
/* @end JAVASCRIPT formCommon */

/* @JAVASCRIPT questionPage */
Core.register("questionPage",function(a){return{oClasses:{ok:"msg_ok",ko:"msg_ko"},init:function(){var f=$.makeArray($(".answer_body p:first-child",document.getElementById("content_list_asnwers")));var e=f.length;var h=0;var b=45;var d=null;var g=$("a.suscribe");var c=$(document.getElementById("inadequate_button"));this.createLinks();if(e){for(;h<e;h++){d=new Cutter();d.applyTo(f[h]).setWords(b).setTarget(f[h]).setTexts({more:Namespace.utilities.i18n.getText("Read answer")}).init()}this.addVoteLinksBehaviour()}if(g){g.bind("click",{oInstance:this},this.addSubscribeLinkBehaviour)}if(c){c.bind("click",{oInstance:this},this.inadequateLinkBehaviour)}f=b=h=e=d=null;a.listen([],this.handleNotification,this)},inadequateLinkBehaviour:function(b){var c=b.data.oInstance;var e=this.parentNode;var d=$(document.getElementById("inadequate_button"));$.ajax({url:d.attr("href"),type:"POST",data:{action:"reportQuestion",question:document.getElementById("id_question").value,type:"inadequate"},success:function(f){if("OK"===f.status){e.innerHTML=document.getElementById("marked_ok").innerHTML;e.className=c.oClasses.ok}else{if("KO"===f.status){e.innerHTML=document.getElementById("marked_ko").innerHTML;e.className=c.oClasses.ko}else{e.innerHTML=document.getElementById("marked_error").innerHTML;e.className=c.oClasses.ko}}}});return false},addSubscribeLinkBehaviour:function(b){var c=b.data.oInstance;var e=document.getElementById("user_id_profile");var d=null;var f=this.parentNode;if(e){d=e.value}if(b.type==="click"&&!d){$(document.getElementById("login_link")).trigger("click")}else{var g=$("a.suscribe");$.ajax({url:g.attr("href"),type:"POST",data:{action:"subscribeQuestion",question:document.getElementById("id_question").value},success:function(i){g.remove();if("OK"===i.status){var h="";if("suscribed"===i.data){h="You are now following this question and its activity."}else{h="You are not following this question anymore.";Namespace.tracking.trackEvent(["Answers - question_page","unsubscribe"])}f.innerHTML=Namespace.utilities.i18n.getText(h);f.className=c.oClasses.ok}else{f.innerHTML=Namespace.utilities.i18n.getText("Error on suscribe");f.className=c.oClasses.ko}}})}return false},addVoteLinksBehaviour:function(){var f=$.makeArray($(".answers",document.getElementById("content_2col_right")));var e=f.length;var i=0;var c=null;var d=null;var h=[];var b=new Image();var g=function(){var j=d.id.split("-")[1];var k=h;var l=b;return function(){var n=this.innerHTML;var m=this;this.innerHTML="";this.appendChild(l);l.className="";$.ajax({url:"/question-actions",type:"POST",data:{action:"voteAnswer",value:this.rev,id_answer:j},dataType:"json",success:function(o){setTimeout(function(){if(o.status==="OK"){k[0].innerHTML="<span>"+k[0].title+"</span>"+o.data["votes-for"];k[1].innerHTML="<span>"+k[1].title+"</span>"+o.data["votes-against"]}else{alert(o.data.message);m.innerHTML=n}l.className="hidden"},500)}});return false}};b.src=window.url_images_shared+"download/post_download_loader_s.gif";for(;i<e;i++){d=f[i];c=$(".vote_answers",d)[0];h=c.getElementsByTagName("a");$(h[0]).bind("click",g());$(h[1]).bind("click",g())}},createLinks:function(){var f=$.makeArray($(".answer_body span.jsurl"));var e=f.length;var b=0;var d=null;var g=null;var c="";for(;b<e;b++){g=f[b];c=html_entity_decode(g.innerHTML);d=document.createElement("a");d.href=c;d.title=c;d.innerHTML=g.innerHTML;g.innerHTML="";g.appendChild(d);$(d).bind("click",this.openExternalUrl)}g=nElements=e=d=null},openExternalUrl:function(){window.open(this.href);return false},handleNotification:function(b){},destroy:function(){a.stopListen([],this)}}});
/* @end JAVASCRIPT questionPage */

/* @JAVASCRIPT questionListPage */
Core.register("questionListPage",function(a){return{init:function(){this.createFiltersMore();Namespace.utilities.enableBackButton();a.listen([],this.handleNotification,this)},createFiltersMore:function(){var c=document.getElementById("tags_filters").getElementsByTagName("ul")[0];var e=c.getElementsByTagName("li");var b=e.length;var d=8;var g=null;var f=null;if(b>d){g=document.createElement("li");f=document.createElement("a");f.innerHTML="+";g.className="more";for(;d<b;d++){e[d].className="hidden"}g.appendChild(f);c.appendChild(g);$(f).bind("click",function(){if(c.className.indexOf("show_all")!==-1){c.className=c.className.replace("show_all","");f.innerHTML="+"}else{c.className="show_all";f.innerHTML="-"}})}},handleNotification:function(b){},destroy:function(){a.stopListen([],this)}}});
/* @end JAVASCRIPT questionListPage */

/* @JAVASCRIPT formAddAnswer */
Core.register("formAddAnswer",function(a){return{init:function(){var c=$.makeArray($(".aws_form"));var g=c.length;var d=0;var h=70;var f=document.getElementById("user_id_profile");var e=null;var b=function(i){if(i.type==="click"&&!e){$(document.getElementById("login_link")).trigger("click")}Namespace.utilities.resizeTextarea(this,h)};if(f){e=f.value}if(g>0){for(;d<g;d++){$form=$(c[d]);$form.validate({hideErrorList:true,focusInvalid:false,errorElement:"div",rules:Namespace.formValidation.rules.addAnswer,messages:Namespace.formValidation.messages.addAnswer,submitHandler:function(i){Namespace.tracking.trackEvent(["Answers - question_page","answer"]);i.submit()}});$("textarea",$form).bind("keyup click",b)}}a.listen([],this.handleNotification,this)},handleNotification:function(b){switch(b.type){}},destroy:function(){a.stopListen([],this)}}});
/* @end JAVASCRIPT formAddAnswer */

/* @JAVASCRIPT for_AddAnswer */
Namespace.formValidation.rules.addAnswer={body:{required:true,minlength:2}};Namespace.formValidation.messages.addAnswer={body:{required:Namespace.utilities.i18n.getText("Please write something, we would like to know your answer."),minlength:Namespace.utilities.i18n.getText("Explain your answer, make it as detailed as you can.")}};
/* @end JAVASCRIPT for_AddAnswer */

/* @JAVASCRIPT formAddQuestionModule */
Core.register("formAddQuestionModule",function(a){return{init:function(){var e=null;var c=document.getElementById("ask_form");var d=$("#question_title")[0];var g=document.getElementById("user_id_profile");var f=null;var b=document.createElement("p");if(g){f=g.value}$(c).validate({focusInvalid:false,errorElement:"div",rules:Namespace.formValidation.rules.addQuestion,messages:Namespace.formValidation.messages.addQuestion});$(d).bind("click",function(){if(!f){$(document.getElementById("login_link")).trigger("click")}else{b.className="counter";b.innerHTML=Namespace.utilities.i18n.getText("Questions need to contain at least 10 characters.");d.parentNode.appendChild(b)}});a.listen([],this.handleNotification,this)},handleNotification:function(b){switch(b.type){}},destroy:function(){a.stopListen([],this)}}});
/* @end JAVASCRIPT formAddQuestionModule */

/* @JAVASCRIPT for_AddQuestion */
Namespace.formValidation.rules.addQuestion={question_title:{required:true,minlength:10,maxlength:100}};Namespace.formValidation.messages.addQuestion={question_title:{required:Namespace.utilities.i18n.getText("Please write your question, don't leave this blank."),minlength:Namespace.utilities.i18n.getText("Explain your question a bit, that way everyone can understand it."),maxlength:Namespace.utilities.i18n.getText("Keep it simple, remember you'll be able to add more details on the next step.")}};Namespace.formValidation.rules.editQuestion={"tags[]":{required:true}};Namespace.formValidation.messages.editQuestion={"tags[]":{required:Namespace.utilities.i18n.getText("Please choose at least one subject to classify your question")}};
/* @end JAVASCRIPT for_AddQuestion */

/* @JAVASCRIPT cutter */
(function(c,b){var a=null,e=null,d=null;a=function(){this.more="more"};e=function(){this.more="View more"};d=function(){this.fpBeforeCallback=function(){};this.fpAfterCallback=function(){};this.oApplyTo=null;this.oBackupApplyTo=null;this.oTarget=null;this.oClasses=new a();this.oTexts=new e();this.nWords=0;this.nWordsCounter=0;this.oViewMore=null;this.oSerialized={};this.oDocumentFragment=b.createDocumentFragment();this.bTest=false;this.nIdTest=0;this.bNeedViewMore=false;this.bForceBreak=false;this.bBreakFound=false;this.sForceBreakData="#read_more#";this.bNotViewMore=false;this.oDinamic=null};d.prototype.setDinamicClass=function(f){this.oDinamic=f;return this};d.prototype.setBeforeCallback=function(f){this.fpBeforeCallback=f;return this};d.prototype.setAfterCallback=function(f){this.fpAfterCallback=f;return this};d.prototype.applyTo=function(f){if(!f){return this}this.oApplyTo=f;this.oBackupApplyTo=f.cloneNode(true);return this};d.prototype.setTarget=function(f){if(!f){return this}this.oTarget=f;return this};d.prototype.setClasses=function(f){if(!f){return this}this.oClasses=f;return this};d.prototype.setTexts=function(f){if(!f){return this}this.oTexts=f;return this};d.prototype.setWords=function(f){if(!f){return this}this.nWords=f-1;return this};d.prototype.trim=function(f){return f.replace(/^\s+/g,"").replace(/\s+$/g,"")};d.prototype.countWords=function(f){if(this.bForceBreak!==true){return this.trim(f).split(" ").length}else{return 0}};d.prototype.getOnlyNumberOfWords=function(g,f){return this.trim(g).split(" ").splice(0,f).join(" ")};d.prototype.createViewMore=function(){var f=b.createElement("a");f.className=this.oClasses.more;f.title=this.oTexts.more;f.href="#";f.innerHTML=this.oTexts.more;this.oViewMore=f};d.prototype.getFirstElementOfObject=function(g){var f=null,h="";for(h in g){if(g.hasOwnProperty(h)){f=g[h];break}}return f};d.prototype.deserializeObject=function(i,h){var f=null,g="";if(i.nodeType===1){f=b.createElement(i.tagName);if(typeof i.attributes!=="undefined"){for(g in i.attributes){if(i.attributes.hasOwnProperty(g)){f.setAttribute(g,i.attributes[g])}}}h.appendChild(f)}else{if(i.nodeType===3){if(typeof i.textContent!=="undefined"){f=b.createTextNode(i.textContent)}else{if(i.data){f=b.createTextNode(i.data)}else{f=b.createTextNode(i.innerText)}}h.appendChild(f)}}if(typeof i.childNodes!=="undefined"){this.loopOnDeserialize(i.childNodes,f)}};d.prototype.loopOnDeserialize=function(h,g){var f="";for(f in h){if(h.hasOwnProperty(f)){this.deserializeObject(h[f],g)}}};d.prototype.deserializeSerializedObject=function(i,h){var g=false,f=null;if(typeof i==="undefined"){i=this.getFirstElementOfObject(this.oSerialized);this.oDocumentFragment=b.createDocumentFragment();g=true}if(typeof h==="undefined"){f=b.createElement("div");this.oDocumentFragment.appendChild(f);h=f}this.deserializeObject(i,h);if(typeof i.childNodes!=="undefined"){this.loopOnDeserialize(i.childNodes,h)}};d.prototype.serializeDomObject=function(l,i){var g=Math.random()*15412457562,f=null,n=[],p=null,h=0,m=0,k=0,o=0,j=l.childNodes.length;if(this.bTest){g="__"+(this.nIdTest+=1)+"__"}if(this.nWordsCounter<this.nWords){f={};f.nodeType=l.nodeType;if(f.nodeType===8&&l.data===this.sForceBreakData){this.bBreakFound=true;return false}if(typeof l.tagName!=="undefined"){f.tagName=l.tagName.toLowerCase()}n=l.attributes;if(n){f.attributes={};m=n.length;for(;h<m;h+=1){p=n[h];if(p.nodeValue){f.attributes[p.name]=p.value}}}if(f.nodeType===3){k=this.nWordsCounter;if(typeof l.textContent!=="undefined"){this.nWordsCounter+=this.countWords(this.trim(l.textContent))}else{if(l.data){this.nWordsCounter+=this.countWords(this.trim(l.data))}else{this.nWordsCounter+=this.countWords(this.trim(l.innerText))}}if(this.nWordsCounter<this.nWords){if(typeof l.textContent!=="undefined"){f.textContent=l.textContent}else{if(l.data){f.innerText=l.data}else{f.innerText=l.innerText}}}else{this.bNeedViewMore=true;if(k<this.nWords&&this.nWordsCounter>this.nWords){if(typeof l.textContent!=="undefined"){f.textContent=this.getOnlyNumberOfWords(l.textContent,(this.nWords-k))}else{if(l.data){f.innerText=this.getOnlyNumberOfWords(l.data,(this.nWords-k))}else{f.innerText=this.getOnlyNumberOfWords(l.innerText,(this.nWords-k))}}}else{if(b.body.textContent){f.textContent=""}else{f.innerText=""}}}}if(l.hasChildNodes()){f.childNodes={};o=0;j=l.childNodes.length;for(;o<j;o+=1){if(!this.bBreakFound&&this.serializeDomObject(l.childNodes[o],f.childNodes)===false){break}}}if(typeof i==="undefined"){this.oSerialized[g]=f}else{i[g]=f}}};d.prototype.addEvent=function(f,h,g){if(f.addEventListener){f.addEventListener(h,g,false)}else{if(f.attachEvent){f.attachEvent("on"+h,g)}}};d.prototype.preventDefault=function(f){if(typeof f.preventDefault!=="undefined"){f.preventDefault()}else{if(typeof f.cancelBubble!=="undefined"){f.returnValue=false}}};d.prototype.hasForceBreak=function(){var h=this.oBackupApplyTo.innerHTML.replace(/\t/g,"");var g=h.indexOf(this.sForceBreakData);var f=h.length-(this.sForceBreakData.length+7);if(g!==-1){if(g+1<f){this.bNeedViewMore=true}this.bForceBreak=true}};d.prototype.setBehaviour=function(){var f=this;this.addEvent(this.oViewMore,"click",function(g){f.preventDefault(g);f.showAll();return false})};d.prototype.showAll=function(){var f=this.oTarget,g=f.parentNode;g.insertBefore(this.oBackupApplyTo,f);g.removeChild(f)};d.prototype.setDots=function(f){if(!f){return this}if(f.nodeType!==3&&(f.innerText||f.textContent).length>0){f.appendChild(b.createTextNode("..."))}};d.prototype.init=function(){var f=null;this.fpBeforeCallback();this.hasForceBreak();this.serializeDomObject(this.oApplyTo);this.deserializeSerializedObject();f=this.oDocumentFragment.childNodes[0];f.removeChild(this.oDocumentFragment.childNodes[0].childNodes[0]);this.oTarget.innerHTML="";this.createViewMore();var g=this.oDocumentFragment.childNodes[0].childNodes[this.oDocumentFragment.childNodes[0].childNodes.length-1];if(g){this.setDots()}if(this.bNeedViewMore&&!this.bNotViewMore){f.appendChild(this.oViewMore);this.setBehaviour()}this.oTarget.appendChild(this.oDocumentFragment);this.fpAfterCallback()};d.run=function(l,g,k,h,j,f){var i=new d();i.applyTo(l).setTarget(g).setWords(k);if(typeof h!=="undefined"){i.setTexts(h)}if(typeof j!=="undefined"){i.setClasses(j)}if(typeof f!=="undefined"){i.setDinamicClass(f)}i.init()};c.Cutter=d}(window,document));
/* @end JAVASCRIPT cutter */

/* @JAVASCRIPT homePageAnswers */
Core.register("homePageAnswers",function(a){return{init:function(){this.cutActivityList();this.createLinks();a.listen([],this.handleNotification,this)},cutActivityList:function(){var e=$.makeArray($(".answer_body p",document.getElementById("activity_list")));var d=e.length;var f=0;var b=45;var c=null;if(d){for(;f<d;f++){c=new Cutter();c.applyTo(e[f]).setWords(b).setTarget(e[f]).setTexts({more:Namespace.utilities.i18n.getText("Read answer")}).init()}}},createLinks:function(){var f=$.makeArray($(".answer_body span.jsurl"));var e=f.length;var b=0;var d=null;var g=null;var c="";for(;b<e;b++){g=f[b];c=html_entity_decode(g.innerHTML);d=document.createElement("a");d.href=c;d.title=c;d.innerHTML=g.innerHTML;g.innerHTML="";g.appendChild(d);$(d).bind("click",this.openExternalUrl)}g=nElements=e=d=null},openExternalUrl:function(){window.open(this.href);return false},handleNotification:function(b){},destroy:function(){a.stopListen([],this)}}});
/* @end JAVASCRIPT homePageAnswers */
/* js_templates_placeholder */