$(function (){
	WindowHeight(0);setTimeout("WindowHeight(0)",500);
	try {
		ToSource('def');
		ToWriter('def');
		CheckAddition();
	}catch (e) {}
	try {
		CheckVote();
	}catch (e) {}
	try {
		$("#img").mouseover(function() {

			}).hover(function() { 
				$('#imgView').css({"display":""});
				if ($id('img').value.substr(0,7)=="http://"){
					$id('imgView').src=$id('img').value;
				}else{
					$id('imgView').src=$id('imgAdminDir').value + $id('img').value;
				}
			}, function(){
				$('#imgView').css({"display":"none"});
		});

	}catch (e) {}

});


// 检测表单
function CheckForm(){
	if ($id('time').value == ""){alert("发布时间不能为空");$id('time').focus();return false}
	if ($id('theme').value == ""){alert("标题不能为空");$id('theme').focus();return false}
	if ($id('typeStr').value == ""){alert("请选择分类");$id('typeStr').focus();return false}
//	if ($id('contentKey').value == ""){alert("内容摘要不能为空");$id('contentKey').focus();return false}
	return true
}

// 载入文章来源
function ToSource(str){
	if (str=="def"){
		if ($id('source').value==""){
			$id('source').value=$id('sourceItem').value;
		}
	}else{
		$id('source').value=$id('sourceItem').value;
	}
}

// 载入文章作者
function ToWriter(str){
	if (str=="def"){
		if ($id('writer').value==""){
			$id('writer').value=$id('writerItem').value;
		}
	}else{
		$id('writer').value=$id('writerItem').value;
	}
}

// 检查查看等级限制
function SetUserLevel(){
	levelStr = $id('userLevelStr').value;
	levelArr = levelStr.split('|');
	$id('userLevel').value = levelArr[0];
	$id('score1').value = levelArr[1];
	$id('score2').value = levelArr[2];
	$id('score3').value = levelArr[3];
	$id('score4').value = levelArr[4];
	$id('score5').value = levelArr[5];
}


// 检测重复标题
function CheckRepeatTheme(){
	themeStr = $id('theme').value;

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

	var ajax=new AJAXRequest();
	ajax.encode = function(str) { 
		return escape(str); 
	} 
	ajax.get(
		"readDeal2.asp?mudi=checkInfoRepeatTheme&dataID="+ $id('dataID').value +"&theme="+ escape(themeStr) +"",
		// 回调函数，注意，是回调函数名，不要带括号
		function(obj) {
			retStr = obj.responseText;
			alert(retStr);
		}
	);
	return false;

}


