/* 	window.js 
	window management functions
	by: 		Neil Johnson
	created:	26 Jan 98
	project:	ROI CD-ROM
*/

function
centerNewWindow (windowWidth, windowHeight, srcName, winName ) {


	var screenMargin = 1.2 // if the screen is at least 20% larger than the window size
	viewPortHorizontal	= screen.width;
	viewPortVertical	= screen.height;

	// determine coords to center the window
	if ( viewPortHorizontal > windowWidth * screenMargin) 
		{
		winLeft = ( viewPortHorizontal / 2 ) -
					( windowWidth / 2 );
		}
	else 
		{
		winLeft = 0;
		}

	if ( viewPortVertical > windowHeight * screenMargin )
		{
		winTop = ( viewPortVertical / 2 ) -
					( windowHeight / 2 );
		}
	else 
		{
		winTop = 0;
		}


	// all window features not specified are FALSE
	windowFeaturesList	= "innerWidth=" + windowWidth +
							",innerHeight=" + windowHeight +
							",screenX=" + winLeft +
							",screenY=" + winTop;
	
	newWindow = window.open(srcName,
		winName,
		windowFeaturesList);

	newWindow.focus();
}


function
viewProgram () {
	centerNewWindow (800, 600, "main.htm", "mainWindow");

}


function
openBig () {
	centerNewWindow (630, 420, "mainwin.htm", "mainWindow");

}

function
openWinstaller () {
	centerNewWindow (500, 430, "winst1.htm", "installWindow");

}

function
openUnixSup () {
	centerNewWindow (500, 430, "../help/unixcalc.htm", "installWindow");

}

function ExitIPIMS(){
	self.close()
}

function textwin(URL,windowname) {
    openwin = window.open(URL,windowname,"menubar=yes,scrollbars=yes,width=700,height=500,toolbar=no,resizable=1");
}

function figurewin(URL,windowname) {
    openfigure = window.open(URL,windowname,"width=500,height=500,resizable=1,dependent=true");
}

// NM 01-29-2008
function figurewin(URL,windowname) {
  var fixBeg = 0
  var fixEnd = 0
  var fixURL = ""
  for(A=0; A < URL.length ; A++){
    if(URL.substring(A,A+1) == "?"){
      fixBeg = A + 6 ;
    }
    if(URL.substring(A,A+1) == "&" && fixEnd == 0 ){
      fixEnd = A ;
    }
  }
  fixURL = URL.substring(fixBeg,fixEnd) + windowname;
  openfigure = window.open(URL,fixURL,"width=500,height=500,resizable=1,dependent=true");
}

function figurewin2(URL,windowname) {
 openfigure = window.open(URL,windowname,"width=500,height=500,resizable=1");
}


function videowin(URL) {
    openvideo = window.open(URL,"video","width=360,height=360");
}

function ChangeStatus(message) {
    self.status = message;
}

function open_window(url) {
email = window.open(url,"eMailHelp",'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=550,height=500');
}

function open_window2(url) {
email = window.open(url,"Help",'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=750,height=400');
}

function helpWin(url,windowName) 
{
  openwin = window.open(url,windowName,"menubar=no,scrollbars=yes,toolbar=no,resizable=1,width=750,height=400");
}

function detailWinMul(url,windowName) 
{
  openwin = window.open(url,windowName,"menubar=no,scrollbars=yes,toolbar=no,resizable=1,width=500,height=300");
}

function devWin(url,windowName) 
{
  openwin = window.open(url,windowName,"menubar=no,scrollbars=no,toolbar=no,resizable=0,width=430,height=340");
}

function SponWin(url,windowName) 
{
  openwin = window.open(url,windowName,"menubar=no,scrollbars=no,toolbar=no,resizable=0,width=450,height=500");
}

function CaptureWin(url,windowName) 
{
  openwin = window.open(url,windowName,"menubar=no,scrollbars=yes,toolbar=no,resizable=0,width=600,height=600");
}

function popup() {
var page = "blurb.asp";
windowprops = "height=300,width=450,location=no,"
+ "scrollbars=no,menubars=no,toolbars=no,resizable=no";

window.open(page, "Popup", windowprops);
}

function popup2() {
var page = "intro.asp";
windowprops = "height=500,width=450,location=no,"
+ "scrollbars=no,menubars=no,toolbars=no,resizable=no";

window.open(page, "Popup2", windowprops);
}

function ReportWin(url,windowName) 
{
  openwin = window.open(url,windowName,"menubar=no,scrollbars=no,toolbar=no,resizable=0,width=700,height=500");
}

