﻿function PhotoPage_AddPicComments()
{
    var cPhotoID = $("#Photo_ID").text();
    $.post("AddPhotoComments.ashx", { AppEntryID:"APPID_ALBUM_COMMENTS",TargetID:cPhotoID,FatherID:"/",Title:$("#Comment_Title").val(),Content:$("#Comment_Content").val(),Format:"Txt"}, function(data){ ShowMsg(data) ; RefreshAlbumCommentsList(cPhotoID);});
}
function PhotoPage_AddPicIdentMemo(cCMD,cMemo)
{
    var cPhotoID = $("#Photo_ID").text();
    var cTitle = "";
    if (cCMD=="Delete") cTitle="【自动备注】删除鉴定单";
    if (cCMD=="SetDefault") cTitle="【自动备注】采纳鉴定单";
    $.post("/User/AddPhotoComments.ashx", { AppEntryID:"APPID_ALBUM_CMDMEMO",TargetID:cPhotoID,FatherID:"/",Title:cTitle,Content:cMemo,Format:"Txt"}, function(data){ ShowMsg(data) ;});
}
function RefreshAlbumCommentsList(cPhotoID)
{
    $.post("/AjaxServer/GetPhotoCommentsListHtml.ashx", { PhotoID:cPhotoID }, function(data){ $("#Album_Comments_History").html(data); } ); 
}
function RefreshCurrentPhotoCommentsList()
{
    RefreshAlbumCommentsList($("#Photo_ID").text());
}
function DeleteCommentsLabel(cWebDocID)
{
    if (confirm("帖子被删除将不可恢复，请确认是否执行？","执行","取消"))
    {
        $.post("DeletePhotoComments.ashx", { ID:cWebDocID }, function(data){ ShowMsg(data) ; RefreshCurrentPhotoCommentsList();});    
    }
}

