var extWinEverOpened = false;
var extWin = false;
var aW = false;

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_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_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;
	
	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=1,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 () {
	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 openL(fname) {
	extWin = openExtAtCenter(fname,"LINK",0,390,1)
	extWinEverOpened = true;
	if (is_ie && is_mac) setTimeout("moveExt(screen.availWidth,390);", 1500);
	if (!aW.closed) aW.close();
	focusExt();
}
