// JavaScript Document

var sMenuHr="<tr><td align=center valign=middle height=2><TABLE border=0 cellpadding=0 cellspacing=0 width=193 height=2><tr><td height=1 class=HrShadow><\/td><\/tr><tr><td height=1 class=HrHighLight><\/td><\/tr><\/TABLE><\/td><\/tr>";
var sMenu1="<div style=\"border-top:1px #ccc solid;border-left:1px #ccc solid;background-color:#000000;\"><TABLE border=0 cellpadding=0 cellspacing=0 class=Menu width=195><tr><td width=195 class=RightBg><TABLE border=0 cellpadding=0 cellspacing=0>";
var sMenu2="<\/TABLE><\/td><\/tr><\/TABLE><\/div>";
var oPopMenu = null;

// 取标准的format菜单行
function getFormatMenuRow(menu, html, image){
	var s_Disabled = "";
	if (!LinziWebEditor.document.queryCommandEnabled(menu)){
		s_Disabled = "disabled";
	}
	var s_Event = "format('"+menu+"')";
	var s_Image = menu+".gif";
	if (image){
		s_Image = image;
	}
	return getMenuRow(s_Disabled, s_Event, s_Image, html)
}

// 取菜单行
function getMenuRow(s_Disabled, s_Event, s_Image, s_Html) {
	var s_MenuRow = "";
	s_MenuRow = "<tr><td align=center valign=middle><TABLE border=0 cellpadding=0 cellspacing=0 width=195><tr "+s_Disabled+"><td valign=middle height=20 class=MouseOut onMouseOver=this.className='MouseOver'; onMouseOut=this.className='MouseOut';";
	if (s_Disabled==""){
		s_MenuRow += " onclick=\"parent."+s_Event+";parent.oPopMenu.hide();\"";
	}
	s_MenuRow += ">"
	if (s_Image !=""){
		s_MenuRow += "&nbsp;<img border=0 src='ButtonImage/standard/"+s_Image+"' width=20 height=20 align=absmiddle "+s_Disabled+">&nbsp;";
	}else{
		s_MenuRow += "&nbsp;";
	}
	s_MenuRow += s_Html+"<\/td><\/tr><\/TABLE><\/td><\/tr>";
	return s_MenuRow;
}

// 右键菜单
function showContextMenu(event){
	if (!bEditMode) return false;

	var width = 199;
	var height = 0;
	var lefter = event.clientX;
	var topper = event.clientY;

	var sMenu="";
	
	sMenu += getFormatMenuRow("cut", "剪切");
	sMenu += getFormatMenuRow("copy", "复制");
	sMenu += getFormatMenuRow("paste", "粘贴");
	sMenu += getFormatMenuRow("delete", "删除");
	height += 80;
	
	//if(isCursorInSiteBox()){
		var isobj = (LinziWebEditor.document.selection.type == "Control");
		sMenu += sMenuHr;
		if(!isobj){
			sMenu += getMenuRow("", "SiteNameInsert()", "about.gif", "插入网站名称");
			height += 20;
		}
		sMenu += getMenuRow("", "SiteUrlInsert()", "createlink.gif", "添加网站链接");
		if(!isobj){
			sMenu += getMenuRow("", "SiteInforInsert()", "insertparagraph.gif", "插入站点Logo");
			height += 20;
		}
		height += 23;
	//}else{
//		if(LinziWebEditor.document.selection.type != "Control"){
//			sMenu += sMenuHr;
//			sMenu += getMenuRow("", "SiteBoxInsert()", "abspos.gif", "插入站点占位符");
//			height += 23;
//		}
	//}
	
	if (isCursorInTableCell()){
		sMenu += sMenuHr;
		sMenu += getTableMenuRow("TableProp");
		sMenu += getTableMenuRow("TableCell");
		height += 287;
	}

	if (isControlSelected("TABLE")){
		sMenu += sMenuHr;
		sMenu += getTableMenuRow("TableProp");
		height += 23;
	}

	if (isControlSelected("IMG")){
		sMenu += sMenuHr;
		sMenu += getMenuRow("", "ShowDialog('dialog/img.htm', 350, 315, true)", "img.gif", "图片属性...");
		sMenu += sMenuHr;
		sMenu += getMenuRow("", "zIndex('forward')", "forward.gif", "上移一层");
		sMenu += getMenuRow("", "zIndex('backward')", "backward.gif", "下移一层");
		height += 65;
	}
	height += 1;

	sMenu = sMenu1 + sMenu + sMenu2;

	oPopMenu = window.createPopup();
	oPopDocument = oPopMenu.document;

	oPopDocument.open();
	oPopDocument.write("<html><head><link href=\"MenuArea.css\" type=\"text/css\" rel=\"stylesheet\"></head><body scroll=\"no\" onConTextMenu=\"event.returnValue=false;\">"+sMenu+"</body></html>");
	oPopDocument.close();

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

	oPopMenu.show(lefter, topper, width, height, LinziWebEditor.document.body);
	return false;
}


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




