
var gselectedNote=null;function NMCommAddNote(win,doc,url)
{var left=rand(500);var top=rand(200);if(win.getSelection)
{var select=win.getSelection();if(select!="")
{var range=select.getRangeAt(0);var anchor=win.selection.anchorNode;}}
else
{var select=doc.selection;if(select)
{var range=select.createRange();left=range.offsetLeft;top=range.offsetTop;doc.execCommand('Unselect');}}
var url0=UrlEncode(url);var content=prompt("Please enter your comments here","My Text");if(!content||content.length==0)
{return;}
var note=new Array();note['content']=content;note['x']=left;note['y']=top;var pub=1;var reqContent="content="+UrlEncode(content)
+"&x="+left
+"&y="+top
+"&pub="+pub;var url=gnmcommurl+"&func=note_add($uid,$rid,$_REQUEST)@noteadd"+"&xml=1"
+"&url="+UrlEncode(url);NMXmlRequest(url,'POST',reqContent,function(xmlObj)
{var errmsg=NMRequestErrGUI_Handler(xmlObj);if(errmsg!="")
return;var obj=XML_selectSingleNode("//noteadd",xmlObj);note['noteid']=obj.childNodes[0].nodeValue;note['noteid']=obj.childNodes[0].nodeValue;note['rid']=grsr['rid'];note['uid']=gme['uid'];note['login']=gme['login'];note['ts']='';note['title']='';NoteAddItem(win,doc,note);});}
function NMCommUpdateNote(win,doc,url)
{if(gselectedNote==null)
{alert("Please select a note first");return;}
var note=null;try{note=gselectedNote.mydata;}catch(err){alert("Please Select a note before updating first");return;}
var content=prompt("Please enter your updated comments here",note['content']);if(!content||content.length==0)
{return;}
var img=doc.getElementById('note_img_'+note['noteid']);var div=doc.getElementById('note_div_'+note['noteid']);if(img.style.pixelLeft)
{note['x']=img.style.pixelLeft;note['y']=img.style.pixelTop;}else
{note['x']=parseInt(img.style.left);note['y']=parseInt(img.style.top);}
note['content']=content;var reqContent="content="+UrlEncode(note['content'])
+"&x="+note['x']
+"&y="+note['y'];var commurl=gnmcommurl+"&func=note_update($uid,"+note['noteid']+",$_REQUEST)@noteupdate"+"&xml=1"
+"&url="+UrlEncode(url);NMXmlRequest(commurl,'POST',reqContent,function(xmlObj)
{var errmsg=NMRequestErrGUI_Handler(xmlObj);if(errmsg!="")
return;NoteHideItem(doc,note['noteid']);NoteRemoveItem(doc,note['noteid']);NoteAddItem(win,doc,note);});}
function NMCommDelNote(win,doc,url)
{if(gselectedNote==null)
{alert("Please select a note first");return;}
var note=null;try{note=gselectedNote.mydata;}catch(err){alert("Please Select a note before updating first");return;}
if(note['uid']!=gme['uid'])
{alert("You cannot delete notes from others");return;}
var res=confirm("Are you sure to delete this note");if(!res)
return;var url=gnmcommurl+"&func=note_del(1,"+note['noteid']+")"+"&xml=1";NMXmlRequest(url,'GET',null,function(xmlObj)
{var errmsg=NMRequestErrGUI_Handler(xmlObj);if(errmsg!="")
return;NoteHideItem(doc,note['noteid']);NoteRemoveItem(doc,note['noteid']);});}
function NMCommGetNotes(win,doc,url,ui)
{var commurl=gnmcommurl+"&func=note_list($uid,$rid,0,10)@notes"+"&xml=1"
+"&url="+url;NMXmlRequest(commurl,'GET',null,function(xmlObj)
{NMCommGetNotes_Handler(xmlObj,win,doc,ui);});gselectedNote=null;}
function NMCommGetNotes_Handler(xmlObj,win,doc,ui)
{var errmsg=NMRequestErr_Handler(xmlObj,ui);if(errmsg!="")
{NMCommSetMsg(errmsg);return-1;}
items=XML_selectNodes('//notes/item',xmlObj);if(items==null||items.length==0)
return 0;for(var i=0;i<items.length;i++)
{var note=XmlNodeToArray(items[i]);NoteAddItem(win,doc,note);}
return items.length;}
function NoteToggleAll(doc,show)
{gselectedNote=null;if(show)
{NoteShowAll(doc);}else
{NoteHideAll(doc);}}
function NoteShowAll(doc)
{gselectedNote=null;var ids=ObjGetAllIds(doc,"div","note_div_");if(!ids)
{return;}
for(var id in ids)
{NoteShowItem(doc,id);}}
function NoteHideAll(doc)
{gselectedNote=null;var ids=ObjGetAllIds(doc,"div","note_div_");if(!ids)
{return;}
for(var id in ids)
{NoteHideItem(doc,id);}}
function NoteRemoveAll(doc)
{var ids=ObjGetAllIds(doc);for(var id in ids)
{NoteRemoveItem(doc,id);}}
function NoteShowItem(doc,id)
{var img=doc.getElementById('note_img_'+id);if(!img)
return;img.style.visibility='visible';}
function NoteHideItem(doc,id)
{var div=doc.getElementById('note_div_'+id);var img=doc.getElementById('note_img_'+id);if(!img||!div)
return;div.style.visibility='hidden';img.style.visibility='hidden';}
function NoteShowText(doc,id)
{var div=doc.getElementById('note_div_'+id);var img=doc.getElementById('note_img_'+id);if(div&&img)
{ObjMoveBy(div,0,0,img);div.style.visibility='visible';}}
function NoteHideText(doc,id)
{var div=doc.getElementById('note_div_'+id);if(div)
{div.style.visibility='hidden';}}
function NoteRemoveItem(doc,id)
{RemoveObjById(doc,'note_div_'+id);RemoveObjById(doc,'note_img_'+id);}
function NoteGetDivHtml(note)
{var html="";html+="<B>"+note['login']+"</B>"+"&nbsp;"
+note['ts']+"<BR>"
+note['content'];return html;}
function NoteAddItem(win,doc,note)
{var id=note['noteid'];var left=note['x'];var top=note['y'];if(left<0)left=20;if(top<0)top=20;var html=NoteGetDivHtml(note);var obj=doc.getElementById("note_div_"+id);if(obj!=null)
{NoteShowItem(doc,id);return null;}
var newDiv=WinAppendHtml2(win,doc,doc.body,"DIV",html);newDiv.id="note_div_"+id;newDiv.style.position="absolute";newDiv.style.top=top+((isIE)?"":"px");newDiv.style.left=left+((isIE)?"":"px");newDiv.style.padding=20;newDiv.style.backgroundColor="lightgreen";if(!isIE5)
{newDiv.style.filter="alpha(opacity=50)";}
newDiv.style.visibility="hidden";var newImg=WinAppendHtml2(win,doc,doc.body,"IMG","");newImg.id="note_img_"+id;newImg.src=gnmcommfileurl+'/img/markerJie.gif';newImg.style.position=(isIE)?"absolute":"fixed";newImg.style.top=top+((isIE)?"":"px");newImg.style.left=left+((isIE)?"":"px");newImg.style.width=30;newImg.style.height=30;newImg.style.filter="alpha(opacity=50)";newImg.style.zIndex=10000000;EventCatch(newImg,"mouseover",function(e){NoteShowText(doc,id);});EventCatch(newImg,"mouseout",function(e){NoteHideText(doc,id);});EventCatch(newImg,"mousedown",function(e){gselectedNote=EventGetSrc(win,e);});newImg.mydata=note;if(gme!=null&&note['uid']==gme['uid'])
{newImg.style.backgroundColor="lightgreen";if(g_drag)
{g_drag.add(newImg);}}
return newImg;}