// globals
var ericWindow_innerWidth	= 0;
var ericWindow_innerHeight = 0;
var ericWindow_top			= 0;
var ericWindow_left		= 0;
var ericWindow_showroomNeedDetails;
var ericWindow_eric_window = 'undefined';

function setDimension(){
	if (screen.width == 800) {
		ericWindow_innerWidth = screen.width - 10;
		ericWindow_innerHeight = screen.height - 58;		
	} else {		
		ericWindow_innerWidth = 1014; 
//	    var browser = navigator.userAgent.toLowerCase(); 
//	    var isMS_IE = (browser.indexOf("msie") != -1);

//		if (isMS_IE) 
		ericWindow_innerHeight = 705;
	}
}

function setPosition() {
	setDimension();
	if (screen.width > 1024) {
		ericWindow_top  = ( screen.height - ericWindow_innerHeight ) / 2;
		ericWindow_left = ( screen.width - ericWindow_innerWidth ) / 2;
	} else {
		ericWindow_top = 0;
		ericWindow_left = 0;
	}
}

function setSmallDimension(){
	ericWindow_innerWidth = 400;
	ericWindow_innerHeight = 300;
}

function openPopup(controllerURIPath, parameter) {
	openNamedPopup(controllerURIPath, parameter, "popup");
}

function openNamedPopup( controllerURIPath, parameter, name ) {
	setPosition();	
	openParamPopup(controllerURIPath, parameter, name, ericWindow_left, ericWindow_top, 'no');
}

function openPopupWithScrollbar( controllerURIPath, parameter, name ) {
	setPosition();	
	openParamPopup(controllerURIPath, parameter, name, ericWindow_left, ericWindow_top, 'yes');
}

function openParamPopup( controllerURIPath, parameter, name, left, top, scrollbars ) {
	window.open(
		controllerURIPath + "?" + parameter,
		name, // "_blank"
		"toolbar=no,location=no,directories=no," + 
		"status=no," +
		"menubar=no,scrollbars=" + scrollbars +
		", resizable=no,copyhistory=no,dependent=yes," +
		"top=" + top + 
		",left=" + left + ", width="+ericWindow_innerWidth+ ", height=" + ericWindow_innerHeight);
		
//		+ ",screenX=0,screenY=0,fullscreen=1"
}

function newWindow( controllerURIPath, parameter, name) {		
	if (ericWindow_eric_window == 'undefined') {			
		ericWindow_eric_window = openNamedPopup( controllerURIPath, parameter, name);
		ericWindow_eric_window = 'undefined'; //reset the var.
	}
	else {
		ericWindow_eric_window.location.href=controllerURIPath + "?" + parameter;
	}
}

/*
http://www.faqts.com/knowledge_base/view.phtml/aid/844/fid/124

NN4 has a undocumented modal feature for the window.open function but 
this requires trusted script:
  netscape.security.PrivilegeManager.enablePrivilege
('UniversalBrowserWrite');
  var w = open ('http://www.faqts.com', 'faqts', 
      'modal=1,width=300,height=300,rezisable=1,scrollbars=1');

The given goodman url has a cross browser modal window simulation.

It seems that NN6 has
  openDialog('url', 'windowName', 'modal=1,width=300,height=300')

*/

function openModalWindow (parentForm, parameter, url, width, height ) {
	var	features =	
//		"status:yes" +
		"status:no" +
//		";scrollbars:no" +
		";resizable:no"+
		";center:yes"+
		";dialogWidth:" + width + "px" +
		";dialogHeight:" + height + "px";

	var argumentsObject = new Object();
	argumentsObject.parentForm = parentForm;
	argumentsObject.parameter = parameter;
	return showModalDialog(url, argumentsObject, features);
}

function openParamModalWindow (parameterElement, parentForm, parameter, url, width, height ) {
	var	features =	
//		"status:yes" +
		"status:no" +
//		";scrollbars:no" +
		";resizable:no"+
		";center:yes"+
		";dialogWidth:" + width + "px" +
		";dialogHeight:" + height + "px";

	var argumentsObject = new Object();
	argumentsObject.parameterElement = parameterElement;
	argumentsObject.parentForm = parentForm;
	argumentsObject.parameter = parameter;
	return showModalDialog(url, argumentsObject, features);
}

function openTipWindowWithContent (evt, title, htmlContent, width, height) {
	var w = openTipWindow(evt, '', title, width, height)
	writeInWindow( w, htmlContent );
}

function openTipWindowFromUrl (evt, url, title, width, height) {
	return openTipWindow (evt, url, title, width, height);
}

function openTipWindow (evt, url, title, width, height) {
	var x = evt.screenX - width + 3;
	var y = evt.screenY - 10;
	var w = open ( url, title, 
		'width=' + width + ',height=' + height
		 + ',screenX=' + x + ',left=' + x
		 + ',screenY=' + y + ',top=' + y 
		 + ',toolbar=no,location=no,directories=no,resizable=no,status=no,menubar=no,scrollbars=yes,dependent=yes');
//	w.document.onMouseout = close();
	return w;
}

function writeInWindow (w, htmlContent) {
	w.document.open();
	w.document.write( wrapContent( htmlContent ) );
	w.document.close();
}

function wrapContent (htmlContent) {
	return '<HTML><BODY SCROLL="auto" ONBLUR="window.close();"' 
		+ ' BGCOLOR="lightyellow">' 
		+ '<TABLE WIDTH="100%" HEIGHT="100%"><TR>' 
		+ '<TD ALIGN="center" VALIGN="middle">' 
		+ '<B>' + htmlContent + '<\/B>' 
		+ '<\/TD><\/TR><\/TABLE><\/BODY><\/HTML>';
}

function getPopup(){
	return document.getElementById("popup");
}

function centerPopup1(){
	//alert("centerPopup" );
	
	var popup = getPopup();
	
	popup.style.left = (window.innerWidth - popup.offsetWidth) / 2;
	popup.style.top = (window.innerHeight - popup.offsetHeight) / 2;
}

function setPopupVisibility( visibility ){
	getPopup().style.visibility = ( visibility ? "visible" : "hidden" );
}

