// Determine browser.
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;

/**********************************************************************************   
WindowScript 
*   Copyright (C) 2001 Thomas Brattli
*   This script was released at DHTMLCentral.com
*   Visit for more great scripts!
*   This may be used and changed freely as long as this msg is intact!
*   We will also appreciate any links you could give us.
*
*   Made by Thomas Brattli
*
*   Script date: 07/03/2001 (keep this date to check versions) 
*********************************************************************************/
function lib_bwcheck(){ //Browsercheck (needed)
	this.ver=navigator.appVersion
	this.agent=navigator.userAgent
	this.dom=document.getElementById?1:0
	this.opera5=(navigator.userAgent.indexOf("Opera")>-1 && document.getElementById)?1:0
	this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom && !this.opera5)?1:0; 
	this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom && !this.opera5)?1:0;
	this.ie4=(document.all && !this.dom && !this.opera5)?1:0;
	this.ie=this.ie4||this.ie5||this.ie6
	this.mac=this.agent.indexOf("Mac")>-1
	this.ns6=(this.dom && parseInt(this.ver) >= 5) ?1:0; 
	this.ns4=(document.layers && !this.dom)?1:0;
	this.bw=(this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.opera5)
	return this
}
var bw=lib_bwcheck()
var oWin=new Array; oWin.zIndex=10; oWin.dragobj=-1; oWin.resizeobj=-1; oWin.zIndex=100

//Start Variables to set ******************************************************************
//This script works in IE4+, NS4+ and Opera5. 
//Just remember that NS4 and Opera5 does not reflow the content when you resize the windows.

oWin.bordercolor="#BECCD3" //Remember that you have to change the images as well if you change this color
oWin.bgcolor="#000000" //Default background color -- Controlled in window fn
oWin.bgcoloron="#000000"  //The "active" background color -- Controlled in window fn
oWin.bgscroll="#D2DDE3" //The background-color for the scroll area"
oWin.bottomh=12 //The height of the bottom "border"
oWin.headh=0 //The height of the head "border"
oWin.bordersize=0 //The left and right bordersize
oWin.scrollw=12 //The width of the scroll area
oWin.scrollimgh=12 //The width of the scroll images
oWin.buttonsw=151 //The width of the buttons image
oWin.resizeh=157 //The width of the resize img
oWin.resizew=13 //The height of the resize img

oWin.starty=5
oWin.defwidth=200
oWin.defheight=200
oWin.between=15

//Set this variable to 1 if you want to be able to control the area the windows can be scrolled.
oWin.keepinside=0 //VALUE: 1 || 0
	oWin.maxX=500
	oWin.maxY=500
	oWin.minX=50
	oWin.minY=50
	
//In the next version of this script all variables can be set on each individual window as well
//End Variables to set ********************************************************************

function lib_bwcheck(){ //Browsercheck (needed)
	this.ver=navigator.appVersion
	this.agent=navigator.userAgent
	this.dom=document.getElementById?1:0
	this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom)?1:0;
	this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom)?1:0;
	this.ie4=(document.all && !this.dom)?1:0;
	this.ie=this.ie4||this.ie5||this.ie6
	this.mac=this.agent.indexOf("Mac")>-1
	this.opera5=this.agent.indexOf("Opera 5")>-1
	this.ns6=(this.dom && parseInt(this.ver) >= 5) ?1:0; 
	this.ns4=(document.layers && !this.dom)?1:0;
	this.bw=(this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.opera5)
	return this
}
var bw=new lib_bwcheck(); 
//Uncomment the next line if you want the user to be sent to another page if he's using an old browser
//if(!bw.bw) location.href='sorry.html'

