/*
	New window functions.
*/


/* 
	Window dimension functions.
*/
// position left and top
window.getLeft = function() {
	return self.screenLeft || self.screenX;
}

window.getTop = function() {
	return self.screenTop || self.screenY;
}

// inner width and height
window.getInnerWidth = function() {
	return self.innerWidth || document.body.clientWidth || document.documentElement.clientWidth;
}

window.getInnerHeight = function() {
	return self.innerHeight || document.body.clientHeight ||  document.documentElement.clientHeight;
}

// get the outer width of a window
window.getOuterWidth = function() {
	return self.outerWidth || document.body.clientWidth || document.documentElement.clientWidth ;
}

window.getOuterHeight = function() {
	return self.outerHeight || document.body.clientHeight ||  document.documentElement.clientHeight;
}

// pack the contents of a window
window.pack = function() {
	// add some extra for window features
	var borderWidth = window.getOuterWidth() - window.getInnerWidth();
	var borderHeight = window.getOuterHeight() - window.getInnerHeight();
	window.resizeTo(document.getWidth() + borderWidth, document.getHeight() + borderHeight);
}

// attempt to center a window on the more appropriate one
window.center = function() {
	if (opener)
		window.centerOnWindow(opener);
	else if (parent)
		window.centerOnWindow(parent);
	else
		window.centerOnScreen();
}

// center the window on screen
window.centerOnScreen = function() {
	window.moveTo((screen.availWidth - window.getOuterWidth()) / 2, (screen.availHeight - window.getOuterHeight()) / 2);
}

// center the window on another window, e.g. opener or parent
window.centerOnWindow = function(win) {
	window.moveTo(
		win.getLeft() + (win.getOuterWidth() - window.getOuterWidth()) / 2,
		win.getTop() + (win.getOuterHeight() - window.getOuterHeight()) / 2
	);
}

// get suitable centering options for window.open
window.getOptions = function(width, height) {
	var left = getLeft() + (getOuterWidth() - width) / 2;
	var top = getTop() + (getOuterHeight() - height) / 2;
	
	return "left=" + left + ",top= " + top + ",width=" + width + ",height=" + height + ",dependent";
}


	



// IE support.
// See:
//   http://www.scss.com.au/family/andrew/webdesign/xmlhttprequest/
//
if (window.ActiveXObject && !window.XMLHttpRequest) {
	window.XMLHttpRequest = function() {
		return new ActiveXObject(navigator.userAgent.match(/msie 5/i) ? 
			"Microsoft.XMLHTTP" : "Msxml2.XMLHTTP");
 	}
 	
}
