﻿// 显示当前日期，时间
function setCurrentDateTime(o){
	var d = new Date();
	var da = d.getDate();
	var mo = d.getMonth() + 1;
	var y = d.getFullYear();
	var h = d.getHours();
	if(h<10){h='0'+h}
	var m = d.getMinutes();
	if(m<10){m='0'+m}
	var s = d.getSeconds();
	if(s<10){s='0'+s}
	var week = ['天','一','二','三','四','五','六'];
	if(typeof(o) != 'object'){o=$$(o)}
	o.innerHTML = y+'年'+mo+'月'+da+'日 星期'+week[d.getDay()]+'<br />'+h+':'+m+':'+s;
	window.setTimeout(function(){setCurrentDateTime(o)}, 1000);	
}

function CheckSearchData()
{
	var type = $("#search_channeltype").val();
	if($("#search_keywords").val()=="")
	{
		alert("请输入关键字");
		return;
	}
	window.open(site.Dir + 'search/index.aspx?type='+type+'&k='+escape($("#search_keywords").val()));
}

var $$_JSON_Modules = {
	recordcount: 3, 
	table: [
		{no: 0, id: 5, title: '防务译文', type: 'version'},
		{no: 1, id: 7, title: '电子杂志', type: 'journal'},
		{no: 2, id: 6, title: '其他文档', type: 'document'}
	]
}
function BindModuleRadio(spanId,selecdType)
{
	var data = $$_JSON_Modules;
	var html = "";
	for (i=0;i<data.table.length;i++) {
		html += "<input id=\"RaChannelType_" + data.table[i].type + "\" type=\"radio\" name=\"type\" value=\"" + data.table[i].type + "\"";
		if(data.table[i].type == selecdType)
			html += " checked=\"checked\"";
		html += " /> <label for=\"RaChannelType_" + data.table[i].type + "\">" + data.table[i].title + "</label>";
	}
	html += "<input id=\"RaChannelType_all\" type=\"radio\" name=\"type\" value=\"all\"";
	if("all" == selecdType || "" == selecdType)
		html += " checked=\"checked\"";
	html += " /> <label for=\"RaChannelType_all\">全部</label>";
	$("#"+spanId).html(html);
}
var $$_JSON_Modes = {
	recordcount: 2, 
	table: [
		{no: 0, title: '宽松匹配'},
		{no: 1, title: '严格匹配'}
	]
}
function BindModeRadio(spanId,selecdMode)
{
	var data = $$_JSON_Modes;
	var html = "";
	for (i=0;i<data.table.length;i++) {
		html += "<input id=\"RaSearchMode_" + data.table[i].no + "\" type=\"radio\" name=\"mode\" value=\"" + data.table[i].no + "\"";
		if(data.table[i].no == selecdMode)
			html += " checked=\"checked\"";
		html += " /> <label for=\"RaSearchMode_" + data.table[i].no + "\">" + data.table[i].title + "</label>";
	}
	$("#"+spanId).html(html);
}
var $$_JSON_Channels = {
	recordcount: 6, 
	table: [
		{no: 0, id: 8, title: '防务译文'},
		{no: 1, id: 23, title: '电子杂志'},
		{no: 2, id: 20, title: '防务报告'},
		{no: 3, id: 21, title: '美军条例'},
		{no: 4, id: 22, title: '外军期刊'},
		{no: 5, id: 24, title: '防务资源'}
	]
}
function BindChannelRadio(spanId,selecdId)
{
	var data = $$_JSON_Channels;
	var html = "";
	for (i=0;i<data.table.length;i++) {
		html += "<input id=\"RaChannelType_" + data.table[i].id + "\" type=\"radio\" name=\"ch\" value=\"" + data.table[i].id + "\"";
		if(data.table[i].id == selecdId)
			html += " checked=\"checked\"";
		html += " /> <label for=\"RaChannelType_" + data.table[i].id + "\">" + data.table[i].title + "</label>";
	}
	html += "<input id=\"RaChannelType_0\" type=\"radio\" name=\"ch\" value=\"0\"";
	if("0" == selecdId || "" == selecdId)
		html += " checked=\"checked\"";
	html += " /> <label for=\"RaChannelType_0\">不限</label>";
	$("#"+spanId).html(html);
}
function ajaxLoginbar(w)
{
	var uName="";
	var uPass="";
	if(w==null) w=0;
	if(w==-1)
	{
		$.ajax({
			type:		"get",
			dataType:	"json",
			data:		"time="+(new Date().getTime()),
			url:		"/ajax/user.aspx?oper=ajaxUserInfo",
			success:	function(data){
				window.location.href=site.LogoutUrl+"?userkey="+data.userkey;
			}
		});
	}
	else
	{
		$.ajax({
			type:		"post",
			dataType:	"json",
			data:		"name="+escape(uName)+"&pass="+escape(uPass)+"&state="+w,
			url:		"/ajax/user.aspx?oper=ajaxLoginbar&time="+(new Date().getTime()),
			error:		function(XmlHttpRequest,textStatus, errorThrown){if(XmlHttpRequest.responseText!=""){alert(XmlHttpRequest.responseText);}},
			success:	function(d){
				$("#ajaxLoginbar").setTemplateURL("/templates/_loginbar.htm?time="+(new Date().getTime()), null, {filter_data: true});
				$("#ajaxLoginbar").processTemplate(d);
			}
		});	
	}
}
///////////////////////////////////////////////////////////////////////////
//特约专题
///////////////////////////////////////////////////////////////////////////
function ajaxPluginSpecialList(oDiv, save2file)
{
	if(oDiv==null) oDiv="ajaxPluginSpecialList";
	if(save2file=="js")
		ExecuteJsonData("/_data/json/special.js", site.Dir + "templates/_speciallist.htm", oDiv, site.Dir + "_data/style/p_special.js", "", "js");
	else if(save2file=="html")
		ExecuteJsonData("/_data/json/special.js", site.Dir + "templates/_speciallist.htm", oDiv, site.Dir + "_data/html/p_special.htm", "", "html");
	else
		ExecuteJsonData("/_data/json/special.js", site.Dir + "templates/_speciallist.htm", oDiv);
}
function ajaxGo2View(ccId,id)
{
	$.ajax({
		type:		"post",
		dataType:	"json",
		data:		"contentid="+id+"&channelid="+ccId+"&time="+(new Date().getTime()),
		url:		"/ajax/content.aspx?oper=ajaxGo2View",
        	error:		function(XmlHttpRequest,textStatus, errorThrown){if(XmlHttpRequest.responseText!=""){alert(XmlHttpRequest.responseText);}},
		success:	function(d){
			window.open(d.returnval);
		}
	});
}
function ajaxViewCount(cType,id,randomid,needadd)
{
	var addit = needadd == false ? 0 : 1;
	$.ajax({
		type:		"get",
		dataType:	"json",
		data:		"oper=ajaxViewCount&id="+id+"&addit="+addit+"&cType="+cType+"&time="+(new Date().getTime()),
		url:		"/ajax/content.aspx",
		error:		function(XmlHttpRequest,textStatus, errorThrown){if(XmlHttpRequest.responseText!=""){alert(XmlHttpRequest.responseText);}},
		success:	function(d){
			$("#ajaxViewCount_"+id+"_"+randomid).text(d.count);
		}
	});
}
function replaceContentTags(ccid,cType,taglist,bodyid)
{
	try{
		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='"+site.Dir + "extends/search/index.aspx?type="+cType+"&k="+escape(tags[i])+"&t=tag' target='_blank'><span class='tag'>"+tags[i]+"</span></a>");
			}
		}
		$("#"+bodyid).html(returnhtml);
	}
	catch(e){}
}
function addFavorite(ccid,cType,id)
{
	$.ajax({
		type:		"get",
		dataType:	"html",
		data:		"oper=addFavorite&id="+id+"&ccid="+ccid+"&cType="+cType+"&time="+(new Date().getTime()),
		url:		"/ajax/content.aspx",
		error:		function(XmlHttpRequest,textStatus, errorThrown){if(XmlHttpRequest.responseText!=""){alert(XmlHttpRequest.responseText);}},
		success:	function(d){
			alert(d);
		}
	});
}
var _closeTimer = -1;
function Go2PageForm(url)
{
	var _adminid = KnowfarCms.Cookie.get("kcms_user", "adminid");
	if(_adminid != "" && _adminid != "0")
		window.open("/plus/"+url+"&userkey="+user.userkey);
	else{
		var oDialog = new jcms$$Dialog('1', '确认框', 350, 130, 'success', false);
		oDialog.init();
		var sHtml = '<form id="Go2PageForm"><table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">\
				<tr><td height="30" align="left"><span id="closetimer"></span></td></tr>\
				<tr><td height="60" align="left">确定要下载该资源吗？<br /><br />同一资源只扣除一次点数。</td></tr>\
				<tr><td height="20" align="left"><input type="button" value="开始下载" onclick="Go2PageCheck(\''+url+'\');" />&nbsp;&nbsp;<input type="button" value="稍后再说" onclick="Go2PageStop();" /></td></tr>\
			</table></form>\
		';
		oDialog.event(sHtml,'');
		Go2PageStart();
	}
}
function Go2PageCheck(url){
	window.open("/plus/"+url+"&userkey="+user.userkey);
	Go2PageStop();
}
function Go2PageStart(){
	_closeTimer = 30;
	Go2PageAutoClose(_closeTimer, "closetimer");
}
function Go2PageStop(){
	_closeTimer = - 1;
	Go2PageAutoClose(_closeTimer, "closetimer");
}
function Go2PageAutoClose(secs, spanid){
	if($$(spanid) == null)
		return;
	if(secs > 0) 
	{
		_closeTimer = secs - 1;
		$('#'+spanid).html('还有 <span style="color:red;">' + _closeTimer + '</span> 秒自动关闭');
		window.setTimeout("Go2PageAutoClose(" + _closeTimer + ",'" + spanid + "')", 1000);
	} 
	else if(secs == 0) 
	{
		_closeTimer = -1;
		Go2PageAutoClose(_closeTimer,spanid);
	} 
	else
	{
		new jcms$$Dialog().reset();
	}
}