function lib_doc_size(){ //Page positions - needed!
	this.x=0;this.x2=bw.ie && document.body.offsetWidth-20||innerWidth||0;
	if(bw.ns6) this.x2-=2
	this.y=0;this.y2=bw.ie && document.body.offsetHeight-5||innerHeight||0;
	if(bw.ns6) this.y2-=4
	if(!this.x2||!this.y2) return message('Document has no width or height') 
	this.x50=this.x2/2;     this.y50=this.y2/2;
	this.x10=(this.x2*10)/100;this.y10=(this.y2*10)/100
	this.ytop=140*100/this.y2
	this.avail=(this.y2*(100-this.ytop))/100
	this.origy=this.y2
	return this;
}
function lib_moveIt(x,y){this.x=x;this.y=y; this.css.left=x;this.css.top=y}
function lib_moveBy(x,y){this.moveIt(this.x+x,this.y+y)}
function lib_showIt(){this.css.visibility="visible"}
function lib_hideIt(){this.css.visibility="hidden"}
function lib_bg(color){
	if(bw.opera5) this.css.background=color
	else if(bw.dom || bw.ie4) this.css.backgroundColor=color
	else if(bw.ns4) this.css.bgColor=color  
}
function lib_clipTo(t,r,b,l,setwidth){ 
	if(t<0)t=0;if(r<0)r=0;if(b<0)b=0;if(b<0)b=0
	this.ct=t; this.cr=r; this.cb=b; this.cl=l
	if(bw.ns4){
		this.css.clip.top=t;this.css.clip.right=r
		this.css.clip.bottom=b;this.css.clip.left=l
	}else if(bw.opera5){this.css.pixelWidth=r; this.css.pixelHeight=b; this.w=r; this.h=b
	}else{
		this.css.clip="rect("+t+","+r+","+b+","+l+")";
		if(setwidth){this.css.width=r; this.css.height=b; this.w=r; this.h=b}
	}
}
function lib_writeIt(text,startHTML,endHTML){
	if(bw.ns4){
		if(!startHTML){startHTML=""; endHTML=""}
		this.ref.open("text/html"); this.ref.write(startHTML+text+endHTML); this.ref.close()
	}else this.evnt.innerHTML=text
}
//Default lib functions
function lib_obj(obj,nest,dnest,ddnest,num){
	if(!bw.bw) return lib_message('Old browser')
	if(!bw.ns4) this.evnt=bw.dom && document.getElementById(obj)||bw.ie4 && document.all[obj]
	else{
		if(ddnest){this.evnt=document[nest].document[dnest].document[ddnest].document[obj]?document[nest].document[dnest].document[ddnest].document[obj]:0;
		}else if(dnest){this.evnt=document[nest].document[dnest].document[obj]?document[nest].document[dnest].document[obj]:0;
		}else if(nest){this.evnt=document[nest].document[obj]?document[nest].document[obj]:0;
		}else{this.evnt=document.layers[obj]?document.layers[obj]:0;}	
	}
	if(!this.evnt) return lib_message('The layer does not exist ('+obj+') - Exiting script\n\nIf your using Netscape please check the nesting of your tags!')
	this.css=bw.dom||bw.ie4?this.evnt.style:this.evnt;  
	this.ref=bw.dom||bw.ie4?document:this.css.document;   
	this.moveIt=lib_moveIt; this.moveBy=lib_moveBy; 
	this.showIt=lib_showIt; this.hideIt=lib_hideIt;
	this.bg=lib_bg; this.num=num; this.writeIt=lib_writeIt; 	
	this.clipTo=lib_clipTo;	this.obj = obj + "Object"; 	eval(this.obj + "=this")
	return this
}
/*****************************************************************************
Creating windows
*****************************************************************************/
function create_window(i,x,y,w,h,bg,bga){
	if(!w) w=oWin.defwidth; if(!h) h=oWin.defheight
	if(!bg) bg=oWin.bgcolor; if(!bga) bga=oWin.bgcoloron
	oWin[i]=new lib_obj('divWin'+i,"","","",i)
	oWin[i].oWindow=new lib_obj('divWindow'+i,'divWin'+i)
	oWin[i].oWindow.moveIt(oWin.bordersize,oWin.headh)
	oWin[i].oText=new lib_obj('divWinText'+i,'divWin'+i,'divWindow'+i)
	oWin[i].oHead=new lib_obj('divWinHead'+i,'divWin'+i)
	oWin[i].oButtons=new lib_obj('divWinButtons'+i,'divWin'+i)
	oWin[i].oResize=new lib_obj('divWinResize'+i,'divWin'+i)
	if(!bw.ns4) oWin[i].oHead.evnt.ondblclick=new Function("mdblclick(0,"+i+")")
	oWin[i].defbg=bg; oWin[i].defbga=bga	
	oWin[i].bg(oWin.bordercolor); oWin[i].oWindow.bg(oWin[i].defbg)
	oWin[i].oUp=new lib_obj('divWinUp'+i,'divWin'+i); oWin[i].oDown=new lib_obj('divWinDown'+i,'divWin'+i)
	oWin[i].oUp.bg(oWin.bgscroll); oWin[i].oDown.bg(oWin.bgscroll); 
	oWin[i].lastx=x;oWin[i].lasty=y;oWin[i].origw=w; oWin[i].origh=h
	oWin[i].resize=win_resize;	oWin[i].close=win_close;
	oWin[i].regwin=win_regwin; oWin[i].checkscroll=win_checkscroll;
	oWin[i].up=win_up;	oWin[i].down=win_down;	oWin[i].addZ=win_addZ;	oWin[i].state="reg"
	oWin[i].moveIt(x,y); oWin[i].resize(w,h); 
}
/*****************************************************************************
Window functions 
*****************************************************************************/
function win_regwin(){
	this.oResize.css.visibility="inherit"
	this.resize(this.origw,this.origh)
	this.moveIt(this.lastx,this.lasty)
	this.state="reg"; this.addZ()
	this.checkscroll()
}
function win_close(){this.hideIt(); this.oUp.hideIt(); this.oDown.hideIt()}
function win_resize(w,h){
	this.oButtons.moveIt(w-oWin.buttonsw,0); this.oResize.moveIt(w-oWin.resizew,h-oWin.resizeh)
	this.oWindow.clipTo(0,w-oWin.bordersize*2,h-oWin.bottomh-oWin.headh,0,1); this.clipTo(0,w,h,0,1)
	this.oHead.clipTo(0,w,oWin.headh,0,1); this.oText.moveIt(2,3)
	this.oUp.hideIt(); this.oDown.hideIt()
}
function win_checkscroll(w,h){
	this.oText.height=this.oText.evnt.offsetHeight||this.oText.css.pixelHeight||this.oText.ref.height||0
	w=this.cr; h=this.cb
	if(this.oText.height>h-oWin.bottomh-oWin.headh && this.state!="min"){
		this.oWindow.clipTo(0,w-oWin.scrollw-oWin.bordersize*2,h-oWin.bottomh-oWin.headh,0,1); 
		this.oUp.moveIt(w-oWin.scrollw,oWin.headh)
		this.oUp.clipTo(0,oWin.scrollw-oWin.bordersize,h-oWin.bottomh-oWin.scrollimgh-oWin.headh,0,1); 
		this.oDown.moveIt(w-oWin.scrollw,h-oWin.bottomh-oWin.scrollimgh)
		this.oDown.clipTo(0,oWin.scrollw-oWin.bordersize,oWin.scrollimgh,0,1); this.oUp.showIt()
		this.oDown.showIt()
	}else{this.oUp.hideIt(); this.oDown.hideIt()}
}
var sctim=100;
var winScroll;
function win_up(){
	clearTimeout(sctim);
	if(this.oText.y>=this.oWindow.cb-this.oText.height-10 && winScroll){
		this.oText.moveBy(0,-8); 
		setTimeout(this.obj+".up()",30)
	}
}
function win_down(){
	clearTimeout(sctim);
	if(this.oText.y<=0 && winScroll){
		this.oText.moveBy(0,8);
		setTimeout(this.obj+".down()",30)
	}
}
function noScroll(){clearTimeout(sctim);winScroll=false}
function win_addZ(){oWin.zIndex++; this.css.zIndex=oWin.zIndex}
/*****************************************************************************
Initiating winpage
*****************************************************************************/
function win_init(){
grabCoordinates() 
}
/*****************************************************************************
Adding window to winpage!
*****************************************************************************/
var lastx,lasty,lastw,lasth
function addWindow(heading,content,x,y,w,h,bg,bga){
	var num=oWin.length; wins=num+1; var str=""
	str+='<div id="divWin'+num+'" class="clWin">\n'
	str+='<div class="clLogo"></div>\n'
	+'<div id="divWinHead'+num+'" class="clWinHead">'+heading+'</div>\n'
	+'<div id="divWinButtons'+num+'" class="clWinButtons">\n'
	+'</div>\n'
	+'<div id="divWinResize'+num+'" class="clWinResize">\n'
	+'</div>\n'
	+'<div id="divWindow'+num+'" class="clWindow">\n'
		+'<div id="divWinText'+num+'" class="clText">'
	if(content){
		str+=content+'</div>\n'
		+'</div>\n'
		+'<div id="divWinUp'+num+'" class="clUp"><a href="#" onclick="return false" onmouseover="winScroll=1; oWin['+num+'].down();"  onmouseout="noScroll()"><img src="images/arrow_up.gif" width="12" height="12" alt="" border="0"></a></div>\n'
		+'<div id="divWinDown'+num+'" class="clDown"><a href="#" onclick="return false" onmouseover="winScroll=1; oWin['+num+'].up();" onmouseout="noScroll()"><img src="images/arrow_down.gif" width="12" height="12" alt="" border="0"></a></div>\n'
		+'</div>'
	}
	document.write(str)
	if(content) create_window(num,x,y,w,h,bg,bga)
}
function endWin(){
	num=wins-1
	str='\n</div>\n'
	+'</div>\n'
		+'<div id="divWinUp'+num+'" class="clUp"><a href="#" onclick="return false" onmouseover="winScroll=1; oWin['+num+'].down();"  onmouseout="noScroll()"><img src="images/arrow_up.gif" width="12" height="8" alt="" border="0"></a></div>\n'
		+'<div id="divWinDown'+num+'" class="clDown"><a href="#" onclick="return false" onmouseover="winScroll=1; oWin['+num+'].up();" onmouseout="noScroll()"><img src="images/arrow_down.gif" width="12" height="8" alt="" border="0"></a></div>\n'
	+'</div>'
	return str
}

