// Copyright tham chun-hong // email : tham123@yahoo.com // feel free to give me your comments // var ns = (document.layers); var ie = (document.all); var ns6 = (!document.all && document.getElementById); if (ns) document.captureEvents(Event.MOUSEMOVE) document.onmousemove = getMouseXY; var mousePosX = 0; var mousePosY = 0; function DynamicLayer() { var a=arguments; this.id=a[0]; this.position=a[1]; this.x=a[2]; this.y=a[3]; this.w=a[4]; this.h=a[5]; this.bgColor=a[6]; this.zIndex='1'; this.newlyr=null; this.mouseout='mouseOutLyr'; this.mouseover='mouseOverLyr'; this.click='mouseClick'; this.styleclass=''; this.visible=false; } DynamicLayer.prototype.setzIndex=function(idx) { this.zIndex = idx; } DynamicLayer.prototype.setMouseOver=function(data) { this.mouseover = data; } DynamicLayer.prototype.setVisible=function(data) { this.visible = data; } DynamicLayer.prototype.setMouseOut=function(data) { this.mouseout = data; } DynamicLayer.prototype.setContent=function(data) { this.content = data; } DynamicLayer.prototype.setMouseClick=function(data) { this.click = data; } DynamicLayer.prototype.setStyleClass=function(data) { if (ns) this.styleclass = data; else if (ie) this.styleclass = 'class="'+ data +'"'; } DynamicLayer.prototype.create=function() { if (ie) { document.body.insertAdjacentHTML("beforeEnd", this.getContent()); this.newlyr = document.getElementById(this.id); } else if (ns) { if (this.mouseout == 'mouseOutLyr') this.mouseout = mouseOutLyr; if (this.mouseover == 'mouseOverLyr') this.mouseover = mouseOverLyr; if (this.click == 'mouseClick') this.click = mouseClick; var dvis = (this.visible) ? 'show' : 'hide'; this.newlyr = new Layer(this.w, window); this.newlyr.layerID = this.id; this.newlyr.position = this.position; this.newlyr.left = this.x; this.newlyr.top = this.y; this.newlyr.clip.height = this.h; this.newlyr.zIndex = this.zIndex; this.newlyr.visibility = dvis; this.newlyr.bgColor = this.bgColor; this.newlyr.onmouseover = this.mouseover; this.newlyr.onmouseout = this.mouseout; // if there is a table inside the layer, clicking // the table will NOT fire thr onClick event! // this.newlyr.document.onclick = this.click; this.newlyr.document.open(); this.newlyr.document.write(this.getContent()); this.newlyr.document.close(); } else if (ns6) { if (this.mouseout == 'mouseOutLyr') this.mouseout = mouseOutLyr; if (this.mouseover == 'mouseOverLyr') this.mouseover = mouseOverLyr; if (this.click == 'mouseClick') this.click = mouseClick; var dvis = (this.visible) ? 'visible' : 'hidden'; this.newlyr = document.createElement("div"); this.newlyr.id = this.id; this.newlyr.layerID = this.id; this.newlyr.style.position = this.position; this.newlyr.style.left = this.x; this.newlyr.style.top = this.y; this.newlyr.style.clip.height = this.h; this.newlyr.style.zIndex = this.zIndex; this.newlyr.style.visibility = dvis; this.newlyr.style.background = this.bgColor; this.newlyr.addEventListener("mouseover", this.mouseover, false); this.newlyr.addEventListener("mouseout", this.mouseout, false); this.newlyr.addEventListener("click", this.click, false); document.body.appendChild(this.newlyr); this.newlyr.innerHTML = this.getContent(); } } DynamicLayer.prototype.getContent=function() { var str = ""; var dvis = ""; if (ie) { dvis = (this.visible) ? 'visible' : 'hidden'; str = "\n
"+ ((this.content)?this.content:"") +"
\n"; //str += ";'>"+ ((this.content)?this.content:"") +"\n"; } else if (ns || ns6) { str = this.content; } return str; } DynamicLayer.prototype.setContent=function(data) { this.content = data; } DynamicLayer.prototype.remove=function() { if (ns) { this.newlyr.visibility = 'hide'; delete this.newlyr; } else if (ie || ns6) { this.newlyr.style.visibility = 'hidden'; var test = this.newlyr.innerHTML; if (test!=null && test!='') { this.newlyr.innerHTML = ""; this.newlyr.outerHTML = ""; } } } DynamicLayer.prototype.moveTo=function(x, y) { if (ns) { this.newlyr.top = y; this.newlyr.left = x; } else if (ie || ns6) { this.newlyr.style.top = y; this.newlyr.style.left = x; } } DynamicLayer.prototype.show=function() { if (ns) { this.newlyr.visibility = 'show'; } else if (ie || ns6) { this.newlyr.style.visibility = 'visible'; } } DynamicLayer.prototype.clear=function() { if (ns) { this.newlyr.visibility = 'hide'; } else if (ie || ns6) { this.newlyr.style.visibility = 'hidden'; } } DynamicLayer.prototype.setBgColor=function(color) { if (ns) { this.newlyr.bgColor = color; } else if (ie || ns6) { this.newlyr.style.background = color; } } function StaticLayer() { var a=arguments; this.id=a[0]; this.position=a[1]; this.x=a[2]; this.y=a[3]; this.w=a[4]; this.h=a[5]; this.bgColor=a[6]; this.zIndex='1'; this.mouseout='mouseOutLyr'; this.mouseover='mouseOverLyr'; this.click='mouseClick'; this.styleclass=''; this.visible=false; } StaticLayer.prototype.setzIndex=function(idx) { this.zIndex = idx; } StaticLayer.prototype.setMouseOver=function(data) { this.mouseover = data; } StaticLayer.prototype.setVisible=function(data) { this.visible = data; } StaticLayer.prototype.setMouseOut=function(data) { this.mouseout = data; } StaticLayer.prototype.setContent=function(data) { this.content = data; } StaticLayer.prototype.setMouseClick=function(data) { this.click = data; } StaticLayer.prototype.setStyleClass=function(data) { this.styleclass = data; } StaticLayer.prototype.createString=function() { return this.generate(false); } StaticLayer.prototype.create=function() { return this.generate(true); } StaticLayer.prototype.generate=function(output) { var str = ""; var dvis = ""; if (ie || ns6) { dvis = (this.visible) ? 'visible' : 'hidden'; str = "\n
"+ ((this.content)?this.content:"") +"
\n"; //str += ";'>"+ ((this.content)?this.content:"") +"\n"; } else if (ns) { if (this.position == 'relative') { str = "\n"+ ((this.content)?this.content:"") +"\n"; } else { dvis = (this.visible) ? 'show' : 'hide'; str = "\n"+ ((this.content)?this.content:"") +"\n"; //str += " >"+ ((this.content)?this.content:"") +"\n"; } } if (output) document.write(str); return str; } StaticLayer.prototype.moveTo=function(x, y) { if (ns) { document.layers[this.id].top = y; document.layers[this.id].left = x; } else if (ie) { document.all[this.id].style.top = y; document.all[this.id].style.left = x; } else if (ns6) { document.getElementById(this.id).style.top = y; document.getElementById(this.id).style.left = x; } } StaticLayer.prototype.clear=function() { if (ns) { document.layers[this.id].visibility = 'hide'; } else if (ie) { document.all[this.id].style.visibility = 'hidden'; } else if (ns6) { document.getElementById(this.id).style.visibility = 'hidden'; } } StaticLayer.prototype.show=function() { if (ns) { document.layers[this.id].visibility = 'show'; } else if (ie) { document.all[this.id].style.visibility = 'visible'; } else if (ns6) { document.getElementById(this.id).style.visibility = 'visible'; } } StaticLayer.prototype.setBgColor=function(color) { if (ns) { document.layers[this.id].bgColor = color; } else if (ie) { document.all[this.id].style.background = color; } else if (ns6) { document.getElementById(this.id).style.background = color; } } function mouseOverLyr(vid) { return; } function mouseOutLyr(vid) { return; } function mouseClick(vid) { return; } function getMouseXY(e) { if (ie) { mousePosX = event.clientX + document.body.scrollLeft; mousePosY = event.clientY + document.body.scrollTop; } else { mousePosX = e.pageX; mousePosY = e.pageY; } if (mousePosX < 0) mousePosX = 0; if (mousePosY < 0) mousePosY = 0; } function addSlash(str) { var size = str.length; var ret = ""; var test; var i = 0; for (i=0; i