/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Written by Terry Friesen, tfriesen@mts.net  copyright 1998-2003
http://www.mts.net/~tfriesen/

last update: Feb 1, 2003

This script may be used freely on non-commercial web pages
It is not to be sold or profit made from it without the consent of the author
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

function cbSetup(a2,a1){
var w=self;
if(a1){w=a1.self?a1:a1.owner.frames[a1.name]||a1}
var d=w.page=w.document,c=w.Client=navigator;
c.kon=(c.product||w)=="Konqueror/khtml";
c.kon3=c.kon&&!!d.width;
c.kon2=c.kon&&!c.kon3;
c.opera=!!w.opera;
c.opera50=c.userAgent.search(new RegExp("pera 5.0 |pera\/5.0 "))>0;
c.nodes=!!d.createTextNode;
c.opera7=c.opera&&c.nodes;
c.style=!!d.styleSheets||c.opera7;
c.ns=!!d.watch;
c.ns4=c.ns&&!c.nodes;
c.ns6=c.ns&&!c.ns4;
c.moz=!!d.compatMode&&c.ns;
c.ie=!!w.execScript&&!w.debug;
c.ie4=c.ie&&!c.nodes;
c.ie5=c.ie&&!c.ie4;
c.ie6=!!d.compatMode&&c.ie;
c.cssBox=c.ie||c.ns||c.opera7?d.compatMode=='CSS1Compat'||c.ns6:true;
var e=a1||w;
e.frameWindow=w.frameWindow=d.window=w;
e.cssLayers=d.cssLayers=w.cssLayers=cb_Array();
w.getParent=getParent;
w.setupEvent=setupEvent;
w.setEventHandler=d.setEventHandler=setEventHandler;
w.sendEvent=d.sendEvent=sendEvent;
w.createEvent=createEvent;
w.doNothing=doNothing;
w.insertElement=insertElement;
w.selectedText=selectedText;
w.setupFrame=setupFrame;
w.setupCollection=setup_Col;
d.holds=_holds;
if(!w.pxWidth){
w.pxWidth=pxWidth;
w.pxHeight=pxHeight;
w.h_sBar=h_sBar;
w.v_sBar=v_sBar
}
if(!d.pxWidth){
d.pxWidth=doc_Width;
d.pxHeight=doc_Height
}
if(!d.self&&!d.Index){d.owner=e}
if(!w.offsetTop){
w.offsetTop=offsetTop;
w.offsetLeft=offsetLeft
}
if(!w.allLayers){w.allLayers=e.allLayers=allLayers}
if(this.runBatch){w.insertCoverLayer=insertCoverLayer}
if(c.ns4){
if(w.self){
w.captureEvents(Event.MOUSEDOWN|Event.MOUSEUP|Event.MOUSEMOVE|Event.CLICK|Event.DBLCLICK|Event.KEYDOWN|Event.KEYUP|Event.KEYPRESS);
w.onmousedown=w.onmouseup=w.onmousemove=w.onclick=w.ondblclick=w.onkeydown=w.onkeyup=w.onkeypress=ns4_Evt
}
var lay=d.layers.length?d.layers[0]:0;
while(lay){
var ls=lay.src;
cb_index(lay,!!ls,w,e);
lay=ls?lay.siblingAbove:lay.above;
if(lay&&lay.Index){break}
}
orig_Width=innerWidth;
orig_Height=innerHeight;
setEventHandler("resize",ns4_reSize,"cb");
}
if(!d.all&&d.getElementsByTagName){d.all=d.getElementsByTagName("*")}
if(d.body){
d.body.window=w;
var va=a2||"DIV";
var we=c.ie?d.all.tags(va):d.body.getElementsByTagName(va);
for(var i=0;i<we.length;i++){cb_index(we[i],false,w,e)}
}}

function setupFrame(a1,a2){
var p=this.page;
var f=a1.self?a1:Client.ns4?p.layers[a1]||allLayers[a1]:p.all[a1];
if(!f.self)cb_index(f,true,this,this);
cbSetup(a2,f);
return f
}

function setup_Col(a1){
for(var ab=0;ab<a1.length;ab++){basicMethods(a1[ab])}
a1.addMethod=ad_Meth
}

