var sPop = null;
var postSubmited = false;

function $(id){
	return document.getElementById(id);
}
function ctlent(obj) {
	if(postSubmited == false && (event.ctrlKey && window.event.keyCode == 13) || (event.altKey && window.event.keyCode == 83)) {
		if(this.document.input.pmsubmit) {
			postSubmited = true;
			this.document.input.pmsubmit.disabled = true;
			this.document.input.submit();
		} else if(validate(this.document.input)) {
			postSubmited = true;
			if(this.document.input.topicsubmit) this.document.input.topicsubmit.disabled = true;
			if(this.document.input.replysubmit) this.document.input.replysubmit.disabled = true;
			if(this.document.input.editsubmit) this.document.input.editsubmit.disabled = true;
			this.document.input.submit();
		}
	}
}
function checkall(form, prefix) {
	var node = document.forms[form].elements;
	var length = node.length;	
	for(var i = 0; i < length; i++) {		
		var e = document.forms[form].elements[i];
		if(e.name != 'chkall' && (!prefix || (prefix && e.name.match(prefix)))) {
			e.checked = document.forms[form].chkall.checked;
		}
	}
}

function findobj(n, d) {
	var p,i,x; if(!d) d=document;
	if((p=n.indexOf("?"))>0 && parent.frames.length) {
		d=parent.frames[n.substring(p+1)].document;
		n=n.substring(0,p);
	}
	if(!(x=d[n])&&d.all) x=d.all[n];
	for(i=0;!x && i<d.forms.length;i++) x=d.forms[i][n];
	for(i=0;!x && d.layers&&i>d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
	return x;
}

function copycode(obj) {
	var rng = document.body.createTextRange();
	rng.moveToElementText(obj);
	rng.scrollIntoView();
	rng.select();
	rng.execCommand("Copy");
	rng.collapse(false);
}

function dzconfirm(theURL, ConfirmMsg) {
	if (confirm( ConfirmMsg ))	{
		window.location.href=theURL;
	} else {
		return;
	} 
}

function validate(theform)
{	
	if (theform.subject.value == "" || _eweb.getHTML() == '')
	{		
		alert("标题和内容不能为空！");
		return false;
	}

	theform.topicsubmit.disabled = true;
	return true;
}

function _validate(theform)
{
	if (_eweb.getHTML() == "")
	{
		alert("内容不能为空！");
		return false;
	}

	theform.topicsubmit.disabled = true;
	return true;
}

function checkvote(theform)
{
	if (theform.subject.value == "" ||  theform.voteitem.value == "")
	{
		alert("标题和投票选项不能为空！");
		return false;
	}

	theform.topicsubmit.disabled = true;
	return true;
}

function preview(){
	if($('subject').value != '' && _eweb.getHTML() != ''){
		document.forms[0].action = 'post.php?action=preview';
		document.forms[0].submit();
	}else{
		alert('标题和内容不能为空');
		return false;
	}	
}