﻿/** 文章删除确认 */
function delConfirm(articleid, menuid){
	if(window.confirm("确定要删除该文章吗？")){
		document.location.href = "article.do?method=deleteArticle&id=" + articleid + "&menuId=" + menuid;	  
	}
}

/** 表单校验 */
function checkForm() {
	editarticle.onsubmit();
	var article_title, article_content, article_date;
	article_title = document.editarticle.articleTitle;
	article_content = document.editarticle.articleContent;
	article_date = document.editarticle.postDate;
	if(isBlank(article_title.value)) {
		alert("文章标题不能为空!");
		article_title.focus();
		return false;
	} else if(!isUndefined(article_date) && !isValidDate(article_date.value)) {
		alert("文章发布日期输入格式有误!");
		article_date.focus();
		return false;
	}else if(isBlank(article_content.value)) {
		alert("文章内容不能为空!");
		return false;
	}
	else {
		article_content.value = (article_content.value).replace(/\u00A0/g, '&nbsp;');
		document.editarticle.submit();
	}
}

function checkMenu() {
	var menu_id = document.selectmenu.menuId;
	if(isBlank(menu_id.value)) {
		alert("栏目不能为空!");
		return false;
	} 
	var temp = menu_id.value.split(",");
	var menuId = temp[0];
	var menuType = temp[1];
	if(menuType == 1) {
		alert("该栏目是顶级菜单,不能添加文章!");
		return false;
	} else if(menuType == 3) {
		document.selectmenu.action = "article.do?method=findArticleById&id=" + menuId + "&flag=menuId";
	} else {
		document.selectmenu.action = "articleEdit.jsp?menuId=" + menuId;
	} 
	document.selectmenu.submit();	
}
  
/** 判断字符串是否为空 */
function isBlank(str) {
	if(str == null || str.trim() == "") 
		return true;
	return false;
}
 
/** 判断对象是否定义 */
function isUndefined(obj) {
	if(obj == undefined)
		return true;
	return false;	
}

/** 判断字符串是否为合法日期 */
function isValidDate(str) {
	var pattern = /^[0-9]{4}\-[0-1][0-9]\-[0-3][0-9]$/;
    if (!pattern.exec(str)) 
    	return false;
    return true;
}

/***
列表中表格背景色的变换****/
function mouseon(tr){
		tr.style.backgroundColor="#EEEEEE";
}
function mouseout(tr){
	tr.style.backgroundColor="#ffffff"; 
}
