// JavaScript Document
$(document).ready(function(){
						   

	$(".display_big_img").live("click",function(){
		
		var path_img = $(this).attr("src");
		
		var split_path = path_img.split("/");
		
		var new_path = "big_" + split_path[split_path.length-1].replace("thumb_","");
		
		
		
		$.ajax({
			async: 		false,
			type:		"POST",
			data:		{flag:"display_big_img",data:new_path},
			url:		"inc_verify_big_img.asp",
			success:	function(html){
						$("#displayer_big_img").html('');
						$("#displayer_big_img").html(html);
						$("#displayer_big_img img").load(function(){
										var image_src = $("#displayer_big_img img").attr("src");
										var imageInfo = new Image();
										imageInfo.src = image_src;										
										
										var center_top = ($(window).height() / 2) - (parseInt(imageInfo.height)/2) + $(window).scrollTop();
										var center_left = ($(window).width() / 2) - (parseInt(imageInfo.width)/2) + $(window).scrollLeft();										
														
										$("#displayer_big_img").dialog({						
											position: [center_left,center_top],						   
											modal:true,
											close: function(){
												$("#displayer_big_img").unbind('html');
											}
										});								
						});
						
			}
		});
		
	});
	
	
	$(".youtube_promo").live('click',function(){
						

			html = '<iframe width="560" height="349" src="http://www.youtube.com/embed/' + $(this).attr("src") + '" frameborder="0" allowfullscreen></iframe>';
		
			$("#display_youtube_video").html(html);
			$("#display_youtube_video").dialog({
				modal:true						   
			});
		
		
	});
	
	$("#UniteImg").live('click',function(){
		if($(this).attr("alt") == "0"){
			$(".ensemble_dimension_main").hide();
			$(".ensemble_dimension_second").show();
		} else {
			$(".ensemble_dimension_main").show();
			$(".ensemble_dimension_second").hide();
		}
	});
	
	var temp_demande_info = "";
	
	$("#btn-demande-information").live("click",function(event){
			event.preventDefault();
			
			temp_demande_info = $("#demande-information").html();
			$("#demande-information").dialog({
				title:	"Demande d'information",
				width: 520,
				height: 470,
				modal: 	true,
				close: function(ev, ui){
					$("#demande-information").html(temp_demande_info);	
				}								
			});
	});
			
	$("#btn-commander").live("click",function(event){
			event.preventDefault();
			
			$.ajax({
					url: 	"inc_infocommande.asp",
					type:	"POST",
					success:	function(html){
						$("#commande-div").html(html);	
					},
					error:		function(xhr,status,errorThrown){
						alert(errorThrown);
					}
			});
			
			$("#commande-div").dialog({
						title: "Commander",
						modal:	true,
						width: 520,
						height: 320
			});
	});
	
	$("#submit-demande-information").live("click", function(event){
			event.preventDefault();
		
			if($("#sender_firstname").val() == ""){
				alert("Vous devez inscrire votre pr\351nom");
				return false;
			}	
			
			if($("#sender_lastname").val() == ""){
				alert("Vous devez inscrire votre nom");
				return false;				 
			}
			
			if($("#sender_email").val() == "" || !isEmail($("#sender_email").val())){
				alert("Vous devez inscrire une adresse courriel valide");
				return false;
			} 
			
			if($("#sender_phone").val() == ""){
				alert("Vous devez inscrire votre num\351ro de t\351l\351phone");
				return false;
			}
			
			if($("#sender_note").val() == ""){
				alert("Vous devez inscrire un message");
				return false;
			}
			
			$.post("send_demande_info.php",$("#form-demande-information").serialize(), function(data){
				$("#demande-information").html(data);													   
			});
	});
	
	$("#close-demande-information").live("click",function(event){
			event.preventDefault();			
			$("#demande-information").dialog("close");
			$("#demande-information").html(temp_demande_info);
	});
	
	$("#close-commander").live("click",function(event){
			event.preventDefault();			
			$("#commande-div").dialog("close");
	});
				
});
function updateDimension(){
	
	
}

function ValidRechercheArticle(){
		
		if($("#RechercheProduit").val().length < 3){
			alert('Vos critères de recherche doivent contenir plus de 2 caractères!');
			return false;
		}
		
		if(!validChar($("#RechercheProduit").val())){
			alert('Vous ne pouvez pas utiliser les caractères \'"%+ dans la recherche!');
			return false;
		}
}
	
