// JavaScript Document

//open new browser window
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

//random number function
function randomNumber(limit){
  return Math.floor(Math.random()*limit);
}

//quotes array for home page
	quotes = new Array();
	quotes[0] = '&ldquo;Great exercise! I\'m glad to see it continuing.&rdquo;';
	quotes[1] = '&ldquo;I really love this program because it gives real-world problems in a real-world setting. It makes me want to run for political office.&rdquo;';
	quotes[2] = '&ldquo;This is a fantastic vehicle to enable residents to understand the major policy choices.&rdquo;';
	quotes[3] = '&ldquo;Excellent education; makes a hugely complex system more comprehensible.&rdquo;';
	quotes[4] = '&ldquo;This is an excellent way to strengthen public understanding of the state budget. Thank you!&rdquo;';
	quotes[5] = '&ldquo;I like the fact that I can choose based on what I feel is important.&rdquo;';
	quotes[6] = '&ldquo;This is amazing. A wonderful tool. Maybe our legislators should give this a try.&rdquo;';
	quotes[7] = '&ldquo;That certainly made me better appreciate the tough choices before the Legislature.&rdquo;';

//BUDGET CHALLENGE
// *************** GLOBALS ******************
var gsCurrentWin=null;	//holds handle to current pop up window
//*******************************************

// used to open the main app
function OpenAppWin(xsURL) {
	var vsWidth=1000;
	var vsHeight=724;
	var vsLeft=0;
	var vsTop=0;
	var vsName='BudgetApp';
	openWindow(xsURL, vsWidth, vsHeight, vsLeft, vsTop, vsName,false,false);
}
// used to open the popup box windows in the introduction
function OpenIntroBoxWin(xsURL) {
	var vsWidth=617;
	var vsHeight=540;
	var vsLeft=60;
	var vsTop=50;
	var vsName='IntroWin'
	openWindow(xsURL, vsWidth, vsHeight, vsLeft, vsTop, vsName,true,true);
}

// used to open the external link popup box windows in the introduction
function OpenOutsideLink(xsURL) {
	var vsWidth=800;
	var vsHeight=600;
	var vsLeft=30;
	var vsTop=25;
	var vsName='OutsideLinkWin'
	openWindow(xsURL, vsWidth, vsHeight, vsLeft, vsTop, vsName,true,true);
}


// used to open the details box window from the policy options screen
function OpenDetailsBoxWin(xsURL) {
	var vsWidth=617;
	var vsHeight=540;
	var vsLeft=60;
	var vsTop=50;
	var vsName='DetailsWin'
	openWindow(xsURL, vsWidth, vsHeight, vsLeft, vsTop, vsName,true,true);
}


// used to open the timeout box window 
function OpenTimeoutWin(xsURL,xsAnchor) {
	var vsWidth=617;
	var vsHeight=540;
	var vsLeft=60;
	var vsTop=50;
	var vsName='DetailsWin';
	
	openWindow(xsURL, vsWidth, vsHeight, vsLeft, vsTop, vsName,true,true);
	
	gsTimeOutAnchor = "../moreinfo/moreinfobody.htm#" + xsAnchor;
	setTimeout("gsCurrentWin.focus();gsCurrentWin.mainFrame.location.href = gsTimeOutAnchor", 1000) ;
}

// used to open the larger details window from the top nav bar
function OpenDetailsWin(xsURL) {
	var vsWidth=790;
	var vsHeight=580;
	var vsLeft=10;
	var vsTop=10;
	var vsName='DetailsWin'
	
	openWindow(xsURL, vsWidth, vsHeight, vsLeft, vsTop, vsName,true,true);
}

// used to open a glossary definition window
function OpenGlossaryBoxWin(xsURL) {
	var vsWidth=445;
	var vsHeight=290;
	var vsLeft=20;
	var vsTop=20;
	var vsName='GlossaryWin'
	
	openWindow(xsURL, vsWidth, vsHeight, vsLeft, vsTop, vsName,true,true);
}

