
function na_open_window(name, url, left, top, width, height, toolbar, menubar, statusbar, scrollbar, resizable) {
	JQpopup (name, url, false);
}

function nph_open_window(url, name, feature) {
	var new_window = window.open(url, name, feature);
	new_window.focus();
}

//commentaires
function popComments(nom) {
	var page = "/popup/commentaire.php?nom="+nom;
	JQpopup ("Commentaires", page, true);
}

//marques pages
function Favoris() {
	if (!statut) {
		alert("Vous devez être connecté pour utiliser gérer vos favoris.");
		return false;
	}
	JQpopup ("Favoris", chemin + "/scripts/ajax/favoris.php", false);
}

//votes des musiques
function popVote(titre, id, action) {
	JQpopup (titre, "/popup/em/vote.php?id="+id+"&act="+action, false);
}

//mp
function popMP(id, type, titre) {
	if (typeof titre == 'undefined')
		titre = "Bienvenue !";
	JQpopup (titre, "/popup/em/lire.php?id="+id+"&type="+type, false);
}

//résultats em sur profil
function popResult(titre, id, type) {
	JQpopup (titre, "/popup/em/resultats.php?id="+id+"&type="+type, true, 300);
}

//alertes que pour admins
function Alerte() {
	JQpopup ("Alerte", "/popup/admin/alertes.php", false)
}

var JQpopup_url;
var maxHeight = 500;
var maxWidth = 570;
var titleHeight = 20;
var popOpened = false;

//recharger par exemple les marques pages
function JQpopup_Reload() {
	$("#jqmContent").load(JQpopup_url, {}, function() {
		var h = $("#jqmContent").height();
		$('#modalWindow').css('height', h+titleHeight+5);
	});
}

//popup JS avec jqModal
function JQpopup (titre, urlOrSource, isUrl, popWidth) {
	var myUrl = (urlOrSource.substr(0,7)=='http://') ? urlOrSource : chemin+urlOrSource;
	JQpopup_url = myUrl;
	
	if (!isUrl || typeof popWidth == 'undefined')
		popWidth = maxWidth;

	loading();
	nettoyer();
	//ajout de la barre de titre
	$('#jqmTitle').html('<img class="jqmClose" src="'+chemin+'/images/design/symboles/close.gif"><b>'+titre+'</b>').addClass('texte2').css('padding', '1px');
	$('.jqmClose').click(function() { $('#modalWindow').jqmHide(); }); //fix
	//ajout de l'iframe
	$('#jqmContent').css("padding", "2px").css("background-color", "white").html('<iframe id="jqmIframe" frameborder="0" marginheight="0" marginwidth="0" src=""></iframe>');
	//placement de la popup
	$('#modalWindow').css({ width: popWidth, height: titleHeight, left: Math.floor((documentw-popWidth)/2), top: "50%" }).addClass('cell_alt');

	var myClosePopup = function(hash){
		hash.w.fadeOut('1000', function(){
			hash.o.remove();
		});
		popOpened = false;
		nettoyer();
	};

	//bug jqModal (mauvaise fct appelée si pas défini)
	var myShowPopup = function(hash){};
	var myLoadIframe = function(hash){};

	//popup iframe (commentaires news + critiques glossaire + modif boutique)
	if (isUrl) {
		var openInIframe = function(hash){
			var newHeight;

			//charger iframe
			$('#jqmIframe')
				.attr('src', myUrl)
				.css('height', 1)
				.load(function() {
					//calcul de la hauteur 
					$('#modalWindow').show(); //obligé sinon h = 0
					newHeight = this.contentWindow.document.body.scrollHeight;
					newHeight = this.contentWindow.document.body.scrollHeight; //IE aura la bonne valeur la 2ème fois..............
					$('#modalWindow').hide();

					//scrollbar?
					if (newHeight > maxHeight) {
						newHeight = maxHeight;
						$(this).css("overflow", "auto").css("overflow-x", "hidden");
					}

					//régler la largeur
					if (popWidth <= maxWidth)
						$('#modalWindow').css("left", Math.floor((documentw-popWidth)/2));

					//nouveau placement de la popup + nouvelle hauteur iframe
					$(this).css('height', newHeight);
					$('#modalWindow').css("height", newHeight+titleHeight+5).css("top", Math.floor((documenth-newHeight)/2)).hide().fadeIn();
						
					if (!popOpened) {
						popOpened = true;
						loading();
					}
				});	
		};
		$('#modalWindow')
			.jqm({
				target: '#jqmIframe',
				onShow: openInIframe,
				onLoad: myLoadIframe,
				onHide: myClosePopup
			})
			.jqmShow();
	}
	else {
		//popup ajax
		var myLoadAjax = function(hash){
			//calcul de la hauteur
			$('#modalWindow').show(); //obligé sinon h = 0
			var h = $('#jqmContent').height();
			//nouveau placement de la popup
			$('#modalWindow').css("height", h+titleHeight+5).css("top", Math.floor((documenth-h)/2)).hide().fadeIn();
			loading();
		};
		$('#modalWindow')
			.jqm({
				target: '#jqmContent',
				ajax: myUrl,
				onShow: myShowPopup,
				onHide: myClosePopup,
				onLoad: myLoadAjax
			})
			.jqmShow();
	}
}
