function popup(fileName,caption,width,height)
{
	if(getCookie("nopop")){
		stopPop(fileName);
	}
	else
	{
		var fileType=(fileName.indexOf(".swf")>-1 ? "swf" : 
			fileName.indexOf(".flv") > -1 ? "swf" : 
			fileName.indexOf(".png") > -1 ? "img" : 
			fileName.indexOf(".jpg") > -1 ? "img" : 
			fileName.indexOf(".gif") > -1 ? "img" : "doc");
		
		fileType=="swf" ? popDoc(fileName,0,caption) : 
			fileType=="img" ? photoPop(fileName,caption) : 
			popDoc(fileName,1);
	}
}

function photoDims(photo)
{
	var dimensions=new Array();
	var photoImg=new Image();
	photoImg.src=photo;
	var w=photoImg.width;
	var h=photoImg.height;
	
	if(w>450)
	{
		w=450;
		h=parseInt((w/photoImg.width)*h);
	}
	if(h > 500)
	{
		w=parseInt((500/h)*w);
		h=500;
	}
	dimensions[0]=w;
	dimensions[1]=h;
	return dimensions;
}

function photoPop(photo,caption)
{
	var title;
	var photoSizes=photoDims(photo);
	var w=photoSizes[0];
	var h=photoSizes[1];
	var windowWidth=w+50;
	var windowHeight=h+60;

	var windowContent;

	if(!caption || caption=="")
	{
		title="PhotoViewer";
	}
	else
	{		
		title=caption;
		windowHeight=windowHeight+50;
	}

	var windowProps='top=0,left=0,width='+windowWidth+',height='+windowHeight+
			'toolbar=0,location=0,addressbar=0,toolbar=0,directories=0,status=0,'+
			'personalbar=0,scrollbars=1,resizable=1,menubar=0';

	if(top.consoleRef){top.consoleRef.close()}
	top.consoleRef=window.open('',"PhotoViewer",windowProps);
	{
		var windowContent=''+
		'<html><head><title>'+title+'</title>'+
		'<style type="text/css">'+
		'body {font: 80% verdana,arial,helvetica,sans-serif; text-align: center; background: #cccccc;}'+
		'img {padding: 2px; border: solid 1px #666666; '+
		' background: #ffffff; display:block; margin: auto; width: '+w+'px; height: '+h+'px; }'+
		'a {display: block; width: inherit; text-decoration: none; font-weight: bold; '+
		'border: solid 2px; border-color: #ff0000 #660000 #660000 #ff0000; margin: auto; '+
		'color: #ffffff; width: 150px; background: #aa0000;}'+
		'a:hover {background: #cccccc; color: #666666; border-color: #ffffff;}'+
		'div{margin: 5px; font-weight: bold;}'+
		'</style>'+
		'</head><body onload="self.focus()">'+
		'<img src="'+photo+'" alt="'+caption+'" />'+
		'<div>'+caption+'</div>'+
		'<a href="javascript: void window.close()">Close Window</a>'+
		'</body></html>';
		top.consoleRef.document.writeln(windowContent);
		top.consoleRef.document.close();

	}
}

function popDoc(fileName,propsType,caption)
{
	var poppedWindow;
	var height=parseInt(screen.availHeight);
	var width=parseInt(height*1.2);
	
	if(fileName.indexOf(".swf") > -1 || fileName.indexOf(".flv") > -1)
	{
		width=screen.availWidth;
		if(width > 1000)
		{
			width=1000;
			height=600;
		}
	}
	var windowName="documentWindow";

		var windowProps='top=0,left=0,width='+width+',height='+height+
			'toolbar='+propsType+',location='+propsType+',addressbar='+propsType+
			',toolbar='+propsType+',directories='+propsType+',status='+propsType+
			','+'personalbar='+propsType+',scrollbars=1,resizable=1,menubar='+propsType;
	
				
		if(!poppedWindow || poppedWindow.closed)
		{
			poppedWindow=window.open(fileName,windowName,windowProps);
			if(poppedWindow)
			{
				poppedWindow.focus();
			}
			else
			{
				location.href=fileName;
			}
		}
		else
		{
			poppedWindow.location.href=fileName;
			poppedWindow.focus();	
		}
}