// used to open the main glossary window
function OpenGlossaryWin(xsURL) {
	var vsWidth=816;
	var vsHeight=540;
	var vsLeft=10;
	var vsTop=10;
	var vsName='GlossaryWin'
	
	openWindow(xsURL, vsWidth, vsHeight, vsLeft, vsTop, vsName,true,true);
}

// used to open the feedback window
function OpenFeedbackWin(xsURL) {
	var vsWidth=700;
	var vsHeight=540;
	var vsLeft=10;
	var vsTop=10;
	var vsName='FeedbackWin'
	
	openWindow(xsURL, vsWidth, vsHeight, vsLeft, vsTop, vsName,true,true);
}

// used to open the Introduction window
function OpenIntroductionWin(xsURL) {
	var vsWidth=700;
	var vsHeight=540;
	var vsLeft=10;
	var vsTop=10;
	var vsName='IntroductionWin'
	
	openWindow(xsURL, vsWidth, vsHeight, vsLeft, vsTop, vsName,true,true);
}

// used to open the history window
function OpenHistoryWin(xsURL) {
	var vsWidth=660;
	var vsHeight=540;
	var vsLeft=10;
	var vsTop=10;
	var vsName='HistoryWin'
	
	openWindow(xsURL, vsWidth, vsHeight, vsLeft, vsTop, vsName,true,true);
}

// open URL in a window of specific size and name
function openWindow(xsURL, xsWidth, xsHeight, xsLeft, xsTop, xsName, xsScroll, xsResize) {
	var vsName;
	if(xsName) { 
		vsName = xsName;
	} else { 
		vsName = "NewWin";
	}
	
	var adjWidth; 
	var adjHeight;
	
	if (detectOS() == 'Windows' && detectBrowser() == 'IE'){
		adjWidth = 0; 
		adjHeight = 0; 
	} else if ((detectOS() == 'Macintosh') && (detectBrowser() == 'Netscape')){ 
		adjWidth = 0; 
		adjHeight = 0;
		xsResize = true;
	} else if ((detectOS() == 'Windows') && (detectBrowser() == 'Netscape')){ 
		adjWidth = 0; 
		adjHeight = 0; 
	} else if ((detectOS() == 'Macintosh') && (detectBrowser() == 'IE')){ 
		adjWidth = 0; 
		adjHeight = 0;
		xsResize = true;
	}
	var viWidth = (xsWidth+adjWidth);
	var viHeight = (xsHeight+adjHeight);
	
	if (screen.availHeight < viHeight){
		viHeight = screen.availHeight;
		if (detectBrowser() == 'IE'){
			viHeight = viHeight * .95;
		}
	}
	if (screen.availWidth < viWidth){
		viWidth = screen.availWidth;
		if (detectBrowser() == 'IE'){
			viWidth = viWidth * .95;
		}
	}
	
	
	var scrollOpt;
	scrollOpt = xsScroll == true ? 'yes' : 'no';
	
	var resizeOpt;
	resizeOpt = xsResize == true ? 'yes' : 'no';
	
	
	var vsNewWindow = window.open(xsURL, vsName,'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=' + scrollOpt + ',resizable=' + resizeOpt + ',copyhistory=yes,width='+viWidth+',height='+viHeight+',left='+xsLeft+',top='+xsTop+',screenX='+xsLeft+',screenY='+xsTop+'');
	
	vsNewWindow.focus();
	
	if ( gsCurrentWin && !gsCurrentWin.closed ) {
		if ( gsCurrentWin.name != vsName ) gsCurrentWin.close();
	}
	
	gsCurrentWin = vsNewWindow;
}
function detectVersion(){ 
	version = parseInt(navigator.appVersion);
	return version; 
} 

function detectOS(){ 
	if(navigator.userAgent.indexOf('Win') == -1) {
		OS = 'Macintosh'; 
	} else { 
		OS = 'Windows'; 
	} 
	return OS; 
} 

function detectBrowser(){ 
	if(navigator.appName.indexOf('Netscape') == -1) {
		browser = 'IE'; 
	} else { 
		browser = 'Netscape';
	} 
	return browser; 
} 