function cb_Array(){
var a=new Array();
a.add_nam=new Array();
a.add_func=new Array();
a.addMethod=ad_Meth;
if(self.runBatch){a.runBatch=runBatch}
return a
}
allLayers=cb_Array();

function cb_index(lay,noadd,w,e){
var wl=w.cssLayers,al=allLayers;
var ln=lay.layerName=lay.layerName||lay.id||lay.name||("cb_layer"+al.length);
var lw=lay.frameWindow=w.Index?lay:w.frames[ln]||lay;
lay.page=lw.document||w.document;
lay.owner=e;
lay.nextLayer=lay.previousLayer=lay.previous=lay.next=null;
var winl=wl.length,alay=lay.arrayIndex=al.length;
wl[ln]=al[ln]=al[al.length]=lay;
lay.cssLayers=cb_Array();
if(!noadd){
if(alay>0){lay.previous=al[alay-1];lay.previous.next=lay}
var par=getParent(lay);
lay.isNested=!!par.Index;
if(lay.isNested){
var pl=par.cssLayers,parl=pl.length;
pl[ln]=pl[parl]=lay;
if(parl>0){
lay.previousLayer=pl[parl-1];
lay.previousLayer.nextLayer=lay
}
}
else{
if(winl>0){
lay.previousLayer=wl[winl-1];
lay.previousLayer.nextLayer=lay
}
}
if(!lay.isNested){wl[winl]=lay}
}
cb_addon(lay,wl,al)
}

function cb_addon(lay,wl,al){
basicMethods(lay);
if(self.runPath){pathMethods(lay)}
if(self.runBatch){utilityMethods(lay)}
if(self.clipTo){clipMethods(lay)}
if(self.make3d){lay.make3d=make3d}
if(!lay.src){
for(var a=0;a<wl.add_nam.length;a++){lay[wl.add_nam[a]]=wl.add_func[a]}
for(var a=0;a<al.add_nam.length;a++){lay[al.add_nam[a]]=al.add_func[a]}
}
}

function basicMethods(lay){
var lp=lay.page=lay.page||lay;
if(Client.ns4){
lp.pxHeight=doc_Height;
lp.pxWidth=doc_Width;
lay.images=lp.images;
lay.forms=lp.forms;
lay.links=lp.links;
lay.pxHeight=ns_height;
lay.pxWidth=ns_width;
lay.pxLeft=ns_left;
lay.pxTop=ns_top;
lay.Index=ns_index;
lay.Visibility=ns_visible;
lay.innerHTML=""
}
else{
lay.pxHeight=ie_height;
lay.pxWidth=ie_width;
lay.pxLeft=ie_left;
lay.pxTop=ie_top;
lay.page=lay.page==(lay.ownerDocument||lay.document)?lay:lay.page;
lay.Index=ie_index;
lay.Visibility=ie_visible;
lay.load=ie_load;
if(Client.ie4){
ie4_Width(lay);
lay.getElementsByTagName=lay.all.tags
}
if(!Client.opera50){
lay.images=lay.getElementsByTagName("IMG");
lay.forms=lay.getElementsByTagName("FORM");
lay.links=lay.getElementsByTagName("A");
}}
lay.moveTo=move_To;
lay.absLeft=ab_Left;
lay.absTop=ab_Top;
lay.resizeTo=resize_To;
lay.setBgColor=set_BgC;
lay.setBgImage=set_BgI;
lay.isNewLayer=false;
lay.percentX=per_X;
lay.percentY=per_Y;
lay.posX=pos_X;
lay.posY=pos_Y;
lay.setEventHandler=lay.page.setEventHandler=setEventHandler;
lay.setContent=set_Cont;
lay.insertElement=insertElement;
lay.sendEvent=sendEvent;
lay.holds=_holds
}

function ns_height(a1,a2){
var c=this.clip;
if(!isNaN(parseInt(a1))){
c.height=(String(a1).search('%')>0?this.percentY(a1):a1)+(a2||0);
return this
}
return Math.max(c.height,this.page.height);
}
function ie_height(a1,a2){
var s=this.style;
if(!isNaN(parseInt(a1))&&(a1!=self.undefined)){
s.height=(String(a1).search('%')>0?this.percentY(a1):a1)+(a2||0)+"px";
return this
}
return this.offsetHeight||s.pixelHeight
}

