// JavaScript Document

// Tout Cocher/Decocher avec la Checkbox id="CheckAll"
/*function selection_deselection_tout() {
	if(document.liste.CheckAll.checked==false) {
		deselection_tout();
	}
	else {
		selection_tout();
	}
}*/

var ClickStatus = 0;
function selection_deselection_tout() {
	
	if(ClickStatus > 0)
	{
		deselection_tout();
		ClickStatus = 0;
	}
	else
	{
		selection_tout();
		ClickStatus = 1;
	}
}

function deselection_tout()
{
        var ne = document.liste.length;      
	    for (i=0;i<ne;i++)
	        {	   
			var champ = document.liste.elements[i] ;
			if (champ.type == "checkbox") 
			     {
					 if (champ.name.substr(0,12) == "selectionner")
					 {
						 champ.checked = false ;
						 Custom.clear(); /* fonctionne avec les coches CUSTOM FORM ELEMENTS */
					 }
				}
		    }
}

function selection_tout()
{
       var ne =document.liste.length;
	   for (i=0;i<ne;i++)
	        {
	        var champ = document.liste.elements[i];	
			if (champ.type == "checkbox")
			    {
					if (champ.name.substr(0,12) == "selectionner")
					{
						champ.checked = true ;
						Custom.clear(); /* fonctionne avec les coches CUSTOM FORM ELEMENTS */
					}
				}
			}
}


// fonction qui recupere les refs selectionnees-->
// Dedermine la taille du tableau
function selection() 
  {
   var nombre=0;
   var ne = document.liste.length;
   for (i=0;i<ne;i++)
	    {
	     var champ = document.liste.elements[i];	
	     if (champ.name.substr(0,12) == "selectionner") { if (champ.checked==true) {nombre=nombre+1;} }
	    }
  var ref_select=new Array(nombre);
  // rempli le tableau
  var nb =0;
  var ne =document.liste.length;
  for (i=0;i<ne;i++)
	   {
	    var champ = document.liste.elements[i];	
		if (champ.name.substr(0,12) == "selectionner")
		    {
		    if (champ.checked==true)
			   {
				ref_select[nb] = document.liste.elements[i].value;
				nb= nb + 1;
				}  
	   		 }
		}
		return ref_select; 
 }

function ComparerOffre(ref_select)
 {
	if (ref_select==null) {
 		ref_select=selection();
 	}
  if (ref_select==0)
     {
		 $("div.btn-comparer").qtip("enable"); // Enables the tooltip
	 }
     else 
     { 
		var tableautxt=ref_select.toString()
		var tableau = tableautxt.split(",");
		
		document.liste.refcache.value=ref_select;
		//document.liste.idcatcache.value='comparer';
		//window.open('/offre/tableau_comparatif.php?references='+ref_select+'&IdCategorie='+document.liste.idcatcache.value+'&style='+document.liste.stylecache.value, 'nom','toolbar=0, location=0, directories=0, status=0, scrollbars=yes, resizable=1, copyhistory=0, menuBar=0, width=880, height=750, left=0, top=0');
		
		var url = '/offre/tableau_comparatif.php?references='+ref_select+'&IdCategorie='+document.liste.idcatcache.value+'&style='+document.liste.stylecache.value;
		
		
		/*$(document).ready(function(){
			$(".btn-comparer").colorbox({href: url, open:true, iframe:true, width:"950", height:"90%", close:""}); 
		});*/
		
		$(document).ready(function(){
			$.fn.colorbox({href: url, open:true, iframe:true, width:"950", height:"95%", close:"", rel:"catalogue"}); 
		});
		
		//document.liste.submit();
		
	   
      }
 }
 
 function CartoOffre(ref_select)
 {
	if (ref_select==null) {
 		ref_select=selection();
 	}
  if (ref_select==0)
     {
		 $("div.btn-carto").qtip("enable"); // Enables the tooltip
	 }
     else 
     { 
		var tableautxt=ref_select.toString()
		var tableau = tableautxt.split(",");
		
		document.liste.refcache.value=ref_select;
		//document.liste.idcatcache.value='comparer';
		//window.open('/offre/cartographie.php?references='+ref_select+'&IdCategorie='+document.liste.idcatcache.value+'&style='+document.liste.stylecache.value, 'nom','toolbar=0, location=0, directories=0, status=0, scrollbars=yes, resizable=1, copyhistory=0, menuBar=0, width=880, height=750, left=0, top=0');
		
		var url = '/offre/cartographie.php?references='+ref_select+'&IdCategorie='+document.liste.idcatcache.value+'&style='+document.liste.stylecache.value;
		
		$(document).ready(function(){
			$.fn.colorbox({href: url, open:true, iframe:true, width:"950", height:"95%", close:"", rel:"catalogue"}); 
		});		
		
		//document.liste.submit();
      }
 }
 
 function CartoOffreAll()
 {
	var url = '/offre/cartographie.php?IdCategorie='+document.liste.idcatcache.value+'&style='+document.liste.stylecache.value;
	
	$(document).ready(function(){
		$.fn.colorbox({href: url, open:true, iframe:true, width:"950", height:"95%", close:"", rel:"catalogue"}); 
	});		
 } 
 
 function CartoEnsemble(IdCategorie, Categories, Style)
 {
	var url = '/offre/cartographie.php?categories='+Categories+'&IdCategorie='+IdCategorie+'&style='+Style;
	
	$(document).ready(function(){
		$.fn.colorbox({href: url, open:true, iframe:true, width:"950", height:"95%", close:"", rel:"catalogue"}); 
	});		
 } 
 


$(document).ready(function(){
	$("div.btn-comparer").qtip(
	{
		content: "Sélectionnez les références à comparer",
		position:
		{
			corner:
			{
				tooltip: 'topMiddle', // Use the corner...
				target: 'bottomMiddle' // ...and opposite corner
			},
			target: $('.selectall a')
		},	
	   	style:
		{ 
			tip: 'topMiddle',
			border:
			{
				width: 3,
				radius: 5
			},
			name: 'red' // Inherit the rest of the attributes from the preset dark style
	   	},
	   	show: 'click'
	});
	
	$("div.btn-carto").qtip(
	{
		content: "Sélectionnez les références à imprimer",
		position:
		{
			corner:
			{
				tooltip: 'topMiddle', // Use the corner...
				target: 'bottomMiddle' // ...and opposite corner
			},
			target: $('.selectall a')
		},	
	   	style:
		{ 
			tip: 'topMiddle',
			border:
			{
				width: 3,
				radius: 5
			},
			name: 'red' // Inherit the rest of the attributes from the preset dark style
	   	},
	   	show: 'click'
	});
	
	$("div.btn-comparer").qtip("disable"); // Disable the tooltip	
	$("div.btn-carto").qtip("disable"); // Disable the tooltip
});
