notSavedYet = '';
// pb_blnCloseWindow = false;
// pb_strConfirmCloseMessage ="";
// notSavedYet = "";
// pb_msg="是否放弃对该条目的创建?"; (这些参数在外面赋值更恰当)
// pb_state=1; //1创建条目 2编辑条目
var jqePath='http://www.huimg.cn/jqeditor/';
jQEditor.config('jqePath', jqePath);
if(typeof jqe_autoHeight != 'number'){
	jqe_autoHeight = 1;
}
var HD={
	util: {
		getData: function(){
			return jQEditor.getHTML();
		}
	}
};
HD.plugin = {};
HD.plugin["image"] = {
	insert: function(f,link){
		jQEditor.plugin('HdImage').insert(f,link);
	},
	
	error: function(info){
		jQEditor.plugin('HdImage').error(info);
	}
}
function initEditor() {
	$.editor({
		id: 'jqe-group',
		contentId: 'content',
		height:240,
		autoHeight:jqe_autoHeight,
		toolbar: ['Undo','Redo','Bold','FontSize','ForeColor','BackColor','JustifyLeft','BaikeLink','Link','HdImage','Video','InsertTable','SpecialChar','InsertOrderedList','InsertUnorderedList','Source'],
		disabled:['Cleanup'],
		plugin:{
			HdImage: {
				config : {
					max_width : 550
				},
				settings: {
					static_url : jqePath,
					img_src_action : 'http://group.hudong.com/createGroupTopic.do',
					moreSize : true,
					moreAlign  : true,
					getFileAction : function() {
						var url = "http://a5.att.hudong.com/",
							doctitle = $('#_doc_title').length ? $('#_doc_title').val() : '',
							iden = $('#curuser_iden').length ? $('#curuser_iden').val() : '',
							art_iden=$('#art_iden').length ? $('#art_iden').val() : '';
						url += 'uploadFileNew.wiki?curuser_iden=' + iden + '&doc_title=' + encodeURI(doctitle);
						return url;
					},
					getUrlAction : function() {
						var url = "http://a5.att.hudong.com/",
							doctitle = $('#_doc_title').length ? $('#_doc_title').val() : '',
							iden = $('#curuser_iden').length ? $('#curuser_iden').val() : '';
						url +='uploadUrl.wiki?curuser_iden='+iden+'&doc_title='+encodeURI(doctitle);
						return url;
					}
				}
			}
		}
	});
}

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

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

function addTag() {
	if (tagdiv.childNodes.length >= 40) {
		alert("标签最多只允许填写20个！");
		return;
	}
	tagdiv.innerHTML = tagdiv.innerHTML
			+ '<input class="button35" type="text" name="tag" size="8" style="height:12px"><a href="javascript:void(0)" onclick="removeTag(this)" class="bg12" title="删除">[X]</a>';
}

function removeTag(obj) {
	if (tagdiv.childNodes.length <= 4) {
		alert("您至少需要填写两个标签！");
		return;
	}
	if (confirm("确认删除标签:" + 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("标签中不能含有分号“;”！");
			tags[i].focus();
			return false;
		}
		if (tag.length > 0) {
			for (k = 0; k < i; k++) {
				if (tag.toLowerCase() == tags[k].value.Trim().toLowerCase()) {
					alert("该标签已经存在，请重新输入！");
					tags[i].focus();
					return false;
				}
			}
		}
		tagnum++;
	}
	if (tagnum < 2) {
		alert("您至少需要填写两个标签！");
		return false;
	}
	return true;
}

function mySubmit() {
	if (editor.getHTML() == "" || editor.getHTML() == "<p />") {
		alert("请输入条目内容再保存！");
		return false;
	}

	if (pb_state == 2) {
		if (document.getElementById("edit_reason").value.length > 80) {
			alert("条目修改原因过长！");
			document.getElementById("edit_reason").focus();
			return false;
		}
	}

	if (!check2tag())
		return false;
	document.form2.ta.readonly = true;
	document.form2.target = "_self";
	document.form2.onsubmit();
	document.form2.submit();
}

function myPreview() {
	document.form2.onsubmit();
	window.open('http://www.huimg.cn/group/editor/popups/preview.html');
}

