/* Container.js is only loaded by SRL.html. It controls the functions used on the 
   SRL container: the browser sniffer, the size adjust, the CU name, and the maximize 
   and minimize functions. */
  
//Browser Sniffer
	var IE = false;
	var N4 = false;
	var N6 = false;
	if (document.all) {
		IE = true;
	} else if (document.layers) {
		N4 = true;
	} else if (document.getElementById) {
		N6 = true;
	} 

	var firstSearchPage = false;   //Is this the first page after search results

	var maximized = false;

	function adjustSize() {
		if (maximized) {
			return;
		}
		var distance, m;   //Dimension modifiers
			
		//These are set because the different browsers and the
		//different resolutions see things slightly differently when it
		//comes to dimensions.		
		distance = 20;
		m = 0;
		var lib = document.getElementById("library");
		var men = document.getElementById("menu");
		var head = document.getElementById("headTable");
		var cell = document.getElementById("graphic");

		theLeft = cell.offsetLeft + cell.offsetWidth + distance;
		theTop = ( head.offsetTop + head.offsetHeight );
		theHeight = document.body.offsetHeight - theTop - 5;

		lib.style.top = theTop;
		men.style.top = theTop;
		lib.style.bottom = 0;
		men.style.bottom = 0;
		lib.style.left = theLeft;
		men.style.width = theLeft;
		lib.style.width = document.body.offsetWidth - theLeft - 4;
		lib.style.height = theHeight - m;
		men.style.height = theHeight - m;
		// Standard: 241, 107
		//alert ("theLeft: " + theLeft + " theTop: " + theTop);
				
	}
	
	function setCUName() {
		if ( getCookie( "cuName", false ) != null && getCookie( "cuName", false ) != "null" ) {
			document.getElementById( "creditU" ).innerHTML = getCookie( "cuName", false );
		}
		// Use the fact that we check the name onload to also launch
		// the checking of tips and search menu settings.
		checkTips();
		checkSearchDisplay();
		
		/* If tips are not on, focus on the search text box.
		 * If it does this when tips ARE on, the tips window gets shoved to the 
		 * back. */ 
		if ( getCookie("tip") == "false" ) { 
			document.simpleform.searchWord.focus()
		}
	}
	
	function checkTips() {
		if (getCookie('tip') == null) {
			setCookie('tip','false')
		} 	
		if (getCookie('tip') == 'true'){
			Tip_OnLoad()
		}
    }
	
var adWindow3;
	
	function printTheWindow() {
		document.library.focus();
		document.library.print()

	}
	
