﻿//QcmsCms!NET_3.0.0322
//////////////////////////////////////////////////////////////////////////
function escape2(str){
	return escape(str).replace(/\+/g,"%2b");
}
function ajaxPluginTopNav()
{
	$.ajax({
		type:       "get",
		dataType:   "json",
		data:       "time="+(new Date().getTime()),
		url:        "/cmsfile/ajaj/readjson.aspx?file=channelclass.js",
		error: function(){
			//alert('Error loading JSON document');
		},
		success:    function(d){
			if(d.recordcount > 0){
				$("#ajaxPluginTopNav").setTemplateURL("/cmsfile/ajaj/readtemplate.aspx?file=topnav.htm&time="+(new Date().getTime()), null, {filter_data: true});
				$("#ajaxPluginTopNav").processTemplate(d);
			}else{
				$("#ajaxPluginTopNav").html("");
			}
		}
	});
}

//评论的地方
function ajaxPluginComment(ccid,id)
{
	if(PluginComment==null)
	{
		$("#ajaxPluginComment").hide();
		return;
	}
	$.ajax({
		type:       "get",
		dataType:   "json",
		data:       "oper=ajaxPluginComment&id="+id+"&ccid="+ccid+"&time="+(new Date().getTime()),
		url:        "/cmsfile/extends/comment/ajax.aspx",
		error: function(){
			//alert("oper=ajaxPluginComment&id="+id+"&ccid="+ccid+"&time="+(new Date().getTime()));
		},
		success:    function(d){
			$("#ajaxPluginComment").setTemplateURL("/cmsfile/extends/comment/templates/_comment.htm?time="+(new Date().getTime()), null, {filter_data: true});
			$("#ajaxPluginComment").processTemplate(d);
		}
	});
}
function ajaxPluginCommentCount(ccid,id)
{
	$.ajax({
		type:       "get",
		dataType:   "json",
		data:       "oper=ajaxPluginCommentCount&id="+id+"&ccid="+ccid+"&time="+(new Date().getTime()),
		url:        "/cmsfile/extends/comment/ajax.aspx",
		error: function(){
			//alert('Error loading JSON document');
		},
		success:    function(d){
			$("#ajaxPluginCommentCount_"+id).text(d.count);
		}
	});
}
function ajaxPluginCommentAdd(ccid,id)
{
	var uName=$("#commentName").val();
	var parentid=$("#commentParentId").val();
	var content=$("#commentContent").val();
	var codes = $("#code").val();
	if(!uName) {
		QcmsCms.Alert("用户名不能为空!","0");
		return;
	}
	if(uName.length>16){
		QcmsCms.Alert("用户名太长!","0");
		return;
	}
	if(!content || content.length<5) {
		QcmsCms.Alert("评论字符太少!","0");
		return;
	}
	if(content.length>200){
		QcmsCms.Alert("评论字符太多!","0");
		return;
	}
	//alert(codes);
	//$("#btnCommentAdd").attr("disabled","disabled");
	
	$.ajax({
		type:       "post",
		dataType:   "html",
		data:       "codes="+codes+"&ccid="+ccid+"&id="+id+"&parentid="+parentid+"&name="+escape(uName)+"&content="+escape(content),
		url:        "/cmsfile/extends/comment/ajax.aspx?oper=ajaxPluginCommentAdd&time="+(new Date().getTime()),
		error: function(){
			alert('Error loading JSON document');
		},
		success:    function(d){
			if(d=="ok")
			{
				$("#commentContent").val("");
				if(parentid=="0")
					QcmsCms.Alert("成功发表评论","1");
				else
					QcmsCms.Alert("成功回复评论","1");
        ajaxPluginCommentList(ccid,id,1);
			}
			else
			{
				QcmsCms.Alert(d,"0");
			}
		}
	});
}
function ajaxPluginCommentList(ccid,id,page)
{
	$.ajax({
		type:       "get",
		dataType:   "html",
		data:       "oper=ajaxPluginCommentList&ccid="+ccid+"&&id="+id+"&page="+page+"&time="+(new Date().getTime()),
		url:        "/cmsfile/extends/comment/ajax.aspx",
		error: function(){
			//alert('Error loading JSON document');
		},
		success:    function(d){
			$("#ajaxPluginCommentList").html(d);
		}
	});
}
function ajaxPluginCommentReply2(parentid)
{
	$("#commentParentId").val(parentid);
	$("#commentContent").val("");
	$("#commentContent")[0].focus();
}
function ajaxPluginCommentUserInfo()
{
	$.ajax({
		type:       "get",
		dataType:   "json",
		data:       "oper=ajaxPluginCommentUserInfo&time="+(new Date().getTime()),
		url:        "/cmsfile/extends/comment/ajax.aspx",
		error: function(){
			//alert('Error loading JSON document');
		},
		success:    function(d){
			$("#commentName").val(d.username);
			if(d.username!="游客")
				$("#commentName").attr("disabled","disabled");
		}
	});
}
function ajaxPluginTopNavStuHover() {
	var cssRule;
	var newSelector;
	for (var i = 0; i < document.styleSheets.length; i++)
		for (var x = 0; x < document.styleSheets[i].rules.length ; x++)
			{
			cssRule = document.styleSheets[i].rules[x];
			if (cssRule.selectorText.indexOf("LI:hover") != -1)
			{
				 newSelector = cssRule.selectorText.replace(/LI:hover/gi, "LI.iehover");
				document.styleSheets[i].addRule(newSelector , cssRule.style.cssText);
			}
		}
	var getElm = document.getElementById("topnavbar").getElementsByTagName("LI");
	for (var i=0; i<getElm.length; i++) {
		getElm[i].onmouseover=function() {
			this.className+=" iehover";
		}
		getElm[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" iehover\\b"), "");
		}
	}
}
function ajaxCopyright()
{
	$.ajax({
		type:       "get",
		dataType:   "json",
		data:       "time="+(new Date().getTime()),
		url:        "/cmsfile/ajaj/readjson.aspx?file=systeminfo.js",
		error: function(){
			//alert('Error loading JSON document');
		},
		success:    function(d){
			$("#ajaxCopyright").setTemplateURL("/cmsfile/ajaj/readtemplate.aspx?file=copyright.htm&time="+(new Date().getTime()), null, {filter_data: true});
			$("#ajaxCopyright").processTemplate(d);
		}
	});
}
function ajaxViewCount(cType,id,randomid)
{
	$.ajax({
		type:       "get",
		dataType:   "json",
		data:       "oper=ajaxViewCount&id="+id+"&cType="+cType+"&time="+(new Date().getTime()),
		url:        "/cmsfile/ajaj/content.aspx",
		error: function(){
			//alert('Error loading JSON document');
		},
		success:    function(d){
			$("#ajaxViewCount_"+id+"_"+randomid).text(d.count);
		}
	});
}
function replaceContentTags(ccid,taglist,bodyid)
{
	var elms1 = $("#"+bodyid+" a");
	for (i = 0; i < elms1.length; i++){elms1[i].title="";}
	var elms2 = $("#"+bodyid+" img");
	for (i = 0; i < elms2.length; i++){elms2[i].alt="";}
	var returnhtml=$("#"+bodyid).html();
	var tags=taglist.split(',');
	for (i = 0; i < tags.length; i++) {
		if(tags[i].length>1)//只取2个字符以上的
		{
			returnhtml=returnhtml.replace(tags[i],"<a href='/cmsfile/extends/search/index.aspx?ch="+ccid+"&keys="+escape(tags[i])+"&t=tag' target='_blank'><font color='blue'>"+tags[i]+"</font></a>");
		}
	}
	$("#"+bodyid).html(returnhtml);
}
function addFavorite(ccid,cType,id)
{
	$.ajax({
		type:       "get",
		dataType:   "html",
		data:       "oper=addFavorite&id="+id+"&ccid="+ccid+"&cType="+cType+"&time="+(new Date().getTime()),
		url:        "/cmsfile/ajaj/content.aspx",
		error: function(){
			//alert('Error loading JSON document');
		},
		success:    function(d){
			QcmsCms.Alert(d,"0");
		}
	});
}
