function popup(adr,nompop,larg,haut,res){window.open(adr,nompop,'width='+larg+',height='+haut+',scrollbars=1,toolbar=0,location=0,status=0,menubar=0,resizable='+res);}
function imgPopup(nomPop,img,fond,txt,css){
   imgPop = window.open("",nomPop,"scrollbars=yes,width=700,height=550");
   imgPop.document.write("<html>\n\n");
   imgPop.document.write("<head><title>Apercu d'image</title></head>\n\n");
   imgPop.document.write("<body bgcolor=\""+fond+"\">\n");
   imgPop.document.write("  <table border=\"0\" cellpadding=\"0\" cellspacing=\"2\" width=\"100%\">\n");
   imgPop.document.write("    <tr><td align=\"center\"><img src=\"ressources/"+img+"\"></td></tr>\n");
   imgPop.document.write("    <tr><td align=\"center\">\n");
   imgPop.document.write("      <table border=\"0\" cellpadding=\"0\" cellspacing=\"2\">\n");
   imgPop.document.write("        <tr><td><span style=\""+css+"\">"+txt+"</span></td></tr>\n");
   imgPop.document.write("      </table>\n");
   imgPop.document.write("    </td></tr>\n");
   imgPop.document.write("  </table>\n");
   imgPop.document.write("</body>\n\n");
   imgPop.document.write("</html>");
}
function MakepopPicture(img,my_l,my_h,my_s,my_status,my_resize,my_name){
	/* Version 1.0 */
	/* Creation  Imed Azaza */
	addPop=open("",my_name,"width="+my_l+",height="+my_h+",scrollbars="+my_s+",toolbar=0,location=0,status="+my_status+",menubar=no,resizable="+my_resize);
    addPop.focus();
	addPop.document.write("<HTML><HEAD><TITLE>"+my_name+"</TITLE></HEAD>");
	addPop.document.write("<SCRIPT language=javascript>function checksize()  { if (document.images[0].complete) {  window.resizeTo(document.images[0].width+12,document.images[0].height+30); window.focus();} else { setTimeout('check()',250) } }</"+"SCRIPT>");
	addPop.document.write("<BODY onload='checksize()' leftMargin=0 topMargin=0 marginwidth=0 marginheight=0><IMG src='"+img+"' border=0>");
	addPop.document.write("");
	addPop.document.write("</BODY></HTML>");
	addPop.document.close();
}

function Makepop(url,my_l,my_h,my_s,my_status,my_resize,my_name){
	/* Version 1.0 */
	/* Creation Marc alias DMC */
	addPop=window.open(url,my_name,"width="+my_l+",height="+my_h+",scrollbars="+my_s+",toolbar=0,location=0,status="+my_status+",menubar=no,resizable="+my_resize);addPop.focus();
}

/* ////////////////////////////////////////////// */
/*	Test un ensemble de caract ?res                */
/*	@return true ou false                         */
/* ////////////////////////////////////////////// */
function defendu(string) {
if (!string){return false;}

   var iChars = "abcdefghijklmnopqrstuvwxyz@-_.~0123456789";
   for (var i = 0; i < string.length; i++) {
		if (iChars.indexOf(string.charAt(i).toLowerCase()) == -1){
			return false;
		}
   }
   return true;
} 
/* ////////////////////////////////////////////// */
/*	Test l'email                                  */
/*	@return false ou String                       */
/* ////////////////////////////////////////////// */
function is_Email(emails){
	// emails=trim(emails);
	if (emails.indexOf("@") != -1 && emails.indexOf("..")==-1 && defendu(emails)==true){
			var longueur = emails.split("@");
			if((longueur.length==2) && (longueur[0]!="" && longueur[1]!="")){
				var taille=longueur[1].lastIndexOf(".");
				if(taille!=-1){
					if((longueur[1].length-1-taille)==2 || (longueur[1].length-1-taille)==3 || (longueur[1].length-1-taille)==4){
						return true;
					}
					return false;
				}
				return false;
			}
			return false;
	}
	return false;		
}
function isselectionne(champformulaire) {return (champformulaire.selectedIndex>0);} 
function isremplit(valeur){return (valeur!="");} 
function isValidTVA(valeur){
	var formatTVA=new RegExp("^([A-Z]{1,2}||[A-Z]{2}[a-zA-Z0-9]*)$");
	 if(formatTVA.test(valeur) == true){
	  return true;
	 }else{
	  return false;
	 }
}
function isValidMdp(valeur){
	var formatMdp=new RegExp("^([ a-zA-Z0-9]*)$");
	 if(formatMdp.test(valeur) == true){
	  return true;
	 }else{
	  return false;
	 }
}

