var pb_blnCloseWindow = false;
var pb_strConfirmCloseMessage =JS_LANG['jsEditorLeavePage'];
var notSavedYet = JS_LANG['jsEditorGaveUp'];
var pb_msg=JS_LANG['jsEditorCreateGaveUp'];
var pb_url="doc.php?action=createdoc";
var pb_state=1;

function ConfirmClose() {
	window.event.returnValue = pb_strConfirmCloseMessage;
	pb_blnCloseWindow = true;
}
function ShowConfirmClose() {
	if(confirm(pb_msg)){
		window.location = pb_url;
	}
}

window.onbeforeunload =function(e){
/*	if(document.body.clientWidth-window.event.clientX < 170 && window.event.clientY < 0 || window.event.altKey){
		return notSave(e);
	}*/
}

var tagdiv=document.getElementById("tagdiv");

function addTag() {
	if(tagdiv.childNodes.length>=40)
	{
		alert(JS_LANG['jsEditorTag']);
		return ;
	}
	tagdiv.innerHTML= tagdiv.innerHTML+'<input class="button35" name="tag[]" value="" size="8" maxlength="20" /><a class="dlzt" href="javascript:void(0)" onclick="removeTag(this)" title="'+JS_LANG['topicAdminDel']+'">[X]</a>';
}

function removeTag(obj){
	if(tagdiv.childNodes.length<=4)
	{
		alert(JS_LANG['jsEditorTagTwo']);
		return ;
	}
	if(confirm(JS_LANG['jsEditorTagDel']+obj.previousSibling.value+"?"))
	{
		tagdiv.removeChild(obj.previousSibling);
		tagdiv.removeChild(obj);
	}
}

function initTag()
{
	if(tagdiv==null)return ;
	while(tagdiv.childNodes.length<16)
	{
		addTag();
	}
}

function check2tag()
{
	if(tagdiv==null)return true;
	var tags=document.getElementsByName("tag[]");
	var tagnum=0;
	for(i=0;i<tags.length;i++){
		tag=tags[i].value.Trim();
		if(tag=="")continue;
		if(tag.indexOf(";")!=-1){
			alert(JS_LANG['jsEditorTagForb']);
			tags[i].focus();
			return false;
		}
		if(tag.length>0){
			for(k=0;k<i;k++){
				if (tag.toLowerCase() == tags[k].value.Trim().toLowerCase()){
					alert(JS_LANG['jsEditorTagExist']);
					tags[i].focus();
					return false;
				}
			}
		}
		tagnum++;
	}
	if(tagnum<2)
	{
		alert(JS_LANG['jsEditorTagTwo']);
		return false;
	}
	return true;
}

function mySubmit() {
    var html=editor.data();alert('成功发表！感谢您的支持！');
	if(html=="" ||html=="<p />"){
		alert(JS_LANG['jsEditorContent']);
		return false;
	}
	if(pb_state==2){
		if(document.getElementById("edit_reason").value.length>80){
			alert(JS_LANG['jsEditorReasonLong']);
			document.getElementById("edit_reason").focus();
			return false;
		}
	}
	if(!check2tag()) return false;
	document.form2.target="_self";
	document.form2.submit();
}


function myPreview()
{
	eval(HD_OBJ_NAME).data();
	var newWin = window.open('', 'kindPreview','width=800,height=600,left=30,top=30,resizable=yes,scrollbars=yes');
	KindWriteFullHtml(newWin.document, document.getElementsByName(eval(HD_OBJ_NAME).hiddenName)[0].value);
	KindDisableMenu();
}

function refreshLock()
{
	docid=document.form2.docid.value;
	createXMLHttpRequest();
	var url = "lock.php?action=lock&docid="+docid;
	xmlHttp.open("GET",url,true);
	xmlHttp.onreadystatechange =callback;
	xmlHttp.send(null);
}

function callback(){
	if (xmlHttp.readyState == 4) {
		if (xmlHttp.status == 200) {
			setTimeout("refreshLock()",60000);
		}
	}
}


initTag();
if(pb_state==2)
{
	refreshLock();
}