initEditor();
initTag();
if (pb_state == 2) {
	refreshLock();
}
function CloseMessageA() {
	CloseMessage();
	pb_blnCloseWindow = true;
}
function CloseMessage() {
	var window_div = document.getElementById("popup_message_dialog");
	if (window_div != null) {
		window_div.style.visibility = "hidden";
	}
	var window_div_text = document.getElementById("popup_message_text");
	if (window_div_text != null) {
		window_div_text.innerHTML = "";
	}
	var window_div_bar = document.getElementById("popup_message_dialog_bar");
	var window_div_img = document.getElementById("popup_message_dialog_img");
	if (window_div_bar != null) {
		if (IE) {
			window_div_bar.className = "grajaxhang1";
		} else {
			window_div_bar.setAttribute("class", "grajaxhang1");
		}
	}
	if (window_div_img != null) {
		window_div_img.src = "http://www.huimg.cn/group/images/mima.gif";
	}
}

function Message(v_message_text, v_type) {
	var window_div = document.getElementById("popup_message_dialog");
	if (window_div != null) {
		if (typeof v_type != 'undefined') {
			var window_div_bar = document
					.getElementById("popup_message_dialog_bar");
			var window_div_img = document
					.getElementById("popup_message_dialog_img");
			v_type = v_type.Trim().toUpperCase();
			switch (v_type) {
				case "INFOR" :
					if (window_div_bar != null) {
						if (IE) {
							window_div_bar.className = "grajaxhang2";
						} else {
							window_div_bar.setAttribute("class", "grajaxhang2");
						}
					}
					if (window_div_img != null) {
						window_div_img.src = "http://www.huimg.cn/group/images/002.gif";
					}
					break;
				default :// "ERROR" ,"WARNING"
					if (window_div_bar != null) {
						if (IE) {
							window_div_bar.className = "grajaxhang1";
						} else {
							window_div_bar.setAttribute("class", "grajaxhang1");
						}
					}
					if (window_div_img != null) {
						window_div_img.src = "http://www.huimg.cn/group/images/mima.gif";
					}
			}
		}
		var scrollPos = 0;
		if (typeof window.pageYOffset != 'undefined') {
			scrollPos = window.pageYOffset;
		} else if (typeof document.compatMode != 'undefined'
				&& document.compatMode != 'BackCompat') {
			scrollPos = document.documentElement.scrollTop;
		} else if (typeof document.body != 'undefined') {
			scrollPos = document.body.scrollTop;
		}
		window_div.style.top = scrollPos + 160 + "px";
		window_div.style.left = 250 + "px";

		var window_div_text = document.getElementById("popup_message_text");
		if (window_div_text != null) {
			window_div_text.innerHTML = v_message_text;
		}
		window_div.style.visibility = "visible";
	}
}
function CloseConfirmA() {
	CloseConfirm();
	pb_blnCloseWindow = true;
}
function CloseConfirm() {
	var window_div = document.getElementById("popup_confirm_dialog");
	if (window_div != null) {
		window_div.style.visibility = "hidden";
	}
	var window_div_text = document.getElementById("popup_confirm_text");
	if (window_div_text != null) {
		window_div_text.innerHTML = "";
	}
	var window_div_ok = document.getElementById("popup_confirm_dialog_ok");
	if (window_div_ok != null) {
		window_div_ok.onclick = CloseConfirm;
	}
}
function _Confirm(v_confirm_text, v_confirm_func) {
	var window_div = document.getElementById("popup_confirm_dialog");
	if (window_div != null) {
		var window_div_bar = document
				.getElementById("popup_confirm_dialog_bar");
		if (window_div_bar != null) {
			if (IE) {
				window_div_bar.className = "grajaxhang0";
			} else {
				window_div_bar.setAttribute("class", "grajaxhang0");
			}
		}
		var scrollPos = 0;
		if (typeof window.pageYOffset != 'undefined') {
			scrollPos = window.pageYOffset;
		} else if (typeof document.compatMode != 'undefined'
				&& document.compatMode != 'BackCompat') {
			scrollPos = document.documentElement.scrollTop;
		} else if (typeof document.body != 'undefined') {
			scrollPos = document.body.scrollTop;
		}
		window_div.style.top = scrollPos + 160 + "px";
		window_div.style.left = 250 + "px";

		var window_div_text = document.getElementById("popup_confirm_text");
		if (window_div_text != null) {
			window_div_text.innerHTML = v_confirm_text;
		}

		if (typeof v_confirm_func != 'undefined') {
			var window_div_ok = document
					.getElementById("popup_confirm_dialog_ok");
			if (window_div_ok != null) {
				v_confirm_func = v_confirm_func.Trim().toUpperCase();
				switch (v_confirm_func) {
					case "DELETETAG" :
						window_div_ok.onclick = deleteTag;
						break;
				}
			}
		}

		window_div.style.visibility = "visible";
	}
}

