/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Written by Terry Friesen,  tfriesen@mts.net  copyright 1998,1999
http://members.xoom.com/tfriesen/

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
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

ns4=document.layers;
ie4=document.all;
var div=new Array();
var divcount=0;
var lastVisDiv=null;
var lastIndexDiv=null;
var lastClipDiv=null;
var lastIndex=null;

if(ns4){
for(i=0;i<ns4.length;i++){nsmethods(ns4[i]);}
links=document.links;
origWindowWidth=innerWidth;
origWindowHeight=innerHeight;
onresize=function(){
if((innerWidth !=origWindowWidth)||(innerHeight !=origWindowHeight))
location.reload()
}
document.captureEvents(Event.KEYPRESS|Event.KEYUP|Event.KEYDOWN);
}

if(ie4){
for(i=0;i<ie4.length;i++){
if((ie4[i].id !='')&&(ie4[i].offsetParent.id =='')){
iemethods(ie4[i]);
}}
links=new Array();
for(i=0;i<document.links.length;i++){
offPar=document.links[i].offsetParent;
if(offPar.id ==''){
links[i]=document.links[i];
}}}

function nsmethods(theLayer){
theLayer.parentDiv=theLayer.parentLayer;
theLayer.images=theLayer.document.images;
theLayer.forms=theLayer.document.forms;
theLayer.links=theLayer.document.links;
theLayer.Height=nsheight;
theLayer.Width=nswidth;
theLayer.Left=nsleft;
theLayer.Top=nstop;
theLayer.Index=nsindex;
theLayer.Visibility=nsvisibility;
theLayer.setClip=nsclip;
theLayer.clipTop=nscliptop;
theLayer.clipRight=nsclipright;
theLayer.clipBottom=nsclipbottom;
theLayer.clipLeft=nsclipleft;
theLayer.setBgColor=nsbgcolor;
theLayer.setBgImage=nsbgimage;
theLayer.setContent=nscontent;
commonmethods(theLayer);
}

function iemethods(theLayer){
theLayer.name=theLayer.id;
theLayer.parentDiv=theLayer.offsetParent;
theLayer.images=theLayer.all.tags("IMG");
theLayer.forms=theLayer.all.tags("FORM");
theLayer.links=theLayer.all.tags("A");
theLayer.Height=ieheight;
theLayer.Width=iewidth;
theLayer.resizeTo=resizeTo;
theLayer.resizeBy=resizeBy;
theLayer.Left=ieleft;
theLayer.Top=ietop;
theLayer.moveTo=moveTo;
theLayer.moveBy=moveBy;
theLayer.Index=ieindex;
theLayer.Visibility=ievisibility;
theLayer.setClip=ieclip;
theLayer.clipTop=iecliptop;
theLayer.clipRight=ieclipright;
theLayer.clipBottom=ieclipbottom;
theLayer.clipLeft=ieclipleft;
theLayer.setBgColor=iebgcolor;
theLayer.setBgImage=iebgimage;
theLayer.setContent=iecontent;
commonmethods(theLayer);
}

function commonmethods(theLayer){
div[divcount]=theLayer;
div[theLayer.name]=theLayer;
theLayer.contentHeight=contentHeight;
theLayer.contentWidth=contentWidth;
theLayer.Right=Right;
theLayer.Bottom=Bottom;
theLayer.setMouseDown=setMouseDown;
theLayer.setMouseUp=setMouseUp;
theLayer.setMouseMove=setMouseMove;
theLayer.arrayIndex=divcount;
theLayer.isNewDiv=false;
theLayer.isNested=(theLayer.parentDiv.arrayIndex>-1);
if(div[theLayer.arrayIndex-1]){theLayer.previousDiv=div[theLayer.arrayIndex-1];}
if(theLayer.previousDiv){theLayer.previousDiv.nextDiv=theLayer;}
theLayer.divName=theLayer.id;
divcount++
}

function nsheight(arg1,arg2){
if(! isNaN(arg1)){
this.clip.height=resY(arg1,arg2)||arg1;
}
return this.clip.height;
}
function ieheight(arg1,arg2){
if(! isNaN(arg1)){
this.style.pixelHeight=resY(arg1,arg2)||arg1;
}
return this.offsetHeight;
}

function nswidth(arg1,arg2){
if(! isNaN(arg1)){
this.clip.width=resX(arg1,arg2)||arg1;
}
return this.clip.width;
}
function iewidth(arg1,arg2){
if(! isNaN(arg1)){
this.style.pixelWidth=resX(arg1,arg2)||arg1;
}
return this.offsetWidth;
}

function contentHeight(arg1,arg2){
content=this.scrollHeight||this.document.height;
if(arg1){this.Height(content+(arg2||0));}
return content
}
function contentWidth(arg1,arg2){
content=this.scrollWidth||this.document.width;
if(arg1){this.Width(content+(arg2||0));}
return content
}

function resizeTo(){
this.style.pixelWidth=arguments[0];
this.style.pixelHeight=arguments[1];
}
function resizeBy(){
this.style.pixelWidth=this.Width()+arguments[0];
this.style.pixelHeight=this.Height()+arguments[1];
}