function WebTrendsWin(url,windowName) 
{
  openwin = window.open(url,windowName,"menubar=no,scrollbars=yes,toolbar=no,resizable=1,width=700,height=500");
}

function genericWin(URL,windowname,WindowWidth,WindowHeight,Scroll){
  genericwin(URL,windowname,WindowWidth,WindowHeight,Scroll);
} 

function genericwin(URL,windowname,WindowWidth,WindowHeight,Scroll) 
{
	windowFeaturesList = "menubar=0,directories=0,menubar=0," +
     						       "width=" + WindowWidth +
						           ",height=" + WindowHeight + 
						           ",scrollbars=" + Scroll + 
						           ",toolbar=0,resizable=1"

	openwin = window.open(URL,windowname,windowFeaturesList);   
}

function submitform() 
{
  document.form.submit();
}


function fitWindowSize() {


var isNav4, isIE4;
if (parseInt(navigator.appVersion.charAt(0)) >= 4) {
isNav4 = (navigator.appName == "Netscape") ? 1 : 0;
isIE4 = (navigator.appName.indexOf("Microsoft") != -1) ? 1 : 0;
}
if (isNav4) {
window.innerWidth = document.images[0].width + 20;
window.innerHeight = document.images[0].height + 20;
}
if (isIE4) {
window.resizeTo(500,500);
width = 500 - (document.body.clientWidth -  document.images[0].width-30);
height = 500 - (document.body.clientHeight -  document.images[0].height-36);
window.resizeTo(width, height);

}
//clearInterval(htimeout);
}


function pop(term,definition,picture) 
{
// to make sure that the last timeout is stopped, so the def won't quiclky disappear
window.clearTimeout( htimeout); 
//
//<!-- Original:  Mike McGrath (mike_mcgrath@lineone.net) -->
//-- Web Site:  http://website.lineone.net/~mike_mcgrath/index.htm  -->
//  this version has been significantly changed:
//  it autosizes the popup
//  it doesn't move once opened ( more professional)
//  it opens to the proper side of screen based upon which side of the browser it is on
//  it is more compatible with IE esp for long documents
//  it also has a timed hide after mouseout Nice look ..
//

// browser detect
nav = (document.layers) ? true : false; 
ie  = (document.all) ? true : false;
document.onmousemove = sustain;
if (nav) document.captureEvents(Event.MOUSEMOVE);
if (nav) skin = document.topdeck;
if (ie)  skin = topdeck.style;
//
//
// if you wanna make this function smaller, you can delete these variables, this is used for ease of reading

definitionwidth = definition.length;
var pixperchar = 7.5;
// -------- border colors
var tpcolor =GetTermBgColor();//GetTermTXTColor()
var bottomcolor=GetDefBgColor();//
//   ------ word colors
var topwordcolor=GetTermTXTColor();//
var bottomwordcolor=GetDefTXTColor();//

toggle="open"; // used to keep the definitions in one place
term=term+": ";

var shadowcolor='#a6a6a6';
definitionwidth = definitionwidth * pixperchar;
if (definitionwidth>300) definitionwidth=300;
content="<TABLE id=\"def0\" WIDTH="+definitionwidth+" BORDER=0 CELLPADDING=2 CELLSPACING=0 BGCOLOR="+tpcolor+"><TR><TD>"+"<TABLE id=\"def1\" WIDTH=100% BORDER=0 CELLPADDING=0 CELLSPACING=0><TR><TD><FONT id=\"def2\" COLOR="+topwordcolor+" SIZE=2><B>" + term + "</B></FONT></TD></TR></TABLE><TABLE id=\"def3\" WIDTH="+"100% BORDER=0 CELLPADDING=2 CELLSPACING=0 BGCOLOR="+bottomcolor+"><TR><TD><FONT id=\"def4\" COLOR="+bottomwordcolor+" SIZE=2>"+definition +"</FONT></TD></TR></TABLE></TD></TR></TABLE>";
shadowcont="<TABLE id=\"def0\" WIDTH="+definitionwidth+" BORDER=0 CELLPADDING=2 CELLSPACING=0 BGCOLOR="+shadowcolor+"><TR><TD>"+"<TABLE id=\"def1\" WIDTH=100% BORDER=0 CELLPADDING=0 CELLSPACING=0><TR><TD><FONT id=\"def2\" COLOR="+shadowcolor+" SIZE=2><B>" + term + "</B></FONT></TD></TR></TABLE><TABLE id=\"def3\" WIDTH="+"100% BORDER=0 CELLPADDING=2 CELLSPACING=0 BGCOLOR="+shadowcolor+"><TR><TD><FONT id=\"def4\" COLOR="+shadowcolor+" SIZE=2>"+definition +"</FONT></TD></TR></TABLE></TD></TR></TABLE>";
//<img src='../../images/ball.gif' align=LEFT width=81 height=65 >
	
if (nav) 
{
    var canvas = document.topdeck.document; 
	canvas.write(content); 
	canvas.close();
	//skin.visibility = "show"; we'll show it when we get the coordinates in sustain()
}
  else if (ie) 
{
	document.all("topdeck").innerHTML = content;
	//skin.visibility = "visible"; we'll show it when we get the coordinates in sustain()
	
}  
	
}

