//openTheWins();
//focusWinFromBack();


// alert("entering script_popup.js");
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);
	
var extWinEverOpened = false;
var extWin = false;
var aW = false;

function openVertAtCenter(w_url, w_id, w_inner_width, w_inner_height, sb) {
	adj_wW = w_inner_width;
	adj_wH = w_inner_height;
//	alert("script_popup.js, openVertAtCenter, adj_wW, adj_wH = "+ adj_wW + ", " + adj_wH);

	if (adj_wW==0) {
		if (is_safari) adj_wW = screen.availWidth;
		if (is_ie  && is_mac) adj_wW = screen.availWidth;
		if (is_ie  && is_win) adj_wW = screen.availWidth -  9;
		if (is_nav && is_mac) adj_wW = screen.availWidth - 10;
		if (is_nav && is_win) adj_wW = screen.availWidth - 11;
	}
	if (adj_wH==0) {
		if (is_safari) adj_wH = screen.availHeight;
		if (is_ie  && is_mac) adj_wH = screen.availHeight;
		if (is_ie  && is_win) adj_wH = screen.availHeight - 29;	
		if (is_nav && is_mac) adj_wH = screen.availHeight - 30;
		if (is_nav && is_win) adj_wH = screen.availHeight - 31;
	}
	if ((sb == 1) && is_mac) adj_wW += 15;
	if ((sb == 1) && is_win) adj_wW += 16;
	
	adj_left = 0;
	if (w_inner_width != 0) {
		adj_left = ((screen.width - w_inner_width) / 2) - 14;
		if (is_win) adj_left +=1;
	}
//	alert("adj_left= "+adj_left+", screen.width= "+screen.width);
	adj_top = 0;
	if (w_inner_height != 0) {
		adj_top = ((screen.height - w_inner_height) / 2) - 0;
		if (is_win) adj_top +=0;
	}
	
	adj_left = Math.round (adj_left); adj_top = Math.round (adj_top); adj_wW = Math.round (adj_wW); adj_wH = Math.round (adj_wH);
	theW = window.open(w_url, w_id, "screenX=" +adj_left +",screenY=" +adj_top +",left=" +adj_left +",top=" +adj_top
		+",width=" +adj_wW +",height=" +adj_wH 
		+",toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=" +sb +",resizable=0");
		
	return theW;
}

function openExtAtCenter (w_url, w_id, w_inner_width, w_inner_height, sb) {
	adj_wW = 0;
	adj_wH = w_inner_height;

	if (adj_wW==0) {
		if (is_safari) adj_wW = screen.availWidth;
		if (is_ie  && is_mac) adj_wW = screen.availWidth;
		if (is_ie  && is_win) adj_wW = screen.availWidth - 11;
		if (is_nav && is_mac) adj_wW = screen.availWidth - 13;
		if (is_nav && is_win) adj_wW = screen.availWidth - 11;
	}
	
	adj_left = 0;
	
	if (is_safari)        adj_top = ((screen.height      - w_inner_height) / 2) - 21;
	if (is_mac && is_nav) adj_top = ((screen.height      - w_inner_height) / 2) - 17;
	if (is_mac && is_ie ) adj_top = ((screen.height      - w_inner_height) / 2) - 21;
	if (is_win) adj_top = ((screen.availHeight - w_inner_height) / 2) -  6;
	
	adj_left = Math.round (adj_left); adj_top = Math.round (adj_top); adj_wW = Math.round (adj_wW); adj_wH = Math.round (adj_wH);
	if (is_safari) {
	//	alert ("openExtAtCenter, is_safari = TRUE!");
	//	alert ("adj_top= " + adj_top);
	}
	theW = window.open(w_url, w_id, "screenX=" +adj_left +",screenY=" +adj_top +",left=" +adj_left +",top=" +adj_top
		+",width=" +adj_wW +",height=" +adj_wH 
		+",toolbar=1,location=1,directories=0,status=1,menubar=0,scrollbars=" +sb +",resizable=1");

	return theW;
}