function nsleft(arg1,arg2){
if(! isNaN(arg1)){
this.left=resX(arg1,arg2)||arg1;
}
if(arg1=='center'){
this.left=centerX(this)+(arg2||0);
}
return this.left
}
function ieleft(arg1,arg2){
if(! isNaN(arg1)){
this.style.pixelLeft=resX(arg1,arg2)||arg1;
}
if(arg1=='center'){
this.style.pixelLeft=centerX(this)+(arg2||0);
}
return this.style.pixelLeft||this.offsetLeft;
}

function nstop(arg1,arg2){
if(! isNaN(arg1)){
this.top=resY(arg1,arg2)||arg1;
}
if(arg1=='center'){
this.top=centerY(this)+(arg2||0);
}
return this.top;
}
function ietop(arg1,arg2){
if(! isNaN(arg1)){
this.style.pixelTop=resY(arg1,arg2)||arg1;
}
if(arg1=='center'){
this.style.pixelTop=centerY(this)+(arg2||0);
}
return this.style.pixelTop||this.offsetTop;
}

function centerX(clayer){
par=clayer.parentDiv;
if(par.Width){return par.Width()/2-clayer.Width()/2}
else{return windowWidth(par)/2-clayer.Width()/2+pageLeftOffset(par)}
}
function centerY(clayer){
par=clayer.parentDiv;
if(par.Height){return par.Height()/2-clayer.Height()/2}
else{return windowHeight(par)/2-clayer.Height()/2+pageTopOffset(par)}
}

function Right(){return this.Left()+this.clipRight()}
function Bottom(){return this.Top()+this.clipBottom()}

function moveTo(){
this.style.pixelLeft=arguments[0];
this.style.pixelTop=arguments[1];
}
function moveBy(){
this.style.pixelLeft=this.Left()+arguments[0];
this.style.pixelTop=this.Top()+arguments[1];
}

function resX(arg1,arg2){return arg1*screen.width/arg2}
function resY(arg1,arg2){return arg1*screen.height/arg2}

function nsindex(arg1){
if(! isNaN(arg1)){this.zIndex=arg1;}
lastIndex=this.zIndex;
lastIndexDiv=this;
return lastIndex;
}

function ieindex(arg1){
if(! isNaN(arg1)){this.style.zIndex=arg1;}
lastIndex=this.style.zIndex||getstyle(this.id,this.tagName,this.className,'zIndex',this.document.parentWindow);
lastIndexDiv=this;
return lastIndex;
}

function nsvisibility(){
this.visibility=arguments[0]||this.visibility;
lastVisDiv=this;
if(this.visibility=='hide')return 'hidden';
if(this.visibility=='show')return 'visible';
if(this.visibility=='inherit')return 'inherit';
}
function ievisibility(){
this.style.visibility=arguments[0]||this.style.visibility;
lastVisDiv=this;
return this.style.visibility||getstyle(this.id,this.tagName,this.className,'visibility',this.document.parentWindow)||'visible'
}

function nsclip(t,r,b,l){
this.clip.top=t||'0';
this.clip.right=r||'0';
this.clip.bottom=b||'0';
this.clip.left=l||'0';
lastClipDiv=this;
}
function ieclip(t,r,b,l){
t=t||'0';r=r||'0';b=b||'0';l=l||'0';
this.style.clip="rect("+t+","+r+","+b+","+l+")";
lastClipDiv=this
}

function nscliptop(arg1){
if(! isNaN(arg1)){
this.clip.top=arg1;
lastClipDiv=this;
}
return this.clip.top
}
function nsclipright(arg1){
if(! isNaN(arg1)){
this.clip.right=arg1;
lastClipDiv=this;
}
return this.clip.right
}
function nsclipbottom(arg1){
if(! isNaN(arg1)){
this.clip.bottom=arg1;
lastClipDiv=this;
}
return this.clip.bottom
}
function nsclipleft(arg1){
if(! isNaN(arg1)){
this.clip.left=arg1;
lastClipDiv=this;
}
return this.clip.left
}

function iecliptop(arg1){
if(! isNaN(arg1)){
this.setClip(arg1||'0',this.clipRight(),this.clipBottom(),this.clipLeft());
lastClipDiv=this;
}
clipstr=(this.style.clip||getstyle(this.id,this.tagName,this.className,'clip',this.document.parentWindow)).split(" ");
clip=parseInt(clipstr[0].substr(5))||0;
return clip
}
function ieclipright(arg1){
if(! isNaN(arg1)){
this.setClip(this.clipTop(),arg1||'0',this.clipBottom(),this.clipLeft());
lastClipDiv=this;
}
clipstr=(this.style.clip||getstyle(this.id,this.tagName,this.className,'clip',this.document.parentWindow)).split(" ");
clip=parseInt(clipstr[1])||this.Width();
return clip
}
function ieclipbottom(arg1){
if(! isNaN(arg1)){
this.setClip(this.clipTop(),this.clipRight(),arg1||'0',this.clipLeft());
lastClipDiv=this;
}
clipstr=(this.style.clip||getstyle(this.id,this.tagName,this.className,'clip',this.document.parentWindow)).split(" ");
clip=parseInt(clipstr[2])||this.Height();
return clip
}
function ieclipleft(arg1){
if(! isNaN(arg1)){
this.setClip(this.clipTop(),this.clipRight(),this.clipBottom(),arg1||'0');
lastClipDiv=this;
}
clipstr=(this.style.clip||getstyle(this.id,this.tagName,this.className,'clip',this.document.parentWindow)).split(" ");
clip=parseInt(clipstr[3])||0;
return clip
}