function sustain(e) 
{ 

 if (toggle=="open") // toggle keeps the box not moving
{
		var nav = (document.layers) ? true : false; 
		var ie  = (document.all) ? true : false;
		if (nav) skin = document.topdeck;
		if (ie)  skin = topdeck.style;
    toggle="close"; // as soon as we get in lets lock the position
		var x = (nav) ? e.pageX : event.x; 
        var y = (nav) ? e.pageY : event.y;
	
	var xscr,yscr,xadjust,yadjust,margin;
	margin=25; // safe distance from the window
	xadjust=15; // to the right as default
	yadjust=15; // underneath as  default
	if (nav) xscr=document.width; // get the width of the screen and go from there
	if (nav) yscr=document.height;
	
	if (ie) xscr=document.body.clientWidth;
	if (ie) yscr=document.body.clientHeight;
	if (ie) yadjust+=document.body.scrollTop;//arghh!!!!!
	
	if (x+definitionwidth+xadjust+25 > xscr) xadjust=-definitionwidth;
    if ((nav) && y + 25 > yscr) yadjust = yadjust-100;
	if ((ie) && y + topdeck.clientHeight + yadjust > yscr) yadjust -= (topdeck.clientHeight+35);
	
	skin.left=x+xadjust;
	skin.top=y+yadjust;


	
	
	//alert(window.topdeck.clientHeight+','+topdeck.clientWidth);
	
	// debugger
	//window.status="xscr="+xscr+" yscr="+yscr+" xadjust="+xadjust+" yadjust="+yadjust+" x="+x+" y="+y;
	
	var shadowcast=shadow.style;
	document.all("shadow").innerHTML = shadowcont;
	shadowcast.left= x+xadjust+3;
	shadowcast.top= y+yadjust+3 ;
	shadowcast.visibility="visible";

	
	if (nav) skin.visibility = "show";
    if (ie) skin.visibility = "visible";

}
} 
 
function hidepopup(){
  var shadowcast = shadow.style;
  var nav = (document.layers) ? true : false; 
	var ie  = (document.all) ? true : false;
	if (nav) skin = document.topdeck;
	if (ie){
		skin = topdeck.style; 
  }
	skin.visibility = (nav) ? "hide" : "hidden";
  shadowcast.visibility = (nav) ? "hide" : "hidden";
}
function hidepop()  // timer to hide it ... so it closes softly, the htimeout is a handle used to make sure that we don't 
                    // close it in advertantly!!
{
       htimeout=setTimeout("hidepopup();",750);
}

function mouseoverpop()
{
//pop('Coming Soon','Definitions for any word, search for news documents by selecting a word and clicking.');
//toggle='open';
//window.clearTimeout(htimeout);
//htimeout=setTimeout("hidepop();",750);

}
function GetTermTXTColor()
{
var todayy=new Date();

var today=todayy.getDate();

if (today>=10)

{ return "#ffffcc";}

else if (today>=20)

{ return "#ffffcc";}

else if (today>=31)

{ return "#ffffcc";}


}

function GetDefTXTColor()
{
var todayy=new Date();

var today=todayy.getDate();

if (today>=10)

{ return "#000000";}

else if (today>=20)

{ return "#000000";}

else if (today>=31)

{ return "#000000";}


}
function GetTermBgColor()
{
var todayy=new Date();

var today=todayy.getDate();

if (today>=10)

{ return "#999900";}

else if (today>=20)

{ return "#003399";}

else if (today>=31)

{ return "#006600";}


}
function GetDefBgColor()
{
var todayy=new Date();

var today=todayy.getDate();

if (today>=10)

{ return "#E5E5B3";}

else if (today>=20)

{ return "#BFCCF2";}

else if (today>=31)

{ return "#E6F0E6";}


}

function helpWin850x650(url,windowName) {
  x = window.open(url,windowName,"menubar=no,scrollbars=yes,toolbar=no,resizable=1,width=850,height=650");
}