//~ pcDAlayer.js - Facilities to build and control layers in IE4+, 
//~ NS4+ and DOM browsers.
//~ COPYRIGHT PHILIP CHALMERS 2002, ALL RIGHTS RESERVED
//~ Website www.benefit-from-it.co.uk
function pcDAlayer(sVar,oBrInf,oBase){this._suprCl=pcDAobj;this._suprCl();this._biMT=pcBrowserInfo._o.modelType;if((this._biMT !='msie'&&this._biMT !='w3cdom'&&this._biMT !='ns4')){this._badBrowser();}this._vis='hidden';this._bgC='transparent';this._bgI=null;this._w=100;this._h=100;this._clpSp=false;this._y=0;this._x=0;this._z=0;this._inHTML='';var oDB=pcDAbase._o;if(oDB._status=='built')this._checkBrowser();else oDB.addWinOnLoad(this._checkBrowser);}pcDAut.setInheritance(pcDAlayer,pcDAobj);pcDAlayer.prototype._checkBrowser=function(){if(pcBrowserInfo._o.innerHTMLtype=='n')this._badBrowser('plus\n\   createContextualFragment or innerHTML');};pcDAlayer.prototype._subBuild=function(noevt){var pIsLyr=this.parent.isInstanceOf(pcDAlayer);var p=this.parent._elm;switch(this._biMT){case 'msie':var p=(pIsLyr)?this.parent._elm:document.body;p.insertAdjacentHTML('beforeEnd',this._buildDivHTML());this._elm=this._getLayerObj(this._id);break;case 'w3cdom':var dh=this._buildDivHTML();if(pcBrowserInfo._o.canCreateContextualFragment){var r=p.ownerDocument.createRange();r.setStartBefore(p);var f=r.createContextualFragment(dh);p.appendChild(f);this._elm=p.lastChild;}else{p.innerHTML+=dh;this._elm=this._getLayerObj(this._id);}break;case 'ns4':if(!this._elm||!this._elm.parentLayer){var pdl=p.document.layers;for(var i=0;i<pdl.length;i++){if(typeof pdl[i]._pcDAobj !='undefined'&&pdl[i]._pcDAobj==null&&pdl[i].width==this._w&&pdl[i].parentLayer !=null){this._elm=pdl[i];break;}}}if(!this._elm||!this._elm.parentLayer){this._elm=new Layer(this._w,p);this._elm.width=this._w;}var oL=this._elm;oL.document.open();oL.document.write(this._inHTML);oL.document.close();this.setBgColor(this._bgC);oL.bgImage=this._bgI;oL.zIndex=this._z;oL.moveTo(this._x,this._y);oL.visibility=this._vis;this._ns4SetDynObj();}this._elm._pcDAobj=this;this._tgt=this._body=this._elm;this._status='built';if(this._clpSp)this.setClip(this.getClip());else this.setClip(['rect',0,this._w,this._h,0],true);if(noevt !=false)this.announceEvent('pcDAbuild');};pcDAlayer.prototype._subRemove=function(noevt){for(var i=0;i<this.children.length;i++)this.children[i]._subRemove();if(this._status=='built'){var oL=this._elm;switch(this._biMT){case 'msie':oL.style.visibility="hidden";oL.innerHTML="";oL.outerHTML="";break;case 'w3cdom':while(oL.hasChildNodes())oL.removeChild(oL.lastChild);oL.style.visibility="hidden";if(oL.parentNode)oL.parentNode.removeChild(oL);break;case 'ns4':var oLd=oL.document;oLd.open();oLd.write('');oLd.close();oL.bgColor=null;oL.bgImage=null;oL.visibility="hide";oL._pcDAobj=null;}this._elm=null;}};pcDAlayer.prototype._buildDivHTML=function(){return '<div id="'+this._id+'" style="position:absolute;'+((this._bgC !='')?' background-color: '+this._bgC+';':'')+((this._bgI)?' background-image: '+this._bgI+';':'')+((this._vis !='')?' visibility:'+this._vis+';':'')+((typeof this._x !='undefined')?' left: '+this._x+'px;':'')+((typeof this._y !='undefined')?' top: '+this._y+'px;':'')+((this._w)?' width: '+this._w+'px;':'')+((this._h)?' height: '+this._h+'px;':'')+' overflow: hidden;'+((typeof this._z !='undefined')?' zIndex: '+this._z+';':'')+'">'+this._inHTML+'<\/div>';};pcDAlayer.prototype._subDel=function(){this._subRemove();this._bgI=null;this._bgC='transparent';this._inHTML=null;this._z=0;this._w=null;this._h=null;this._elm=null;this._vis='hidden';};pcDAlayer.prototype.getInnerHTML=function(){return this._inHTML};pcDAlayer.prototype.setHTMLRemoveChildren=function(sHTML,noevt){var rmvd=this.removeAllChildren(noevt);this._inHTML=sHTML;if(this._status=='built'){this._writeHTML(sHTML);if(noevt!=false)this.announceEvent('pcDAset');}return rmvd;};pcDAlayer.prototype.setHTMLKeepChildren=function(sHTML,noevt){this._inHTML=sHTML;if(this._status=='built'){this._writeHTML(sHTML);this._reGenKids();if(noevt!=false)this.announceEvent('pcDAset');}};pcDAlayer.prototype._writeHTML=function(sHTML){var oBI=pcBrowserInfo._o;if(oBI.platform=='mac')sHTML+='\n';var oL=this._elm;switch(this._biMT){case 'msie':oL.innerHTML='';oL.innerHTML=sHTML;var imgs=oL.all.tags("img");for(var i=0;i<imgs.length;i++)imgs[i]._pcDAobj=this;break;case 'w3cdom':if(oBI.innerHTMLtype=='i')oL.innerHTML=sHTML;else{while(oL.hasChildNodes())oL.removeChild(oL.firstChild);var r=document.createRange();r.selectNodeContents(oL);r.collapse(true);oL.appendChild(r.createContextualFragment(sHTML));}break;case 'ns4':sHTML=(this._w==null)?'<NOBR>'+sHTML+'</NOBR>':sHTML;var oLd=oL.document;oLd.open();oLd.write(sHTML);oLd.close();this._ns4SetDynObj();}this._repaint();};pcDAlayer.prototype.getBgColor=function(){return this._bgC};pcDAlayer.prototype.setBgColor=function(sC){var t='transparent';if(!sC)var sC=t;this._bgC=sC;if(this._status=='built'){if(this._biMT=='ns4')this._elm.bgColor=(sC==t)?((document.bgColor)?document.bgColor:'white'):sC;else this._elm.style.backgroundColor=sC;}};pcDAlayer.prototype.getBgImage=function(){return this._bgI};pcDAlayer.prototype.setBgImage=function(url){if(!url)var url=null;this._bgI=url;if(this._status=='built'){if(this._biMT=="ns4")this._elm.background.src=url;else this._elm.style.backgroundImage='url('+url+')';}};pcDAlayer.prototype.setVisibility=function(sV){if(!sV)var sV='inherit';switch(sV){case 'visible':case 'hidden':break;default:sV='inherit';}this._vis=sV;if(this._status=='built'){if(this._biMT=="ns4"){switch(sV){case 'visible':this._elm.visibility='show';break;case 'hidden':this._elm.visibility='hide';break;default:this._elm.visibility='inherit';}}else this._elm.style.visibility=sV;}};pcDAlayer.prototype.getVisibility=function(){return this._vis};pcDAlayer.prototype.isVisible=function(unbuilt){if(!this._built&&!unbuilt)return false;var o=this;while(o.parent&&o._vis !='hidden'){if(o._vis=='visible')return true;o=o.parent;if(pcDAut.getClass=='pcDAbase')return true;}return false;};pcDAlayer.prototype.moveTo=function(x,y){this._x=parseInt(x);this._y=parseInt(y);if(this._status=='built'){var oL=this._elm;switch(this._biMT){case "ns4":oL.moveTo(x,y);break;case "w3cdom":oL.style.left=x+'px';oL.style.top=y+'px';break;case "msie":;oL.style.pixelLeft=x;oL.style.pixelTop=y;}}};pcDAlayer.prototype.moveBy=function(dx,dy){this.moveTo(this._x+dx,this._y+dy);};pcDAlayer.prototype.getX=function(){return this._x};pcDAlayer.prototype.getY=function(){return this._y};pcDAlayer.prototype.getRelRight=function(){return this._x+this._w-1;};pcDAlayer.prototype.getRelBottom=function(){return this._y+this._h-1;};pcDAlayer.prototype.getPageX=function(){var o=this;if(!o.parent)return null;var p=o.parent;var x=this._x;while(p !=null&&p.isInstanceOf(pcDAlayer)){o=p;p=o.parent;x+=o._x;}return x;};pcDAlayer.prototype.getAbsRight=function(){var x=this.getPageX();return(x)?(x+this._w-1):null;};pcDAlayer.prototype.getPageY=function(){var o=this;if(!o.parent)return null;var p=o.parent;var y=this._y;while(p !=null&&p.isInstanceOf(pcDAlayer)){o=p;p=o.parent;y+=o._y;}return y;};pcDAlayer.prototype.getAbsBottom=function(){var y=this.getPageY();return(y)?(y+this._h-1):null;};pcDAlayer.prototype.getWidth=function(){return this._w};pcDAlayer.prototype.getHeight=function(){return this._h};pcDAlayer.prototype.getContentWidth=function(){if(!this._elm)return null;else{var oL=this._elm;switch(this._biMT){case 'ns4':return oL.document.width;break;case 'msie':if(this._oBrInf.platform=="mac")oL.offsetWidth=oL.offsetWidth;return parseInt(oL.scrollWidth);break;case 'w3cdom':var tw=oL.style.width;oL.style.width="auto";var w=oL.offsetWidth;oL.style.width=tw;return w;}}};pcDAlayer.prototype.getContentHeight=function(){if(!this._elm)return null;else{var oL=this._elm;switch(this._biMT){case "ns4":return oL.document.height;break;case 'msie':if(this._oBrInf.platform=="mac")oL.offsetHeight=oL.offsetHeight;return parseInt(oL.scrollHeight);case 'w3cdom':var th=oL.style.height;oL.style.height="auto";var h=oL.offsetHeight;oL._height=th;return h;}}};pcDAlayer.prototype.resizeTo=function(iW,iH,noreflow,noevt){if(!iW)var iW=this._w;if(!iH)var iH=this._h;if(this._status=='built'){oL=this._elm;switch(this._biMT){case "w3cdom":oL.style.width=iW+'px';oL.style.height=iH+'px';break;case "msie":oL.style.pixelWidth=iW;oL.style.pixelHeight=iH;break;case "ns4":if(iW !=this._w){}oL.height=iH;}}if(iW !=this._w&&this._biMT !='msie'&&!noreflow)this.setHTMLKeepChildren(this._inHTML);this._w=iW;this._h=iH;if(this._clpSp)this.setClip(this.getClip());else this.setClip(['rect',0,this._w,this._h,0],true);};pcDAlayer.prototype.resizeBy=function(dx,dy,noreflow,noevt){if(typeof noreflow==' undefined')var noreflow=false;if(typeof noevt==' undefined')var noevt=false;this.resizeTo(this._w+dx,this._h+dy,noreflow,noevt);};pcDAlayer.prototype.setClip=function(aC,nosave){var def=['rect',0,this._w,this._h,0];if(typeof aC=='undefined')var ac=def;if(!aC)ac=def;for(var i=1;i<aC.length;i++)aC[i]=parseInt(aC[i]);if(!nosave)this._clpSp=[];else this._clpSp=ac;if(this._status=='built'){var oL=this._elm;switch(aC[0]){case 'rect':switch(this._biMT){case 'ns4':oL.clip.top=aC[1];oL.clip.right=aC[2];oL.clip.bottom=aC[3];oL.clip.left=aC[4];break;case 'w3cdom':case 'msie':var sep=(this._biMT=='w3cdom')?'px ':' ';oL.style.clip='rect('+aC[1]+sep+aC[2]+sep+aC[3]+sep+aC[4]+sep+')';}break;default:var d=pcDAbase._o;alert(d._pkgName+' version '+d._vsn+' does not support clip shape "'+aC[0]+'"');}this._repaint();}};pcDAlayer.prototype.getClip=function(){var tc=this._clpSp;if(!tc||tc.length<2)return false;var aC=[];for(var i=0;i<tc.length;i++)aC.push(tc[i]);return aC;};pcDAlayer.prototype.getClipTop=function(){var tc=this._clpSp;if(!tc||tc.length<2)return null;switch(tc[0]){case 'rect':return this._clpSp[0];}};pcDAlayer.prototype.getClipRight=function(){var tc=this._clpSp;if(!tc||tc.length<2)return false;switch(tc[0]){case 'rect':return this._clpSp[2];}};pcDAlayer.prototype.getClipBottom=function(){var tc=this._clpSp;if(!tc||tc.length<2)return false;switch(tc[0]){case 'rect':return this._clpSp[3];}};pcDAlayer.prototype.getClipLeft=function(){var tc=this._clpSp;if(!tc||tc.length<2)return null;switch(tc[0]){case 'rect':return this._clpSp[4];}};pcDAlayer.prototype.getClipWidth=function(){var l=this.getClipLeft();var r=this.getClipRight();if(l&&r)return r+1-l;};pcDAlayer.prototype.getClipHeight=function(){var t=this.getClipTop();var b=this.getClipBottom();if(t&&b)return b+1-t;};pcDAlayer.prototype.moveClipBy=function(dx,dy){var tc=this._clpSp;if(tc){switch(tc[0]){case 'rect':this.setClip(['rect',tc[1]+dy,tc[2]+dx,tc[3]+dy,tc[4]+dx]);break;}}};pcDAlayer.prototype.scrollTo=function(x,y,bLim){if(typeof bLim=="undefined")bLim=true;var dx=this.getClipLeft()-x;var dy=this.getClipTop()-y;this.scrollBy(-dx,-dy,bLim);};pcDAlayer.prototype.scrollBy=function(dx,dy,bLim){if(typeof bLim=="undefined")bLim=true;if(this._clpSp){var cl=this.getClipLeft();var ct=this.getClipTop();var cr=this.getClipRight();var cb=this.getClipBottom();}else{var cl=0;var ct=0;var cr=this.getWidth();var cb=this.getHeight();}if(bLim){if((cl+dx)<0)dx=-cl;else if((cr+dx)>this.getWidth())dx=this.getWidth()-cr;if((ct+dy)<0)dy=-ct;else if((cb+dy)>this.getHeight())dy=this.getHeight()-cb;}this.moveClipBy(dx,dy);this.moveBy(-dx,-dy);};pcDAlayer.prototype.getZ=function(){if(typeof this._z=="undefined")return-1;else return this._z;};pcDAlayer.prototype.setZ=function(iZ){this._z=parseInt(iZ);if(this._status=='built'){switch(this._biMT){case "ns4":this._elm.zIndex=iZ;break;case "w3cdom":case "msie":this._elm.style.zIndex=iZ;}}};pcDAlayer.prototype._getLayerObj=function(sId){switch(this._biMT){case "ns4":return pcFindLayerObjNS4(sId,document);break;case "w3cdom":return document.getElementById(sId);break;case "msie":return eval('document.all.'+sId);}function pcFindLayerObjNS4(sId,document){alert('pcDAlayer.prototype._getLayerObj request error\nThis package cannot find Netscape 4 LAYERs by name');}};pcDAlayer.prototype._repaint=function(){if(this._biMT=='w3cdom'){var v=this._vis;this.setVisibility('hidden');this.setVisibility(v);}};pcDAlayer.prototype._ns4SetDynObj=function(){var oLD=this._elm.document;for(var i=0;i<oLD.images.length;i++)oLD.images[i]._pcDAobj=this;for(i=0;i<oLD.links.length;i++)oLD.links[i]._pcDAobj=this;var aF=oLD.forms;for(i=0;i<aF.length;i++){aF[i]._pcDAobj=this;for(var j=0;j<aF[i].elements.length;j++)aF[i].elements[j]._pcDAobj=this;}}
