var popupTab = new Array();

this.Sleep = function ZZzzzZZzzzzzzZZZz(naptime){
	naptime = naptime * 1000;
	var sleeping = true;
	var now = new Date();
	var alarm;
	var startingMSeconds = now.getTime();
	//alert("starting nap at timestamp: " + startingMSeconds + "\nWill sleep for: " + naptime + " ms");
	while(sleeping)
	{
		alarm = new Date();
		alarmMSeconds = alarm.getTime();
		if(alarmMSeconds - startingMSeconds > naptime){ sleeping = false; }
	}
	//alert("Wakeup!");
}


function openPopup(url,hauteur,largeur,id,config) {
	var top=(screen.height-hauteur)/2;
	var left=(screen.width-largeur)/2;
	var configIntern = "resizable=no,toolbar=no,location=no,status=no,directories=no,menubar=no,scrollbars=no,width="+largeur+",height="+hauteur+",left="+left+",top="+top;;
	var idIntern = "Popup";
	
	if((typeof(id)!='undefined') && !isWhitespace(id))
		idIntern = id;
	
	if((typeof(config)!='undefined') && !isWhitespace(config))
		configIntern = config
	
	//alert("1) typeof()="+typeof(popupTab[idIntern])+" popupTab["+idIntern+"]="+popupTab[idIntern]);
	//alert("1) typeof()="+typeof(popupTab[idIntern]));
	/*	
	if(	typeof(popupTab[idIntern])!='undefined')
		alert("id="+idIntern+" isClose="+popupTab[idIntern].closed);
		*/
	if(typeof(popupTab[idIntern])!='undefined'/*&&!popupTab[idIntern].closed*/) {
		//alert("id="+idIntern+" isClose="+popupTab[idIntern].closed);
		
		if(popupTab[idIntern].closed!=true)
			popupTab[idIntern].close();
			
		//popupTab[idIntern] = null;
		delete popupTab[idIntern];
		//Sleep(1);
		
		//alert("2) typeof()="+typeof(popupTab[idIntern])+" popupTab["+idIntern+"]="+popupTab[idIntern]);
		//popupTab[idIntern] = null;
		
		//alert("typeof(eltPopup)="+typeof(eltPopup)+" popupTab["+idIntern+"]="+popupTab[idIntern]);
		/*
		if(typeof(eltPopup)!='undefined') {
			eltPopup.close();
			popupTab[idIntern] = null;
			alert("typeof(eltPopup)="+typeof(eltPopup)+" popupTab["+idIntern+"]="+popupTab[idIntern]);
		}*/
	}
	
	/*
	var win = window.open(url,idIntern,configIntern);
	win.focus();
	//return win;
	*/

	/*
	Sleep(1);
	var win = window.open(url,idIntern,configIntern);
	win.focus();
	
	popupTab[idIntern] = win;
	alert("2) "+idIntern+"="+typeof(popupTab[idIntern]));	
	*/
	//Sleep(1);
	//alert("1) "+idIntern+"="+typeof(popupTab[idIntern]));
	popupTab[idIntern] = window.open(url,idIntern,configIntern);//win;
	//alert("2) "+idIntern+"="+typeof(popupTab[idIntern]));	
	popupTab[idIntern].focus();
	
	//var test = popupTab[idIntern];
	//alert("2) "+idIntern+"="+typeof(test));
	//alert("3) typeof()="+typeof(popupTab[idIntern])+" popupTab["+idIntern+"]="+popupTab[idIntern]);
	
}

function openCenterPopUp(url,hauteur,largeur,titre,id) {
	var top=(screen.height-hauteur)/2;
	var left=(screen.width-largeur)/2;
	var config = "resizable=no,toolbar=no,location=no,status=no,directories=no,menubar=no,scrollbars=no,width="+largeur+",height="+hauteur+",left="+left+",top="+top;
	openPopup(url,hauteur,largeur,id,config);
}

function openCenterPopUpResizable(url,hauteur,largeur,titre,id) {
	var top=(screen.height-hauteur)/2;
	var left=(screen.width-largeur)/2;
	var config = "resizable=yes,toolbar=no,location=no,status=no,directories=no,menubar=no,scrollbars=yes,width="+largeur+",height="+hauteur+",left="+left+",top="+top;
	openPopup(url,hauteur,largeur,id,config);
}

var childIsInit = false;
function init()
{
	childIsInit = true;
	//window.onunload = closeChildBackParent;
}

function closeChildBackParent() {
	if(childIsInit) {
		childIsInit = false;
		//alert("closeChildBackParent");//DEBUG
		window.opener.history.back();				// back parent
		window.opener.focus();          			// bring parent window to the top
		window.close();                 			// close child
	}
}
/*
function closeChildCurrentParent() {
	window.opener.location = window.opener.history.previous;				// back parent
	window.opener.focus();          			// bring parent window to the top
	window.close();                 			// close child
}
*/
function closeChildRedirectParent(argURL) {
	childIsInit = false;
	//alert("closeChildRedirectParent");//DEBUG
	var basePath = "http://localhost/ECLIPSE_PHP_PROJECTS/aestefanAlbum1/aestefanAlbum1/";
	//alert("URL=" + argURL);//DEBUG
	window.opener.location = basePath + argURL; // redirect parent
	window.opener.focus();          			// bring parent window to the top
	window.close();                 			// close child
}

