jQuery(document).ready(function() {

	/**
	 * Pour chercher la ref produit ds une url
	 **/
	function getRefFromPB(url) {
		var ref = url.split('ref=')[1];
		if (typeof(ref) != 'undefined') {
			ref = ref.split('&')[0];

		} else {  /*  Nouvelles url PowerBoutique */
			ref = url.split(',')[3];
			ref = ref.split('.')[0];

		}
		return(ref);
	}

	jQuery.noConflict();

	/* Nouveau code par OS-Consultant.com (Philippe Aragon <fil at os-consultant.com>) */
	jQuery("span#texte_disponible_liste_produits").each(function(){
		var infos = jQuery(this).parent().parent().parent().parent().parent();
		var ref   = getRefFromPB(infos.find('a')[0].href);
		var name  = infos.find('a#texte_liste_nom_liste_produits').text()
			if (ref){
				if(jQuery(this).html().toLowerCase().indexOf('rupture')>=0) jQuery(this).html(" <a href='javascript:OutOfStockPopup(\""+ref+"\",\""+name.replace(/'/,"&rsquo;")+"\");'><img border='0' src='ludo3_img/images/oos_short_fr.gif'/></a>");
				if(jQuery(this).html().toLowerCase().indexOf('unavail')>=0) jQuery(this).html(" <a href='javascript:OutOfStockPopup(\""+ref+"\",\""+name.replace(/'/,"&rsquo;")+"\");'><img border='0' src='ludo3_img/images/oos_short_en.gif'/></a>");
			}
	});

/* Ancien code PH-ENIX
	jQuery("#contenu table table").each(function(){
		if(jQuery(this).find("#texte_disponible_liste_produits").eq(0).length > 0){
			var name = jQuery(this).find("#texte_liste_nom_liste_produits").text();
			var ref = getRefFromPB(jQuery(this).find("a")[0].href);
			if (ref){
				jQuery(this).find("#texte_disponible_liste_produits").eq(0).each(function() {
					if(jQuery(this).html().toLowerCase().indexOf('rupture')>=0) jQuery(this).html(" <a href='javascript:OutOfStockPopup(\""+ref+"\",\""+name.replace(/'/,"&rsquo;")+"\");'><img border='0' src='ludo3_img/images/oos_short_fr.gif'/></a>");
					if(jQuery(this).html().toLowerCase().indexOf('unavail')>=0) jQuery(this).html(" <a href='javascript:OutOfStockPopup(\""+ref+"\",\""+name.replace(/'/,"&rsquo;")+"\");'><img border='0' src='ludo3_img/images/oos_short_en.gif'/></a>");
				});
			}
		}
	});
*/
});

var currentPopupContainer;
var currentPopupContent;

function OutOfStockPopup(ref,name){
	jQuery('#Popup').css({display:'block'});
	jQuery('#PopupBack').css({height:window.document.body.scrollHeight+'px'}); 
	//$('#Popup').css({height:window.document.body.offsetHeight+'px'}); 
	jQuery('#Popup').css({top:(document.body.scrollTop)+'px'});
	jQuery('#PopupBack').css({display:'block'}); 
	currentPopupContainer = jQuery('#outOfStockContent');
	jQuery('#outOfStockFrame').attr("src","http://www.ph-enix.com/ludocortex/OutStockReport.php?ref="+ref+"&title="+name);
	currentPopupContent = currentPopupContainer.html();
	jQuery('#PopupContent').append(currentPopupContent);	
}

