

// 修改信息_类型检测
function CheckRevInfoType(){
	for (var i=0; i<$name("revType").length; i++){
		if ($name("revType")[i].checked==true){
			$id($name("revType")[i].value +"Box").style.display="";
		}else{
			$id($name("revType")[i].value +"Box").style.display="none";
		}
	}
}

// 修改信息_检测表单
function CheckRevForm(){
	var selValue = "";
	for (var i=0; i<$name("revType").length; i++){
		if ($name("revType")[i].checked==true){
			selValue = $name("revType")[i].value;
		}
	}
	if (selValue==""){
		alert("请先选择修改类型.");$name("revType")[0].focus();return false;
	}

	if (selValue=="info"){
		try {
			if ($id("realname").value==""){alert("称呼不能为空！");$id("realname").focus();return false;}
		}catch (e) {}

	}
	else if (selValue=="password"){
		try {
			if ($id("userpwdOld").value==""){alert("原密码不能为空！");$id("userpwdOld").focus();return false;}
		}catch (e) {}
		if ($id("userpwd").value==""){alert("新密码不能为空！");$id("userpwd").focus();return false;}
		if ($id("userpwd").value.length<6){alert("新密码长度不能少于6位！");$id("userpwd").focus();return false;}
		if ($id("userpwd").value!=$id("userpwd2").value){alert("两次密码不一致！");$id("userpwd2").focus();return false;}

	}
	else if (selValue=="mail"){
		if ($id("mail").value==""){alert("新邮箱不能为空！");$id("mail").focus();return false;}
		if (! IsMail($id("mail").value)){alert("新邮箱格式错误！");$id("mail").focus();return false;}
		if ($id("mailPwd").value==""){alert("登录密码不能为空！");$id("mailPwd").focus();return false;}

	}
	else if (selValue=="question"){
		if ($id("question").value==""){alert("密保问题不能为空！");$id("question").focus();return false;}
		if ($id("answer").value==""){alert("密保答案不能为空！");$id("answer").focus();return false;}

	}

	if (dbPathPart=="../"){ $id('revForm').action = dbPathPart + $id('revForm').action; }
//	if ($id("verCode").value==""){alert("验证码不能为空！");$id("verCode").focus();return false;}
	if (selValue=="face"){
		$id("revForm").target = "DataDeal";
	}else{
		AjaxPostDeal("revForm");
		return false;
	}
}



// 检测发表文章
var wNewsWaitTime = 0;
var wNewsCutWaitFunc = null;
function CheckNewsForm(){
	if ($id("theme").value==""){alert("标题不能为空！");$id("theme").focus();return false;}
	if ($id("typeStr").value==""){alert("请选择分类！");$id("typeStr").focus();return false;}
	try {
		KE.sync('content');
	}catch (e) {}
	contentStr = setContent($id("content").value);
	if (contentStr.length<10){alert("内容不能小于10字符！");return false;}
	try {
		jsPageNum = parseInt($id("pageNum").value);
		if (isNaN(jsPageNum)){ jsPageNum=0; }
		if (jsPageNum>0 && jsPageNum<500){
			alert("自动分页字数最少500设置起");$id("pageNum").focus();return false;
		}
	}catch (e) {}
	if (wNewsWaitTime>0){
		alert("已提交，请稍等一会儿...("+ wNewsWaitTime +")");return false;
	}
		wNewsWaitTime = 10;
		wNewsCutWaitFunc = window.setInterval("CutWnewsWaitTime()",1000);
	if (dbPathPart=="../"){ $id('dealForm').action = dbPathPart + $id('dealForm').action; }
	AjaxPostDeal("dealForm");
	return false;
}

function CutWnewsWaitTime(){
	if (wNewsWaitTime<=0){
		window.clearInterval(wNewsCutWaitFunc);
		return false;
	}else{
		wNewsWaitTime --;
	}
}


// 清空文章表单内容
function NewsClearBtn(){
	if (confirm('确定要清空？')){
		$id('theme').value = "";
		$id('source').value = "";
		$id('writer').value = "";
		$id('typeStr').value = "";
		$id('content').value = "";
		$id('themeKey').value = "";
		$id('contentKey').value = "";
	}
}

// 删除文章
function DelNews(dataID,isAudit){
	auditStr = "";
	if (isAudit==1){
		auditStr = "\n\n删除该文章将扣除";
		if (parseInt($id('delScore1').value)>0){
			auditStr += "\n\n"+ $id('score1Name').value +"："+ $id('delScore1').value;
		}
		if (parseInt($id('delScore2').value)>0){
			auditStr += "\n\n"+ $id('score2Name').value +"："+ $id('delScore2').value;
		}
		if (parseInt($id('delScore3').value)>0){
			auditStr += "\n\n"+ $id('score3Name').value +"："+ $id('delScore3').value;
		}
		if (parseInt($id('delScore4').value)>0){
			auditStr += "\n\n"+ $id('score4Name').value +"："+ $id('delScore4').value;
		}
		if (parseInt($id('delScore5').value)>0){
			auditStr += "\n\n"+ $id('score5Name').value +"："+ $id('delScore5').value;
		}
	}else{
		auditStr = "";
	}
	if (confirm('你确定要删除该文章？'+ auditStr)){
		AjaxGetDeal(dbPathPart +'usersNews_deal.asp?mudi=del&dataID='+ dataID);
	}
	
}


// 载入关键词(标签)
function ToThemeKey(){
	themeStr = $id('theme').value;
	try {
		KE.sync('content');
	}catch (e) {}
	contentStr = setContent($id('content').value);

	if (themeStr=="" || contentStr==""){
		alert("获取关键词(标签)，标题和内容不能为空.");return false;
	}

	$id('onloadThemeKey').innerHTML = "<img src='inc_img/onload.gif' style='margin-right:5px;' />请稍等，关键词获取中...</center>";
	var ajax=new AJAXRequest();
	ajax.encode = function(str) { 
		return escape(str); 
	} 
//	var a=window.open(dbPathPart +"read.asp?mudi=getKeyWord&theme="+ escape(themeStr) +"&content="+ escape(contentStr));
	ajax.get(
		dbPathPart +"read.asp?mudi=getKeyWord&theme="+ escape(themeStr) +"&content="+ escape(contentStr).substr(0,1750),
		// 回调函数，注意，是回调函数名，不要带括号
		function(obj) {
			$id('onloadThemeKey').innerHTML = "";
			retStr = obj.responseText;
			if (retStr=="0"){ alert("获取不到关键词(标签)，请手动添加。");return false; }
			$id('themeKey').value = retStr;
		}
	);
	return false;

}

// 载入内容摘要
function ToContentKey(){
	try {
		KE.sync('content');
	}catch (e) {}
	str = setContent($id('content').value);
	try {
		str = LTrim(str);
	}catch (e) {}
	if (str==""){
		alert('请先填写内容');return false;
	}
	$id('contentKey').value = str.substring(0,140) +"...";
}

function CheckRefNewsForm(){
	OpenPopup('newsManage','&refTypeStr='+ escape($id("refTypeStr").value) +'&refTheme='+ escape($id("refTheme").value) +'&refSource='+ escape($id("refSource").value) +'&refWriter='+ escape($id("refWriter").value) +'');
}

function setContent(str) {
	str = str.replace(/<\/?[^>]*>/g,''); //去除HTML tag
	str = str.replace(/[ | ]*\n/g,'\n'); //去除行尾空白
	str = str.replace(/\n[\s| | ]*\r/g,'\n'); //去除多余空行
	return str;
}
