
JSOC=function(){var Cache={};return{"get":function(n){var obj={},val=Cache[n];obj[n]=val;if(val)return obj;},"getMulti":function(l){var a=[];for(var k in l)a.push(this.get(l[k]));return a;},"getType":function(t){var a=[];for(var o in Cache)if(typeof(Cache[o])==t.toLowerCase()){a.push(this.get(o))}
return a;},"set":function(n,v){if(Cache[n])delete(Cache[n]);Cache[n]=v;if(arguments[2]){var ttl=arguments[2].ttl||null;if(ttl)var self=this,to=setTimeout(function(){self.remove(n)},ttl);}
return(Cache[n])?1:0;},"add":function(n,v){if(!Cache[n]){Cache[n]=v;if(arguments[2]){var ttl=arguments[2].ttl||null;if(ttl)var self=this,to=setTimeout(function(){self.remove(n)},ttl);}
return(Cache[n])?1:0;}},"replace":function(n,v){if(Cache[n]){delete(Cache[n]);Cache[n]=v;if(arguments[2]){var ttl=arguments[2].ttl||null;if(ttl)var self=this,to=setTimeout(function(){self.remove(n)},ttl);}
return(Cache[n])?1:0;}},"remove":function(n){delete(Cache[n]);return(!Cache[n])?1:0;},"flush_all":function(){for(var k in Cache)delete(Cache[k]);return 1;}}}
var _editingComments=new Object();function getFullComment(container,id,isThread){if(isThread)
url=base_url+"getcommentmsg/?id="+id;else
url=base_url+"getcomment/?id="+id;$('#'+container).load(url);}
function markAsFavorite(tipID){$.ajax({url:base_url+"markfavorite/",data:"id="+tipID,dataType:"html",success:function(html){markedTipAsFavorite();}});}
function markAsInappropiate(id,isThread){if(isThread)
var url_ajax=base_url+"markinappropiatethread/";else
var url_ajax=base_url+"markinappropiate/";$.ajax({url:url_ajax,data:"id="+id,dataType:"html",success:function(html){if(isThread)
markedMsgAsInappropiate();else
markedTipAsInappropiate();}});}
function editComment(id,comment_id,comment_position,isThread){_editingComments[comment_id]=new Object();_editingComments[comment_id].metaHTML=$("#cmetaid-"+comment_id).html();_editingComments[comment_id].bodyHTML=$("#cbodyid-"+comment_id).html();if(isThread){var url_post=base_url+"edit_comment_form_thread/";var dades_url="msg_id="+id+"&comment_id="+comment_id+"&comment_position="+comment_position;}else{var url_post=base_url+"edit_comment_form/";var dades_url="tip_id="+id+"&comment_id="+comment_id+"&comment_position="+comment_position;}
$.ajax({url:url_post,type:"POST",data:dades_url,dataType:"html",success:function(htmlResponse){if(htmlResponse=="0"){editCommentError();}else{$("#cmetaid-"+comment_id).html("");$("#cbodyid-"+comment_id).html(htmlResponse);$("#cbodyid-"+comment_id).css("height","205");document.getElementById("commentedit-"+comment_id).focus();}}});}
function cancelEditComment(comment_id){$("#cmetaid-"+comment_id).html(_editingComments[comment_id].metaHTML);$("#cbodyid-"+comment_id).html(_editingComments[comment_id].bodyHTML);_editingComments[comment_id]=undefined;}
function markCommentAsInappropiate(commentID,isThread){if(isThread)
var url_post=base_url+"markcommentinappropiatethread/";else
var url_post=base_url+"markcommentinappropiate/";$.ajax({url:url_post,data:"id="+commentID,dataType:"html",success:function(html){markedCommentAsInappropiate(commentID);}});}
function tooltip(){}
tooltip.id="tooltip";tooltip.main=null;tooltip.offsetx=10;tooltip.offsety=10;tooltip.shoffsetx=8;tooltip.shoffsety=8;tooltip.x=0;tooltip.y=0;tooltip.tooltipShadow=null;tooltip.tooltipText=null;tooltip.title_saved='';tooltip.saveonmouseover=null;tooltip.timeout=null;tooltip.active=false;tooltip.elementInitialWidth=0;tooltip.cache=new JSOC();tooltip.ie=(document.all)?true:false;if(tooltip.ie)tooltip.ie5=(navigator.userAgent.indexOf('MSIE 5')>0);else tooltip.ie5=false;tooltip.dom2=((document.getElementById)&&!(tooltip.ie5))?true:false;tooltip.show=function(event,text){if(this.dom2==false)return false;if(this.tooltipShadow==null){this.tooltipShadow=document.createElement("div");this.tooltipShadow.setAttribute("id","tooltip-shadow");document.body.appendChild(tooltip.tooltipShadow);this.tooltipText=document.createElement("div");this.tooltipText.setAttribute("id","tooltip-text");document.body.appendChild(this.tooltipText);}
this.saveonmouseover=document.onmousemove;document.onmousemove=this.mouseMove;this.elementInitialWidth=this.tooltipText.scrollWidth;this.mouseMove(event);this.setText(text);this.tooltipText.style.visibility="visible";this.tooltipShadow.style.visibility="visible";this.active=true;return false;}
tooltip.setText=function(text){tooltip.tooltipShadow.style.width=0+"px";tooltip.tooltipShadow.style.height=0+"px";this.tooltipText.innerHTML=text;setTimeout('tooltip.setShadow()',1);return false;}
tooltip.setShadow=function(){tooltip.tooltipShadow.style.width=tooltip.tooltipText.clientWidth+"px";tooltip.tooltipShadow.style.height=tooltip.tooltipText.clientHeight+"px";}
tooltip.hide=function(event){if(this.dom2==false)return false;document.onmousemove=this.saveonmouseover;this.saveonmouseover=null;if(this.tooltipShadow!=null){this.tooltipText.style.visibility="hidden";this.tooltipShadow.style.visibility="hidden";this.tooltipText.innerHTML='';}
this.active=false;}
tooltip.mouseMove=function(e){if(tooltip.ie){tooltip.x=event.clientX;tooltip.y=event.clientY;}else{tooltip.x=e.pageX;tooltip.y=e.pageY;}
tooltip.moveTo(tooltip.x+tooltip.offsetx,tooltip.y+tooltip.offsety);}
tooltip.moveTo=function(xL,yL){if(this.ie){xL+=document.documentElement.scrollLeft;yL+=document.documentElement.scrollTop;}
if(this.elementInitialWidth>0&&document.documentElement.clientWidth>0&&xL>document.documentElement.clientWidth*0.6){xL=xL-this.elementInitialWidth-2*this.offsetx;}
this.tooltipText.style.left=xL+"px";this.tooltipText.style.top=yL+"px";xLS=xL+this.shoffsetx;yLS=yL+this.shoffsety;this.tooltipShadow.style.left=xLS+"px";this.tooltipShadow.style.top=yLS+"px";}
tooltip.c_show=function(event,type,element,link){if(this.dom2==false)return false;if(type=='id'){target_text='comment-'+element;target_author='cauthor-'+element;target=document.getElementById(target_text);author_target=document.getElementById(target_author);if(!target||!author_target)return false;text='<strong>'+author_target.innerHTML+'</strong><br/>'+target.innerHTML;}else if(type=='order'){this.ajax_delayed(event,'get_comment_tooltip',element+"&link="+link);return;}else{text=element;}
return this.show(event,text);}
tooltip.clear=function(event){if(this.timeout!=null){clearTimeout(this.timeout);this.timeout=null;}
this.hide(event);}
tooltip.ajax_delayed=function(event,script,id,maxcache){maxcache=maxcache||600000;if(this.active)return false;if((object=this.cache.get(script+id))!=undefined){tooltip.show(event,object[script+id]);}else{this.show(event,'loading...');this.timeout=setTimeout("tooltip.ajax_request('"+script+"', '"+id+"', "+maxcache+")",100);}}
tooltip.ajax_request=function(script,id,maxcache){var url=base_url+'ajax/'+script+'?id='+id;alert("ajax tooltip call "+url);tooltip.timeout=null;$.ajax({url:url,dataType:"html",success:function(html){tooltip.cache.set(script+id,html,{'ttl':maxcache});tooltip.setText(html);}});}
function applyTag(id,tag){obj=document.getElementById(id);if(obj)wrapText(obj,tag,tag);}
function wrapText(obj,tag){if(typeof obj.selectionStart=='number'){var start=obj.selectionStart;var end=obj.selectionEnd;if(start==end||end<start)return false;obj.value=obj.value.substring(0,start)+replaceText(obj.value.substring(start,end),tag)+obj.value.substring(end,obj.value.length);}else if(document.selection){obj.focus();var range=document.selection.createRange();if(range.parentElement()!=obj)return false;if(range.text=="")return false;if(typeof range.text=='string')
document.selection.createRange().text=replaceText(range.text,tag);}else
obj.value+=text;}
function replaceText(text,tag){text=text.replace(/(^|\s)[\*_]([^\s]+)[\*_]/gm,'$1$2')
text=text.replace(/([^\s]+)/gm,tag+"$1"+tag)
return text;}
