function getElementsByClass(classe)
{var divs=document.getElementsByTagName('div');var resultats=new Array();for(var i=0;i<divs.length;i++)
if(divs[i].className==classe)
resultats.push(divs[i]);return resultats;}
$.fn.bxdolcmtanim=function(action,effect,speed,h)
{return this.each(function()
{var sFunc='';var sEval;if(0==speed)
effect='default';switch(action)
{case'show':switch(effect)
{case'slide':sFunc='slideDown';break;case'fade':sFunc='fadeIn';break;default:sFunc='show';}
break;case'hide':switch(effect)
{case'slide':sFunc='slideUp';break;case'fade':sFunc='fadeOut';break;default:sFunc='hide';}
break;default:case'toggle':switch(effect)
{case'slide':sFunc='slideToggle';break;case'fade':sFunc=($(this).filter(':visible').length)?'fadeOut':'fadeIn';break;default:sFunc='toggle';}}
if((0==speed||undefined==speed)&&undefined==h)
{sEval='$(this).'+sFunc+'();';}
else
if((0==speed||undefined==speed)&&undefined!=h)
{sEval='$(this).'+sFunc+'(); $(this).each(h);';}
else
{sEval='$(this).'+sFunc+"('"+speed+"', h);";}
eval(sEval);return this;});};function BxDolCmts(options)
{this.oCmtElements={};this._sObjName=undefined==options.sObjName?'oCmts':options.sObjName;this._sSystem=options.sSystem;this._iObjId=options.iObjId;this._sActionsUrl=options.sBaseUrl+'cmts.php';this._sDefaultErrMsg=undefined==options.sDefaultErrMsg?'Errod Occured':'';this._sConfirmMsg=undefined==options.sConfirmMsg?'Are you sure?':options.sConfirmMsg;this._isEditAllowed=parseInt(undefined==options.isEditAllowed?0:options.isEditAllowed);this._isRemoveAllowed=parseInt(undefined==options.isRemoveAllowed?0:options.isRemoveAllowed);this._iSecsToEdit=parseInt(undefined==options.iSecsToEdit?0:options.iSecsToEdit);this._oSavedTexts={};this._sAnimationEffect=undefined==options.sAnimationEffect?'slide':options.sAnimationEffect;this._iAnimationSpeed=undefined==options.iAnimationSpeed?'slow':options.iAnimationSpeed;if($('#cmts-box-'+this._iObjId+' > .cmt-post-reply > form').length)
{$('#cmts-box-'+this._iObjId+' > .cmt-post-reply > form')[0].reset();$('#cmts-box-'+this._iObjId+' > .cmt-post-reply > form > [name=CmtParent]').val(0);}
var $this=this;$('#cmts-box-'+this._iObjId).click(function(event)
{var iRate=0;if($(event.target).filter('.cmt-pos').length)
{iRate=1;event.preventDefault();}
else
if($(event.target).filter('.cmt-neg').length)
{iRate=-1;event.preventDefault();}
else
if($(event.target).filter('.cmt-hid').length)
{$this._toggleHidden(event.target,parseInt(event.target.id.substr(8)));event.preventDefault();}
if(0!=iRate&&!$(event.target).parent().filter('.cmt-rate-disabled').length)
{var e=$(event.target).parent().children().filter('span').get(0);$this._rateComment(e,parseInt(event.target.id.substr(8)),iRate);}});}
BxDolCmts.prototype.showMore=function(e,iPerView)
{$('#cmts-box-'+this._iObjId+' > ul > .cmt:hidden:lt('+iPerView+')').bxdolcmtanim('show',this._sAnimationEffect,this._iAnimationSpeed);var n=$('#cmts-box-'+this._iObjId+' > ul > .cmt:hidden').length;if(n==0)
{$('#cmts-box-'+this._iObjId+' > .cmt-show-more').remove();}
else
{var iStart=$('#cmts-box-'+this._iObjId+' > ul > .cmt:visible').length+1;if(n>(iPerView-1))
{$('#cmts-box-'+this._iObjId+' > .cmt-show-more b').html(iStart);$('#cmts-box-'+this._iObjId+' > .cmt-show-more u').html(iStart+iPerView-1);}
else
{$('#cmts-box-'+this._iObjId+' > .cmt-show-more b').html(iStart);$('#cmts-box-'+this._iObjId+' > .cmt-show-more u').html(iStart+n-1);}}}
BxDolCmts.prototype.toggleReply=function(e,iCmtParentId)
{var h=function(){if($(this).filter(':visible').length)
$(this).parent().addClass('cmt-post-reply-expanded');else
$(this).parent().removeClass('cmt-post-reply-expanded');}
if(0==iCmtParentId&&$(e).parent().next('form').length)
{$(e).parent().next('form').bxdolcmtanim('toggle',this._sAnimationEffect,this._iAnimationSpeed,h);}
else if(0!=iCmtParentId)
{if($(e).next('form').length)
$(e).next('form').bxdolcmtanim('toggle',this._sAnimationEffect,this._iAnimationSpeed,h);else
$(e).after($('#cmts-box-'+this._iObjId+' > .cmt-post-reply > form').clone().show().hide()).next('form').bxdolcmtanim('toggle',this._sAnimationEffect,this._iAnimationSpeed,h).children().filter('[name=CmtParent]').val(iCmtParentId);}}
BxDolCmts.prototype.toggleCmts=function(e,iCmtParentId)
{var sId='#cmt'+iCmtParentId;if($(sId+'>ul').length)
{if($(sId+'>ul:visible').length)
{$(sId+'>ul').bxdolcmtanim('hide',this._sAnimationEffect,this._iAnimationSpeed,function(){$(sId+' > .cmt-cont .cmt-replies').removeClass('cmt-replies-hover');$(sId+' > .cmt-cont .cmt-replies .cmt-replies-hide').hide();$(sId+' > .cmt-cont .cmt-replies .cmt-replies-show').show();});}
else
{$(sId+'>ul').bxdolcmtanim('show',this._sAnimationEffect,this._iAnimationSpeed);$(sId+' > .cmt-cont > .cmt-replies').addClass('cmt-replies-hover');$(sId+' > .cmt-cont .cmt-replies .cmt-replies-show').hide();$(sId+' > .cmt-cont .cmt-replies .cmt-replies-hide').show();}}
else
{this._getCmts(e,iCmtParentId,function(){$(sId+' > .cmt-cont .cmt-replies').addClass('cmt-replies-hover');$(sId+' > .cmt-cont .cmt-replies .cmt-replies-show').hide();$(sId+' > .cmt-cont .cmt-replies .cmt-replies-hide').show();});}}
BxDolCmts.prototype.cmtRemove=function(e,iCmtId)
{if(!this._confirm())return;var $this=this;var oData=this._getDefaultActions();oData['action']='CmtRemove';oData['Cmt']=iCmtId;this._loading(e,true);jQuery.get(this._sActionsUrl,oData,function(s)
{$this._loading(e,false);if(jQuery.trim(s).length)
alert(s);else
$('#cmt'+iCmtId).bxdolcmtanim('hide',$this._sAnimationEffect,$this._iAnimationSpeed,function(){$(this).remove();});});}
BxDolCmts.prototype.cmtEdit=function(e,iCmtId)
{var $this=this;var oData=this._getDefaultActions();oData['action']='CmtEdit';oData['Cmt']=iCmtId;if($('#cmt'+iCmtId+'>.cmt-cont>.cmt-body>form').length)
{$('#cmt'+iCmtId+'>.cmt-cont>.cmt-body').removeClass('cmt-post-reply-expanded').bxdolcmtanim('hide',$this._sAnimationEffect,$this._iAnimationSpeed,function(){$(this).html($this._oSavedTexts[iCmtId]).bxdolcmtanim('show',$this._sAnimationEffect,$this._iAnimationSpeed)});return;}
else
{this._oSavedTexts[iCmtId]=$('#cmt'+iCmtId+'>.cmt-cont>.cmt-body').html();}
this._loading(e,true);jQuery.get(this._sActionsUrl,oData,function(s)
{$this._loading(e,false);if('err'==s.substring(0,3))
alert(s.substring(3));else
$('#cmt'+iCmtId+'>.cmt-cont>.cmt-body').bxdolcmtanim('hide',$this._sAnimationEffect,$this._iAnimationSpeed,function(){$(this).html(s).bxdolcmtanim('show',$this._sAnimationEffect,$this._iAnimationSpeed,function(){$(this).addClass('cmt-post-reply-expanded');})});});}
BxDolCmts.prototype._getCmts=function(e,iCmtParentId,h)
{var $this=this;var oData=this._getDefaultActions();oData['action']='CmtsGet';oData['CmtParent']=iCmtParentId;this._loading(e,true);jQuery.get(this._sActionsUrl,oData,function(s)
{h();$('#cmt'+iCmtParentId).append($(s).filter('.cmts').addClass('cmts-margin').hide()).children().filter('.cmts').bxdolcmtanim('show',$this._sAnimationEffect,$this._iAnimationSpeed);$this._loading(e,false);});}
BxDolCmts.prototype._getCmt=function(f,iCmtParentId,iCmtId)
{var $this=this;var oData=this._getDefaultActions();oData['action']='CmtGet';oData['Cmt']=iCmtId;if(0==iCmtParentId)
$('#cmts-box-'+this._iObjId+'>.cmt-post-reply').hide();var eUl=$('#cmts-box-'+$this._iObjId+'>ul').get();this._loading(eUl,true);jQuery.get(this._sActionsUrl,oData,function(s)
{$this._loading(eUl,false);if(0==iCmtParentId)
{$('#cmts-box-'+$this._iObjId+'>ul>.cmt-no').remove();if($('#cmts-box-'+$this._iObjId+'>ul>li.cmt:last').length)
$('#cmts-box-'+$this._iObjId+'>ul>li.cmt:last').after(s);else
$('#cmts-box-'+$this._iObjId+'>ul').html(s);}
else
{if($('#cmt'+iCmtParentId+' > .cmt-cont > .cmt-post-reply-to').length)
{$('#cmt'+iCmtParentId+' > .cmt-cont > .cmt-post-reply-to').replaceWith($(s).addClass('cmts-margin'));}
else
{$('#cmt'+iCmtParentId+' > .cmts > .cmt-reply-to').remove();$('#cmt'+iCmtParentId+'>ul>li:last').after(s);}}
$this._runCountdown(iCmtId);});}
BxDolCmts.prototype.submitComment=function(f,formu)
{var eSubmit=$(f).children().filter(':submit').get();try{var photoID=document.getElementById("photoID").value;}catch(e){;};if(photoID)
this._iObjId=photoID;var $this=this;var oData=this._getDefaultActions();$this._err(eSubmit,false);if(!this._getCheckElements(f,oData))return;oData['action']='CmtPost';oData['fb_feed']=this._sObjName;this._loading(eSubmit,true);jQuery.post(this._sActionsUrl,oData,function(s)
{$this._loading(eSubmit,false);if(!jQuery.trim(s).length)
$this._err(eSubmit,true,$this._sDefaultErrMsg);else{var a=s.split('#');$this._getCmt(f,oData['CmtParent'],parseInt(a[0]));var i_link=String(document.location);var item_link='<a href="'+String(document.location)+'" target="_blank">';switch(a[3]){case'oCmtsArticleposts':var titre="the article '"+item_link+getElementsByClass('captionBlock')[0].innerHTML+"'";var titre_url="the article '"+item_link+getElementsByClass('captionBlock')[0].innerHTML+"</a>'";break;case'oCmtsSharedVideo':var titre="the video '"+String(window.document.title)+"'";var titre_url="the video '"+item_link+String(window.document.title)+"</a>'";break;case'oCmtsBlogposts':var titre="the blog post '"+String(window.document.title)+"'";var titre_url="the blog post '"+item_link+String(window.document.title)+"</a>'";break;case'oCmtsSharedMusic':var titre="the music '"+String(window.document.title)+"'";var titre_url="the music '"+item_link+String(window.document.title)+"</a>'";break;case'oCmtsProfile':var titre=String(window.document.title);titre=(titre.split(':'))[0]+"'s profile";var titre_url=item_link+titre+"</a>";break;case'oCmtsClassifieds':var titre="a classified";var titre_url=item_link+"a classified"+"</a>";break;case'oCmtsSharedPhoto':var titre="the photo '"+String(window.document.title)+"'";var titre_url="the photo '"+item_link+String(window.document.title)+"</a>'";break;case'oCmtsPhoto':var titre="a profile picture";var titre_url=item_link+"a profile picture"+"</a>";break;}
var text=document.getElementsByName("CmtText")[0].value;var comment_data={"title":titre,"title_url":titre_url,"text":text,"url":i_link};FB_RequireFeatures(["Connect"],function(){FB.init("31a47c66e3cde51d3a2edda892c427ac","xd_receiver.htm");if(a[1]==-1)
FB.Connect.showFeedDialog(195839626396,comment_data);else
FB.Connect.showFeedDialog(195839636396,comment_data,a[1]);});}});}
BxDolCmts.prototype.updateComment=function(f,iCmtId)
{var eSubmit=$(f).children().filter(':submit').get();var $this=this;var oData=this._getDefaultActions();$this._err(eSubmit,false);if(!this._getCheckElements(f,oData))return;this._oSavedTexts[iCmtId]='';oData['action']='CmtEditSubmit';oData['Cmt']=iCmtId;this._loading(eSubmit,true);jQuery.post(this._sActionsUrl,oData,function(s)
{$this._loading(eSubmit,false);if(!jQuery.trim(s).length)
$this._err(eSubmit,true,$this._sDefaultErrMsg);else
$('#cmt'+iCmtId+'>.cmt-cont>.cmt-body').bxdolcmtanim('hide',$this._sAnimationEffect,$this._iAnimationSpeed,function(){$(this).removeClass('cmt-post-reply-expanded').html(s).bxdolcmtanim('show',$this._sAnimationEffect,$this._iAnimationSpeed);});});}
BxDolCmts.prototype._toggleHidden=function(e,iCmtId)
{$('#cmt'+iCmtId+' > .cmt-cont').bxdolcmtanim('toggle',this._sAnimationEffect,this._iAnimationSpeed);}
BxDolCmts.prototype._rateComment=function(e,iCmtId,iRate)
{var $this=this;var oData=this._getDefaultActions();oData['action']='CmtRate';oData['Cmt']=iCmtId;oData['Rate']=iRate;this._loading(e,true);jQuery.get(this._sActionsUrl,oData,function(s)
{$this._loading(e,false);if(jQuery.trim(s).length)
{alert(s);}
else
{e.innerHTML=parseInt(e.innerHTML)+iRate;$(e).parent().addClass('cmt-rate-disabled');if(0>iRate)
$('#cmt'+iCmtId+'>.cmt-cont').bxdolcmtanim('hide',$this._sAnimationEffect,$this._iAnimationSpeed);}});}
BxDolCmts.prototype._getCheckElements=function(f,oData)
{var $this=this;var bSuccess=true;jQuery.each($(f).children().filter(':input'),function()
{if(this.name.length&&$this.oCmtElements[this.name])
{var isValid=true;if($this.oCmtElements[this.name]['reg'])
{try{eval('var isValid = this.value.match('+$this.oCmtElements[this.name]['reg']+');');}catch(ex){};}
if(!isValid)
{bSuccess=false;$this._err(this,true,$this.oCmtElements[this.name]['msg']);}
else
{$this._err(this,false);}
oData[this.name]=this.value;}});return bSuccess;}
BxDolCmts.prototype._runCountdown=function(iCmtId)
{if(this._isEditAllowed||this._isRemoveAllowed||0==this._iSecsToEdit)return;$('#cmt-jp-'+iCmtId+' span').html(this._iSecsToEdit);window.setTimeout(this._sObjName+'.onCountdown('+iCmtId+','+this._iSecsToEdit+');',1000);}
BxDolCmts.prototype.onCountdown=function(iCmtId,i)
{var i=parseInt($('#cmt-jp-'+iCmtId+' span').html());if(0==--i)
{$('#cmt-jp-'+iCmtId).remove();return;}
else
{$('#cmt-jp-'+iCmtId+' span').html(i);window.setTimeout(this._sObjName+'.onCountdown('+iCmtId+','+i+');',1000);}}
BxDolCmts.prototype._loading=function(e,bShow)
{if(bShow&&!$(e).next('b').length)
$(e).after(' <b>Loading...</b>');else if(!bShow&&$(e).next('b').length)
$(e).next('b').remove();}
BxDolCmts.prototype._err=function(e,bShow,s)
{if(bShow&&!$(e).next('.cmt-err').length)
$(e).after(' <b class="cmt-err">'+s+'</b>');else if(!bShow&&$(e).next('.cmt-err').length)
$(e).next('.cmt-err').remove();}
BxDolCmts.prototype._confirm=function()
{return confirm(this._sConfirmMsg);}
BxDolCmts.prototype._getDefaultActions=function()
{return{'sys':this._sSystem,'id':this._iObjId};}