function nsbgcolor(){this.bgColor=arguments[0]||null}
function iebgcolor(){this.style.backgroundColor=arguments[0]||'transparent'}

function nsbgimage(){this.background.src=arguments[0]||null}
function iebgimage(){this.style.backgroundImage="url("+arguments[0]+")"}

function nscontent(){
this.document.write(arguments[0]||'');
this.document.close();
}
function iecontent(){this.innerHTML=arguments[0]||''}

function setMouseDown(){
if(ns4){this.captureEvents(Event.MOUSEDOWN)}
if(ie4){this.ondragstart=nodragstart}
this.onmousedown=arguments[0]||null;
return false;
}

function nodragstart(){window.event.returnValue=false}

function setMouseUp(){
if(ns4){this.captureEvents(Event.MOUSEUP)}
this.onmouseup=arguments[0]||null;
}

function mouseX(e){
e=e||event;
if(arguments[1]){mouse=e.offsetX||e.x}
else{mouse=e.pageX||e.x}
return mouse;
}
function mouseY(e){
e=e||event;
if(arguments[1]){mouse=e.offsetY||e.y}
else{mouse=e.pageY||e.y}
return mouse;
}

function setMouseMove(arg1){
if(ns4){
if(this.Height){this.captureEvents(Event.MOUSEMOVE)}
else{document.captureEvents(Event.MOUSEMOVE)}
}
if(this.Height){this.onmousemove=arg1||null}
else{document.onmousemove=arg1||null}
}

function windowWidth(win){
win=win||self;
whatwin=win.document.body||win;
return whatwin.clientWidth||whatwin.innerWidth;
}
function windowHeight(win){
win=win||self;
whatwin=win.document.body||win;
return whatwin.clientHeight||whatwin.innerHeight;
}

function pageTopOffset(win){
win=win||self;
whatwin=win.document.body||win;
return whatwin.scrollTop||whatwin.pageYOffset||0;
}
function pageLeftOffset(win){
win=win||self;
whatwin=win.document.body||win;
return whatwin.scrollLeft||whatwin.pageXOffset||0;
}

function pageHeight(){
theheight=document.height||document.body.scrollHeight;
document.height=arguments[0]||theheight;
return theheight;
}
function pageWidth(){
thewidth=document.width||document.body.scrollWidth;
document.width=arguments[0]||thewidth;
return thewidth;
}

function getKey(e){
e=e||event;
key=e.keyCode||e.which;
if((arguments[1]=='letter')&&(key)){return String.fromCharCode(key)}
else{return key}
}

function getSelection(){
return document.selection.createRange().text||document.getSelection();
}

function addDivMethod(){
for(i=0;i<div.length;i++){
for(a=0;a<arguments.length;a++){
theMethod=arguments[a];
eval('div[i].'+theMethod+'='+theMethod);
}}}

function addDivProperty(arg1,arg2){
theProp=arg1;
propValue=arg2;
for(i=0;i<div.length;i++){
eval('div[i].'+theProp+'='+propValue);
}}

function newDiv(arg1,arg2){
name=arg1||("new_div"+divcount);
par=arg2||document.body||self;
if(ie4){
if(par.self){par=par.document.body}
thediv="<div ID="+name+" style='position:absolute;height:0;top:0;left:0;visibility:hidden;'></div>";
par.insertAdjacentHTML("AfterBegin",thediv);
div[name]=par.document.all[name];
iemethods(div[name]);
}
if(ns4){
div[name]=new Layer(screen.width,par);
div[name].zIndex=0;
nsmethods(div[name]);
}
div[name].divName=name;
div[name].isNewDiv=true;
utilsetup();pathsetup();
return div[name];
}

function getstyle(id,tag,sclass,prop,win){
var theprop='';
var sheets=win.document.styleSheets;

for(a=0;a<sheets.length;a++){
for(b=0;b<sheets[a].rules.length;b++){
therule=sheets[a].rules[b];
ruleprop=eval("sheets[a].rules[b].style."+prop);

if((therule.selectorText==(tag+'.'+sclass))&&(ruleprop)){
theprop=ruleprop;
}
if((therule.selectorText==('#'+id))&&(ruleprop)){
theprop=ruleprop;
break;
}}}
return theprop
}

function addDiv(id,par){
if(ie4){
if(par.self){par=par.document.body}
iemethods(par.all[id])
}
if(ns4){nsmethods(par.document.layers[id])}
utilsetup();pathsetup();
return div[id];
}

function utilsetup(){}
function pathsetup(){}

function cbscript(){
alert("Cross-browser script written by:\nTerry Friesen, tfriesen@mts.net\n\nLast modified: 2/07/99")
}