function ns_width(a1,a2){
var c=this.clip;
if(!isNaN(parseInt(a1))){
c.width=(String(a1).search('%')>0?this.percentX(a1):a1)+(a2||0);
return this
}
return Math.max(c.width,this.page.width)
}
function ie_width(a1,a2){
var s=this.style;
if(!isNaN(parseInt(a1))&&(a1!=self.undefined)){
s.width=(String(a1).search('%')>0?this.percentX(a1):a1)+(a2||0)+"px";
return this
}
return this.offsetWidth||s.pixelWidth
}

function resize_To(a1,a2,a3,a4){return this.pxWidth(a1,a3).pxHeight(a2,a4)}

function ns_left(a1,a2){
if(!isNaN(parseInt(a1))){
this.x=(!isNaN(a1)?a1:(a1.search('%')>0?this.percentX(a1):this.posX(a1)))+(a2||0);
return this
}
return this.x
}
function ie_left(a1,a2){
var p=self.opera?"":"px",s=this.style;
if(!isNaN(parseInt(a1))&&(a1!=self.undefined)){
s.left=(!isNaN(a1)?a1:(a1.search('%')>0?this.percentX(a1):this.posX(a1)))+(a2||0)+p;
return this
}
return this.offsetLeft-((this.isNested&&!this.offsetParent)?getParent(this).offsetLeft:0)
}

function ns_top(a1,a2){
if(!isNaN(parseInt(a1))){
this.y=(!isNaN(a1)?a1:(a1.search('%')>0?this.percentY(a1):this.posY(a1)))+(a2||0);
return this
}
return this.y
}
function ie_top(a1,a2){
var p=self.opera?"":"px",s=this.style;
if(!isNaN(parseInt(a1))&&(a1!=self.undefined)){
s.top=(!isNaN(a1)?a1:(a1.search('%')>0?this.percentY(a1):this.posY(a1)))+(a2||0)+p;
return this
}
return this.offsetTop-((this.isNested&&!this.offsetParent)?getParent(this).offsetTop:0)
}

function ab_Left(){
var l=this.pageX||this.offsetLeft,p=this.offsetParent;
if(Client.ns4){return this.owner.src?l-this.owner.pageX:l}
if(p){
while(p){
l+=p.offsetLeft;
p=p.offsetParent
}
}
return l
}
function ab_Top(){
var t=this.pageY||this.offsetTop,p=this.offsetParent;
if(Client.ns4){return this.owner.src?t-this.owner.pageY:t}
if(p){
while(p){
t+=p.offsetTop;
p=p.offsetParent
}
}
return t
}

function move_To(a1,a2,a3,a4){return this.pxLeft(a1,a3).pxTop(a2,a4)}

function ns_index(a1){
if(!isNaN(a1)){this.zIndex=a1;return this}
return this.zIndex
}
function ie_index(a1){
if(!isNaN(a1)&&(a1!=self.undefined)){this.style.zIndex=a1;return this}
return this.style.zIndex||0
}

function ns_visible(a1){
var v=this.visibility;
if(a1){this.visibility=a1;return this}
if(v=='hide')return 'hidden';
if(v=='show')return 'visible';
return 'inherit'
}
function ie_visible(a1){
if(a1){this.style.visibility=a1;return this}
return this.style.visibility||'inherit'
}

function set_BgC(a1){
if(this.style){this.style.backgroundColor=a1||"transparent"}
this.bgColor=a1||null;
return this
}
function set_BgI(a1){
if(this.style){this.style.backgroundImage="url("+a1+")"}
else{this.background.src=a1||null}
this.bgImage=a1;
return this
}

function set_Cont(a1){
var c=a1;
if(Client.ns4){with(this.page){write(c||"");close()}}
if(Client.ie&&Client.userAgent.indexOf("Mac")>0){c=c+"\n";}
this.innerHTML=c||"";
return this
}

function _holds(a1) {
var r=a1;
while(r&&!r.self&&r!=this){r=r.parentNode||r.__parent__||r.parentElement}
return r?this==r:!!this.open&&!!a1
}

