var popupWindow=''; // global persistents is important here!

// function to highlight choices
function hoverBox(elemId,isover){
	var element=$(elemId);
	if(isover) {
		element.setStyle({backgroundColor:'#dddddd'});
		element.setStyle({backgroundColor:'#ffff80'});
		element.setStyle({backgroundColor:'#ddddff'});
	} else {
		element.setStyle({backgroundColor:'#ffffff'});
	}
}

// How to tell if a window is acting as an opener
function isOpener() {
// level 2 definition
// the window has an opener and the opener is open
// indicates that the window in question is a popup with a parent

	if(!!window.opener) {//trick to make object true or null false
		// popup
		if(window.opener.closed) {
			// zombied popup
			alert('open the next window as a target');
		} else {
			// popup
			alert('update the content of the parent window and set focus to it');
		}
	} else {
		// normal window
		alert('open the next window using normal method');
	}
	return false;
}

// function to perform pop up
function popitup(url)
{
	// If the popup is open, replace the content of the popup.
	if(!popupWindow.closed && popupWindow.location){
		if(!!popupWindow.opener){
			popupWindow.location.href=url;
		} else {
			return true;
		}
	// If the popup is closed, open a brand new  popup.
	} else {	
		x=parseInt(window.screenX)+100;
		y=parseInt(window.screenY)+200;
		tend='height=500,width=880,top='+y+',left='+x+',menubar=yes,resizable=yes,scrollbars=yes,toolbar=no';
		popupWindow=window.open(url,'name',tend);
		// Does the popup have an opener?
		if(!popupWindow.opener) {
			// if no, make the popup window opener itself
			// popupWindow.opener=self;
			0;
		}
	}
	// Does opener have focus?
	if(window.focus) {
		// give the popup window focus
		popupWindow.focus();
	}
	return false;
}

// call from window to determine whether to 
function showInOpener(url) {
	if(!!window.opener){ // pop up; show in opener
		window.opener.location.href=url;
		window.opener.focus();
	} else { // use href instead
		return true;
	}
	return false;
}

function smartClose(url){
	if(!!!window.opener) {
		window.location.href=url;
		return false;
	}
	window.close();
	return false;
}
function asPopUp(elemId){
        var element=$(elemId);
        if(!!self.opener) {
                element.innerHTML='close';
        } else {
                element.innerHTML='getsatprep.com';
        }
}

