// ============================================================================
// Window Helpers
// ============================================================================

function openWindow(url,name,width,height,chrome,scroll,xpos,ypos){
	var features = "";
	chrome = chrome ? "yes" : "no";
	scroll = scroll ? "yes" : "no";
	features += "toolbar="+chrome+",status="+chrome+",menubar=no,location=no";
	features += ",scrollbars="+scroll+",resizable="+scroll;
	if(width) features += ",width="+width;
	if(height) features += ",height="+height;
	if(xpos) features += ",screenX="+xpos+",left="+xpos;
	if(ypos) features += ",screenY="+ypos+",top="+ypos;
	openWindowReference = window.open(url,name,features);
	if(openWindowReference != null && !openWindowReference.closed){
		openWindowReference.focus();
	}
}
function openCenterWindow(url,name,width,height,chrome,scroll){
	var xpos = window.screen.availWidth ? Math.round((window.screen.availWidth-parseInt(width))/2) : null;
	var ypos = window.screen.availHeight ? Math.round((window.screen.availHeight-parseInt(height))/2) : null;
	openWindow(url,name,width,height,chrome,scroll,xpos,ypos);
}
function openCenter(url,name,width,height){
	openCenterWindow(url,name,width,height,false,false);
}
function openCenterChrome(url,name,width,height){
	openCenterWindow(url,name,width,height,true,false);
}
function openCenterScroll(url,name,width,height){
	openCenterWindow(url,name,width,height,false,true);
}
function openCenterChromeScroll(url,name,width,height){
	openCenterWindow(url,name,width,height,true,true);
}

// --------------------------------------------------

function getWindowWidth(){
	if(document.all) return (document.getElementById && document.documentElement.clientWidth) ? document.documentElement.clientWidth : document.body.clientWidth;
	else return window.innerWidth;
}

// --------------------------------------------------

function fixCenteringContent(){
	var windowWidth = getWindowWidth();
	if(windowWidth % 2 != 0) var offset = "0 1px 0 0";
	else var offset = "0";
	document.getElementsByTagName("body")[0].style.margin = offset;
}

// --------------------------------------------------

var ua = navigator.userAgent.toLowerCase();
var win = ua.indexOf("win") != -1;
var w3cDom = document.getElementById ? true : false;
var ieDom = document.all ? true : false;
var gecko = ua.indexOf("gecko") != -1;
var safari = ua.indexOf("safari") != -1;

if((ieDom && w3cDom && win) || (gecko && !safari)){// IE5+ Win / Moz1+ Compatible MacWin
	//window.onload = fixCenteringContent;
	//window.onresize = fixCenteringContent;
}