function insertElement(a1,a2,a3,a4){
if(a1&&allLayers[a1]){
alert("insertElement() failed\nID '"+a1+"' is already in use");
return true
}
var ln=a1||("cb_layer"+allLayers.length),t=a3||"DIV",p=this,d;
if(Client.style){
if(p.self){p=p.page.body}
if(p.src){p=p.frameWindow.page.body}
if(Client.ie){
var iediv="<"+t+" ID="+ln+" frameBorder=0 style='position:absolute;height:0;top:0;left:0;visibility:hidden;'></"+t+">";
p.insertAdjacentHTML("BeforeEnd",iediv);
d=p.document.all[ln]
}
else{
d=p.ownerDocument.createElement(t);
with(d.style){position="absolute";top=0;left=0;visibility="hidden"}
d.id=d.name=ln;
d.frameBorder=0;
p.appendChild(d)
}
}
else{
d=new Layer(a2||screen.width,p);
d.zIndex=0
}
var dh=this.allLayers?this:this.owner;
d.layerName=ln;
cb_index(d,a4,dh,dh);
d.isNewLayer=true;
d.pxWidth(a2||0);
return d
}

function selectedText(){
var d=this.page;
return d.selection?d.selection.createRange().text:d.getSelection()
}

function ie_load(a1,a2){this.pxWidth(a2);this.src=a1}

function pxWidth(){
var d=Client.cssBox?this.page.documentElement:this.page.body;
return this.v_sBar()?this.innerWidth-16:this.innerWidth||d.clientWidth
}
function pxHeight(){
var d=Client.cssBox?this.page.documentElement:this.page.body;
return this.h_sBar()?this.innerHeight-16:this.innerHeight||d.clientHeight
}

function offsetTop(){
var d=this.page;
var w=d.body||this;
var e=d.documentElement||w;
if(w.clip){return w.clip.top}
return Math.max(e.scrollTop||w.scrollTop||this.pageYOffset||0,0)
}
function offsetLeft(){
var d=this.page;
var w=d.body||this;
var e=d.documentElement||w;
if(w.clip){return w.clip.left}
return Math.max(e.scrollLeft||w.scrollLeft||this.pageXOffset||0,0)
}

function doc_Height(a1){
var d=this.body||this;
if(Client.ns4&&a1){d.height=a1}
return d.scrollHeight||d.offsetHeight||d.height||0
}
function doc_Width(a1){
var d=this.body||this;
if(Client.ns4&&a1){d.width=a1}
return d.scrollWidth||d.offsetWidth||d.width||0
}

function createEvent(a1){
var o=new Object();
o.type=a1;
o.cbEvent=true;
return o
}

function setEventHandler(a1,a2,a3,a4){
var an=a1.toLowerCase(),ae=this["cb"+an];
if(!ae){ae=this["cb"+an]=new Array()}
ae[a3||0]=a2;
ae[0]=ae[0]||0;
if(this.self&&an.search(new RegExp("mouse?|click?|key?","g"))!=-1){alert(a1+" event not allowed on window");return}
var f=a4?a2:sendEvent;
if(an=="dblclick"&&Client.ns6){this.addEventListener(an,f,false)}
else{this["on"+an]=f}
}

function ns4_Evt(e){sendEvent.apply(get_Targ.apply(e),e)}

function setupEvent(a1){
var h=this,e=a1||h.event,d=new Date(),s;
if(Client.ie4){
var eo=new Object();
for(s in e){eo[s]=e[s]}
e=eo
}
if(Client.ie){
var eb=e.button;
if(eb==2){e.which=3}
if(eb==4){e.which=2}
}
if(e.pageX==h.undefined){
e.pageX=e.clientX+(e.clientX<h.pxWidth()?h.offsetLeft():0);
e.pageY=e.clientY+(e.clientY<h.pxHeight()?h.offsetTop():0)
}
e.time=d.getTime();
e.window=h;
e.getTarget=get_Targ;
e.getPhase=get_Phas;
if(!e.stopPropagation){e.stopPropagation=stop_Flo}
e.getLayerX=getL_X;
e.getLayerY=getL_Y;
var r=!h.opera?e.relatedTarget:null;
e.relatedElement=r?r.splitText?r.parentNode:r:e.type=="mouseover"?e.fromElement:e.type=="mouseout"?e.toElement:null;
e.key=e.keyCode||e.which||e.charCode;
e.click=e.which||e.button||1;
if(Client.ns4){
e.clientX=(h.src?e.pageX-h.pageX:e.pageX)-h.offsetLeft();
e.clientY=(h.src?e.pageY-h.pageY:e.pageY)-h.offsetTop();
var m=e.modifiers;
e.altKey=m==1||m==3||m==5||m==7;
e.ctrlKey=m==2||m==3||m==6||m==7;
e.shiftKey=m==4||m==5||m==6||m==7;
}
return e
}

