/**
 * @version 1.0
 *
 * @copyright Copyright 2010 WnG Solutions Sàrl, all rights reserved
 * @author Daniel Calderini <daniel [DOT] calderini [AT] wng [DOT] ch>
 * @package VA
 */

/**
 * Redirige un utilisateur vers l'URL choisie si elle n'est pas nulle
 *
 * @param string url
 * @return void
 */
function va_jumpbox_goto(url) {
	if (url == '')
		return;
	
	window.location = url;
}

/**
 * Ouvre un popup avec la configuration donnee
 *
 * @param string urlPage Adresse de la page a ouvrir
 * @param int width Largeur de la fenetre
 * @param int height Hauteur de la fenetre
 * @param bool functions Afficher ou non la barre d'outils du navigateur
 * @param bool newWindow Forcer ou non a utiliser la meme fenetre
 * @param string windowName Nom de la fenetre a ouvir
 * @return void
 */
function open_window(urlPage, width, height, functions, newWindow, windowName) { 
	dom = (document.getElementById) ? true : false;
	
	ns4	= (document.layers) ? true : false;
	ie	= (document.all) ? true : false;
	ie4 = ie && !dom;
	mac = (navigator.appVersion.indexOf("Mac") != -1);
	ie4m = ie4 && mac;
	
	new_navigator = (dom || ns4 || (ie4 && !ie4m));

	var Hauteur = screen.height;
	var Largeur = screen.width;

	if (width == "")
		width = 800;
	
	if (height == "")
		height = 600;

	if (Largeur == 800 && width >= 800)
		width = 790;
	
	if (Hauteur == 600 && height >= 600)
		height = 540;

	if (Largeur == 800 && width > 600) {
		var winl = 20;
		var wint = 85;
	} else {
		var winl = 150;
		var wint = 85;
	}

	if (width + winl > Largeur) {
		winl = Largeur - width - 20;
		
		if (winl < 0)
			winl = 0;
	}
	
	if (height + wint > Hauteur) {
		wint = Hauteur - height - 60;
		
		if (wint < 0)
			wint = 0;
	}
	
	var option = (functions == true) ? "yes" : "no";
	var windowName = (!windowName) ? "fenetre" : windowName;

	if (!new_navigator) {
		alert("Pour ouvrir cette fenêtre vous devez posséder Netscape 3, IE 4 ou supérieur"); 
	} else {
		if (!ns4) {
			if (!newWindow && fen != null && !fen.closed)
				fen.close();
			
			fen = window.open(
				urlPage,
				windowName,
				'width=' + width + ',height=' + height + ',statusbar=yes,toolbar=' + option + ',menubar=' + option + ',scrollbars=yes,location=no,titlebar=' + option + ',resizable=yes,top=' + wint + ',left=' + winl
			);
		} else {
			fen = window.open(
				urlPage,
				windowName,
				'width=' + width + ',height=' + height +' ,statusbar=yes,toolbar=' + option + ',menubar=' + option + ',scrollbars=yes,location=no,titlebar=' + option + ',resizable=yes,screenY=' + wint + ',screenX=' + winl
			);
		}
		
		fen.focus();
	}
}