// 主页：http://www.shuziren.com
// QQ:66237000(24小时隐身在线)

// 菜单常量
var gvMenuHr="<tr><td align=center valign=middle height=2><TABLE border=\"0\" cellpadding=\"0\" "+
	"cellspacing=0 width=128 height=2><tr><td height=\"1\" class=\"HrShadow\"><\/td><\/tr><tr>"+
	"<td height=1 class=\"HrHighLight\"><\/td><\/tr><\/TABLE><\/td><\/tr>";
var gvMenu1="<TABLE border=\"0\" cellpadding=\"0\" cellspacing=\"0\" class=\"Menu\" width=\"100%\" height=\"100%\"><tr><td width=\"20\" "+
	" valign=\"bottom\" align=\"center\" style='background:url(imgs/contextmenu.gif);background-position:bottom;'>"+
	"<font color=\"#176DB5\">1<\/font>&nbsp;&nbsp;&nbsp;&nbsp;<\/td>"+
	"<td class=\"RightBg\"><TABLE border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\">";
var gvMenu2="<\/TABLE><\/td><\/tr><\/TABLE>";

// 取菜单行
function getMenuRow(gv_Disabled, gv_Event, gv_Image, gv_Html) {
	var gv_MenuRow = "";
	gv_MenuRow = "<tr><td align=center valign=middle><TABLE border=0 cellpadding=0 cellspacing=0 width=\"100%\">"+
	"<tr "+gv_Disabled+"><td valign=middle height=20 class=\"MouseOut\" onMouseOver=this.className='MouseOver'; onMouseOut=this.className='MouseOut';";
	if (gv_Disabled==""){
		gv_MenuRow += " onclick=\"parent."+gv_Event+";parent.oPopupMenu.hide();\"";
	}
	gv_MenuRow += ">"
	if (gv_Image !=""){
		gv_MenuRow += "&nbsp;<img border=0 src='imgs/"+config.StyleDir+"/"+gv_Image+"' align=absmiddle "+gv_Disabled+">&nbsp;";
	}else{
		gv_MenuRow += "&nbsp;";
	}
	gv_MenuRow += gv_Html+"<\/td><\/tr><\/TABLE><\/td><\/tr>";
	return gv_MenuRow;

}

// 取标准的format菜单行
function getFormatMenuRow(menu, html, image){
	var gv_Disabled = "";
	if (!shuziren_editor.document.queryCommandEnabled(menu)){
		//queryCommandEnabled返回表明指定命令是否可于给定文档当前状态下使用 execCommand 命令成功执行的 Boolean 值。
		gv_Disabled = "disabled";
	}
	var gv_Event = "format('"+menu+"')";
	var gv_Image = menu+".gif";
	if (image){
		gv_Image = image;
	}
	return getMenuRow(gv_Disabled, gv_Event, gv_Image, html)
}

// 取表格菜单行
function getTableMenuRow(what){
	var gv_Menu = "";
	var gv_Disabled = "disabled";
	switch(what){
	case "TableInsert":
		if (!isTableSelected()) gv_Disabled="";
		gv_Menu += getMenuRow(gv_Disabled, "TableInsert()", "TableInsert.gif", "插入表格...")
		break;
	case "TableProp":
		if (isTableSelected()||isCursorInTableCell()) gv_Disabled="";
		gv_Menu += getMenuRow(gv_Disabled, "TableProp()", "TableProp.gif", "表格属性...")
		break;
	case "TableCell":
		if (isCursorInTableCell()) gv_Disabled="";
		gv_Menu += getMenuRow(gv_Disabled, "TableCellProp()", "TableCellProp.gif", "单元格属性...")
		gv_Menu += getMenuRow(gv_Disabled, "TableCellSplit()", "TableCellSplit.gif", "拆分单元格...")
		gv_Menu += gvMenuHr;
		gv_Menu += getMenuRow(gv_Disabled, "TableRowProp()", "TableRowProp.gif", "表格行属性...")
		gv_Menu += getMenuRow(gv_Disabled, "TableRowInsertAbove()", "TableRowInsertAbove.gif", "插入行（在上方）");
		gv_Menu += getMenuRow(gv_Disabled, "TableRowInsertBelow()", "TableRowInsertBelow.gif", "插入行（在下方）");
		gv_Menu += getMenuRow(gv_Disabled, "TableRowMerge()", "TableRowMerge.gif", "合并行（向下方）");
		gv_Menu += getMenuRow(gv_Disabled, "TableRowSplit(2)", "TableRowSplit.gif", "拆分行");
		gv_Menu += getMenuRow(gv_Disabled, "TableRowDelete()", "TableRowDelete.gif", "删除行");
		gv_Menu += gvMenuHr;
		gv_Menu += getMenuRow(gv_Disabled, "TableColInsertLeft()", "TableColInsertLeft.gif", "插入列（在左侧）");
		gv_Menu += getMenuRow(gv_Disabled, "TableColInsertRight()", "TableColInsertRight.gif", "插入列（在右侧）");
		gv_Menu += getMenuRow(gv_Disabled, "TableColMerge()", "TableColMerge.gif", "合并列（向右侧）");
		gv_Menu += getMenuRow(gv_Disabled, "TableColSplit(2)", "TableColSplit.gif", "拆分列");
		gv_Menu += getMenuRow(gv_Disabled, "TableColDelete()", "TableColDelete.gif", "删除列");
		break;
	}
	return gv_Menu;
}

