//
var FileName = diarydirjs+"p/Autosave/CommentAutoSave.xml";					//设置暂存文件名
var AutoSaveTime = 3;								//修改保存时间间隔(秒)<input type='button' name='Submit' value='查看' onclick='FileView();'> <input type='button' onclick='FileSaving();' name='Submit' value='暂存' onclick='FileView();'>
var TimeConfigc = 180;
var msg = null;
var MakeBtn = null;

function init(){
	msg = document.getElementById("msg");
	MakeBtn = document.getElementById("MakeBtn");
	MakeBtn.innerHTML ="<input type='submit' name='Submit' value='发布'> <input type='reset' name='Submit2' value='重来'> <input type='button' onclick='FileRestore();' name='Submit' value='恢复' onclick='FileView();'>"
}

window.setTimeout("timer()", 0);
function window.onload(){
	//init();			//由于加载意外，将此调用转到调用页面，采用defer
}
function InitXML(){
	var HttpDom=false; 
	try { HttpDom = new ActiveXObject("Msxml2.XMLHTTP"); } 
	catch (e) { try { 
	HttpDom = new ActiveXObject("Microsoft.XMLHTTP");
	} catch (e) { HttpDom = false; } }
	if (!HttpDom && typeof XMLHttpRequest!='undefined') { 
		HttpDom = new XMLHttpRequest(); 
	} 
	return HttpDom;
}
function FileSaving(){
	if (SetParament!=null){
		var url = diarydirjs+"p/Autosave/AutoSaver.asp";
		var RequestStr = "";
		var CheckNull = "";
		var ParamentValue = new Array();
		var ParamentName = SetParament.split(",")
		for(i=0;i<ParamentName.length;i++){ 
			if(ParamentName[i]=="myEditor"){
				ParamentValue[i] = myEditor.getHTML()	//HTML编辑器接口，默认是ewebeditor
			}else{
				ParamentValue[i] = document.getElementById(ParamentName[i]).value
			}
			RequestStr = RequestStr + ParamentName[i] + "=" + escape(ParamentValue[i]) + "&"
			CheckNull = CheckNull + ParamentValue[i];
		}
		if (CheckNull.length>0){
			var HttpDom = InitXML();
			HttpDom.open("POST", url, true); 
			HttpDom.setRequestheader("Content-length",RequestStr.length)
			HttpDom.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); 
			HttpDom.send(RequestStr);
			HttpDom.onreadystatechange = function() { 
				if (HttpDom.readyState == 4 && HttpDom.status == 200) { 
					msg.innerHTML = HttpDom.responseText; 
				}
			} 
				TimeConfig = -1000;
		}else{
			msg.innerHTML = "无内容";
			TimeConfig = -1000;
		}
	}else{
		msg.innerHTML = "等待载入或窗体名填写错误";TimeConfig = -1000;
	}
}

function FileRestore(){
	if (window.confirm('确定要恢复上一次保存吗?')){
		if (SetParament!=null){
			var url = FileName;
			var HttpDom = InitXML();
			HttpDom.open("GET", url, true); 
			HttpDom.onreadystatechange = function() { 
			if (HttpDom.readyState == 4 && HttpDom.status == 200) { 
				var ParamentXML = HttpDom.responseXML;
				var AllDate = ParamentXML.getElementsByTagName("AllDate")[0].childNodes
				for(var i=0;i<AllDate.length;i++) {
					if(AllDate[i].nodeName=="myEditor"){
						myEditor.setHTML(AllDate[i].firstChild.nodeValue)
					}else{
						document.getElementById(AllDate[i].nodeName).value = AllDate[i].firstChild.nodeValue;
						KE.util.focus("Content");KE.util.selection("Content");KE.util.insertHtml("Content",AllDate[i].firstChild.nodeValue);
//var file ="55555555555";KE.show({id:'Content',afterCreate:function(id){KE.util.focus(id);KE.util.selection(id);KE.util.insertHtml(id,file);}}); 
					}
				}
				msg.innerHTML ="已恢复。"; } } 
			HttpDom.send(null); 
			TimeConfig = -1000;
		}else{
			msg.innerHTML = "等待载入或窗体名填写错误";
			TimeConfig = -1000;		}
	}
}