function validChar(str){
	var oRegExp = /[\/+\n'&;\\"%]/;
	return !oRegExp.test(str);
}	
	
function FonctionRechercheProduit(MotsCles, Page){	
	if (window.document.getElementById('lstArticle')){
		if (MotsCles != 'Rechercher un article'){
			if (MotsCles.length < 3){
				alert('Vos critères de recherche doivent contenir plus de 2 caractères!');
				return false;
			}
		
			SubmitString = "flag=LstArticlesParMotsCles";
			SubmitString += "&MotsCles=" + escape(MotsCles);
			SubmitString += "&Page=" + Page;
		
			sendRequest('gestion/clients_articles_lst.asp', 'lstArticle', SubmitString);
			sendRequest('gestion/client_souscategories.asp', 'lstCategorie', SubmitString);		
			
		}
	}
}
	
function Search(NoSousCategorie, Page){
	_gaq.push(['_trackPageview', '/default.asp?no=16&sscat='+NoSousCategorie]);
	if (window.document.getElementById('lstArticle')){
		SubmitString = "flag=LstArticlesParCategorie";
		SubmitString += "&NoSousCategorie=" + NoSousCategorie;
		SubmitString += "&Page=" + Page;

		sendRequest('gestion/clients_articles_lst.asp', 'lstArticle', SubmitString);
		sendRequest('gestion/client_souscategories.asp', 'lstCategorie', 'NoSousCategorie='+NoSousCategorie);
		document.location.href = "#haut";
	}
}
	
function SearchCat(NoCategorie, NoSousCategorie, Page){
	if (NoSousCategorie != '' && NoSousCategorie != 0) {
		Search(NoSousCategorie, Page);
		return false;
	}
	if (window.document.getElementById('lstArticle')){
		SubmitString = "flag=LstArticlesParCategorie";
		SubmitString += "&NoCategorie=" + NoCategorie;
		SubmitString += "&Page=" + Page;

		sendRequest('gestion/clients_articles_lst.asp', 'lstArticle', SubmitString);
		sendRequest('gestion/client_souscategories.asp', 'lstCategorie', 'NoCategorie='+NoCategorie);
		document.location.href = "#haut";
	}
}	
	
function AffDetails(NoSousCategorie, Page, NoArticle){
	SubmitString = "flag=DetailsArticles";
	SubmitString += "&NoSousCategorie=" + NoSousCategorie;
	SubmitString += "&Page=" + Page;
	SubmitString += "&NoArticle=" + NoArticle;		

	sendRequest('gestion/clients_articles_details.asp', 'lstArticle', SubmitString);
	updateDimension();
	document.location.href = "#haut";
}
	
function AffDetailsRecherche(MotsCles, Page, NoArticle){
	SubmitString = "flag=DetailsArticlesRecherche";
	SubmitString += "&MotsCles=" + escape(MotsCles);
	SubmitString += "&Page=" + Page;
	SubmitString += "&NoArticle=" + NoArticle;		

	sendRequest('gestion/clients_articles_details.asp', 'lstArticle', SubmitString);	
}	
	
function ChangeDimensionUnit(noArticle){
	var MyUnitImg = window.document.getElementById("UniteImg");
	
	if (MyUnitImg.alt=='0'){
		MyUnitImg.alt = '1';
		MyUnitImg.src = "images/unit_pouces.gif";
	}else{
		MyUnitImg.alt = '0';
		MyUnitImg.src = "images/unit_cm.gif";		
	}
		
	SubmitString = "flag=ChangeDimensionUnit";
	SubmitString += "&unit=" + MyUnitImg.alt;
	SubmitString += "&noArticle=" + noArticle;
	
	

	sendRequest('gestion/clients_articles_details.asp', 'divDimension', SubmitString);
}


	

	
function loadDewPlayeur(mp3){
	var tmpSwf = "";
	tmpSwf = tmpSwf + '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="200" height="20" id="dewplayer" align="middle">'
	tmpSwf = tmpSwf + '<param name="wmode" value="transparent" />'
	tmpSwf = tmpSwf + '<param name="allowScriptAccess" value="sameDomain" />'
	tmpSwf = tmpSwf + '<param name="movie" value="/flash/dewplayer.swf?mp3='+mp3+'&amp;showtime=1&amp;volume=80" />'
	tmpSwf = tmpSwf + '<param name="quality" value="high" />'
	tmpSwf = tmpSwf + '<param name="bgcolor" value="E4E2E5" />'
	tmpSwf = tmpSwf + '<embed src="/flash/dewplayer.swf?mp3='+mp3+'&amp;showtime=1&amp;volume=80" quality="high" bgcolor="E4E2E5" width="200" height="20" name="dewplayer" wmode="transparent" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"></embed>'
	tmpSwf = tmpSwf + '</object>'
	document.write(tmpSwf);
}