function isValidFormatAdress(valeur){
var regAdress=new RegExp("^[0-9a-zA-Z ]+$");
if (regAdress.test(valeur)==true){
return false;
}else{
return true;
}
}

function majuscule(obj)
{
	var minus = "aàâäbcçdeéèêëfghiîïjklmnoôöpqrstuùûvwxyz"
	var majus = "AAAABCCDEEEEEFGHIIIJKLMNOOOPQRSTUUUVWXYZ"
	var entree = obj.value;
	var sortie = "";
	for (var i = 0 ; i < entree.length ; i++)
	{
		var car = entree.substr(i, 1);
		sortie += (minus.indexOf(car) != -1) ? majus.substr(minus.indexOf(car), 1) : car;
	}
	obj.value = sortie;
} 

function getselectionRadio(valeur){
	if (valeur[0]) {
		for (var i = 0 ; i < valeur.length ; i++){
			if (valeur[i].checked == true){
				return valeur[i].value;
			}
		}
	} else {
		if (valeur.checked) {
			return valeur.value;
		}
	}
	return null;
} 

function getSelectedRadioValue (radiobutton){
        var returnValue = "";       
         if (radiobutton.length == 1){ 
                    returnValue = radiobutton.value;       
                     } else 
                     {            
                     for (i=0;i<radiobutton.length;i++){               
                      if (radiobutton[i].checked==true) {                    
                      returnValue=radiobutton[i].value;                
                      }            
                      }        
                      }        return returnValue;    }

function setClass(champformulaire,action,classn,classer) {if(action==true){champformulaire.className=classn;} else {champformulaire.className=classer;} } 

function afficherecherche(){
	var _layerRech = Dmc_Layer.is_object("layer");
	if(_layerRech!=false){_layerRech.style.display="block"}
}
function cacherecherche(){
	var _layerRech = Dmc_Layer.is_object("layer");
	if(_layerRech!=false){_layerRech.style.display="none"}
}
/************************/

