/********************************************************************

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 w3c=(document.getElementById)? true: false;
var ns4=(document.layers)?true:false;
var ie5=(w3c && document.all)? true : false;
var ns6=(w3c && !document.all)? true: false;
var d=document;
currIDb=null; xoff=0; yoff=0;
currRS=null; rsxoff=0; rsyoff=0;
oldac=null; newac=null; zdx=5000; mx=0; my=0;
var currFb=null; var currFs=null; var currFID=0; var currFcnt=0;
var cidlist=new Array();

function truebody(){ //Dynamic Drive added function
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

//******* START OF EXPOSED FUNCTIONS. THESE CAN BE USED IN HYPERLINKS. *******\\

function hidebox(id){
if(w3c){
//if(currFb!=d.getElementById(id+'_b')){
d.getElementById(id+'_b').style.display='none';
//}
}}

function showbox(id){
if(w3c){
var bx=d.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 changecontent(id,text){
if(!document.getElementById(id+'_b').isExt){
var d=document.getElementById(id+'_c');
if(ns6)d.style.overflow="hidden";
d.innerHTML=text;
if(ns6)d.style.overflow="block";
}else document.getElementById(id+'_ifrm').src=text;
}

function movePopup(ids,x,y){
if(w3c){
var idb=document.getElementById(ids+'_b');
idb.style.left=x+'px';
idb.style.top=y+'px';
}}

function resizePopup(ids,rx,ry){
if(w3c){
if(d.getElementById(ids+'_rs').rsEnable){
d.gEl=d.getElementById;
d.gEl(ids+"_extWA").style.display="block";
d.gEl(ids+"_rs").style.left=Math.max(rx,((ie6)?88:92))+'px';
d.gEl(ids+"_rs").style.top=Math.max(ry,((ie6)?68:72))+'px';
d.gEl(ids+"_b").style.width=Math.max(rx+((ie6)?12:8),100)+'px';
d.gEl(ids+"_b").style.height=Math.max(ry+((ie6)?12:8),80)+'px';
d.gEl(ids+"_t").style.width=Math.max(rx+((ie6)?4:3),((ns6)?95:92))+'px';
d.gEl(ids+"_btt").style.left=parseInt(d.gEl(ids+"_t").style.width)-96+'px';
d.gEl(ids+"_c").style.width=Math.max(rx-((ie6)?-5:5),((ie6)?92:87))+'px';
d.gEl(ids+"_c").style.height=Math.max(ry-((ie6)?24:28),44)+'px';
d.gEl(ids+"_max").h=parseInt(d.gEl(ids+"_b").style.height);
}}}

//******* END OF EXPOSED FUNCTIONS *******\\

function setAllScrollbars(ishide){
if(document.all){
var id;
for(i=0;i<cidlist.length;i++){
id=cidlist[i];
if(!document.getElementById(id+'_b').isExt)document.getElementById(id+'_c').style.overflow=(ishide)?"hidden":"auto";
}}}

function preloadBttns(){
var btns=new Array();
btns[0]=new Image(); btns[0].src="min.gif";
btns[1]=new Image(); btns[1].src="max.gif";
btns[2]=new Image(); btns[2].src="close.gif";
btns[3]=new Image(); btns[3].src="resize.gif";
}
preloadBttns();

function minimize(){
if(w3c){
d.getElementById(this.cid+"_b").style.height=(ie6)? '28px':'24px';
d.getElementById(this.cid+"_c").style.display='none';
d.getElementById(this.cid+"_rs").style.display='none';
ns6bugfix();
}}

function restore(){
if(w3c){
d.getElementById(this.cid+"_b").style.height=this.h+'px';
d.getElementById(this.cid+"_c").style.display='block';
d.getElementById(this.cid+"_rs").style.display='block';
ns6bugfix();
}}

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+truebody().scrollLeft:evt.pageX;
my=(ie5)?event.clientY+truebody().scrollTop:evt.pageY;
if(!ns6)movepopup();
if((currIDb!=null)||(currRS!=null))return false;
}

function movepopup(){
if((currIDb!=null)&&w3c)movePopup(currIDb.cid,mx+xoff,my+yoff);
if((currRS!=null)&&w3c)resizePopup(currRS.cid,mx+rsxoff,my+rsyoff);
return false;
}

function stopRS(){
d.getElementById(this.cid+"_extWA").style.display="none";
currRS=null;
}

function startRS(evt){
var ex=(ie5)?event.clientX+truebody().scrollLeft:evt.pageX;
var ey=(ie5)?event.clientY+truebody().scrollTop:evt.pageY;
rsxoff=parseInt(this.style.left)-ex;
rsyoff=parseInt(this.style.top)-ey;
currRS=this;
if(ns6)d.getElementById(this.cid+"_c").style.overflow='hidden';
return false;
}

function changez(v){
var th=(v!=null)?v:this;
if(oldac!=null)d.getElementById(oldac.cid+"_t").style.backgroundColor=oldac.inactivecolor;
if(ns6)d.getElementById(th.cid+"_c").style.overflow='auto';
oldac=th;
d.getElementById(th.cid+"_t").style.backgroundColor=th.activecolor;
th.style.zIndex=++zdx;
d.getElementById(th.cid+"_rs").style.zIndex=++zdx;
}

function stopdrag(){
currIDb=null;
document.getElementById(this.cid+"_extWA").style.display="none";
ns6bugfix();
}

function grab_id(evt){
var ex=(ie5)?event.clientX+truebody().scrollLeft:evt.pageX;
var ey=(ie5)?event.clientY+truebody().scrollTop:evt.pageY;
xoff=parseInt(d.getElementById(this.cid+"_b").style.left)-ex;
yoff=parseInt(d.getElementById(this.cid+"_b").style.top)-ey;
currIDb=d.getElementById(this.cid+"_b");
d.getElementById(this.cid+"_extWA").style.display="block";
return false;
}

function subBox(x,y,w,h,bgc,id){
//var v=d.createElement('div');
var v=d.getElementById(id);
//v.setAttribute('id',id);
v.style.position='absolute';
v.style.left=x+'px';
v.style.top=y+'px';
v.style.width=w+'px';
v.style.height=h+'px';
if(bgc!='')v.style.backgroundColor=bgc;
v.style.visibility='visible';
v.style.padding='0px';  
return v;
}

function popUp(x,y,w,h,cid,text,bgcolor,textcolor,fontstyleset,title,titlecolor,titletextcolor,bordercolor,scrollcolor,shadowcolor,showonstart,isdrag,isresize,oldOK,isExt,popOnce,minImg,maxImg,clsImg,rsImg,titleh){
var okPopUp=true;
if(okPopUp){
if(w3c){
cidlist[cidlist.length]=cid;
w=Math.max(w,100);
h=Math.max(h,80);
var rdiv=new subBox(w-((ie6)?12:8),h-((ie6)?12:8),7,7,'',cid+'_rs');
if(isresize){
rdiv.innerHTML='<img src="'+rsImg+'" width="7" height="7">';
rdiv.style.cursor='move';
}
rdiv.rsEnable=isresize;
titleh=((titleh=="")?20:titleh);
var outerdiv=new subBox(x,y,w,h,"#ffffff",cid+'_b');
outerdiv.style.display="block";
outerdiv.style.borderStyle="solid";
outerdiv.style.borderWidth="2px";
outerdiv.style.borderColor="#000000";
outerdiv.style.zIndex=++zdx;
var titlebar=new subBox(0,0,w,titleh,titlecolor,cid+'_t');
titlebar.style.overflow="hidden";
titlebar.style.cursor="default";
var tmp=(isresize)?'<img src="'+minImg+'" width="16" height="16" id="'+cid+'_min"><img src="'+maxImg+'" width="16" height="16"  id="'+cid+'_max">':'';
titlebar.innerHTML='<span style="position:absolute; left:3px; top:1px; font:bold 10pt sans-serif; color:'+titletextcolor+'; height:18px; overflow:hidden; clip-height:16px;">'+title+'</span><div id="'+cid+'_btt" style="position:absolute; width:96px; height:16px; left:'+(w-96)+'px; top:2px; text-align:right">'+tmp+'<img src="'+clsImg+'" width="64" height="16" id="'+cid+'_cls" alt="Close window" title="click to close window"></div>';
th=h-titleh;
var content=new subBox(0,0+titleh,w,th,bgcolor,cid+'_c');
if(isExt){
content.innerHTML='<iframe id="'+cid+'_ifrm" src="'+text+'" width="100%" height="99%" border="0"></iframe>';
iframeName = cid+'_ifrm';
setTimeout('loadIframe("'+iframeName+'", "'+text+'")',300);
content.style.overflow="hidden";
content.style.borderStyle="none";
}else{
if(ie5)content.style.scrollbarBaseColor=scrollcolor;
content.style.overflow="auto";
//content.style.padding="0px 2px 0px 4px";
content.innerHTML=text;
content.style.font=fontstyleset;
content.style.color=textcolor;
}
var extWA=new subBox(0,0+titleh,0,0,'',cid+'_extWA');
extWA.style.display="none";
extWA.style.width='100%';
extWA.style.height='100%';
//outerdiv.appendChild(titlebar);
//outerdiv.appendChild(content);
//outerdiv.appendChild(extWA);
//outerdiv.appendChild(rdiv);
//truebody().appendChild(shadow);
//truebody().appendChild(outerdiv);
d.gEl=d.getElementById;
if(!showonstart)hidebox(cid);
var wB=d.gEl(cid+'_b');
wB.cid=cid;
wB.isExt=(isExt)?true:false;
var wT=d.gEl(cid+'_t');
wT.cid=cid;
if(isresize){
var wRS=d.gEl(cid+'_rs');
wRS.cid=cid;
var wMIN=d.gEl(cid+'_min');
wMIN.cid=cid;
var wMAX=d.gEl(cid+'_max');
wMAX.h=h;
wMAX.cid=cid;
wMIN.onclick=minimize;
wMAX.onclick=restore;
wRS.onmousedown=startRS;
wRS.onmouseup=stopRS;
}
var wCLS=d.gEl(cid+'_cls');
var wEXTWA=d.gEl(cid+'_extWA');
wB.activecolor=titlecolor;
wB.inactivecolor=scrollcolor;
if(oldac!=null)d.gEl(oldac.cid+"_t").style.backgroundColor=oldac.inactivecolor;
oldac=wB;
wCLS.onclick=new Function("hidebox('"+cid+"');");
wB.onmousedown=function(){ changez(this) }
if(isdrag){
wT.onmousedown=grab_id;
wT.onmouseup=stopdrag;
}
}else{
if(oldOK){
var ctr=new Date();
ctr=ctr.getTime();
var t=(isExt)?text:'';
var posn=(ns4)? 'screenX='+x+',screenY='+y: 'left='+x+',top='+y;
var win=window.open(t , "abc"+ctr , "status=no,menubar=no,width="+w+",height="+h+",resizable="+((isresize)?"yes":"no")+",scrollbars=yes,"+posn);
if(!isExt){
t='<html><head><title>'+title+'</title></head><body bgcolor="'+bgcolor+'"><font style="font:'+fontstyleset+'; color:'+textcolor+'">'+text+'</font></body></html>';
win.document.write(t);
win.document.close();
}}}}}

if(ns6)setInterval('movepopup()',40);

if(w3c){
d.onmousemove=trackmouse;
d.onmouseup=new Function("currRS=null;dragapproved=false");
}

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return curleft;
}

var BrowserDetect = {
init: function () {
this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
this.version = this.searchVersion(navigator.userAgent)
|| this.searchVersion(navigator.appVersion)
|| "an unknown version";
this.OS = this.searchString(this.dataOS) || "an unknown OS";
},
searchString: function (data) {
for (var i=0;i<data.length;i++){
var dataString = data[i].string;
var dataProp = data[i].prop;
this.versionSearchString = data[i].versionSearch || data[i].identity;
if (dataString) {
if (dataString.indexOf(data[i].subString) != -1)
return data[i].identity;
}
else if (dataProp)
return data[i].identity;
}
},
searchVersion: function (dataString) {
var index = dataString.indexOf(this.versionSearchString);
if (index == -1) return;
return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
},
dataBrowser: [
{ string: navigator.userAgent,
subString: "OmniWeb",
versionSearch: "OmniWeb/",
identity: "OmniWeb"
},
{
string: navigator.vendor,
subString: "Apple",
identity: "Safari"
},
{
prop: window.opera,
identity: "Opera"
},
{
string: navigator.vendor,
subString: "iCab",
identity: "iCab"
},
{
string: navigator.vendor,
subString: "KDE",
identity: "Konqueror"
},
{
string: navigator.userAgent,
subString: "Firefox",
identity: "Firefox"
},
{
string: navigator.vendor,
subString: "Camino",
identity: "Camino"
},
{// for newer Netscapes (6+)
string: navigator.userAgent,
subString: "Netscape",
identity: "Netscape"
},
{
string: navigator.userAgent,
subString: "MSIE",
identity: "Explorer",
versionSearch: "MSIE"
},
{
string: navigator.userAgent,
subString: "Gecko",
identity: "Mozilla",
versionSearch: "rv"
},
{ // for older Netscapes (4-)
string: navigator.userAgent,
subString: "Mozilla",
identity: "Netscape",
versionSearch: "Mozilla"
}
],
dataOS : [
{
string: navigator.platform,
subString: "Win",
identity: "Windows"
},
{
string: navigator.platform,
subString: "Mac",
identity: "Mac"
},
{
string: navigator.platform,
subString: "Linux",
identity: "Linux"
}
]

};
BrowserDetect.init();
var ie6=(BrowserDetect.browser == "Explorer")? true : false;