// 从DZ库获取关键词(标签)
function GetDzKeyWord(){
	themeStr = $id('theme').value;
	contentStr = GetEditorText('content');

	if (themeStr==""){
		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("read.asp?mudi=getKeyWord&theme="+ escape(themeStr) +"&content="+ escape(contentStr).substr(0,1750));
	ajax.get(
		"read.asp?mudi=getDzKeyWord&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 GetKeyWord(){
	themeStr = $id('theme').value;

	if (themeStr==""){
		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); 
	} 
	ajax.get(
		"read.asp?mudi=getKeyWord&theme="+ escape(themeStr) +"",
		// 回调函数，注意，是回调函数名，不要带括号
		function(obj) {
			$id('onloadThemeKey').innerHTML = "";
			retStr = obj.responseText;
			if (retStr=="0"){ alert("获取不到关键词(标签)，请手动添加。");return false; }
			$id('themeKey').value = retStr;
		}
	);
	return false;

}

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

// 载入缩略图/图片框
function ToImg(str){
	$id('img').value = str;
	$id('editorImgBox').innerHTML = "";
}

// 获取编辑器图片
function GetEditorImg(){
	selImgStr = "";
	imgPath = $id('imgDir').value;
	imgAdminPath = $id('imgAdminDir').value;
	imgStr = $id('upImgStr').value;
	imgArr = imgStr.split('|');
	for (var i=0; i<imgArr.length; i++){
		if (imgArr[i]!=""){
			if (imgArr[i].substr(0,6)!="thumb_"){
				selImgStr += "<div id='edImg"+ i +"' style='width:80px; height:80px; border:1px #707070 solid; overflow:hidden; margin:3px; float:left;'><img src='"+ imgAdminPath + imgArr[i] +"' width='80' class='pointer' onclick=\"ToImg('"+ imgArr[i] +"');\" alt='原图' onerror=\"$id('edImg"+ i +"').style.display='none';\" /></div>";
				selImgStr += "<div id='edSmallImg"+ i +"' style='width:50px; height:50px; border:1px #707070 solid; overflow:hidden; margin:3px; float:left;'><img src='"+ imgAdminPath +"thumb_"+ imgArr[i] +"' width='50' class='pointer' onclick=\"ToImg('thumb_"+ imgArr[i] +"');\" alt='缩略图' onerror=\"$id('edSmallImg"+ i +"').style.display='none';\" /></div>";
			}else{
				selImgStr += "<div id='edSmallImg"+ i +"' style='width:50px; height:50px; border:1px #707070 solid; overflow:hidden; margin:3px; float:left;'><img src='"+ imgAdminPath + imgArr[i] +"' width='80' class='pointer' onclick=\"ToImg('"+ imgArr[i] +"');\" alt='缩略图' onerror=\"$id('edSmallImg"+ i +"').style.display='none';\" /></div>";
			}
		}
	}

	str = GetEditorHTML('content');
	retImgArr = str.match(/src\s*=\s*[\"|\']?\s*[^>\"\'\s]*\.(jpg|jpeg|png|gif|bmp)/gi);
	retImgStr = "";
	for (var i=0; i<retImgArr.length; i++){
		retImgArr[i] = retImgArr[i].replace(/src\s*=\s*[\"|\']?/,'');
		if (retImgArr[i]!="" && selImgStr.indexOf(retImgArr[i])==-1 && retImgStr.indexOf(retImgArr[i])==-1){
			retImgStr += retImgArr[i] +"|";
			selImgStr += "<div id='edImg"+ i +"' style='width:80px; height:80px; border:1px #707070 solid; overflow:hidden; margin:3px; float:left;'><img src='"+ retImgArr[i] +"' width='80' class='pointer' onclick=\"ToImg('"+ retImgArr[i] +"');\" alt='远程图片' onerror=\"$id('edImg"+ i +"').style.display='none';\" /></div>";
		}
	}

	if (selImgStr==""){ selImgStr="<span class='font2_2'>编辑器中无图片</span>"; }
	$id('editorImgBox').innerHTML = selImgStr;
	WindowHeight(0);
}

// 检测属性
function CheckAddition(){
	isImgBox = false;
/*
	for (var i=0; i<$name('addition').length; i++){
		if ($name('addition')[i].checked){
			if ($name('addition')[i].value=="|homeThumb|" || $name('addition')[i].value=="|thumb|" || $name('addition')[i].value=="|img|" || $name('addition')[i].value=="|flash|"){
				isImgBox = true
			}		
		}
	}
*/
	if ($id('isHomeThumb').checked || $id('isThumb').checked || $id('isImg').checked || $id('isFlash').checked){
		isImgBox = true
	}		

	if (isImgBox==true){
		$id('imgBox').style.display="";
	}else{
		$id('imgBox').style.display="none";
	}
	WindowHeight(0);
}

// 检测投票
function CheckVote(){
/*
	isVote1Box = isVote2Box = false;
	for (var i=0; i<$name('voteMode').length; i++){
		if ($name('voteMode')[i].checked){
			if ($name('voteMode')[i].value=="1"){
				isVote1Box = true
			}else if ($name('voteMode')[i].value=="2"){
				isVote2Box = true
			}
		}
	}
	if (isVote1Box==true){
		$id('vote1Box').style.display="";
	}else{
		$id('vote1Box').style.display="none";
	}
	if (isVote2Box==true){
		$id('vote2Box').style.display="";
	}else{
		$id('vote2Box').style.display="none";
	}
*/
	if ($id('voteMode1').checked){
		$id('vote1Box').style.display="";
	}else{
		$id('vote1Box').style.display="none";
	}
	if ($id('voteMode2').checked){
		$id('vote2Box').style.display="";
	}else{
		$id('vote2Box').style.display="none";
	}
	WindowHeight(0);
}



// 栏目批量移动
function MoreMoveTo(){
	if ($id('moreMoveTo').value==""){ return false; }
	var selNum = 0;
	for (var i=0;i<$name("selDataID").length;i++){
		if ($name("selDataID")[i].checked){
			selNum ++;
		}
	}
	if (selNum==0){
		alert('请先选择要移动的记录.');$id('moreMoveTo').value="";return false;
	}
	selOptionValue = $id('moreMoveTo').options[$id('moreMoveTo').selectedIndex].text;
	$id('moreMoveToCN').value = selOptionValue;
	if (confirm("选中"+ selNum +"条记录，你确定要批量移动到栏目【"+ selOptionValue +"】？")==true){
		$id('listForm').action="info_deal.asp?mudi=moreMove";
		$id('listForm').submit();
	}else{
		$id('moreMoveTo').value="";
	}
	
}