

// 修改信息_类型检测
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 CheckRepeatTheme(){
	themeStr = $id('theme').value;

	if (themeStr==""){
		alert("标题不能为空.");return false;
	}

	$.ajaxSetup({cache:false});
	$.get(dbPathPart +"readDeal2.asp?mudi=checkInfoRepeatTheme&dataID="+ $id('dataID').value +"&theme="+ escape(themeStr) +"", function(result){
		alert(result);
	});
	return false;

}


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

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

	$id('onloadThemeKey').innerHTML = "<img src='"+ dbPathPart +"inc_img/onload.gif' style='margin-right:5px;' />请稍等，关键词获取中...</center>";
	$.ajaxSetup({cache:false});
	$.get(dbPathPart +"read.asp?mudi=getDzKeyWord&theme="+ escape(themeStr) +"&content="+ escape(contentStr).substr(0,1750), function(result){
		$id('onloadThemeKey').innerHTML = "";
		if (result=="0"){ alert("获取不到关键词(标签)，请手动添加。");return false; }
		$id('themeKey').value = result;
	});

	return false;

}


// 从本地库获取关键词(标签)
function GetKeyWord(){
	themeStr = $id('theme').value;

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

	$id('onloadThemeKey').innerHTML = "<img src='"+ dbPathPart +"inc_img/onload.gif' style='margin-right:5px;' />请稍等，关键词获取中...</center>";
	$.ajaxSetup({cache:false});
	$.get(dbPathPart +"read.asp?mudi=getKeyWord&theme="+ escape(themeStr) +"", function(result){
		$id('onloadThemeKey').innerHTML = "";
		if (result=="0"){ alert("获取不到关键词(标签)，请手动添加。");return false; }
		$id('themeKey').value = result;
	});
	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;
}