function popStop()
{
	var noPopContent="";
	
	if(getCookie("nopop")) {
 		noPopContent='<span>'+
		'Document popups are turned off</span> '+
		'<a href="javascript: void setCookie(-1,\'nopop\'); '+
		'location.reload(true)">[Turn them back on]</a> ';
	}
	else {
		noPopContent='<a href="javascript: void setCookie(1,\'nopop\'); '+
			'location.reload(true)">'+
			'[Stop opening documents in a new window!]</a>'+
			'<span>You must have cookies enabled to select this option</span>';
	}
	var ps=itemValue("popstop");
	ps.innerHTML=noPopContent;
}

function commonObj(objID)
{
	objID=document.getElementById ? 
		document.getElementById(objID) : document.all[objID];
	return objID;
}

var boxTop;
var boxLeft;

function dynamicInfo(title,id)
{
	id=id.indexOf("#") > -1 && id.length > 1 ? id.substr(id.indexOf("#")+1) : id;
	var contents=document.getElementById(id).innerHTML;
	
	var windowProps=''+
	'top=0,left=0,width=500px,height=300px,scrollbars=1,resizable=1,menubar=0';

	if(top.consoleRef){top.consoleRef.close()}
	
	top.consoleRef=window.open('','dynabox',windowProps);
	{
		var windowContent=''+
		'<html><head>'+
		'<title>'+title+'</title>'+
		'<style type="text/css">'+
		'body {font: 80% arial,helvetica,sans-serif; background: #ccc;}'+
		'.close {'+
		' text-decoration: none; font-weight: bold; '+
		' border: solid 2px; border-color: #f00 #600 #600 #f00; '+
		' color: #fff; background: #a00; padding: 3px;'+
		'}'+
		'p {text-align: center;}'+
		'.close:hover {'+
		' background: #ccc; color: #666; border-color: #fff;}'+
		'div{background: #fff; padding: 10px; border: solid 1px #000;}'+
		'</style>'+
		'</head><body onload="self.focus()">'+
		'<div>'+contents+'</div>'+
		'<p><a class="close" href="javascript: void window.close()">Close Window</a></p>'+
		'</body></html>';
		top.consoleRef.document.writeln(windowContent);
		top.consoleRef.document.close();

	}
}


function helpBox(boxID,sender)
{
/* 
	Increase sender's z-index, to get sender's "real" position.  
	This information will be used to position the helpbox.
*/
	sender.style.position="relative";
	
/* create the object for browsers that don't use getElementById */	
	boxID=commonObj(boxID);
/* toggle display of helpbox */	
	boxID.style.display=(boxID.style.display=="block" ? "none" : "block");
/*	position help box at end of sender and aligned to senders top - a few pixels */	
	boxTop=(sender.offsetTop+sender.offsetHeight);
	boxLeft=(sender.offsetLeft);
	boxID.style.top=boxTop+"px";
	boxID.style.left=(sender.offsetLeft)+"px";
	boxID.style.display=="block" ? pointer() : pointer(true);
	
}

function IE6()
{
	var ie=(navigator.appName=="Microsoft Internet Explorer");
	if(ie) {
		var ver=navigator.appVersion;		
		ver=ver.substring(ver.indexOf("MSIE")+5);
		ver=parseInt(ver.substring(0,1));
		if(ver <7)
		{
			return true;
		}
	}
	else
	{
		return false;
	}
}

function pointer(helpBoxStatus)
{
	var pointID=commonObj("pointer");	
	//change image if ie6
	if(IE6())
	{
		pointID.src=pointID.src.replace(".png",".gif");
	}

//if helpbox is closed
	if(helpBoxStatus){
		pointID.style.display="none";
		return;
	}
	else
	{
		pointID.style.display="inline";
	}
	
	var bt=boxTop-110;
	var bl=(document.body.offsetWidth-90)-boxLeft;

	bt=Math.ceil(bt/20);
	bl=Math.ceil(bl/20);

	pointID.style.position="absolute";
	pointID.style.zIndex="20"
	var newLeft=boxLeft+=bl;
	var newTop=boxTop-=bt;	

	if(newLeft < document.body.offsetWidth-90)
	{
		pointID.style.top=newTop+"px";
		pointID.style.left=newLeft+"px";
		setTimeout("pointer()",5);
	}
}


//if javascript is operational, uses this stylesheet
function ifjs()
{
	document.write('<link rel="stylesheet" type="text/css" href="/inc_lib/ifjs.css" />');
	
}

ifjs();
