function doCheck()
{
	if($('myform').cid.value=='0')
	{
		alert('指定的栏目不允许添加'+channeltitle+'！只允许在其子栏目中添加'+channeltitle+'。');
		ShowTabs(0);
		$('myform').cid.focus();
		return false;
	}
	if($('myform').subject.value=="")
	{
		alert("请输入标题！");
		ShowTabs(0);
		$('myform').subject.focus();
		return false;
	}
	if($('myform').thumb.value=="")
	{
		alert("请选择一张图作为封面！");
		ShowTabs(0);
		return false;
	}
	$('divProcessing').style.display="";
	$('myform').submit.disabled=true;
	return true;
}
function picCheck( pic, rows)
{
	var s_Ext=pic.substring(pic.lastIndexOf(".")).toLowerCase();
	if(s_Ext=='.jpeg' || s_Ext=='.jpg' ||s_Ext=='.gif'){
		return true;
	}else{
		alert("错误的文件格式\n只能是jpeg,jpg,gif");
		fileDel( rows);
		return false;
	}
}

function error()
{
	$('divProcessing').style.display = 'none';
}
function setThumb(obj, url, pid)
{
	Each(getElementsByClassName($('pic-box'),'thumb_over'), function(){
		this.className = 'thumb';	
	})
	$('thumb').value = url;
	obj.className = 'thumb_over';
	if(action == 'edit'){
		var link = "system.php?sys=module&mod="+mod+"&channelid="+channelid+"&action=ajax&action_do=thumb&id="+id;
		AJAX.request(link,{method: 'post',parameters:'pid='+pid+'&myFormAc=update',onComplete: function(resp){
			return true;
		}});
	}
}

function AddImageProxy(url){
	if(!url[1]){
		alert("出错了，没有找到缩略图，可能是图片的尺寸太小了");
		return false;
	}
	var index = url[0].lastIndexOf('.');
	var len = config.url.length;
	var ext = url[0].substr(index+1);
	var url_link = url[0].substr(len);
	url_link = url_link.substr(0, url_link.lastIndexOf('.'));
	if(action == 'add'){
		AddImage('thumb', url_link, ext, 0, 0);
	}else{
		var link = "system.php?sys=module&mod="+mod+"&channelid="+channelid+"&action=ajax&action_do=add&id="+id;
		var _parameters = "url="+url[0]+"&id="+id;
		AJAX.request(link,{method: 'post',parameters:_parameters + '&myFormAc=update',onComplete: function(resp){
			var json = evaljson(resp);
			if(json == null) return alert("upload error");
			AddImage('thumb', url_link, ext, json['pid'],0);
		}});
	}
}
function AddImage(thumb, url, ext, pid, is_thumb)
{
	var li = document.createElement('li');
	var img = config.url + url + '_s.' + ext;
	var cimg = config.url + url + '.' + ext;
	li.innerHTML = "<p class='act'><a href='###' title='设为封面' class='"+ (is_thumb > 0 ? 'thumb_over' : 'thumb') +"' onclick=\"return setThumb(this, '"+url + '.' + ext+"', "+pid+")\"></a><a href='###' title='删除' class='close' onclick=\"return DelImage(this, '"+url+"', "+pid+")\"></a></p><p class='img'><a href='"+img+"'  target='_blank'><img src='"+img+"' /></a><input type='hidden' name='pics[]' value='"+cimg+"' /></p>";
	$('pic-box').appendChild(li);
	return true;
}
var DelImageBuffer = [];
function DelImage(obj, url, pid)
{
	if(action == 'edit'){
		if(DelImageBuffer.indexOf(pid) > -1) return false;
		if(!makeSure()) return false;
		DelImageBuffer.push(pid);
		var link = "system.php?sys=module&mod="+mod+"&channelid="+channelid+"&action=ajax&action_do=delete_one&id="+pid;
		qmeCms.dialogView.ajaxGet(link, function(){
			new colorFocus(obj.parentNode.parentNode, '#ffe900', '#F1F3F5', 'backgroundColor', function(){
				try{
					if(obj == null) return;
					var p = obj.parentNode.parentNode;
					p.parentNode.removeChild(p);
				}catch(e){}
			});
		});
	}else{
		new colorFocus(obj.parentNode.parentNode, '#ffe900', '#F1F3F5', 'backgroundColor', function(){
			try{
				if(obj == null) return;
				var p = obj.parentNode.parentNode;
				p.parentNode.removeChild(p);
			}catch(e){}
		});
	}
	return true;
}

function getFileName(url)
{
	return url.substring(url.lastIndexOf("/")+1)
}