jQuery(document).ready(function($) {
	$("#compte_layer").tooltip({
	   offset: [10, 2],   effect: 'slide'
	}).dynamic({ bottom: { direction: 'down', bounce: true } });
	
	$(".cart_block_no_products").tooltip({
		offset: [10, 2],   effect: 'slide'
	}).dynamic({ bottom: { direction: 'down', bounce: true } });
	
	$(".left").mouseenter(function(event) {
		$("img.fleche1").animate({"marginLeft": "2px"}, 200);
	});
	$(".right").mouseenter(function(event) {
		$("img.fleche2").animate({"marginLeft": "17px"}, 200);
	});
	$(".left").mouseleave(function(event) {
		$("img.fleche1").animate({"marginLeft": "7px"}, 200);
	});
	$(".right").mouseleave(function(event) {
		$("img.fleche2").animate({"marginLeft": "12px"}, 200);
	});
	
	$("#toTop").click(function(event) {
	    event.preventDefault();
	    $("body, html").animate({scrollTop:0}, 200); 
	  });
	$('#header .cols').easyListSplitter({ 
	   colNumber: 6,
	   direction: 'horizontal' 
	});
	
	$(".search_layer").click(function(event) {
		$("#layer").fadeTo(100,1);
		$("#layer").fadeTo(100,1, function(){
			$("#layer").css('filter', 'none');
			$("#layer_top").css('filter', 'none');
		});
		$("#layer_top").fadeTo(200,1);
		$("#layer_top").animate({"marginTop": "46px"}, 200);

	});
	$(".btn_fermer").click(function(event) {
		$("#layer_top").animate({"marginTop": "-46px"}, 200);
		$("#layer_top").fadeTo(200,0);
		$("#layer").fadeTo(100,0, function(){
			$("#layer").css('display', 'none');
			$("#layer").css('filter', 'none');
			$("#layer_top").css('filter', 'none');
		});
		$("#layer").fadeTo(100,0);

	});

  
  $.ajax({
    type: "POST",
	url: "geniecube/web/flash/sources/news.xml",
	dataType: "xml",
	success: function(xml){
	var newsContainer = $("<span class='newsContainer' />"); 
    $(xml).find("news").each(function(index, element) {
	var datedeb = $(this).attr('date_debut');
	var datefin = $(this).attr('date_fin');
	var now=new Date();

	var elem = datedeb.split('/');
	jour = elem[0];
	mois = elem[1];
	annee = elem[2];
	var datedeb2 = mois+'/'+jour+'/'+annee;
	
	var elem = datefin.split('/');
	jour = elem[0];
	mois = elem[1];
	annee = elem[2];
	var datefin2 = mois+'/'+jour+'/'+annee;  		    	

	datedeb2 = Date.parse(datedeb2);
	datefin2 = Date.parse(datefin2);
	var now2 = Date.parse(now);
	
	if((datedeb2 <= now2) && (datefin2 >= now2)){
        var before = "<span>";
        var after = "</span>";
        if($(element).find("url").size() > 0) {
          after = "</a>" + after;
          before += "<a href='" + $(element).find("url").text() + "' target='" + $(element).find("url").attr("target") + "'>";
        }
        newsContainer.append(before + $(element).find("titre").text() + after);
    }
  });      
  $("#flashnews_FR").append(newsContainer);

  effect($(".newsContainer span").eq(0))
    }
  }); 
  $.ajax({
	type: "POST",
    url: "geniecube/web/flash/sources/news_en.xml",
    dataType: "xml",
    success: function(xml){
      var newsContainer = $("<span class='newsContainer' />"); 
      $(xml).find("news").each(function(index, element) {
    	var datedeb = $(this).attr('date_debut');
		var datefin = $(this).attr('date_fin');
    	var now=new Date();

    	var elem = datedeb.split('/');
    	jour = elem[0];
    	mois = elem[1];
    	annee = elem[2];
    	var datedeb2 = mois+'/'+jour+'/'+annee;
    	
    	var elem = datefin.split('/');
    	jour = elem[0];
    	mois = elem[1];
    	annee = elem[2];
    	var datefin2 = mois+'/'+jour+'/'+annee;  		    	

    	datedeb2 = Date.parse(datedeb2);
    	datefin2 = Date.parse(datefin2);
    	var now2 = Date.parse(now);
    	
    	if((datedeb2 <= now2) && (datefin2 >= now2)){
	        var before = "<span>";
	        var after = "</span>";
	        if($(element).find("url").size() > 0) {
	          after = "</a>" + after;
	          before += "<a href='" + $(element).find("url").text() + "' target='" + $(element).find("url").attr("target") + "'>";
	        }
	        newsContainer.append(before + $(element).find("titre").text() + after);
	    }
      });      
      $("#flashnews_EN").append(newsContainer);

      effect($(".newsContainer span").eq(0))
	    }
	  }); 
  $.ajax({
	type: "POST",
    url: "geniecube/web/flash/sources/news_es.xml",
    dataType: "xml",
    success: function(xml){
      var newsContainer = $("<span class='newsContainer' />"); 	
      $(xml).find("news").each(function(index, element) {
    	var datedeb = $(this).attr('date_debut');
		var datefin = $(this).attr('date_fin');
    	var now=new Date();

    	var elem = datedeb.split('/');
    	jour = elem[0];
    	mois = elem[1];
    	annee = elem[2];
    	var datedeb2 = mois+'/'+jour+'/'+annee;
    	
    	var elem = datefin.split('/');
    	jour = elem[0];
    	mois = elem[1];
    	annee = elem[2];
    	var datefin2 = mois+'/'+jour+'/'+annee;  		    	

    	datedeb2 = Date.parse(datedeb2);
    	datefin2 = Date.parse(datefin2);
    	var now2 = Date.parse(now);
    	
    	if((datedeb2 <= now2) && (datefin2 >= now2)){
	        var before = "<span>";
	        var after = "</span>";
	        if($(element).find("url").size() > 0) {
	          after = "</a>" + after;
	          before += "<a href='" + $(element).find("url").text() + "' target='" + $(element).find("url").attr("target") + "'>";
	        }
	        newsContainer.append(before + $(element).find("titre").text() + after);
	    }
      });      
      $("#flashnews_ES").append(newsContainer);

      effect($(".newsContainer span").eq(0))
	    }
	  }); 
  $.ajax({
	type: "POST",
    url: "geniecube/web/flash/sources/news_it.xml",
    dataType: "xml",
    success: function(xml){
      var newsContainer = $("<span class='newsContainer' />"); 
      $(xml).find("news").each(function(index, element) {
    	var datedeb = $(this).attr('date_debut');
		var datefin = $(this).attr('date_fin');
    	var now=new Date();

    	var elem = datedeb.split('/');
    	jour = elem[0];
    	mois = elem[1];
    	annee = elem[2];
    	var datedeb2 = mois+'/'+jour+'/'+annee;
    	
    	var elem = datefin.split('/');
    	jour = elem[0];
    	mois = elem[1];
    	annee = elem[2];
    	var datefin2 = mois+'/'+jour+'/'+annee;  		    	

    	datedeb2 = Date.parse(datedeb2);
    	datefin2 = Date.parse(datefin2);
    	var now2 = Date.parse(now);
    	
    	if((datedeb2 <= now2) && (datefin2 >= now2)){
	        var before = "<span>";
	        var after = "</span>";
	        if($(element).find("url").size() > 0) {
	          after = "</a>" + after;
	          before += "<a href='" + $(element).find("url").text() + "' target='" + $(element).find("url").attr("target") + "'>";
	        }
	        newsContainer.append(before + $(element).find("titre").text() + after);
	    }
      });
      $("#flashnews_IT").append(newsContainer);

      effect($(".newsContainer span").eq(0))
    }
  }); 
	function effect(element) {
	  $(element).show().animate({opacity:1}, 700).delay(3000).animate({opacity: 0}, 700, function() {
	    $(this).hide();
	    if($(this).next().size() > 0) {
	      effect($(this).next());
	    } else {
	      effect($(this).parent().find("span").eq(0));
	    }
	  });
	}
	// Déplacement du 1er scrollable de la page d'accueil
	//if(currentPageNum == 1) {
		$(".bandeau").eq(0).appendTo("#scrollable");
	//}
	// Scrollable
	$(".scrollable").scrollable({ mousewheel: true, circular: true}).autoscroll().navigator({indexed: true});
	$("input[type='text']").fields();
		
		/*****chargement image index-1 onload****************/
		$(".bloc_article .produit a").css("display","none");
		
		/**********hover img principale*************/
		$(".produit a").hover(function() {
			if($(this).hasClass("cloud-zoom")){
				var chemin=$(".produit a").attr("href")
				var chemin_new=chemin.replace(/338x338/,"zoom");
				
				$(this).parent().css("display","block");
				$('.cloud-zoom, .cloud-zoom-gallery').CloudZoom();
			}
		});

		/**********click img principale*************/
		$(".produit a").click(function() {	
				var chemin=$(this).attr("href");
				if(chemin!="javascript:void(0);"){
					$(this).lightBox();
				}
		});
		
		/**********hover vignette*************/
		
		
		$(".img_vignette img").hover(function() {

			// see if same thumb is being clicked
			if ($(this).hasClass("active")) { return; }

			// calclulate large image's URL based on the thumbnail URL (flickr specific)
			var url = $(this).attr("src").replace(/68x68/,"338x338");
			/*alert(url);*/
           
            var spl = url.split('/');
            nomFichier = spl[spl.length-1];
            //alert("fichier:"+nomFichier);

			// get handle to element that wraps the image and make it semi-transparent
            $(".produit div").css("display","none");
            $(".produit a").css("display","none");
            
            //var chemin="images/articles/338x338"+nomFichier;
            
            if ($(".produit a").size()>0){
            $(".produit").find("a").each(function(index, element) {
            	var cible=$(this).attr("id");
                //alert(cible);
            	if(nomFichier==cible){
            		$(this).css("display","block");
            		$(this).parent().css("display","block");
            	}
            });
            }else{
            	$(".produit div").css("display","block");
            }
			// the large image from www.flickr.com
			var img = new Image();

			
			// activate item
			$(".img_vignette img").removeClass("active");
			$(this).addClass("active");
			
			
		// when page loads simulate a "click" on the first image
		}).filter(":first").hover();
		
		
		

		/**********click vignette**************/
		$(".img_vignette img").mouseenter(function() {
			//pas de lightbox img principale
			var chemin1=$(this).parent().attr("href");
			if(chemin1!="javascript:void(0);"){
				var chemin_new_lightbox=chemin1.replace(/68x68/,"900x1000");
				$(this).parent().attr("href",chemin_new_lightbox);
				$(this).parent().lightBox();
			}
		});

	// Temporisation sur l'affichage du menu dans les résultats de recherche
	if( $(".resultat").size() > 0 ) {
		$("#navh").before("<div id=\"trap\" />");
		$("#trap").mouseover(function() {
			setTimeout(function() {
				$("#trap").remove();
			}, 1000);
		});
	}
	
});
jQuery.fn.fields = function() {
	this.each(function(index, element) {
		$(element).data("defaultValue", $(element).val());
		$(element).click(function() {
			if($(this).val() == $(this).data("defaultValue")) {
				$(this).val("");
			}
		}).blur(function() {
			if($(this).val() == "") {
				$(this).val($(this).data("defaultValue"));
			}
		});
	});
};
