$(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).toLowerCase()=="http://" || $id('img').value.substr(0,8).toLowerCase()=="https://"){
					$id('imgView').src=$id('img').value;
				}else{
					$id('imgView').src=$id('imgAdminDir').value + $id('img').value;
				}
			}, function(){
				$('#imgView').css({"display":"none"});
		});

	}catch (e) {}
	try {
		CheckIsCheckUser();
	}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;
	}

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

	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>";

	$.ajaxSetup({cache:false});
	$.get("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='../inc_img/onload.gif' style='margin-right:5px;' />请稍等，关键词获取中...</center>";

	$.ajaxSetup({cache:false});
	$.get("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(){
	str = FiltHtmlTag(GetEditorText('content'));
	try {
		str = LTrim(str);
	}catch (e) {}
	if (str==""){
		alert('请先填写内容');return false;
	}
	$id('contentKey').value = str.substring(0,160).replace(/\r\n/g,"") +"...";
}

// 载入缩略图/图片框
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 CheckIsCheckUser(){
	if ($id('isCheckUser1').checked){
		$id('userScoreK').style.display='';
	}else{
		$id('userScoreK').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;
	}
	selOptionText = $id('moreMoveTo').options[$id('moreMoveTo').selectedIndex].text;
	$id('moreMoveToCN').value = selOptionText;
	if (confirm("选中"+ selNum +"条记录，你确定要批量移动到栏目【"+ selOptionText +"】？")==true){
		$id('listForm').action="info_deal.asp?mudi=moreMove";
		$id('listForm').submit();
	}else{
		$id('moreMoveTo').value="";
	}
	
}