// Wiki 中的原文内容格式化为 HTML 编码
//---------------------------------------------
function WikiFormat(cString)
{
	cString = cString.replace(/ /mg,"&nbsp;");
	cString = cString.replace(/^\*{3}/mg,"&nbsp;&nbsp;&nbsp;◎&nbsp;");
	cString = cString.replace(/^\*{2}/mg,"&nbsp;&nbsp;○&nbsp;");
	cString = cString.replace(/^\*/mg,"&nbsp;●&nbsp;");
	cString = cString.replace(/\n-{4,}\n/mg,"\n<hr size='1' />\n");
	cString = cString.replace(/('')(.*?)('')/mg, "<b>$2</b>");
	cString = cString.replace(/(==)(.*?)(==)/mg, "<strike>$2</strike>");	
	cString = cString.replace(/(__)(.*?)(__)/mg, "<u>$2</u>");	
	cString = cString.replace(/(\/\/)(.*?)(\/\/)/mg, "<em>$2</em>");
	cString = cString.replace(/(~~)(.*?)(~~)/mg, "<sub>$2</sub>");	
	cString = cString.replace(/(\^)(.*?)(\^)/mg, "<sup>"+"$2</sup>");	
	cString = cString.replace(/(\[\[)([^\n\r\|]+)(\]\])/mg, "<a class=\"WikiWordLink\" title=\"点击查看 Wiki 解释\">$2</a>");
	cString = cString.replace(/(\[\[)(.+)(\|)(.+)(\]\])/mg, "<a class=\"WordLink\" href=\"$4\" title=\"打开链接\">$2</a>");
	cString = cString.replace(/(\[)([\>|\<]*)(img\[)([^\[\n\r]+)(\|)([^\[\n\r]+)(\]\])/mg, "<img src='$6' alt='$4' />");
	cString = cString.replace(/\n/mg,"<br />");
	return cString;
}


// 加载一个编辑器
// 参数：容器Div的ID，被编辑的文档的JSON  JSON_Doc.Title  JSON_Doc.Content
function LoadDocEditor(cContainerID,jsonDoc)
{
	var EditorHtml = "<div class='Editor' id=\"Editor_"+cContainerID+"\">";
	EditorHtml += "<div class='Editor_Toolbar'>";
	EditorHtml += "<div id='Editor_Submit' class='Editor_Submit' onClick='SubmitDoc()'></div>";
	EditorHtml += "<div id='Editor_Cancel' class='Editor_Cancel' onClick='CancelDocEdit()'></div>";
	EditorHtml += "<div style='clear:both;height:1px'></div>";
	EditorHtml += "</div>";	
    EditorHtml += "<div style='display:none'><input id=\"Editor_Doc_ID\" type='text' value='"+jsonDoc.ID+"' /></div>";
	EditorHtml += "<div style='clear:both;height:5px'></div>";
	EditorHtml += "<div class='Editor_Panel'>"; 
	EditorHtml += "<div class='Editor_Label'>标题</div>";
	EditorHtml += "<input class='Editor_Txtbox' id=\"Editor_Doc_Title\" type='text' value='"+jsonDoc.Title+"' /><br />"; 
	EditorHtml += "<div class='Editor_Label'>栏目</div>";
	EditorHtml += "<div class='Editor_OptionGroup'>";
	EditorHtml += "<label><input type=\"radio\" name=\"EntryID\" value=\"News\" />本站新闻</label>";
    EditorHtml += "<label><input type=\"radio\" name=\"EntryID\" value=\"UserGuide\" />用户指南</label>";      
    EditorHtml += "<label><input type=\"radio\" name=\"EntryID\" value=\"AboutCFH\" />CFH 概述</label>";
    EditorHtml += "<label><input type=\"radio\" name=\"EntryID\" value=\"PhotoAlbum\" />相册系统</label><div>";
    EditorHtml += "<br />";
	EditorHtml += "<div class='Editor_Label'>内容</div>";
	EditorHtml += "<textarea class='Editor_Content' id=\"Editor_Doc_Content\">"+jsonDoc.Content+"</textarea><br />"; 
	EditorHtml += "<div style='clear:both;height:10px'></div>";
	EditorHtml += "</div>";
	EditorHtml += "</div>";
	$("#"+cContainerID).html(EditorHtml);
	setEntry(jsonDoc.Entry);
	return true;
}
function setEntry(cEntry)
{
    $("input[@name='EntryID']").removeAttr("checked");
    $("input[@name='EntryID'][@value=News]").attr("checked","checked");
}
function NewDoc()
{
    var JSON_Doc = { ID:"",Title:"",Entry:"News",Content:"",Format:"COWiki"}
    return JSON_Doc;
}
// 发表一个CMS文档帖子、新闻...
function SubmitDoc(cContainerId)
{
    $.post("/Master/UpdateDoc.ashx", { AppEntryID:$("input[@name='EntryID']:checked").val(),TargetID:"",FatherID:"/",ID:$("#Editor_Doc_ID").val(), Title:$("#Editor_Doc_Title").val(),Content:$("#Editor_Doc_Content").val(),Format:"COWiki"}, function(data){ ShowMsg(data);});
}
// 取消文档编辑任务
function CancelDocEdit(cContainerId)
{
	$("#Editor_Doc_Title").val("");
	$("#Editor_Doc_Content").val("");
}
// From TiddlyWiki
// Convert & to "&amp;", < to "&lt;", > to "&gt;" and " to "&quot;"
String.prototype.htmlEncode = function()
{
	var regexpAmp = new RegExp("&","mg");
	var regexpLessThan = new RegExp("<","mg");
	var regexpGreaterThan = new RegExp(">","mg");
	var regexpQuote = new RegExp("\"","mg");
	var regexpLF = new RegExp("\n","mg");
		
	return(this.replace(regexpAmp,"&amp;").replace(regexpLessThan,"&lt;").replace(regexpGreaterThan,"&gt;").replace(regexpQuote,"&quot;").replace(regexpLF,"<br />"));
}

String.prototype.htmlDEncode = function()
{
	var regexpAmp = new RegExp("&","mg");
	var regexpLessThan = new RegExp("<","mg");
	var regexpGreaterThan = new RegExp(">","mg");
	var regexpQuote = new RegExp("\"","mg");
	var regexpLF = new RegExp("\n","mg");
		
	return(this.replace(regexpAmp,"&amp;").replace(regexpLessThan,"&lt;").replace(regexpGreaterThan,"&gt;").replace(regexpQuote,"&quot;").replace(regexpLF,"<br />"));
}


// From TiddlyWiki Ends
/// 函数：是否URL 
/// By Bruce
function IsURL(cString)
{
	//return true;
	return (cString.substring(0,7).toUpperCase()=="HTTP://")?true:false;
}
/// 给对象的属性添加一个值（此属性的多个值以空格分隔）
/// 参数：对象(object) 属性(字符串) 值(字符串)
function AddtoObjAttr(Obj, cAttr, cValue)
{
	if (Obj.attr(cAttr)!=undefined && (Obj.attr(cAttr).indexOf(cValue)>-1)) return;
	if (Obj.attr(cAttr)==undefined) { Obj.attr(cAttr, cValue); }
	else { Obj.attr(cAttr, Obj.attr(cAttr)+" "+cValue);}
}


