$(document).ready( function(){
	$('.divSCB').click(function(){
					if( !$(this).hasClass( "openSCB" ) )
					{
		                $(".openSCB .listCheckBox").hide();
		                $(".divSCB").removeClass( "openSCB" );
		                $(this).addClass( "openSCB" );
		                obj = $(".openSCB p .actionSCB").get(0);
			            var curleft = obj.offsetLeft || 0;
			            var curtop = obj.offsetTop || 0;
			            while (obj = obj.offsetParent) {
			                    curleft += obj.offsetLeft
			                    curtop += obj.offsetTop
			            }
			            posTopLeft = {x:curleft,y:curtop};
			                  curtop += $(".openSCB p .actionSCB").height()+2;
			                  curleft += 0;
			            posBottomLeft = {x:curleft,y:curtop};
			                  
			                  $(".openSCB .listCheckBox").css("top",posBottomLeft.y+"px");
			                  $(".openSCB .listCheckBox").css("left",posBottomLeft.x+"px");
			                  
			                  displayVal = $('.openSCB > .listCheckBox').css("display");
			                  if(displayVal != "none")
			                  {
			                      $(".openSCB .listCheckBox").slideUp("fast");
			                  }     
			                  else
			                  {
			                        $(".openSCB .listCheckBox").slideDown("fast");
			                  }     
			           }
			           else
			           {
			           
			               $(".openSCB .listCheckBox").slideUp("fast");
		               	   $(".divSCB").removeClass( "openSCB" );
			           }
			           
	});   
	$(".openSCB , .listCheckBox").hover(function(){ 
		                  $(".openSCB .listCheckBox").slideDown("fast");
		            },function(){
		                   var trigger = function() {
		                 $(".openSCB .listCheckBox").slideUp("fast");
		               	 $(".divSCB").removeClass( "openSCB" );
		              };
		                setTimeout(trigger, 500);
	});
	

});		
function loadInDiv(url,parametre,idDiv)
{
	//post pour ne pas avoir de limite d'envoi
	var myAjax = $.ajax({type: 'post',
				 url: url,
				 data: parametre,
				 async: false,
				 error:function(msg){
					alert( "Error !: " + msg );
				 },
				 success: 
				 function (response){
				 	$("#"+idDiv).show();
					element = document.getElementById(idDiv);
					element.innerHTML = response;
					
					var tmp = element.getElementsByTagName('script');
				    var i=0;
					if (tmp.length > 0) 
					{
						for (i = 0; i < 1; i++) {
							var txt = tmp[i].text;
							eval(txt);
						}
					}
				}		
			 });
}	


function modifyQuantiteProduitRecherche() {

	if (!/^\s+[0-9]+\s+$/.test(this.value) && !isNaN(this.value)){
		this.value = Math.round(this.value);//voir s'il vaut mieux un parseInt ou un round!
	}
	
	if (this.value < 1 || isNaN(this.value)  ){
		this.value = this.defaultValue;
	}
}
function augmenterQuantiteProduitRecherche(idInputQuantite){
	var valeur = $('#'+idInputQuantite).val();
	valeur++;
	$('#'+idInputQuantite).val(valeur.toFixed(0));
}
function diminuerQuantiteProduitRecherche(idInputQuantite){
	var valeur = $('#'+idInputQuantite).val();
	valeur--;
	if (valeur <1 ){
		valeur = 1;
	}
	$('#'+idInputQuantite).val(valeur.toFixed(0));
}
//pages de résultats avec quantité
$(document).ready(function(){
	$('input[name=quantiteProduitResultat]')
		.change(modifyQuantiteProduitRecherche)
		.focus(modifyQuantiteProduitRecherche)
		.blur(modifyQuantiteProduitRecherche)
		;
});

