/************************************************************
NYU SCPS Web Site

GLOBAL CLIENT-SIDE SCRIPTS MODULE

This module contains all functions and variables used throughout
the website.


Media Farm, LLC

April 30, 2002

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


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

GLOBAL VARIABLES

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


var bName = navigator.appName; // browser name
var bPlatform = navigator.platform; // platform
var bVer = parseInt(navigator.appVersion); // version
var browser = ""; // browser name shorthand
var doc = ""; // for dHTML document object model reference
var sty = ""; // for dHTML style attribute reference
var ns6mod = ""; // to work method into object model reference generation

var mouseMoveHandlers = new Array(); // array of event handlers for mousemove events
var mouseDownHandlers = new Array(); // array of event handlers for mousedown events
var mouseUpHandlers = new Array(); // array of event handlers for mouseup events
var initFunctions = new Array(); // array of functions to execute on init

var mouseDownRF = false; // whether or not to return false by mouseDown Handler
var documentReady = false; // whether or not the document has loaded and is ready for rollovers etc

var NNResize_initWidth = 0; // window width & height used to handle NN resize bug
var NNResize_initHeight = 0;

/************************************************************
ON-COMPILE EXECUTABLES
*************************************************************/


// set up dhtml references depending on browser
if (document.all) {
// MSIE 4+
browser="IE";
doc = "document.all.";
sty = ".style";
if (bPlatform=="MacPPC") {
bVerStart = navigator.appVersion.indexOf("MSIE")+5;
bVer = parseInt(navigator.appVersion.substr(bVerStart,5));
}
} else if (document.layers) {
// Netscape Navigator 4+
browser="NN";
doc = "document.";
} else if (document.getElementById) {
// Netscape 6
browser="NS6";
doc = "document.getElementById('";
ns6mod = "')";
sty = ".style";
bVerStart = navigator.userAgent.lastIndexOf("/")+1;
bVer = parseInt(navigator.userAgent.substr(bVerStart,navigator.userAgent.length));
}


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

FUNCTIONS

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

/************************************************************
new windows
*************************************************************/
function getWindowName(url) {
	// returns a valid window name argument based on a given url
	var str="";
	
	// remove any non-letters from url to make name
	for (var i=0;i<url.length;i++) {
		if (((url.charCodeAt(i)>=65)&&(url.charCodeAt(i)<=90))||((url.charCodeAt(i)>=97)&&(url.charCodeAt(i)<=122))) {
			str += url.charAt(i);
		}
	}
	
	return str;
}

function getPlacementStr(w,h) {
	var left = Math.round((screen.availWidth/2)-(w/2));
	var top = Math.round((screen.availHeight/2)-(h/2));
	return (browser=="NN")?"screenX="+left+",screenY="+top:"left="+left+",top="+top;
}

function openBasicWindow(name,url,w,h,scrollbars,toolbar,statusbar,resize) {
	// opens a window with no extras, centered in screen, with unique name
	var placementStr = getPlacementStr(w,h);
	var x,y;
	
	// resize & scrollbar should be yes/no
	
	// set toolbar
	var tools = (toolbar=="tools")?"yes":"no";
	
	// set statusbar
	if (statusbar=="NSstatus") { 
		var status= ((bName=="Netscape")&&(bPlatform="MacPPC"))?"yes":"no";
	} else {
		var status = (statusbar=="status")?"yes":"no";
	}
	
	var str ="toolbar=" + tools + ",location=no,directories=no,status=" + status + ",scrollbars=" + scrollbars + ",resizable=" + resize + ",copyhistory=no," + placementStr + ",width=" + w + ",height=" + h;
	var wind = window.open(url, name, str);                     

	if(wind.focus()) {
		wind.focus();
	}
}

// external site window
function newWin(url) {
	// new window for external url: uses 'mainFocuser' to gaurantee focus of new window
	var windowName = getWindowName(url);

	url = "/util/mainFocuser.html?goto="+escape(url);
	mainWindow = window.open(url,windowName,"toolbar=yes,location=yes,directories=yes,status=yes,scrollbars=yes,resizable=yes,copyhistory=yes," + getPlacementStr(760,500) + ",width=760,height=500");           
	
	if((bName=="Microsoft Internet Explorer")&&(bPlatform=="MacPPC")) {
		var x = Math.round((screen.availWidth/2)-380);
		var y = Math.round((screen.availHeight/2)-250);
		mainWindow.moveTo(x,y);
	}
}

// standard window
function standardWin(name,url) {
	openBasicWindow(name,url,470,380,"yes","no","no","yes");
}

// specific windows, globally used
function popPrivacy() {
	standardWin("privacy","/about/privacy_popup.jsp");
}