/* Copyright (C) 2009 Microsoft Corporation */registerNamespace("Live_CommentControl");Live_CommentControl.focus=function(d){var a=_ge("sn_ccText"+d);if(a){var b=Live_CommentControl._getRte(a);if(b)b.Redisplay();else{function c(){try{a.focus()}catch(b){}}setTimeout(c,0)}}};Live_CommentControl._getRte=function(a){var c=null;if(a.webBindings&&a.webBindings.length>0)for(var b=0;b<a.webBindings.length;b++)if(a.webBindings[b].getType()=="$UI.Editor")c=a.webBindings[b];return c};Live_CommentControl._Error={Delete:"delete",PleaseWait:-2,Empty:-1,None:0,GeneralError:1,CommentTooLong:2,ManagedAsk:3,Managed:4,AbuseDisallowed:5,AbuseBanned:6,AbuseHip:7};Live_CommentControl.AddComment=function(id,PrePostFunction){var params={},elContentBox=_ge("sn_ccText"+id),hasRTE=Live_CommentControl._RecopyRTE(elContentBox),content=elContentBox.value,maxlength=elContentBox.getAttribute("maxlength"),canPost,additionalParams;if(Live_CommentControl._State&&Live_CommentControl._State.inProgress)canPost=false;else if(Live_CommentControl._EmptyTest(content,hasRTE))Live_CommentControl._DisplayErr(id,Live_CommentControl._Error.Empty);else if(content.length>maxlength)Live_CommentControl._DisplayErr(id,Live_CommentControl._Error.CommentTooLong);else if(PrePostFunction){var returnVal=eval(PrePostFunction);canPost=returnVal.CanPost;additionalParams=returnVal.AdditionalParams}else canPost=true;if(canPost){var htype=_ge("sn_ccHType"+id).value;if(!hasRTE)params["htype"]="Plaintext";else params["htype"]=htype;params["content"]=content;params["method"]="Add";params["cnsid"]=_ge("sn_ccParentId"+id).value;params["can"]=_ge("sn_ccCan"+id).value;var elHipInput=_ge("sn_hipInput");if(elHipInput)params["hiptext"]=elHipInput.value;Live_CommentControl._Post(id,Live_CommentControl._MergeParams(additionalParams,params),params["method"])}};Live_CommentControl._EmptyTest=function(b,d){var c;if(d){var a=document.createElement("div");a.innerHTML=b;var c=0!=a.innerText.trim().length||0!=a.getElementsByTagName("IMG").length||0!=a.getElementsByTagName("EMBED").length;a.innerHTML=""}else c=b!=null&&b.trim().length!=0;return !c};Live_CommentControl._DisplayErr=function(a,c){var m=_ge("sn_ccErrEmpty"+a),k=_ge("sn_ccErrLong"+a),i=_ge("sn_ccAddErrManaged"+a),h=_ge("sn_ccAddErrManagedAsk"+a),j=_ge("sn_ccAddErrGeneral"+a),l=_ge("sn_ccDeleteErr"+a),f=_ge("sn_ccWait"+a),d=_ge("sn_ccAbuseNo"+a),e=_ge("sn_ccAbuseBan"+a),g=_ge("sn_ccAbuseHip"+a),b=c;if(c==Live_CommentControl._Error.ManagedAsk){h.style.display="";b=false}else h.style.display="none";if(c==Live_CommentControl._Error.Managed){i.style.display="";b=false}else i.style.display="none";if(c==Live_CommentControl._Error.Delete){l.style.display="";b=false}else l.style.display="none";if(c==Live_CommentControl._Error.Empty){m.style.display="";b=false}else m.style.display="none";if(c==Live_CommentControl._Error.CommentTooLong){k.style.display="";b=false}else k.style.display="none";if(c==Live_CommentControl._Error.PleaseWait){f.style.display="";b=false;var n=_ge("sn_ccHip"+a);if(n)n.style.display="none"}else f.style.display="none";if(c==Live_CommentControl._Error.AbuseDisallowed){d.style.display="";b=false}else d.style.display="none";if(c==Live_CommentControl._Error.AbuseBanned){e.style.display="";b=false}else e.style.display="none";if(c==Live_CommentControl._Error.AbuseHip){g.style.display="";b=false}else g.style.display="none";if(b)j.style.display="";else j.style.display="none"};Live_CommentControl.DeleteComment=function(index,id,PrePostFunction,promptstr){var canPost=true,additionalParams;if(Live_CommentControl._State&&Live_CommentControl._State.inProgress)canPost=false;else if(PrePostFunction){var returnVal=eval(PrePostFunction);canPost=returnVal.CanPost;additionalParams=returnVal.AdditionalParams}else canPost=true;if(canPost){var okToDelete=confirm(promptstr);if(okToDelete){var params={};params["method"]="Delete";params["cnsid"]=document.getElementById("sn_ccId"+id+index).value;params["can"]=document.getElementById("sn_ccCan"+id).value;Live_CommentControl._Post(id,Live_CommentControl._MergeParams(additionalParams,params),params["method"])}}};Live_CommentControl._MergeParams=function(d,e){var b={},c="";if(e)for(var a in e)b[a]=e[a];if(d)for(var a in d)b[a]=d[a];for(var a in b){var f="";if(c)f="&";c+=f+a+"="+(b[a]+"").encodeURIComponent()}return c};Live_CommentControl._PostResponse=function(c){var b=Live_CommentControl._Error.GeneralError,g,h,f=false;try{f=c&&c.status==200}catch(n){f=false}if(f)if(c.responseText&&c.responseText.length>0){var d=c.responseText.split("#",4);b=parseInt(d[0]);if(d.length>=3&&d.length<=5){g=d[1].replace(/\*2/g,"#").replace(/\*1/g,"*");h=d[2].replace(/\*2/g,"#").replace(/\*1/g,"*")}if(isNaN(b))b=Live_CommentControl._Error.GeneralError}if(Live_CommentControl._State.method=="Add"){if(b==Live_CommentControl._Error.AbuseHip)if(!g||!h)b=Live_CommentControl._Error.GeneralError;else{var l=document.getElementById("sn_ccHip"+Live_CommentControl._State.id);l.style.display="";l.innerHTML=g;$newScript(h)}}else if(b)b=Live_CommentControl._Error.Delete;if(b){Live_CommentControl._DisplayErr(Live_CommentControl._State.id,b);Live_CommentControl._State.inProgress=false}else{function k(a){return a.toUpperCase().replace(new RegExp("/","g"),"").replace(new RegExp("\\\\","g"),"")}var a=_ge("sn_ccPRet"+Live_CommentControl._State.id).value;if(k(a).indexOf(k(location.pathname))>=0){var j=Math.floor(Math.random()*1e4),m=/([\?\&]ccr=)[^\?\&\#]*/;if(m.test(a))a=a.replace(m,"$1"+j);else{var e;if(a.indexOf("?")>=0)e="&ccr="+j;else e="?ccr="+j;var i=a.indexOf("#");if(i==-1)a=a+=e;else a=a.substring(0,i)+e+a.substring(i,a.length)}}location.href=a}};Live_CommentControl._Post=function(a,c,e){Live_CommentControl._State={inProgress:true,id:a,method:e};Live_CommentControl._DisplayErr(a,Live_CommentControl._Error.PleaseWait);var d=document.getElementById("sn_ccPostUrl"+a).value,b={};b["Content-Type"]="application/x-www-form-urlencoded";$Network.fetchXML(d,Live_CommentControl._PostResponse,"POST",c,b)};Live_CommentControl._RecopyRTE=function(b){var a;a=Live_CommentControl._getRte(b);if(a){b.value=a.getValue();return true}return false}