/********************************************************************

Popup Windows - V 4.5
Author: Brian Gosselin
Site URL: http://scriptasylum.com
Read the "releasenotes.txt" for supported features and release notes.

************** EDIT THE LINES BELOW AT YOUR OWN RISK ****************/

var ns4=(document.layers)?true:false;
var ie5=(document.all)? true : false;
var ns6=(!document.all)? true: false;
currIDb=null; xoff=0; yoff=0;
oldac=null; newac=null; zdx=1; mx=0; my=0;
var cidlist=new Array();

//******* START OF EXPOSED FUNCTIONS. THESE CAN BE USED IN HYPERLINKS. *******\\

function hidebox(id){
document.getElementById(id+'_b').style.display='none';
}

function showbox(id){
var bx=document.getElementById(id+'_b');
bx.style.display='block';
bx.style.zIndex=++zdx;
if(ns6){
bx.style.MozOpacity=1;
}else{
bx.style.filter="alpha(opacity=100)";
}
changez(bx);
}

/*
function showbox(id,text){
var cx=document.getElementById(id+'_c');
cx.innerHTML=text;
var bx=document.getElementById(id+'_b');
bx.style.display='block';
bx.style.zIndex=++zdx;
if(ns6){
bx.style.MozOpacity=1;
}else{
bx.style.filter="alpha(opacity=100)";
}
changez(bx);
}
*/

function movePopup(ids,x,y){
var idb=document.getElementById(ids+'_b');
idb.style.left=x+'px';
idb.style.top=y+'px';
}

//******* END OF EXPOSED FUNCTIONS *******\\


function ns6bugfix(){
if(navigator.userAgent.indexOf("Netscape/6")>0)setTimeout('self.resizeBy(0,1); self.resizeBy(0,-1);', 100);
}

function trackmouse(evt){
mx=(ie5)?event.clientX+document.body.scrollLeft:evt.pageX;
my=(ie5)?event.clientY+document.body.scrollTop:evt.pageY;
if(!ns6)movepopup();
if((currIDb!=null))return false;
}

function movepopup(){
if((currIDb!=null))movePopup(currIDb.cid,mx+xoff,my+yoff);
return false;
}

function changez(v){
var th=(v!=null)?v:this;
if(oldac!=null)document.getElementById(oldac.cid+"_t").style.backgroundColor=oldac.inactivecolor;
if(ns6)document.getElementById(th.cid+"_c").style.overflow='auto';
oldac=th;
document.getElementById(th.cid+"_t").style.backgroundColor=th.activecolor;
th.style.zIndex=++zdx;
}

function stopdrag(){
currIDb=null;
ns6bugfix();
}

function grab_id(evt){
var ex=(ie5)?event.clientX+document.body.scrollLeft:evt.pageX;
var ey=(ie5)?event.clientY+document.body.scrollTop:evt.pageY;
xoff=parseInt(document.getElementById(this.cid+"_b").style.left)-ex;
yoff=parseInt(document.getElementById(this.cid+"_b").style.top)-ey;
currIDb=document.getElementById(this.cid+"_b");
return false;
}

function popUp(cid,title,text,showonstart,clsImg){

cidlist[cidlist.length]=cid;

var outerdiv=document.createElement('div');
outerdiv.setAttribute('id',cid+'_b');
outerdiv.style.position='absolute';
outerdiv.style.left='100px';
outerdiv.style.top='100px';
outerdiv.style.border='2px outset gray';
outerdiv.style.padding='0px';
outerdiv.style.display='block';
outerdiv.style.backgroundColor='#DFDCB5';
outerdiv.style.zIndex=++zdx;

var titlebar=document.createElement('div');
titlebar.setAttribute('id',cid+'_t');
titlebar.style.backgroundColor='#999967';
titlebar.style.fontWeight='bold';
titlebar.innerHTML='<div style="float:left;height:20px;padding:2px 2px ">'+title+'</div><div style="text-align:right"><img src="'+clsImg+'" width="16" height="16" id="'+cid+'_cls"></div><div style="clear:both"></div>';

var content=document.createElement('div');
content.setAttribute('id',cid+'_c');
content.style.border='2px inset gray';
if(ie5)content.style.scrollbarBaseColor="gray";
content.innerHTML=text;

outerdiv.appendChild(titlebar);
outerdiv.appendChild(content);

document.body.appendChild(outerdiv);

if(!showonstart)hidebox(cid);
var wB=document.getElementById(cid+'_b');
wB.cid=cid;
var wT=document.getElementById(cid+'_t');
wT.cid=cid;

var wCLS=document.getElementById(cid+'_cls');

wB.activecolor="#999967";
wB.inactivecolor="#DFDCB5";
if(oldac!=null)document.getElementById(oldac.cid+"_t").style.backgroundColor=oldac.inactivecolor;
oldac=wB;
wCLS.onclick=new Function("hidebox('"+cid+"');");
wB.onmousedown=function(){ changez(this) }
wT.onmousedown=grab_id;
wT.onmouseup=stopdrag;
}

if(ns6)setInterval('movepopup()',40);

document.onmousemove=trackmouse;