function openPopAtCenter (w_url, w_id, w_inner_width, w_inner_height, sb) {
	adj_wW = 0;
	adj_wH = w_inner_height;

	if (adj_wW==0) {
		if (is_safari)        adj_wW = screen.availWidth;
		if (is_ie  && is_mac) adj_wW = screen.availWidth;
		if (is_ie  && is_win) adj_wW = screen.availWidth - 11;
		if (is_nav && is_mac) adj_wW = screen.availWidth - 13;
		if (is_nav && is_win) adj_wW = screen.availWidth - 11;
	}
	
	adj_left = 0;
	
	if (is_safari)        adj_top = ((screen.height      - w_inner_height) / 2) - 21;
	if (is_mac && is_nav) adj_top = ((screen.height      - w_inner_height) / 2) - 17;
	if (is_mac && is_ie ) adj_top = ((screen.height      - w_inner_height) / 2) - 21;
	if (is_win) adj_top = ((screen.availHeight - w_inner_height) / 2) -  6;
	
	adj_left = Math.round (adj_left); adj_top = Math.round (adj_top); adj_wW = Math.round (adj_wW); adj_wH = Math.round (adj_wH);	
	theW = window.open(w_url, w_id, "screenX=" +adj_left +",screenY=" +adj_top +",left=" +adj_left +",top=" +adj_top
		+",width=" +adj_wW +",height=" +adj_wH 
		+",toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=" +sb +",resizable=0");

	return theW;
}

function do_ie_mac_resize() {
	if (is_ie && is_mac) {
		wxW = screen.availWidth;
		if (screen.height >  1024) wxH = screen.availHeight;
		if (screen.height <= 1024) wxH = screen.height - 44;
		window.resizeTo(wxW, wxH);
	}
}

function openTheWins () {
//	alert("script_popup.js, at openWins = ");
	do_ie_mac_resize();
	var vw1,vh1 = 0;
	aW = openVertAtCenter('madxs_vert.html',"wMADvert",441,0,1)
}

function focusExt() {
	if (extWinEverOpened) {
		if (!extWin.closed) extWin.focus();
	}
}

function closeExt() {
//	alert ("attempting close of external window, extWinEverOpened= " + extWinEverOpened);
	if (extWinEverOpened) {
		if (!extWin.closed) extWin.close();
	}
}

function moveExt(xw,xh) {
		extWin.resizeTo(xw,xh);
}

function focusVert() {
	if (!aW.closed) self.focus();
}

function focusVertFromBack() {
	if (!aW.closed) aW.focus();
}

//function closeVert() { // philip
//if (!aW.closed) aW.close();
//}

function focusWinFromBack() {
	// alert ("focusWinFromBack, extWinEverOpened= " + extWinEverOpened);

	if (!aW.closed) {
		setTimeout("focusVertFromBack();",1000)
	}
	else {
		openTheWins()
	}
closeExt();
	
//	setTimeout("focusExt();",1500);
}


function focusWin() {
	if (!aW.closed) {
		setTimeout("focusVert();",1000)
	}
	else {
		openVertAtCenter('madxs_vert.html',"wMADvert",441,0,1)
	}
	
	setTimeout("focusExt();",1500);
}

function openW(fname) {
	extWin = openExtAtCenter(fname,"wExt",0,441,1)
	extWinEverOpened = true;
	if (is_ie && is_mac) setTimeout("moveExt(screen.availWidth,441);", 1500);
	if (!aW.closed) self.close();
	focusWin();
}

/////////////

function openL(fname) {
	extWin = openExtAtCenter(fname,"LINK",0,441,1)
	extWinEverOpened = true;
	if (is_ie && is_mac) setTimeout("moveExt(screen.availWidth,441);", 1500);
	if (!aW.closed) aW.close();
	focusExt();
}

/////////////

function openVillette(fname) {
	extWin = openPopAtCenter(fname,"LINK",0,390,1)
	extWinEverOpened = true;
	if (is_ie && is_mac) setTimeout("moveExt(screen.availWidth,441);", 1500);
	if (!aW.closed) aW.close();
	focusExt();
}

/////////////

function openRational(fname) {
	extWin = openPopAtCenter(fname,"LINK",0,450,1)
	extWinEverOpened = true;
	if (is_ie && is_mac) setTimeout("moveExt(screen.availWidth,441);", 1500);
	if (!aW.closed) aW.close();
	focusExt();
}

/////////////

function openCENTER(theURL, Name, popW, popH, scroll) {
var winleft = (screen.width - popW) / 2;
var winUp = (screen.height - popH) / 2;
popW = Math.round (popW); popH = Math.round (popH); winleft = Math.round (winleft); winUp = Math.round (winUp);
winProp = 'width='+popW+',height='+popH+',left='+winleft+',top='+winUp+',scrollbars='+scroll+',resizable'
Win = window.open(theURL, Name, winProp)
if (parseInt(navigator.appVersion) >= 4) { Win.window.focus(); }
}
