
var PartRootMenu = new cPopupMenu( window, null, '../Style/Menu.css' );
var PartGroupMenu = new cPopupMenu( window, null, '../Style/Menu.css' );
var ShowPartMenu = new cPopupMenu( window, null, '../Style/Menu.css' );
var HidePartMenu = new cPopupMenu( window, null, '../Style/Menu.css' );

var Ajax, siteName, cName, cTitle;

function Page_load()	//用户登录 系统启动
    {
	PartRootMenu.AddItem( 'secHead', {value:'部件管理'});
	PartRootMenu.AddItem( 'link', {method:'function', value:'新建部件分组(N)', funcRef: Part_Operate, parames:['AddGroup'] });
//	PartRootMenu.AddItem( 'link', {method:'function', value:'安装部件(I)...', funcRef: Part_Operate, parames:['InstPart'] });
	
	PartGroupMenu.AddItem( 'secHead', {value:'部件分组'});
	PartGroupMenu.AddItem( 'link', {method:'function', value:'安装部件(I)...', funcRef: Part_Operate, parames:['InstPart'] });
	PartGroupMenu.AddItem( 'divider' );
	PartGroupMenu.AddItem( 'link', {method:'function', value:'删除(D)', funcRef: Part_Operate, parames:['DelGroup'] });
	PartGroupMenu.AddItem( 'link', {method:'function', value:'重命名(M)', funcRef: Part_Operate, parames:['RenGroup'] });
//	PartGroupMenu.AddItem( 'divider' );
//	PartGroupMenu.AddItem( 'link', {method:'function', value:'属性(R)', funcRef: Part_Operate, parames:[''] });
	
	var menuObj = [
	    {type:'divider'},
	    {type:'link', method:'function', value:'重命名(M)', funcRef: Part_Operate, parames:['RenPart'] },
	    {type:'link', method:'function', value:'卸载部件(U)', funcRef: Part_Operate, parames:['UninstPart'] }
//	    {type:'divider'},
//	    {type:'link', method:'function', value:'属性(R)', funcRef: Part_Operate, parames:[''] }
	];	

	ShowPartMenu.AddItem( 'secHead', {value:'部件'});
	ShowPartMenu.AddItem( 'link', {method:'function', value:'预览部件(A)...', isBold:true, funcRef: Part_Operate, parames:['PartPreview'] });
	ShowPartMenu.AddItem( 'link', {method:'function', value:'隐藏(D)', funcRef: Part_Operate, parames:['HidePart'] });
	ShowPartMenu.AddItemByJson( menuObj );
	
	HidePartMenu.AddItem( 'secHead', {value:'部件'});
	HidePartMenu.AddItem( 'link', {method:'function', value:'预览部件(A)...', isBold:true, funcRef: Part_Operate, parames:['PartPreview'] });
	HidePartMenu.AddItem( 'link', {method:'function', value:'显示(S)', funcRef: Part_Operate, parames:['ShowPart'] });
	HidePartMenu.AddItemByJson( menuObj );
	
	Ajax = new AjaxRequest( 'PartOp.aspx', FreshTree, null );

	document.oncontextmenu = function(){ return false; };
	document.onselectstart = function(){ return false; };
    }   
function ShowMenu( menu )
    {
	cName = event.srcElement.value;
	cTitle = event.srcElement.title;
	
	menu.Show( event.x, event.y );
	return false;
    }
function Part_OnDblClick()
    {
	cName = event.srcElement.value;
	cTitle = event.srcElement.title;
	
	Part_Operate( 'PartPreview' );
    }

function Part_Operate( op )
    {
	if( !cName || !cTitle ) return;
	
//	var postText = 'optype='+ op.toLowerCase();
	var post = new UrlText( ['optype', op] );
	
	switch( op ){
	/******** 分组 操作 ********/
	case'AddGroup':		// 新建部件分组(N) // TitleDlg -- Ajax
	    var ret = Common.ShowDialog( 11, '../CommonUI/NewTitle.htm', {DialogMode:op} );
	    if( ret && ret.name && ret.title ){
//	        postText += '&newname='+ ret.name +'&newtitle='+ escape(ret.title);
	        post.Add( ['newname', ret.name], ['newtitle', ret.title] );
	        Ajax.Post( post.Text );
	    }
	    break;

	case'RenGroup':		// 重命名部件分组(M) // TitleDlg -- Ajax
	    var ret = Common.ShowDialog( 11, '../CommonUI/NewTitle.htm', {DialogMode:op, OldTitle:cTitle} );
	    if( ret && ret.title ){
//	        postText += '&groupname='+ cName +'&newtitle='+ escape(ret.title);
	        post.Add( ['GroupName', cName], ['NewTitle', ret.title] );
	        Ajax.Post( post.Text );
	    }
	    break;

	case'DelGroup':		// 删除部件分组(D) // Confirm -- Ajax
	    if( confirm('您确认要删除部件分组"'+ cTitle +'"?\n\n注意: 分组中如果有部件则无法删除!') ){
//	        postText += '&groupname='+ cName;
	        post.Add( ['GroupName', cName] );
	        Ajax.Post( post.Text );
	    }
	    break;

	/******** 部件 操作 ********/
	case 'InstPart':	// 安装部件(I)... // Frame
	    var url = new UrlText( 'PartInstall.aspx', ['groupName', cName], ['groupTitle', cTitle] );
	    OpenFrame( url.Text ); //"PartInstall.aspx?groupname="+ cName +"&grouptitle="+ escape(cTitle) );
	    break;

	case'PartPreview':	// 预览部件(A) // Frame
	    var url = new UrlText( 'PartPreview.aspx', ['partName', cName], ['parTtitle', cTitle] );
	    OpenFrame( url.Text ); //"PartPreview.aspx?partname="+ cName+"&parttitle="+escape(cTitle) );
	    break;

	case'RenPart':		// 重命名部件(M) // TitleDlg -- Ajax
	    var ret = Common.ShowDialog( 11, '../CommonUI/NewTitle.htm', {DialogMode:op, OldTitle:cTitle} );
	    if( ret && ret.title ){
//	        postText += '&partname='+ cName +'&newtitle='+ escape(ret.title);
	        post.Add( ['PartName', cName], ['NewTitle', ret.title] );
	        Ajax.Post( post.Text );
	    }
	    break;
	    
	case'UninstPart':	// 卸载部件(U) // Confirm -- Ajax
	    if( confirm( '您确认要卸载部件"'+ cTitle +'"?\n\n注意: 部件卸载后无法恢复!' ) ){
//	        postText += '&partname='+ cName;
	        post.Add( ['PartName', cName] );
	        Ajax.Post( post.Text );
	    }
	    break;

	case 'ShowPart':	// 显示(D) // Ajax
	case 'HidePart':	// 隐藏(D) // Ajax
//	    postText += '&partname='+ cName;
	    post.Add( ['PartName', cName] );
	    Ajax.Post( post.Text );
	    break;
	}
    }
function OpenFrame( url )
    {
	self.parent.frames["operateFrame"].location = url;
    }
function FreshTree()
    {
	window.location.reload( true );
    }