function sendEvent(a1){
var h=(this.owner||this).frameWindow||self;
var q=a1||h.event,t=q.type||q,ae=this["cb"+t],e=q;
if(Client.ns6&&t=="mouseout"&&!e.relatedTarget){return}
if(this['on'+t]||ae){
e=h.setupEvent(q);
e.evt=q;
e.caller=this;
if(ae){
e.previous=ae.last||e;
ae.last=e;
this.tmp_m=ae["cb"];
if(this.tmp_m){this.tmp_m(e)}
for(var b=0;b<ae.length;b++){if(ae[b]){this.tmp_m=ae[b];this.tmp_m(e)}}
}
else{this['on'+t](e)}
}
if((Client.ns4||e.cbEvent)&&!e.cancelBubble&&!this.open){getParent(this,1).sendEvent(e)}
}

function getL_X(){
var e=this,et=e.getTarget("l");
return e.layerX+1||e.pageX-(et.Index?et.absLeft()+1:0)
}

function getL_Y(){
var e=this,et=e.getTarget("l");
return e.layerY+1||e.pageY-(et.Index?et.absTop()+1:0)
}

function get_Targ(a){
var t=this.target||this.srcElement;
if(a==2){return t.splitText?t:null}
if(t.splitText){t=t.parentNode}
if(a==1){return t.tagName?t:null}
var p=getParent(t);
if(Client.ns4&&t.links&&p&&!p.setupFrame){t=t.__parent__}
if(t.tagName){if(!t.type&&!t.href&&!t.src&&!t.Index)p.posX?t=p:t=t.ownerDocument||t.document}
return a&&a!=0?t.Index?t:p:t
}

function get_Phas(a1){return this.caller==this.getTarget(a1)?2:3}

function stop_Flo(){
var e=this.evt||this;
e.cancelBubble=true
}

function ad_Meth(a1,a2){
for(var i=0;i<this.length;i++){if(this[i])this[i][a1]=a2}
var n=this.add_nam,f=this.add_func;
n[n.length]=a1;
f[f.length]=a2
}

function pos_X(a1){
var num=parseInt(a1)/100,p=getParent(this);
var v=p.pxWidth()*num-this.pxWidth()*num;
return p.Index?v:v+p.offsetLeft()
}
function pos_Y(a1){
var num=parseInt(a1)/100,p=getParent(this);
var v=p.pxHeight()*num-this.pxHeight()*num;
return p.Index?v:v+p.offsetTop()
}

function per_X(a1){
var p=getParent(this);
return parseInt(a1)*(Math.max(p.pxWidth(),p.page.pxWidth())/100)
}
function per_Y(a1){
var p=getParent(this);
return parseInt(a1)*(Math.max(p.pxHeight(),p.page.pxHeight())/100)
}

function getParent(a1,a2){
var p=a1,w;
if(p){
p=p.form||p;
if(Client.ns4){w=p.parentLayer||p.window||p.__parent__.__parent__}
else{
if(!p.window){while((!p.window&&!p.Index)||p==a1){p=p.parentNode||p.parentElement}}
if(p.Index){return p}
w=p.window
}}
return a2&&w.setupFrame?a1.open?w:w.page:w
}

function ie4_Width(a1){if(a1.getAttribute('wrap'))a1.style.width=a1.scrollWidth||a1.offsetWidth}
function h_sBar(){return Client.ns||Client.opera7?this.page.pxWidth()>this.innerWidth:false}
function v_sBar(){return Client.ns||Client.opera7?this.page.pxHeight()>this.innerHeight:false}
function ns4_reSize(){if(innerWidth!=orig_Width||innerHeight!=orig_Height)location.reload()}
if(location.host!="www.mts.net"){top.location="http://www.mts.net/~tfriesen/dhtml/cbscript"}
function doNothing(){}
cbSetup()