function getImage(name) {
  if (isMinNS4) {
    return findImage(name, document);
  }
  if (isMinIE4)
    return eval('document.all.' + name);
  return null;
}

function findImage(name, doc) {
  var i, img;
  for (i = 0; i < doc.images.length; i++)
    if (doc.images[i].name == name)
      return doc.images[i];
  for (i = 0; i < doc.layers.length; i++)
    if ((img = findImage(name, doc.layers[i].document)) != null) {
      img.container = doc.layers[i];
      return img;
    }
  return null;
}

function getImagePageLeft(img) {

  var x, obj;
  if (isMinNS4) {
    if (img.container != null)
      return img.container.pageX + img.x;
    else
// 16 px adjustment added for NS
      var tempX = img.x - 16;
      return tempX;
  }
  if (isMinIE4) {
    x = 0;
    obj = img;
    while (obj.offsetParent != null) {
      x += obj.offsetLeft;
      obj = obj.offsetParent;
    }
    x += obj.offsetLeft;
    return x;
  }
  return -1;
}

function getImagePageTop(img) {
  var y, obj;
  if (isMinNS4) {
    if (img.container != null)
      return img.container.pageY + img.y;
    else
      return img.y;
  }
  if (isMinIE4) {
    y = 0;
    obj = img;
    while (obj.offsetParent != null) {
      y += obj.offsetTop;
      obj = obj.offsetParent;
    }
    y += obj.offsetTop;
    return y;
  }
  return -1;
}

function grabCoordinates() {
z = 'toolbox';
x = getImagePageLeft(getImage(z));
y = getImagePageTop(getImage(z)) + 20;
z = 'tmpImg';
varBx = x - getImagePageLeft(getImage(z));
varBy = y - getImagePageTop(getImage(z));
}

function showLayer(){
	document.getElementById("divWin0").style.visibility="visible";
	//if (navigator.appName == "Netscape") {
	//	document.layers["divWin0"].visibility="visible";
	//}else{
	//	document.all["divWin0"].style.visibility="visible";
	//}
	oWin[0].checkscroll()
}

function resizeLayer(){
	grabCoordinates()
// Added to manage NS resize thingy
  if (isMinNS4) {
	x = x + 16;
  }
	//y = y + 3;
	y = y - 3;
	oWin[0].moveIt(x,y)
}