// 右键菜单
var oPopupMenu = null;
	if (BrowserInfo.Is55More){
		oPopupMenu = window.createPopup(); //创建弹出窗口。
	}
function showContextMenu(event){
	if (!codeMode) return false;
	var width = 160;
	var height = 0;
	var lefter = event.clientX;
	var topper = event.clientY;

	var oPopDocument = oPopupMenu.document;
	var oPopBody = oPopupMenu.document.body;

	var gvMenu="";
	
	gvMenu += getFormatMenuRow("cut", "剪切");
	gvMenu += getFormatMenuRow("copy", "复制");
	gvMenu += getFormatMenuRow("paste", "常规粘贴");
	gvMenu += getFormatMenuRow("delete", "删除");
	gvMenu += getFormatMenuRow("selectall", "全选");
	gvMenu += gvMenuHr;
	height += 103;

	if (isCursorInTableCell()){
		gvMenu += getTableMenuRow("TableProp");
		gvMenu += getTableMenuRow("TableCell");
		gvMenu += gvMenuHr;
		height += 286;
	}

	if (isControlSelected("TABLE")){
		gvMenu += getTableMenuRow("TableProp");
		gvMenu += gvMenuHr;
		height += 22;
	}
	if (isControlSelected("FIELDSET")){
		gvMenu += getMenuRow("", "ShowDialog('dialog/fieldset.htm', 350, 170, true)", "fieldset.gif", "修改栏目框.");
		gvMenu += gvMenuHr;
		height += 22;
	}
	if (isControlSelected("IMG")){
		gvMenu += getMenuRow("", "ShowDialog('dialog/img.htm', 480, 580, true)", "img.gif", "图片属性...");
		gvMenu += gvMenuHr;
		height += 22;
	}

	gvMenu += getMenuRow("", "findReplace()", "findreplace.gif", "查找替换...");
	height += 22;

	gvMenu = gvMenu1 + gvMenu + gvMenu2;

	oPopDocument.open();
	oPopDocument.write(config.cssMenu+gvMenu);
	oPopDocument.close();

	height+=2;
	if(lefter+width > document.body.clientWidth) lefter=lefter-width;
	//if(topper+height > document.body.clientHeight) topper=topper-height;

	oPopupMenu.show(lefter, topper, width, height, shuziren_editor.document.body);
	return false;
}

// 工具栏菜单
function showToolMenu(menu){
	if (!codeMode) return false;
	var gvMenu = ""
	var width = 150;
	var height = 0;

	var lefter = event.clientX;
	var leftoff = event.offsetX
	var topper = event.clientY;
	var topoff = event.offsetY;

	var oPopDocument = oPopupMenu.document;
	var oPopBody = oPopupMenu.document.body;

	switch(menu){
	case "paste":

		break;
	case "table":		// 表格菜单
		gvMenu += getTableMenuRow("TableInsert");
		gvMenu += getTableMenuRow("TableProp");
		gvMenu += gvMenuHr;
		gvMenu += getTableMenuRow("TableCell");
		height = 306;
		break;
	case "form":		// 表单菜单
		gvMenu += getFormatMenuRow("InsertInputText", "插入输入框", "FormText.gif");
		gvMenu += getFormatMenuRow("InsertTextArea", "插入输入区", "FormTextArea.gif");
		gvMenu += getFormatMenuRow("InsertInputRadio", "插入单选钮", "FormRadio.gif");
		gvMenu += getFormatMenuRow("InsertInputCheckbox", "插入复选钮", "FormCheckBox.gif");
		gvMenu += getFormatMenuRow("InsertSelectDropdown", "插入下拉框", "FormDropdown.gif");
		gvMenu += getFormatMenuRow("InsertButton", "插入按钮", "FormButton.gif");
		height = 120;
		break;
	case "zoom":		// 缩放菜单
		for (var i=0; i<setZoomSize.length; i++){
			if (setZoomSize[i]==defaultZoomSize){
				gvMenu += getMenuRow("", "setZoom("+setZoomSize[i]+")", "checked.gif", setZoomSize[i]+"%")
			}else{
				gvMenu += getMenuRow("", "setZoom("+setZoomSize[i]+")", "space.gif", setZoomSize[i]+"%")
			}
			height += 20;
		}
		break;
	}
	
	gvMenu = gvMenu1 + gvMenu + gvMenu2;
	
	oPopDocument.open();
	oPopDocument.write(config.cssMenu+gvMenu);
	oPopDocument.close();

	height+=2;
	if(lefter+width > document.body.clientWidth) lefter=lefter-width;
	//if(topper+height > document.body.clientHeight) topper=topper-height;

	oPopupMenu.show(lefter - leftoff - 2, topper - topoff + 22, width, height, document.body);

	return false;
}