function FileView(){
	window.open(FileName,'','');
}
var TimeConfig=TimeConfigc;
function timer() {
	TimeConfig = TimeConfig -1;
//	msg.innerHTML = TimeConfig + "秒后自动保存";

if (TimeConfig>=AutoSaveTime){
msg.innerHTML = "";
		}else{
msg.innerHTML = "系统"+TimeConfig + "秒后自动保存草稿";
		}

	if (TimeConfig>=0){
		window.setTimeout("timer()", 1000);
	}else{
		if (TimeConfig<=-1000){
			TimeConfig=AutoSaveTime;
			timer();
		}else{
			msg.innerHTML = "正在保存...";
			FileSaving();
			TimeConfig = TimeConfigc;
			timer();
		}
	}
}
//HTML代码过滤涵数
<!--
function cleanHtml(ReContents)
{
	//清理多余HTML代码
	ReContents = ReContents.replace(/<(.*)>.*<\/\1>|<(.*) \/>/gi,"")
	ReContents = ReContents.replace(/<p>&nbsp;<\/p>/gi,"")
	ReContents = ReContents.replace(/<p><\/p>/gi,"")
	ReContents = ReContents.replace(/<p>/,"")
	ReContents = ReContents.replace(/<\/p>/,"")
	ReContents = ReContents.replace(/<li>/,"")
	ReContents = ReContents.replace(/<lu>/,"")
	ReContents = ReContents.replace(/(<(meta|iframe|frame|span|tbody|layer)[^>]*>|<\/(iframe|frame|meta|span|tbody|layer)>)/gi, "");
	ReContents = ReContents.replace(/<\\?\?xml[^>]*>/gi, "") ;
	ReContents = ReContents.replace(/o:/gi, "");
	ReContents = ReContents.replace(/ /gi, "");
	ReContents = ReContents.replace(/&nbsp;/gi, " ");
	ReContents = ReContents.replace(/(<(style|strong)[^>]*>|<\/(style|strong)>)/gi, "");
	//验证空白行
	ReContents = ReContents.replace(/^\[ \t]*$/,"")
	//表格也要过滤！
	ReContents = ReContents.replace(/(<(table|tbody|tr|td|th|)[^>]*>|<\/(table|tbody|tr|td|th|)>)/gi, "");
	//图片过滤
	ReContents = ReContents.replace(/(<(img)[^>]*>|<\/(img)>)/gi, "");
	//<div>过滤
	ReContents = ReContents.replace(/(<(div|blockquote|fieldset|legend)[^>]*>|<\/(div|blockquote|fieldset|legend)>)/gi, "");
	//<font>过滤
	ReContents = ReContents.replace(/(<(font|i|u|h[1-9]|s)[^>]*>|<\/(font|i|u|h[1-9]|s)>)/gi, "");
	//过滤脚本
	ReContents = ReContents.replace(/(<script[^>]*>|<\/script>)/gi, "");
	//去掉任何标记中的任何事件！
	RegExp = /<(\w[^>|\s]*)([^>]*)(on(finish|mouse|Exit|error|click|key|load|change|focus|blur))(.[^>]*)/gi;
	ReContents = ReContents.replace(RegExp, "<$1")
	RegExp = /<(\w[^>|\s]*)([^>]*)(&#|window\.|id|javascript:|js:|about:|file:|Document\.|vbs:|cookie| name| id)(.[^>]*)/gi;
	ReContents = ReContents.replace(RegExp, "<$1")

	ReContents = ReContents.replace(/\n/gi, "");
	ReContents = ReContents.replace(/\r/gi, "");

	return ReContents;
}