// JavaScript Document


function MM_preloadImages()
{ //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function moveL(container,sv)
{
	if(flag==1)
	{
		flag=0;
		var l=parseInt($(container+'-c').css('left'));
		if(l<=-(sv-10))
		{
		$(container+'-c').animate({left:'+='+String(sv)},700, "", function(){flag=1;});
		}
		else
		flag=1;
	}
}

function moveR(container,sv)
{
	if(flag==1)
	{
		flag=0;
		var wr=parseInt($(container).width());
		var la=parseInt($(container+'-c').css('left'))*(-1);
		var wa=parseInt($(container+'-c').width());
		var ar=wa-(la+wr);
		if(ar>=sv)
		{		
			$(container+'-c').animate({left:'-='+String(sv)},700, "", function(){flag=1;});
			
		}
		else
		flag=1;
	}
}


function latest_offers()
{
	$("#latest-offers .animatel").hover(function()
		{
			moveL("#latest-products",179);
				$si=setInterval('moveL("#latest-products",179)',800);
			
		},function(){clearInterval($si)});
	
		$("#latest-offers .animater").hover(function()
		{
			moveR("#latest-products",179);
				$si=setInterval('moveR("#latest-products",179)',800);
		},function(){clearInterval($si)});
		$('#latest-menu li a').click(function(){
	
		if(!$(this).hasClass('aon'))
		{
			$('#latest-menu li a').removeClass('aon');
			$(this).addClass('aon');
			
					ca=String($(this).parent().attr('class')).replace('pc','').replace(' aon','').replace('last','');
					source=$('#latest-products-c');
					$('#lp-loader').addClass('loader');
					source.hide();
					file='hot-offers.php';
					document.getElementById('latest-products-c').style.left=10;
					$.post(file,{'c_id':ca},function(data){
							
							$('#lp-loader').removeClass('loader');
							source.show();
							source.html(data);
							
							setwidth();
							});								  
		
		} });
		source=$('#latest-products-c');
					$('#lp-loader').addClass('loader');
					source.hide();
					file='hot-offers.php';
					document.getElementById('latest-products-c').style.left=10;
					$.post(file,{'c_id':document.CTL.CatToLoad.value},function(data){
							
							$('#lp-loader').removeClass('loader');
							source.show();
							source.html(data);
							
							setwidth();
							});	
}

function meilleurs()
{
	c=$('#meilleures-c').children().size()-1;
	
	w=c*291;
	$('#meilleures-c').width(w);
	$("#meilleure .animatel").hover(function()
		{
			moveL("#meilleures",291);
				$si=setInterval('moveL("#meilleures",291)',500);
			
		},function(){clearInterval($si)});
	
	$("#meilleure .animater").hover(function()
		{
			moveR("#meilleures",291);
				$si=setInterval('moveR("#meilleures",291)',500);
		},function(){clearInterval($si)});
		
}
function getQuantity()
{
	Items=new getCookieArray("Name");
	try{
	Q=Items[2].split("#");
	var quantity=0;
	for(var i=0; i<Q.length; i++)
	{
		if(!isNaN(parseInt(Q[i])))
		quantity= quantity + parseInt(Q[i]);
	}
	$('#panier-q').text(quantity);
	
}
catch(e){
	$('#panier-q').text('0');}
}
function login()
{
	$('#validerf').click(function(){
		var email=document.forgotpass.email.value;
		if(email=="")
		{
			fBlink("#forgotE");
			document.forgotpass.email.focus();
			return false;
		}
		file='member.php';
		$.post(file,{'email':email,'cAction':'ForgotPass'},function(data){
			$("#forgotpassM").text('vous recevrez votre connexion d\'identification le plus tôt possible'+data); });						  

	});
	
	
	$('#valider').click(function(){
		var email=document.login.email.value;
		var pass=document.login.password.value;					 
		if(email=="")
		{
			fBlink("#Memail");
			document.login.email.focus();
			return false;
		}
		if(pass=="")
		{
			fBlink("#Mpassword");
			document.login.password.focus();
			return false;
		}
		file='member.php';
		$('#loginF').html('&nbsp;<img src="images/loadingAnimation.gif" style="display:none;" id="loginFL" />');
					$('#loginFL').show();
					source=$(this).parent().parent();
					
					$.post(file,{'email':email,'pass':pass,'cAction':'LogIn'},function(data){
							
							
							$('#loginFL').hide();
							if(data!='0')
							{
								source.html('SUCCESSFUL');
								$('#am-panier').addClass('comptebg').html('<a href="logout.php" id="logout">sortir</a><a href="member.php" title="profil">'+data+'</a> ');
								$('#am-compte').addClass('panierbg').html('<a href="_BrowseBasket.php">Votre panier <span class=pc1>{<span id="panier-q" style="color:#606060"></span>}</span></a><input type="hidden" id="MID" value="true" />');
								getQuantity();
								tb_remove();
								
								if(String(window.location).indexOf('_Basket')!==-1)
								{window.location='_BrowseBasket.php';}
								if(String(window.location).indexOf('member.php')!==-1)
								{window.location='member.php';}
							}
							else
							{
								$('#loginF').html('E-mail address ou mot de passe incorrect.');	
							}
							
							});		
								 });
}

function indexfunctions()
{
	setwidth();
	latest_offers();
	meilleurs();
}

function setwidth()
{
	var w=0;
	var c=$('#latest-products-c').children().size();
	w=c*179;
	$('#latest-products-c').width(w);
	
	var h=$('#latest-products-c').height();
	if(h>0)
	$('#latest-products').height(h);
}
var logged=0;
var menuflag=1;
var flag=1;

function fBlink(src)
{
	$(src).addClass("blink");
	$(src).fadeTo("slow", 0.33,function(){$(this).fadeTo("slow", 1,function(){$(this).fadeTo("slow", 0.33,function(){$(this).fadeTo("slow", 1,function(){$(this).fadeTo("slow", 0.33,function(){$(this).fadeTo("slow", 1,function(){$(this).removeClass("blink");});});});});});});
}
function clearFields()
{
	$(".fieldFocus").each(function(){
		this.value=this.title;});
}
function validateAdvanced()
{
	if(isNaN(document.ASearchF.PriceFrom.value))
	{
		fBlink("#PriceFrom");
		return false;
	}
	if(isNaN(document.ASearchF.PriceTo.value))
	{
		fBlink('#PriceTo');
		return false;
	}
				 
	$(".fieldFocus").each(function(){if(this.value==this.title)this.value="";});document.ASearchF.submit();
}
function advanced_init()
{
	try //Internet Explorer
  {
  xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
  }
catch(e)
  {
  try //Firefox, Mozilla, Opera, etc.
    {
    xmlDoc=document.implementation.createDocument("","",null);
    }
  catch(e)
    {
    alert(e.message);
    return;
    }
  }
xmlDoc.async=false;
xmlDoc.load("levels.xml?rand="+Math.random());

var select1 = document.ASearchF.c_id;
var select2 = document.ASearchF.f_id;
var select3 = document.ASearchF.sf_id;
$(xmlDoc).find("categorie").each(function(){
			var c_id=$(this).attr("c_id");
 			$(this).find("famille").each(function(){
				var f_id=$(this).attr("f_id");												  
				$(this).find("sous_famille").each(function(){
					select3.options[select3.options.length] = new Option($(this).attr("sf_name"),$(this).attr("sf_id")); 								   
				});
				select2.options[select2.options.length] = new Option($(this).attr("f_name"),$(this).attr("f_id")); 
			});
			select1.options[select1.options.length] = new Option($(this).attr("c_name"),$(this).attr("c_id")); 
			
		});

$("#c_id").change(function(){
		$("#f_id").find("option").remove();
		$("#sf_id").find("option").remove();
		select2.options[select2.options.length] = new Option("Famille","");
		select3.options[select3.options.length] = new Option("Sous Famille","");
		var indx=$(this).find("option:selected").attr("value");
		$(xmlDoc).find("categorie").each(function(){
			if($(this).attr("c_id")==indx)
			{
				$(this).find("famille").each(function(){
					select2.options[select2.options.length] = new Option($(this).attr("f_name"),$(this).attr("f_id"));
					$(this).find("sous_famille").each(function(){
						select3.options[select3.options.length] = new Option($(this).attr("sf_name"),$(this).attr("sf_id"));
					
					});
				});
					
			}
		});
						   
	});

$("#f_id").change(function(){
		$("#sf_id").find("option").remove();
		select3.options[select3.options.length] = new Option("Sous Famille","");
		var indx=$(this).find("option:selected").attr("value");
		$(xmlDoc).find("famille").each(function(){
			if($(this).attr("f_id")==indx)
			{
				$(this).find("sous_famille").each(function(){
				select3.options[select3.options.length] = new Option($(this).attr("sf_name"),$(this).attr("sf_id"));
				});
			}
		});
	});

}
$(document).ready(function()
{
	
	advanced_init();
	$(".fieldFocus").focus(function(){
		if(this.value==this.title)
		this.value="";
	});
	$(".fieldFocus").blur(function(){
		if(this.value=="")
		this.value=this.title;
		});
	$(".fieldFocus").each(function(){
		if(this.value=="")
		this.value=this.title;});
	getQuantity();
	 login();
	$('li.famille').hover(function(){
		
		$(this).addClass('famille_on').find('ul').show();
		
		if($(this).parent().height()>$(this).find('ul.s1').height())
			$(this).find('ul.s1').height($(this).parent().height());
		else
			$(this).parent().height($(this).find('ul.s1').height());
			
		$('li.famille:eq('+($('li.famille').index($(this))-1)+') a').addClass('borderb');
		$('li.famille:eq('+($('li.famille').index($(this))+1)+')').addClass('nom');
		},function(){
		var p=$('li.famille').index($(this))-1;
		$(this).removeClass('famille_on').find('ul').hide();$('li.famille:eq('+p+') a').removeClass('borderb');	});

	$('#menu-rpt ul li.clickable').click(function(){
		if(!$(this).hasClass('li-home') && !$(this).hasClass('m6'))
		menuflag=0;
		setTimeout('menuflag=1;',300);
		if(!$(this).hasClass('cat-on'))
		{	
		
		if($(this).addClass('cat-on').find('ul').height()<55)
		$(this).addClass('cat-on').find('ul').height(55);
		$('#menu-rpt ul li').removeClass('cat-on').find('ul').hide();
		$(this).addClass('cat-on').find('ul').show();
		$('#search select').hide();
			
		  
	  }
	  else
	  {
		
		$(this).removeClass('cat-on').find('ul').hide();
		$('#search select').show();
	}
	}).click();


$('.item').show();

	//$('div.famille').height($('ul.sous-famille:eq(0)').height());
		$('body').click(function(){
								 
		if(menuflag==1)		
		{
		$('#menu-rpt ul li').removeClass('cat-on').find('ul').hide();
		$('#search select').show();}
	
		
		});
	if($('#main-content').height()<$('#main-content').parent().height()-30)
	$('#main-content').height($('#main-content').parent().height()-30);
});

function setHeightP()
{
	
	if($('.leftc:eq(0)').height()<$('.rightc:eq(0)').height())
	{
		$('.leftc .item').height($('.rightc').height()-24);
		
	}
}

function validateContact(){

	
	if(document.contact.prenom.value=="" || document.contact.prenom.value=="Prénom")
	{
		fBlink("#prenom");
		//alert("S'il vous plaît entrer votre prénom!");
		document.contact.prenom.focus();
		return false;
	}
	if(document.contact.family.value=="" || document.contact.family.value=="Nom de famille")
	{
		fBlink("#family");
		//alert("S'il vous plaît entrer votre nom de famille!");
		document.contact.family.focus();
		return false;
	}
	if(document.contact.email.value=="" || document.contact.email.value=="E-mail")
	{
		fBlink("#cemail");
		//alert("S'il vous plaît entrer votre E-mail");
		document.contact.email.focus();
		return false;
	}
	if(document.contact.comment.value=="" || document.contact.comment.value=="Commentaire")
	{
		fBlink("#comment");
		//alert("S'il vous plaît entrer votre Commentaire");
		document.contact.comment.focus();
		return false;
	}
	document.contact.submit();
}