$(document).ready(function() {
	
	//Lors du chargement 
	
	$('#gamme').removeOption(/./);
	$('#gamme').addOption(0,'--Toutes les gammes--',false);
	iFamilleId = $('#famille').val();
	iGammeId = $('#igammeSelected').val();
	$.getJSON(j_basepath+'index.php?module=produit&action=produitFo_chargeListeGamme',{iFamilleId:iFamilleId},function(toGammes){
		
		var select = $('#gamme');
		
		$(select).each(function(){
			var o = this.options;
			var oL = o.length;
			
			//$('#gamme').addOption(toGammes[0],'--Choisir une gamme--' ,false);
			for (gamme_id in toGammes){
				$('#gamme').addOption(toGammes[gamme_id].gamme_id,toGammes[gamme_id].gamme_titre ,false);
				//$('#gamme').val(toGammes[gamme_id].gamme_id);
				
				$('#gamme').val($('#igammeSelected').val(0));
				
			}
			
			
		});
		
		if ( iGammeId > 0){
			$('#gamme').val(iGammeId);
		}else{
			$('#gamme').val($('#igammeSelected').val(0));
		}
		
					
		
	});
	//chargement de la gamme correspondant ? la famille selectionn?e (ONCHANGE)
	jQuery('#famille').change(function(){
		$('#gamme').removeOption(/./);
		$('#gamme').addOption(0,'--Toutes les gammes--',false);
		iFamilleId = $(this).val();
		
		$.getJSON(j_basepath+'index.php?module=produit&action=produitFo_chargeListeGamme',{iFamilleId:iFamilleId},function(toGammes){
			
			var select = $('#gamme');
			
			$(select).each(function(){
				var o = this.options;
				var oL = o.length;
				
				//$('#gamme').addOption(toGammes[0],'--Toutes les gammes--' ,false);
				for (gamme_id in toGammes){
					$('#gamme').addOption(toGammes[gamme_id].gamme_id,toGammes[gamme_id].gamme_titre ,false);
					//$('#gamme').val(toGammes[gamme_id].gamme_id);
				}
				
				
			});
			
			if ( iGammeId > 0){
				$('#gamme').val(iGammeId);
			}else{
				$('#gamme').val($('#igammeSelected').val(0));
			}
			
		});
	});
	
	//mot de passe oublie
	
	jQuery('#mdp_oublie').click(function(){	
		popUpWindow(j_basepath+'index.php?module=membre&action=membreFo_mdpOublie', 300, 300, 400, 230);
	});
	
	// Code added by NovaShore to send Emailto Friend on 17 Sep 2008
	jQuery('#send_mail').click(function(){
            
                var currPageAddr = document.location.href;                 
		popUpWindow(j_basepath+'index.php?module=membre&action=membreFo_sendMail&currPageAddr='+currPageAddr, 300, 300, 370, 390);
	}
        );
	// End fo Code by Novashore
	
	// Code added by NovaShore to print the promotion on 11 Oct 2008
	jQuery('#print_promo').click(function(){
            
                                 
		popUpPrintWindow(j_basepath+'index.php?module=promotion&action=promotionFo_liste1', 0, 0, 710, 500);
	}
        );

	jQuery('#print_promo1').click(function(){
            
                var z = $('[@name=promotion_id]').val();
                
                popUpPrintWindow(j_basepath+'index.php?module=promotion&action=promotionFo_fiche1&id_promo='+z, 0, 0, 710, 500);
	}
        );


// End fo Code by Novashore


	//telechargement document (Enseigne)
	/*
	jQuery('#downloadEnseigne').click(function(){
		
		var zNomDoc ;
		
		zNomDoc = $('#zNomDoc').val();
		$.post(j_basepath+'index.php?module=enseigne&action=enseigneFo_telechargeDocument',{zNomDoc:zNomDoc},function(){
		
		});
		
	});
	*/
	
});
var popUpWin=0;
function popUpWindow(URLStr, left, top, width, height){
	scrollbar = 'no';
  if(popUpWin){
    if(!popUpWin.closed) popUpWin.close();
  }
	left=(screen.width - width)/2;
  popUpWin = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars='+scrollbar+',resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}

var popUpPrintWin=0;
function popUpPrintWindow(URLStr, left, top, width, height){
	scrollbar = 'yes';
  if(popUpPrintWin){
    if(!popUpPrintWin.closed) popUpPrintWin.close();
  }
	left=(screen.width - width)/2;
  popUpPrintWin = open(URLStr, 'popUpPrintWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars='+scrollbar+',resizable=yes,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}