function addWindow3(winName,winTitle) {
   winStats='toolbar=no,location=no,directories=no,menubar=no,alwaysraised=yes'
   winStats+='scrollbars=no,'
   winY = document.body.offsetHeight;
   if (navigator.appName.indexOf("Microsoft")>=0) {
      winStats+=',left=50,top=2000,width=1,height=1'
    }else{
      winStats+=',screenX=50,screenY=200,width=0,height=0'
    }
	if (window.adWindow3) {
		curURL = "" + window.adWindow3.location
		if (curURL == "") {
		    adWindow3=window.open(winName,"",winStats) 
   			adWindow3.focus() }
		else {
			adWindow3.focus()}
	}
	else {
   adWindow3=window.open(winName,"",winStats) 
   adWindow3.focus() }
  } 

	function maximize() {
		maximized = true;
		res = document.getElementById("restoreDiv");
		men = document.getElementById("menu");
		men.style.display="none";
		res.style.visibility = "visible";
		document.body.style.border = "0";
		top.frames[1].document.body.style.marginRight = "25%";
		fr = document.getElementById("library");
		fr.style.height="100%";
		fr.style.width="96%";
		fr.style.top = "0";
		fr.style.left = "4%";
		top.frames[1].document.location.reload();
	}
	
	function restore() {
		maximized = false;
		men = document.getElementById("menu");
		men.style.display="";
		res = document.getElementById("restoreDiv");
		res.style.visibility="hidden";
		document.body.style.border = "2px inset";
		top.frames[1].document.location.reload();
		adjustSize();
								
	}
	
	function goHome() {
	
		if(screen.availWidth <=800 || screen.availHeight <=600)   
		{
			changeScreen("html/HomePage600.html");
		} else {
			changeScreen("html/HomePage.html");
		}
	}
	/* This section swtiches the Home images on both the Navbar and the
	   Maxbar. */
		
	var img1 = new Image();
	var img2 = new Image();
	var img3 = new Image();
	img1.src = "../Shared Images/bwhouse3.gif"; 
	img2.src = "../Shared Images/bwhouse3-yellow.gif";
	img3.src = "../Shared Images/bwhouse3-buttontext.gif";

	function imgSwap1() {
		navHome.src=img1.src;
	}

	function imgSwap2() {
		navHome.src=img2.src;
	}

	function imgSwap3() {
		maxHome.src=img3.src;
	}

	function imgSwap4() {
		maxHome.src=img1.src;
	}
	
	/*******************************************************
	**		This section is for the Popup window.		  **
	*******************************************************/
	
	
	/* Checks cookie for the current Tutorial setting and sets it accordingly. */
	function checkTutorial() {
		checkCookie = getCookie( 'tutor' );
		if (checkCookie == '1') {
			top.document.getElementById("tutor").onClick = Window_OnLoad();
		}
		else {
			top.document.getElementById("tutor").onClick = popupMessage();
		}
	}
	
	function setTips() {
		checkCookie = getCookie( 'tutor' );
		if (checkCookie == '1') {
			document.getElementById("tipMenu").onClick = top.turnTips();
		}
		else {
			document.getElementById("tipMenu").onClick = popupMessage();
		}
	}
	
	function popupMessage() {
		if (confirm("You must download the Microsoft Agent to view the Tutorial and Tips. This download is contained in the Libary. Do you wish to go to the download page now?")) {
			changeScreen('html/download.html')
		}
		else{}
	}
	
	
	/*----------------- For future release (replaces popupMessage()----------------
	
	// Pop-up window prompting for tutorial downloads and also setting tutor cookie (above).
	
	function checkBrowser(){
		var yourName = navigator.appName
		this.ver=navigator.appVersion
		this.dom=document.getElementById?1:0
		this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom)?1:0;
		this.ie55=(this.ver.indexOf("MSIE 5.5")>-1 && this.dom)?1:0;
		this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom)?1:0;
		this.ie4=(document.all && !this.dom)?1:0;
		this.ns5=(this.dom && parseInt(this.ver) >= 4.3) ?1:0;
		this.ns4=(document.layers && !this.dom)?1:0;
		this.bw=(this.ie6 || this.ie55 || this.ie5 || this.ie4 || this.ns4 || this.ns5)
		return this
	}
	
	var oPopup1 = window.createPopup();

	function richDialog(){
		// Determine the browser level and use popup or new window.
		bw=new checkBrowser();
		if (bw.ie6 || bw.ie55) {
			
			oPopupBody1 = oPopup1.document.body;
			oPopupBody1.innerHTML = oDialog.innerHTML;
			oPopup1.show(100, 100, 400, 400);
			}
		else if (bw.ie5) {
			newWinforOldIE()
		}
	}	

	function newWinforOldIE() {
		newWin=window.open('','','width=300,height=300')
		// if(screen.availWidth <=800 || screen.availHeight <=600) {
		//	newWin.document.write('<link rel="stylesheet" href="summit600.css" type="text/css">');
		//}
		//else {
		//	newWin.document.write('<link rel="stylesheet" href="css/summit.css" type="text/css">')
		//} 
		newWin.document.body.innerHTML ='<div id="myid" style="position:absolute; top:0; left:0; width:100%; height:100%;'+
		'background:#cccccc; border:1px solid black; border-top:1px solid white; '+
		'border-left:1px solid white; padding:10px;  font:normal 10pt tahoma; '+
		'padding-left:18px ">'+
		'<b>Tutorial and Tips Downloads</b>'+
		'<div style="width:220px; font-family:tahoma; font-size:80%; line-height:1.5em"><br>'+
		'<p>In order to view the tutorial and the tips for the Spectrum Reference Library, you\'ll'+
		'need to download the following:</p><ul>'+
		 '<li>James, Summit\'s Microsoft Agent</li>'+
		 '<li>Microsoft Agent Core Components</li>'+
		 '<li>The text-to-speech engine</li></ul>'+
		 '<p>These files are all located within the Library, and can be installed with a few minutes.</p>'+
		 '<button style="background:#cccccc" onclick="myid.style.backgroundColor=\'#3366CC\';" tabindex="-1">Go</button>'+
		 '<br><button tabindex="-1" onclick="parent.oPopup1.hide();" '+
		 'style="border:1px solid black; border-left:1px solid white; '+
		 'border-top:1px solid white; background:#cccccc">Close Message</button><br>'+
		 '<button style="background:#cccccc" onclick="myid.style.backgroundColor=\'#3366CC\';" tabindex="-1">Change Color</button>'+
		 '</div>'
	}
	*/