home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2003 April
/
Chip_2003-04_cd1.bin
/
bonus
/
energyweb
/
inc
/
menu.js
< prev
next >
Wrap
Text File
|
2002-02-04
|
4KB
|
111 lines
var isMinNS4=(navigator.appName.indexOf("Netscape")>=0&&parseFloat(navigator.appVersion)>=4)?1:0;
var isMinIE4=(document.all)?1:0;
var isMinIE5=(isMinIE4&&navigator.appVersion.indexOf("5.")>=0)?1:0;
var pop_up_menus=0;
var pop_up_menus_instances = new Array();
function getLayer(name){if(isMinNS4)return findLayer(name,document);if(isMinIE4)return eval('document.all.'+name);return null;}
function MoveLayerTo(layer,x,y) { if(isMinNS4) { layer.moveTo(x,y); } if(isMinIE4) { layer.style.left=x;layer.style.top=y; } }
function HideLayer(layer){if(isMinNS4)layer.visibility="hide";if(isMinIE4)layer.style.visibility="hidden";}
function ShowLayer(layer) { if(isMinNS4)layer.visibility="show"; if(isMinIE4)layer.style.visibility="visible"; }
function getPageWidth(){if(isMinNS4)return document.width;if(isMinIE4)return document.body.scrollWidth;return-1;}
function getWidth(layer){if(isMinNS4){if(layer.document.width)return layer.document.width;else return layer.clip.right-layer.clip.left;}if(isMinIE4){if(layer.style.pixelWidth)return layer.style.pixelWidth;else return layer.clientWidth;}return-1;}
function getHeight(layer){if(isMinNS4){if(layer.document.height)return layer.document.height;else return layer.clip.bottom-layer.clip.top;}if(isMinIE4){if(layer.style.pixelHeight)return layer.style.pixelHeight;else return layer.clientHeight;}return-1;}
function getLeft(layer){if(isMinNS4)return layer.left;if(isMinIE4)return layer.style.pixelLeft;return-1;}
function getTop(layer){if(isMinNS4)return layer.top;if(isMinIE4)return layer.style.pixelTop;return-1;}
function getRight(layer){if(isMinNS4)return layer.left+getWidth(layer);if(isMinIE4)return layer.style.pixelLeft+getWidth(layer);return-1;}
function getBottom(layer){if(isMinNS4)return layer.top+getHeight(layer);if(isMinIE4)return layer.style.pixelTop+getHeight(layer);return-1;}
function PopUpMenu()
{
this.width = 100;
this.posx = 0;
this.posy = 0;
this.items = new Array();
this.item_count = 0;
this.created = false;
this.index = pop_up_menus++;
this.style = "";
this.backcolor = "#FFFFFF";
this.textcolor = "#000000";
this.open_func = "";
this.base_layer = null;
this.AddItem = PM_AddItem;
this.Create = PM_Create;
this.Open = PM_Open;
this.ReOpen = PM_ReOpen;
this.Close = PM_Close;
pop_up_menus_instances[pop_up_menus-1] = this;
return this;
}
function PM_AddItem(item_text,item_href,href_type)
{
this.item_count++;
this.items[this.item_count-1]= new Array(item_text,item_href,href_type);
}
function PM_Create()
{
if (this.style!="") class_str = "class='"+this.style+"'"; else class_str="";
str = "<div id='_menu_"+this.index+"' style='position:absolute; width:"+this.width+"'><table "+class_str+" bgcolor='"+this.backcolor+"' cellpadding=2 cellspacing=0 width='100%' height='100%'><tr><td>";
for (i=0;i<this.item_count;i++)
{
str = str + "<a href='"+this.items[i][1]+"' style='color:"+this.textcolor+"'>"+this.items[i][0]+"</a><br>";
}
str = str + "</td></tr></table></div>";
if(isMinNS4)
{
this.base_layer = new Layer(this.width);
}
if(isMinIE4)
{
document.body.insertAdjacentHTML("beforeEnd",str);
this.base_layer = getLayer("_menu_"+this.index);
}
HideLayer(this.base_layer);
this.base_layer.onmouseout=PM_MenuOff;
this.base_layer.index = this.index;
}
function PM_Open(x,y)
{
this.posx = x;
this.posy = y;
MoveLayerTo(this.base_layer, this.posx,this.posy);
ShowLayer(this.base_layer);
}
function PM_ReOpen()
{
MoveLayerTo(this.base_layer,this.posx,this.posy);
ShowLayer(this.base_layer);
}
function PM_Close()
{
HideLayer(this.base_layer);
}
function PM_MenuOff(e)
{
var menu = pop_up_menus_instances[this.index];
if(isMinIE4)
{
mouseX=window.event.clientX+document.body.scrollLeft;
mouseY=window.event.clientY+document.body.scrollTop;
}
if(!(mouseX>getLeft(this) && mouseX<getRight(this) && mouseY>getTop(this) && mouseY<getBottom(this)))
HideLayer(this);
}