﻿var onCommentUpdate=null,commentCount=0,v_newcomment=null;
service=Soap.RegisterService(_APPROOT+"/webservices/CommentService.ashx","http://www.17you8.com/webservice","WebServices.CommentService");
Soap.RegisterMethod(service,"GetComments","type","id","startIndex","count");
Soap.RegisterMethod(service,"AddNewComment","type","id","treeid","replyid","content","x","y","z","speed","location","accuracy","ip");
function clearNewComment(){$("commentform").reset();}
function comment(t,i,tid,rid){
var tid=(arguments.length>2)?parseInt(arguemnts[2]):0,rid=(arguments.length>3)?parseInt(arguments[3]):0;
if(isNaN(tid))tid=0;
if(isNaN(rid))rid=0;
if(!v_newcomment){var div=document.createElement("div");
div.innerHTML='<form id="commentform" action="" onsubmit="return false" class="innercontent"><h2 id="commenttitle">发表评论</h2><input type="hidden" id="targetid" value="'+i+'" /><input type="hidden" id="commenttype" value="'+t+'" /><input type="hidden" id="treeid" value="'+tid+'" /><input type="hidden" id="replyid" value="'+rid+'" /><textarea id="commentcontent" rows="4" cols="30"></textarea><p><a id="savecmt" class="normal" href="javascript:beginSaveNewComment()">发 布</a><a id="resetcmt" class="normal" href="javascript:clearNewComment()">清 除</a><a id="cancelcmt" class="normal" href="javascript:cancelComment()">取 消</a></p></form>';
BODY().appendChild(div);SetupMacButton("savecmt","resetcmt","cancelcmt");v_newcomment=new Validation($("commentform"),"allerrorbox");
v_newcomment.addValidation("commentcontent","length:{1,500}","请填写评论的内容。","评论的字数不能超过500字。");}
v_newcomment.reset();$("commenttitle").innerHTML="发表评论";$("commenttype").value=t;$("targetid").value=i;
openInnerWindow("commentform",5);GetCurrentPosition()}
function cancelComment(){$("commentcontent").blur();closeInnerWindow("commentform");}
function beginSaveNewComment(){if(v_newcomment.disabled)return;
if(v_newcomment.validate()){
WebServices.CommentService.AddNewComment($("commenttype").value,$("targetid").value,$("treeid").value,$("replyid").value,$("commentcontent").value,
currentPosition.x,currentPosition.y,currentPosition.z,currentPosition.speed,currentPosition.location,currentPosition.accuracy,currentPosition.ip,endSaveNewComment,onError,function(r){alert(r)});
BeginProcessing("处理中……",2,v_newcomment.form);}}
var CommentTemplate=new Array();
CommentTemplate["List"]='<li><a href="javascript:j(\'user\',{USERID})" class="userhead"><img src="{USERPATH}/userhead.jpg" onerror="this.style.visibility=\'hidden\'" /></a><div class="content"><h5><a href="javascript:j(\'user\',{USERID})">{USERIDNICKNAME}</a>{CONTENT}</h5><p>@{LOCATION} - {TIMEAGO}前</p></div></li>';
function endSaveNewComment(result){switch(parseInt(result)){
case 0:CloseProcessing("评论成功。");closeInnerWindow("commentform");if(onCommentUpdate!=null){setTimeout("onCommentUpdate()",500);}break;
case -1:CloseProcessing("系统忙，请稍候再试。");break;
case -3:
default:
CloseProcessing("系统忙，请稍候再试。");break;}}
function GetComments(id,f,p,startIndex,count,success,error){WebServices.CommentService.GetComments(itemType,itemId,startIndex,count,success,error);return true}

