
function CPopup(p_iWidth, p_iHeight, p_LeftClickEnable, p_ImgPath)
{
	this.Width				= p_iWidth || 140;
	this.Height				= p_iHeight || 0;
	this.LeftClickEnable	= p_LeftClickEnable || false;
	this.imgPath			= p_ImgPath || "";
	
	this.Popup			= window.createPopup();
	this.Html			= "<b>Undefine</b>";
	this.Option			= 0;
	this.OptionHeight	= 23;
	this.OptionHtml		= "";
	this.LineHeight		= 1;
	
	this.bPoPup			= true;
	
	this.isIE		= false;
	if(window.navigator.appName=="Microsoft Internet Explorer"&&window.navigator.appVersion.substring(window.navigator.appVersion.indexOf("MSIE")+5,window.navigator.appVersion.indexOf("MSIE")+8)>=5.5){
		this.isIE=true;
	}else{
		this.isIE=false;}
	
	//method
	this.dopopup	= CP_DoPopup;
	this.click		= CP_Click;
	this.clear		= CP_Clear;
	this.add		= CP_Add;
	this.addline	= CP_AddLine;
	this.addheader	= CP_AddHeader;
	this.load		= CP_HtmlGenerate;
	this.enable		= CP_Enable;
	this.disable	= CP_Disable;
	this.hide		= CP_Hide;
}

function CP_Hide() {
	if(this.isIE && this.bPoPup)
		this.Popup.hide();
}

function CP_DoPopup(x,y) {
	if(this.isIE && this.bPoPup) {
		var oPopupBody = this.Popup.document.body;
		oPopupBody.innerHTML = this.Html;
		this.Popup.show(x, y, this.Width, this.Height, document.body);
	}
}

function CP_Click(e) {
	if(this.isIE && this.bPoPup){
		if(document.all){
			if(event.button==2||event.button==3 || (this.LeftClickEnable && event.button==1)){
				this.dopopup(event.x-1,event.y-1);
			}
		}
	}
}

function CP_Disable(){this.bPoPup=false;}
function CP_Enable(){this.bPoPup=true;}


function CP_HtmlGenerate(){
	this.Html+='<SC'+'RIPT LANGUAGE="JavaScript">\n';
	this.Html+='\n<'+'!--\n';
	this.Html+='window.onerror=null;\n';
	this.Html+='/'+' -'+'->\n';
	this.Html+='</'+'SCRIPT>\n';
	this.Html='<TABLE STYLE="border:1px solid #a9a9a9;padding:2px;" BGCOLOR="#f5f5f5" WIDTH="' + this.Width+ '" CELLPADDING="0" CELLSPACING="0">';
	this.Html+=this.OptionHtml;
	this.Html+='</TABLE>';
}
	
function CP_Add(p_strText,p_strOnclick,p_strImg){
	this.Option+=1;
	this.Height+=this.OptionHeight;
	var strID = 'o' + this.Option;
	var strImg  = p_strImg || "icoMenuItem"
	
	this.OptionHtml+='<TR><TD STYLE="color:#000000;font-family:Tahoma;font-size:8pt;border-style:solid;border-width:1px;border-color:#f5f5f5;" ID="' + strID + '"'
	this.OptionHtml+=' ONMOUSEOVER="document.all.' + strID + '.style.background=\'#dcdcdc\';document.all.' + strID + '.style.border=\'1pt solid #a9a9a9\';"'
	this.OptionHtml+=' ONMOUSEOUT="document.all.' + strID + '.style.background=\'#f5f5f5\';document.all.' + strID + '.style.border=\'1pt solid #f5f5f5\';"'
	this.OptionHtml+=' ONCLICK="' + p_strOnclick + '">'
	this.OptionHtml+='&nbsp;<IMG SRC="' + this.imgPath + 'MGACMS-Engine/image/' + strImg + '.gif" BORDER="0" HSPACE="0" VSPACE="0" ALIGN="absmiddle">&nbsp;' + p_strText + '</TD></TR>';
}
function CP_AddLine(){
	this.Height+= this.LineHeight;
	this.OptionHtml+='<TR><TD STYLE="border:1pt solid #f5f5f5;margin:0 0 0 0;padding:0 0 0 0;"><IMG SRC="' + this.imgPath + 'MGACMS-Engine/ContextMenu/image/pixel.gif" WIDTH="' + (this.Width - 10) + '" HEIGHT="' + this.LineHeight + '"></TD></TR>';
}

function CP_AddHeader(p_strText){
	this.Height+=this.OptionHeight;
	this.OptionHtml+='<TR><TD STYLE="color:#000000;font-family:Tahoma;font-size:8pt;border:1pt solid #f5f5f5" align="center">' + p_strText + '</TD></TR>';
}

function CP_Clear(){
	this.Html='';
	this.OptionHtml='';
	this.Option=0;
	this.Height=0;
}
