function DropDownMenu(MenuId,MenuWidth,MenuBorder,MenuPos,Toppos,Leftpos)
{
	window.lastMenu = null;
	window.clickevent = false;
	window.unloadmenu = true;
	window.lasttdObj = null;
	
	this.MenuId = MenuId;
	this.MenuWidth = MenuWidth;
	this.MenuBorder = MenuBorder;
	this.MenuPos = MenuPos;			// TL = TopLeft, TR = TopRight, BL = BottomLeft, BR = BottomRight
	this.BorderColor = "#000000";
	this.Toppos = Toppos;
	this.Leftpos = Leftpos;
	this.TopSpacing = "0px ";
	this.RightSpacing = "0px ";
	this.BottomSpacing = "0px ";
	this.LeftSpacing = "0px ";
	
	this.MenuHeading = false;
	this.MenuTitle = "Title";
	this.TitleBgColor = "#000000"
	this.TitleFont = "verdana";
	this.TitleFontSize = "12px";
	this.TitleFontColor = "#FFFFFF";
	this.TitleFontWeight = "bold";
	this.TitleFontdecoration =  "none";

	this.MenuBgColor = "#FFFFFF";
	this.MenuOverBgColor = "#0000FF";

	this.MenuFont = "verdana";
	this.MenuFontSize = "12px";
	this.MenuFontColor = "#000000";
	this.MenuFontWeight = "normal";
	this.MenuFontdecoration =  "none";

	this.MenuFont_over = "verdana";
	this.MenuFontSize_over = "12px";
	this.MenuFontColor_over = "#000000";
	this.MenuFontWeight_over = "normal";
	this.MenuFontdecoration_over = "none";
	this.MenuDevider = 0;
	this.MenuDeviderHeight = "2px";
	this.MenuDeviderColor = "#000000"

	this.MenuItemId = new Array();
	this.MenuItem = new Array();
	this.MenuLocation = new Array();
	
	this.SetBorderColor = SetBorderColor;
	this.AddDevider = AddDevider;
	this.AddMenu = AddMenu;
	this.SetSpacing = SetSpacing;

	this.MenuColorAttribute = MenuColorAttribute;
	this.MenuTextAttribute = MenuTextAttribute;
	this.MenuTextOverAttribute = MenuTextOverAttribute;
	this.SetMenuDeviderAttribute = SetMenuDeviderAttribute;
	this.ChangeBG = ChangeBG;
	this.SetTitle = SetTitle;
	this.SetTitleAttribute = SetTitleAttribute;

	this.DrawMenu = DrawMenu;
	this.ShowMenu = ShowMenu;
	this.HideMenu = HideMenu;
	this.setEvent = setEvent;
}
function AddMenu(MenuItemId1,MenuLable,MenuLink)
{
	if((","+this.MenuItemId.toString()+",").indexOf(","+MenuItemId1+",") == -1 )
	{
		this.MenuItemId[this.MenuItemId.length] = MenuItemId1;
		this.MenuItem[this.MenuItem.length] = MenuLable;
		this.MenuLocation[this.MenuLocation.length] = MenuLink;
	}
	else
	{
		alert('Menu item key "'+ MenuItemId1 +'" already exist in '+ this.MenuId  +' menu ');
	}
}
function AddDevider()
{
	var deviderid,deviderstr;
	deviderid = this.MenuId + "Devider"+this.MenuDevider;
	deviderstr = "#MenuDevider#";
	this.AddMenu(deviderid,deviderstr,'');
	this.MenuDevider += 1;
}
function SetBorderColor(MenuBorderColor)
{
	this.BorderColor = "#"+MenuBorderColor;
}
function SetSpacing(top,right,bottom,left)
{
	this.TopSpacing = top+"px ";
	this.RightSpacing = right+"px ";
	this.BottomSpacing = bottom+"px ";
	this.LeftSpacing = left+"px ";
}
function SetTitle(title)
{
	this.MenuHeading = true;
	this.MenuTitle = title
}
function SetTitleAttribute(bgcolor,font,size,color,weight,decoration)
{
	this.TitleBgColor = "#"+bgcolor;
	this.TitleFont = font;
	this.TitleFontSize = size+"px";
	this.TitleFontColor = "#"+color;
	this.TitleFontWeight = weight;
	this.TitleFontdecoration = decoration;
}
function MenuColorAttribute(sltdColor,hoverColor)
{
	this.MenuBgColor = "#"+sltdColor;
	this.MenuOverBgColor = "#"+hoverColor;
}
function MenuTextAttribute(font,size,color,weight,decoration)
{
	this.MenuFont = font;
	this.MenuFontSize = size + "px";
	this.MenuFontColor = "#" + color;
	this.MenuFontWeight	= weight;
	this.MenuFontdecoration =  decoration;
}
function MenuTextOverAttribute(font,size,color,weight,decoration)
{
	this.MenuFont_over = font;
	this.MenuFontSize_over = size + "px";
	this.MenuFontColor_over = "#" + color;
	this.MenuFontWeight_over = weight;
	this.MenuFontdecoration_over =  decoration;
}
function SetMenuDeviderAttribute(Deviderheight,DeviderColor)
{
	this.MenuDeviderHeight = Deviderheight+"px";
	this.MenuDeviderColor = "#"+DeviderColor;
}
function DrawMenu()
{
	var DivOpen,DivClose,Menucontent;
	DivOpen = "<div id='"+this.MenuId +"' style='position:absolute; visibility: hidden; z-index:1000; width:"+this.MenuWidth+"; top:"+this.Toppos+"; left:"+this.Leftpos+";'>";
	DivOpen += "\n<table id='"+this.MenuId +"table' border=0 cellpadding=0 cellspacing=0 width='100%' style='cursor: pointer;cursor: hand;;border:"+ this.MenuBorder +" "+ this.BorderColor +" solid' onClick='javascript:HideMenu(\""+ this.MenuId +"\")'>"
	Menucontent = "";
	if(this.MenuHeading)
	{
		Menucontent +="\n<tr><td bgcolor="+this.TitleBgColor+" style='cursor: text;font-family:"+this.TitleFont+";font-size:"+this.TitleFontSize+";color:"+this.TitleFontColor+";font-weight:"+this.TitleFontWeight+";text-decoration:"+this.TitleFontdecoration+";padding:"+ this.TopSpacing + this.RightSpacing + this.BottomSpacing + this.LeftSpacing +"'>";
		Menucontent += this.MenuTitle;
		Menucontent +="</td></tr>";
	}
	for(i=0;i<this.MenuItemId.length;i++)
	{
		//alert("MenuID :"+this.MenuItemId[i]+"\n I Value : "+i);
		if(this.MenuItem[i] != "#MenuDevider#")
		{
		Menucontent +="\n<tr><td id='"+ this.MenuItemId[i] +"' bgcolor="+this.MenuBgColor+" style='font-family:"+this.MenuFont+";font-size:"+this.MenuFontSize+";color:"+this.MenuFontColor+";font-weight:"+this.MenuFontWeight+";text-decoration:"+this.MenuFontdecoration+";padding:"+ this.TopSpacing + this.RightSpacing + this.BottomSpacing + this.LeftSpacing +"' onmouseover='javascript:ChangeBG(this,\""+this.MenuOverBgColor+"\",\""+this.MenuFont_over+"\",\""+this.MenuFontSize_over+"\",\""+this.MenuFontColor_over+"\",\""+this.MenuFontWeight_over+"\",\""+this.MenuFontdecoration_over+"\")' onmouseout='ChangeBG(this,\""+this.MenuBgColor+"\",\""+this.MenuFont+"\",\""+this.MenuFontSize+"\",\""+this.MenuFontColor+"\",\""+this.MenuFontWeight+"\",\""+this.MenuFontdecoration+"\")' onclick='javascript:location.href=\""+ this.MenuLocation[i] +"\"'>";
		Menucontent += this.MenuItem[i] ;
		Menucontent +="</td></tr>";
		}
		else
		{
			Menucontent +="\n<tr><td id='"+ this.MenuItemId[i] +"' bgcolor="+this.MenuBgColor+" height = '"+this.MenuDeviderHeight+"' style='padding:"+ "0px " + this.RightSpacing + "0px " + this.LeftSpacing +"' ><hr NOSHADE SIZE='"+this.MenuDeviderHeight+"' color='"+this.MenuDeviderColor+"'></td></tr>";
		}
	}
	DivClose = "</table>\n";
	DivClose += "</div>";
	//prompt("",DivOpen + Menucontent + DivClose);
	document.writeln(DivOpen + Menucontent + DivClose);
}
function ChangeBG(tdobj,bgcolor,font,fsize,fcolor,fweight,fdecoration)
{
	tdobj.style.backgroundColor = ""+bgcolor+"";
	tdobj.style.fontFamily = ""+font+"";
	tdobj.style.fontSize = ""+fsize+"";
	tdobj.style.color = ""+fcolor+"";
	tdobj.style.fontWeight = ""+fweight+"";
	tdobj.style.textDecoration = ""+fdecoration+"";
}
function ShowMenu(tdobj)
{
	if(window.clickevent)
	{
		var MenuLeft,MenuTop,MenuObj,tdobjcopy,tdobjleft,tdobjtop;
		MenuObj = document.getElementById(this.MenuId);
		
		tdobjleft = tdobjtop = 0 ;
		tdobjcopy = tdobj;
		while(tdobjcopy){
			tdobjleft += tdobjcopy.offsetLeft;
			tdobjtop += tdobjcopy.offsetTop;
			tdobjcopy = tdobjcopy.offsetParent;
		}

		if(window.lastMenu != null){
			document.getElementById(window.lastMenu ).style.visibility = "hidden";
		}
		if(this.MenuPos == "TL"){
			//alert("inside TL");
			MenuLeft = tdobjleft - MenuObj.offsetWidth - this.Leftpos;
			MenuTop = tdobjtop + this.Toppos ;
		}
		else if(this.MenuPos == "TR"){
			//alert("inside TR");
			MenuLeft = tdobjleft + tdobj.offsetWidth + this.Leftpos;
			MenuTop = tdobjtop + this.Toppos ;
		}
		else if(this.MenuPos == "BL"){
			//alert("inside BL");
			MenuLeft = tdobjleft + this.Leftpos;
			MenuTop = tdobjtop + tdobj.offsetHeight + this.Toppos ;
		}
		else{
			//alert("inside BR");
			MenuLeft = ((tdobjleft + tdobj.offsetWidth) - MenuObj.offsetWidth) + this.Leftpos;
			MenuTop = tdobjtop + tdobj.offsetHeight + this.Toppos ;
		}
		MenuObj.style.top = MenuTop;
		MenuObj.style.left = MenuLeft;
		MenuObj.style.visibility = "inherit";
		window.lastMenu = this.MenuId
	}
}
function HideMenu(MenuId)
{
		document.getElementById(MenuId).style.visibility = "hidden";
		window.clickevent = false;
}
function setEvent(tdobj)
{
	if(!window.clickevent){
	window.clickevent = true;
	window.unloadmenu = false;
	window.lasttdObj = tdobj;
	this.ShowMenu(tdobj);
	}else{
		HideMenu(window.lastMenu);
		if(window.lasttdObj != tdobj){
			window.clickevent = true;
			window.unloadmenu = false;
			window.lasttdObj = tdobj;
			this.ShowMenu(tdobj);
		}
	}
}

window.document.onclick = function bodyclick(){
	if(window.unloadmenu && window.clickevent){
		HideMenu(window.lastMenu);
	}else{
		window.unloadmenu = true;
	}
}