// JavaScript Document
var nS2;
var nb = new Array();

window.addEvent('domready', function()
{
	if( $('login') )
	{
		$('login').onfocus = $('password').onfocus = function()
		{
			this.value = '';
		}
	}
	
	$('key').onfocus = function()
	{
		this.value = '';
	}
		
	if( $('f_login') )
	{
		$('f_login').onfocus = $('f_passwd').onfocus = function()
		{
			this.value = '';
		}
	}
	
	if( $('btAddFile') )
	{
		$('btAddFile').onclick = function()
		{
			$('add_file').style.display = 'block';
		}
		$('btNoFile').onclick = function()
		{
			$('add_file').style.display = 'none';
		}
	}
	if( $('btAddComment') )
	{
		$('btAddComment').onclick = function()
		{
			$('add_comment').style.display = 'block';
		}
		$('btNoComment').onclick = function()
		{
			$('add_comment').style.display = 'none';
		}
	}
	
	if( $('myTabs') )
		myTabs1 = new mootabs('myTabs', {height: '330px', width: '100%', changeTransition: 'none', mouseOverClass: 'over'});	
	
	if( $('cadre') && $('cI') && $('cI').value > 1 )
	{
		for( var i=1; i<=$('cI').value; i++ )
		{
			nb[i-1] = i;
		}
		nS2 = new noobSlide({
			box: $('frame'),
			items: nb,
			interval: 3000,
			size: 192,
			startItem: $('sI').value-1,
			fxOptions: {
				duration: 1000,
				transition: Fx.Transitions.Sine.easeOut,
				wait: false
			},
			addButtons: {
				previous: $('bt_prev'),
				next: $('bt_next')
			}
		});
	}
});

function zoomImage(caption, href, v)
{
	if( nS2 )
		TB_show(caption, href+(nS2.currentIndex+1)+'.jpg', false);
	else
		TB_show(caption, href+v+'.jpg', false);
}

function filter_salon(fil)
{
	if( fil != 'mois' )
		$('mois').selectedIndex = -1;
	if( fil != 'theme' )
		$('theme').selectedIndex = -1;
	if( fil != 'salon' )
		$('salon').selectedIndex = -1;
	//-- on valide le formulaire
	$('f_filter').submit();	
}

function countDevis(f)
{
	var ckb = f['pdts[]'];
	var t = 0;
	for( var i=0; i < ckb.length; i++ )
	{
		ckb[i].checked ? t++ : null;
	}
	
	if( t == 0 )
	{
		alert('Vous n\'avez pas sélectionné de produits');
		return false;
	}
	else
	{
		f.submit();
	}
}

function noaccent(chaine) {
  temp = chaine.replace(/[àâä]/gi,"a");
  temp = temp.replace(/[éèêë]/gi,"e");
  temp = temp.replace(/[îï]/gi,"i");
  temp = temp.replace(/[ôö]/gi,"o");
  temp = temp.replace(/[ùûü]/gi,"u");
  temp = temp.replace(/[ç]/gi,"c");
  temp = temp.replace(/[#«»²’^%$®£…°{}]/gi,"");
  return temp
}

function searchMe(form) {
	var keywords = form.keywords.value;
	if( !browser.isMozilla )
	{
		keywords = noaccent(keywords);
	}
	var url = form.action;
	document.location = url + "#search:" + escape(keywords);
	return false ;
}

function filters()
{
	if( location.href.indexOf("NIVEAUX4_FILTER") != -1 ) 
	{
		$('AFSWidget4').style.display = 'none';
		$('AFSWidget5').style.display = 'none';
		$('AFSWidget6').style.display = 'none';
		$('vos-filtres').style.display = '';
	}
	if( location.href.indexOf("NIVEAUX3_FILTER") != -1 ) 
	{
		$('AFSWidget4').style.display = 'none';
		$('AFSWidget5').style.display = 'none';
		$('AFSWidget6').style.display = '';
		$('vos-filtres').style.display = '';
	}
	else if( location.href.indexOf("NIVEAUX2_FILTER") != -1 )
	{
		$('AFSWidget4').style.display = 'none';
		$('AFSWidget5').style.display = '';
		$('AFSWidget6').style.display = 'none';
		$('vos-filtres').style.display = '';
	}
	else
	{
		$('AFSWidget4').style.display = '';
		$('AFSWidget5').style.display = 'none';
		$('AFSWidget6').style.display = 'none';
		$('vos-filtres').style.display = 'none';
	}
	//-- tracage XiTi
	if( location.href.indexOf("search:") != -1 )
	{
		if( location.href.indexOf("/filter") != -1 )
			end = location.href.indexOf("/filter");
		else
			end = location.href.length;
		mc = location.href.substring( location.href.indexOf("search:")+7, end );
	    temp = mc.replace(/[àâä]/gi,"a");
	    temp = temp.replace(/[éèêë]/gi,"e");
	    temp = temp.replace(/[îï]/gi,"i");
	    temp = temp.replace(/[ôö]/gi,"o");
	    temp = temp.replace(/[ùûü]/gi,"u");
	    temp = temp.replace(/[ç]/gi,"c");
	    mc   = temp.replace(/[ ]/gi,"_");
		//--
		xt_mtcl = mc;        //keyword value
		xt_npg  = "1";        //result page number (0 when no result)
		//do not modify below
		if (window.xtparam!=null){window.xtparam+="&mc="+xt_mtcl+"&np="+xt_npg;}
		else{window.xtparam ="&mc="+xt_mtcl+"&np="+xt_npg;};
	}
}

function onSuggestLoad()
{
	 var suggest = new AFSSuggest(document.getElementById('key'),
	 'http://www.achatsdirects.fr/suggest.php', 236) ;
	  suggest.setPattern("{afs:suggestion}");
	  suggest.addSuggestionHandler({
          			onSuggestion: function(suggestion, feed, metadata) {
    	  				var text = "--";
      					if (suggestion) {
	          				text = "Suggestion: " + suggestion + "\nFeed: "
	          					+ (feed ? feed : "<aucun>");
							searchMe(document.getElementById('recherche'));
      					}
      				}
	  });
}

function showArticle( id )
{
	if( $('art'+id+'-content').style.display == 'block' )
	{
		$('art'+id+'-content').style.display = 'none';
		$('arrow'+id).src = 'imgs/arrow_down.gif';
	}
	else
	{
		$('art'+id+'-content').style.display = 'block';
		$('arrow'+id).src = 'imgs/arrow_up.gif';
	}
}

function zoomNotule( idImg, img )
{
	if( !$('z'+idImg) )
	{
		var imgZoom  = new Element('img', {"src": img, "id": "z"+idImg, "class": "imgZoom", 'events': 
		{
			'mouseout': function(){
				$('z'+idImg).dispose();
			}
		}});
		
		$('a'+idImg).grab(imgZoom);
	}
}