$(document).ready(function(){

	//vAnimateBody();

	vAfficheNewsHeader();	
	vAfficheNewsHome();
	vZoomImage();
	vResizeImage();	
	vAfficheBloc();
	search_price_item();
	ShowTreeCateg();
	//LaunchFeaturedItems();
	EventListWhat();
	ShowTreeConso();
	search_video_youtube();
	//apply_arrondi();
	showPromoSeller();
	EventListWhatAdv();
	EventSlideFeaturedItemsSoco();
	vDeleteJS();
	vAnimatePromoNoel();
	vAnimateMyListPicture();
	
	search_video_youtube_for_mylist();

	validInfoRomanjiEvent();
});


function vAnimateBody()
{

	if ($("#lalng").length == 0)
	{
	//
	}
	else
	{
		if ($('.discountleft').length != 0)
		{
		
			var thelng = $("#lalng").val();
		
			if (thelng == 1)
			{
				$('body').css('background-image', 'url("../../../images/sites/cdandlp/bg-xmas-discounts-fr.jpg")');
			}
			else
			{
				if (thelng == 3)
				{
					$('body').css('background-image', 'url("../../../images/sites/cdandlp/bg-xmas-discounts-jp.jpg")');
				}
				else
				{
					$('body').css('background-image', 'url("../../../images/sites/cdandlp/bg-xmas-discounts-en.jpg")');
				}
			}
		
			/*if ($('.discountleft'))
			{
				$('#discountleft').css('width', '490px');
				$('#discountleft').css('height', jQuery(document).height());
				
				
				var taille_total = 2000;
				if (jQuery(document).width() < taille_total)
				{
					var taille_left = (jQuery(document).width()-1020) / 2;
					var taille_margin = 490 - taille_left;
					$('#discountleft').css('margin-left', '-'+taille_margin+'px');
				}
				
				$('#discountleft').css("display", "block");
			}
		
		
			if ($('.discountright'))
			{
				var taille_right = (jQuery(document).width()-1020) / 2;
			
				$('#discountright').css('width', taille_right+'px');
				$('#discountright').css('height', jQuery(document).height());
				
				
				var taille_total = 2000;
				if (jQuery(document).width() < taille_total)
				{
					var taille_margin = (jQuery(document).width()-1020) / 2;
					var taille_margin = taille_margin + 1020
					$('#discountright').css('margin-left', taille_margin+'px');
				}
				
				$('#discountright').css("display", "block");
			}
		
			$("#discountleft").mouseover(function()
			{
				$(this).css('cursor','pointer');
			});
		
			$("#discountleft").mouseleave(function()
			{
				$(this).css('cursor','auto');
			});
		
			$("#discountleft").click(function()
			{
				window.location.href = "http://"+window.location.hostname+"/seller_sales/index.cfm?lng="+thelng;
			});
		
			$("#discountright").mouseover(function()
			{
				$(this).css('cursor','pointer');
			});
		
			$("#discountright").mouseleave(function()
			{
				$(this).css('cursor','auto');
			});
		
			$("#discountright").click(function()
			{
				window.location.href = "http://"+window.location.hostname+"/seller_sales/index.cfm?lng="+thelng;
			});*/
		}
	}
	
	
}


function vAfficheNewsHeader()
{
	if ($('#effet_slide'))
	{
		$('#effet_slide').slideDown("slow");
	}
}

function vAfficheNewsHome()
{
	if ($('#id_news_home'))
	{
		//alert(navigator.systemLanguage);
		//alert(navigator.language);
		if (!navigator.systemLanguage)
		{
			if ($('#id_news_home').attr('lngnavig') == '3' && navigator.language.indexOf('ja') != -1)
			{
				$('#id_message_accueil').css("display", "none");
				$('#id_news_home').css("display", "block");
			}
		}
		else
		{
			if ($('#id_news_home').attr('lngnavig') == '3' && navigator.systemLanguage.indexOf('ja') != -1)
			{
				$('#id_message_accueil').css("display", "none");
				$('#id_news_home').css("display", "block");
			}
		}
	}
}


function vResizeImage()
{

	//var x = new Image(); 
	//x.src = $("#id_photo_principale").attr('src');

	//$("#id_photo_principale").attr('src', $("#id_photo_principale").attr('thesrc'));

	if($("#id_photo_principale"))
	{
		vApplicResizeImage();
	}

	$("#id_photo_principale").load(function(){
		vApplicResizeImage();
	})

	/*if ($("#disable_product_page").length != 0)
	{
		pos_image = $("#id_photo_principale").position();
		alert(pos_image.top);
		
		$("#disable_product_page").css("margin-top", pos_image.top+'px');
	}*/

}

function vApplicResizeImage()
{


	//alert('toto');
	//$("#id_photo_principale").load(function(){
	if ($("#id_photo_principale_size").attr('value'))
	{
		thesize = $("#id_photo_principale_size").attr('value');
	}
	else
	{
		thesize = '200';
	}

	if ($("#new_methode").attr('value') == 1)
	{
		if ($("#id_photo_principale").attr('height') > $("#id_photo_principale").attr('width'))
		{
			if ($("#id_photo_principale").attr('height') > thesize)
			{
				$("#id_photo_principale").css("height", thesize+'px');
				// Calcul de la largeur :
				iwidth = $("#id_photo_principale").attr('width') * thesize / $("#id_photo_principale").attr('height');
				$("#id_photo_principale").css("width", iwidth+'px');
				//alert(iwidth);
			}
		}
		else
		{
			if ($("#id_photo_principale").attr('width') > thesize)
			{
				$("#id_photo_principale").css("width", thesize+'px');
				// Calcul de la hauteur :
				iheight = $("#id_photo_principale").attr('height') * thesize / $("#id_photo_principale").attr('width');
				$("#id_photo_principale").css("height", iheight+'px');
				//alert(iheight);

			}
		}
		//alert($("#id_photo_principale").attr('height'));
		//alert($("#id_photo_principale").attr('width'));
		if ($("#id_photo_principale").attr('height') > 0)
		{
			thevaluemargintop = (thesize - $("#id_photo_principale").attr('height')) / 2;
			//alert(thevaluemargintop);
			$("#id_photo_principale").css("margin-top", thevaluemargintop+'px');
			// Calcul du margin top :
		}
	}
	else
	{

		if ($("#id_photo_principale").height > $("#id_photo_principale").width)
		{
			$("#id_photo_principale").css("height", thesize+'px');
			// Calcul de la largeur :
			iwidth = $("#id_photo_principale").width * thesize / $("#id_photo_principale").height;
			$("#id_photo_principale").css("width", iwidth+'px');
			//alert(iwidth);
		}
		else
		{
			$("#id_photo_principale").css("width", thesize+'px');
			// Calcul de la hauteur :
			iheight = $("#id_photo_principale").height * thesize / $("#id_photo_principale").width;
			$("#id_photo_principale").css("height", iheight+'px');
			//alert(iheight);
		}
		//alert($("#id_photo_principale").css("width"));
		//alert($("#id_photo_principale").css("height"));

		//$("#id_photo_principale").attr('src', $("#id_photo_principale_hidden").attr('value'));
		//$("#id_photo_principale").aeImageResize({height: 200, width: 200});
	}
	//$("#id_photo_principale").css("display", 'block');
	//})

}


function vZoomImage()
{
	var ddimagepanner={

		magnifyicons: ['http://www.cdandlp.com/images/magnify.gif','http://www.cdandlp.com/images/magnify2.gif', 24,23], //set path to zoom in/out images, plus their dimensions
		maxzoom: 4, //set maximum zoom level (from 1x)

		init:function($, $img, options){
			var s=options
			s.imagesize=[$img.width(), $img.height()]
			s.oimagesize=[$img.width(), $img.height()] //always remember image's original size
			s.pos=(s.pos=="center")? [-(s.imagesize[0]/2-s.wrappersize[0]/2), -(s.imagesize[1]/2-s.wrappersize[1]/2)] : [0, 0] //initial coords of image
			s.pos=[Math.floor(s.pos[0]), Math.floor(s.pos[1])]
			$img.css({position:'absolute', left:s.pos[0], top:s.pos[1]})
			if (s.canzoom=="yes"){ //enable image zooming?
				s.dragcheck={h: (s.wrappersize[0]>s.imagesize[0])? false:true, v:(s.wrappersize[1]>s.imagesize[1])? false:true} //check if image should be draggable horizon and vertically
				s.$statusdiv=$('<div style="position:absolute;color:white;background:#353535;padding:2px 10px;font-size:12px;visibility:hidden">1x Magnify</div>').appendTo(s.$pancontainer) //create DIV to show current magnify level
				s.$statusdiv.css({left:0, top:s.wrappersize[1]-s.$statusdiv.outerHeight(), display:'none', visibility:'visible'})
				this.zoomfunct($, $img, s)
			}
			this.dragimage($, $img, s)
		},

		dragimage:function($, $img, s){
			$img.mousedown(function(e){
				s.pos=[parseInt($img.css('left')), parseInt($img.css('top'))]
				var xypos=[e.clientX, e.clientY]
				$img.bind('mousemove.dragstart', function(e){
					var pos=s.pos, imagesize=s.imagesize, wrappersize=s.wrappersize
					var dx=e.clientX-xypos[0] //distance to move horizontally
					var dy=e.clientY-xypos[1] //vertically
					s.dragcheck={h: (wrappersize[0]>imagesize[0])? false:true, v:(wrappersize[1]>imagesize[1])? false:true}
					if (s.dragcheck.h==true) //allow dragging horizontally?
						var newx=(dx>0)? Math.min(0, pos[0]+dx) : Math.max(-imagesize[0]+wrappersize[0], pos[0]+dx) //Set horizonal bonds. dx>0 indicates drag right versus left
					if (s.dragcheck.v==true) //allow dragging vertically?
						var newy=(dy>0)? Math.min(0, s.pos[1]+dy) : Math.max(-imagesize[1]+wrappersize[1], pos[1]+dy) //Set vertical bonds. dy>0 indicates drag downwards versus up
					$img.css({left:(typeof newx!="undefined")? newx : pos[0], top:(typeof newy!="undefined")? newy : pos[1]})
					return false //cancel default drag action
				})
				return false //cancel default drag action
			})
			$(document).bind('mouseup', function(e){
				$img.unbind('mousemove.dragstart')
			})
		},

		zoomfunct:function($, $img, s){
			var magnifyicons=this.magnifyicons
			var $zoomimages=$('<img src="'+magnifyicons[0]+'" /><img src="'+magnifyicons[1]+'" />')
				.css({width:magnifyicons[2], height:magnifyicons[3], cursor:'pointer', zIndex:1000, position:'absolute',
							top:s.wrappersize[1]-magnifyicons[3]-1, left:s.wrappersize[0]-magnifyicons[2]-3, opacity:0.7
				})
				.attr("title", "Zoom Out")
				.appendTo(s.$pancontainer)
			$zoomimages.eq(0).css({left:parseInt($zoomimages.eq(0).css('left'))-magnifyicons[2]-3, opacity:1}) //position "zoom in" image
				.attr("title", "Zoom In")
			$zoomimages.click(function(e){ //assign click behavior to zoom images
				var $zimg=$(this) //reference image clicked on
				var curzoom=s.curzoom //get current zoom level
				var zoomtype=($zimg.attr("title").indexOf("In")!=-1)? "in" : "out"
				if (zoomtype=="in" && s.curzoom==ddimagepanner.maxzoom || zoomtype=="out" && s.curzoom==1) //exit if user at either ends of magnify levels
					return
				var basepos=[s.pos[0]/curzoom, s.pos[1]/curzoom]
				var newzoom=(zoomtype=="out")? Math.max(1, curzoom-1) : Math.min(ddimagepanner.maxzoom, curzoom+1) //get new zoom level
				$zoomimages.css("opacity", 1)
				if (newzoom==1) //if zoom level is 1x, dim "zoom out" image
					$zoomimages.eq(1).css("opacity", 0.7)
				else if (newzoom==ddimagepanner.maxzoom) //if zoom level is max level, dim "zoom in" image
					$zoomimages.eq(0).css("opacity", 0.7)
				clearTimeout(s.statustimer)
				s.$statusdiv.html(newzoom+"x Magnify").show() //show current zoom status/level
				var nd=[s.oimagesize[0]*newzoom, s.oimagesize[1]*newzoom]
				var newpos=[basepos[0]*newzoom, basepos[1]*newzoom]
				newpos=[(zoomtype=="in" && s.wrappersize[0]>s.imagesize[0] || zoomtype=="out" && s.wrappersize[0]>nd[0])? s.wrappersize[0]/2-nd[0]/2 : Math.max(-nd[0]+s.wrappersize[0], newpos[0]),
					(zoomtype=="in" && s.wrappersize[1]>s.imagesize[1] || zoomtype=="out" && s.wrappersize[1]>nd[1])? s.wrappersize[1]/2-nd[1]/2 : Math.max(-nd[1]+s.wrappersize[1], newpos[1])]
				$img.animate({width:nd[0], height:nd[1], left:newpos[0], top:newpos[1]}, function(){
					s.statustimer=setTimeout(function(){s.$statusdiv.hide()}, 500)
				})
				s.imagesize=nd
				s.curzoom=newzoom
				s.pos=[newpos[0], newpos[1]]
			})
		}

	}

	jQuery.fn.imgmover=function(options){
		var $=jQuery
		return this.each(function(){ //return jQuery obj
			if (this.tagName!="IMG")
				return true //skip to next matched element 
			var $imgref=$(this)
			if (parseInt(this.style.width)>0 && parseInt(this.style.height)>0) //if image has explicit CSS width/height defined
				ddimagepanner.init($, $imgref, options)
			else if (this.complete){ //account for IE not firing image.onload
				ddimagepanner.init($, $imgref, options)
			}
			else{
				$imgref.bind('load', function(){
					ddimagepanner.init($, $imgref, options)
				})
			}
		})
	}

	
	$('#id_photo_principale').click(function(event)
	{
		vAfficheZoom();
	});


	$('#id_photo_principale1').click(function(event)
	{
		vAfficheZoom();
	});

	$('#id_photo_principale2').click(function(event)
	{
		vAfficheZoom();
	});

	$('#id_photo_principale3').click(function(event)
	{
		vAfficheZoom();
	});

	$('#img_petite_zoom_1').click(function(event)
	{
		$("#id_image_zoom").attr('src', $("#img_petite_zoom_1").attr('src'));
	});

	$('#img_petite_zoom_2').click(function(event)
	{
		$("#id_image_zoom").attr('src', $("#img_petite_zoom_2").attr('src'));
	});

	$('#img_petite_zoom_3').click(function(event)
	{
		$("#id_image_zoom").attr('src', $("#img_petite_zoom_3").attr('src'));
	});
		
		/*$("#id_image_zoom").click(function(event)
	{
		if($("#zoom_en_cours").attr('value') == 0)
		{
			$("#zoom_en_cours").attr('value', 1);
			$("#id_image_zoom").height($("#id_image_zoom").height() + 200);
			$("#id_image_zoom").width($("#id_image_zoom").width() + 200);
		}
		else
		{
			$("#zoom_en_cours").attr('value', 0);
			$("#id_image_zoom").height($("#id_image_zoom").height() - 200);
			$("#id_image_zoom").width($("#id_image_zoom").width() - 200);
		}
		$('#zoom_sur_image').CenterIt();
		
	});*/


}

function vAfficheZoom()
{
		//var x = new Image(); 
		//x.src = $("#id_photo_principale").attr('src');

		if ($("#id_photo_principale").width > $("#id_photo_principale").height)
		{
			$("#id_image_zoom").attr('width', $(window).width() / 3);
		}
		else
		{
			$("#id_image_zoom").attr('height', $(window).height() / 1.5);
		}

		//$("#id_image_zoom").aeImageResize({height: $(window).height() / 1.5, width: $(window).width() / 1.5});

		//$("#id_image_zoom").height($(window).height() / 1.5);
		//$("#id_image_zoom").width($(window).width() / 1.5);

		$(".pancontainer").css("width", $("#id_image_zoom").width());
		$(".pancontainer").css("height", $("#id_image_zoom").height());



/*		if (t.height > t.width)
		{
			$("#id_image_zoom").height($(window).height() / 1.5);
		}
		else
		{
			$("#id_image_zoom").width($(window).width() / 1.5);
		}*/
		$('#zoom_sur_image').CenterIt();

		var $pancontainer=$('div.pancontainer')
		$pancontainer.each(function(){
			var $this=$(this).css({position:'relative', overflow:'hidden', cursor:'move'})
			var $img=$this.find('img:eq(0)') //image to pan
			var options={$pancontainer:$this, pos:$this.attr('data-orient'), curzoom:1, canzoom:$this.attr('data-canzoom'), wrappersize:[$this.width(), $this.height()]}
			$img.imgmover(options)
		})

}

function vAfficheBloc()
{

	$("a[id^='a_idem_item_']").click(function(event)
		{
			var id = parseInt(this.id.replace("a_idem_item_", ""));   

			//$("#a_idem_item_" + id).click(function(event)
			//{
				//$('tr[id^="tr_idem_item_'+id+'"]').toggle(500);

				if ( $("#bloc_idem_item_" + id).hasClass("table_alter_tr"))
				{
					$(this).removeClass('infoMoreItemsOpen').addClass('infoMoreItems');
					$("#bloc_idem_item_" + id).removeClass('table_alter_tr');
					$('tr[id^="tr_idem_item_'+id+'"]').hide(500);
				}
				else
				{
					$(this).removeClass('infoMoreItems').addClass('infoMoreItemsOpen');
					$('tr[id^="tr_idem_item_'+id+'"]').show(500);
					$("#bloc_idem_item_" + id).addClass('table_alter_tr');
				}
			//});
		}
	); 
}




// Evenement sur l'email d'inscription (vérif format + unique)
function search_price_item()
{
	$("#prix_actuellement_en_vente").click(function(event)
		{
			$("#recherche_en_cours").html('<img src="http://www.cdandlp.com/images/ajax-loader.gif" height="12" width="12"/>');
			
			$.ajax({
				type: "POST",
				url: "/vendre/common/search_price.cfm",
				data : {the_lng : $('#la_lng').val(), the_artist : $('#foo_artist').val(), the_title : $('#foo_title').val(), the_format : $('#idformat').val(), the_edition : $('#idedition').val()},
				dataTypeString : "json",
				success: function(data) {
					var response = eval(data);
					//$("#prix_min_trouve_en_vente").html(response["0"]);
					//$("#prix_moy_trouve_en_vente").html(response["1"]);
					//$("#prix_max_trouve_en_vente").html(response["2"]);
					//$("#prix_min_trouve_vendu").html(response["3"]);
					//$("#prix_moy_trouve_vendu").html(response["4"]);
					//$("#prix_max_trouve_vendu").html(response["5"]);
					//$("#listderech_article").html(response["6"]);
					
					var infos = "";

					if (response["0"] != "")
					{
						infos = response["0"];
					}
					if (response["4"] != "")
					{
						if (infos != "")
						{
							infos = infos + '<br>';
						}
						infos = infos + response["4"];
					}
					if (response["6"] != "")
					{
						if (infos != "")
						{
							infos = infos + '<br>';
						}
						infos = infos + response["6"];
					}

					$("#info_produit_similaire").html(infos);

					$("#recherche_en_cours").html('');
					$("#affichage_prix_constates").show(300);
				},
				error: function(data) {
					$("#prix_min_trouve_en_vente").html('');
					//$("#prix_moy_trouve_en_vente").html('');
					//$("#prix_max_trouve_en_vente").html('');
					//$("#prix_min_trouve_vendu").html('');
					$("#prix_moy_trouve_vendu").html('');
					//$("#prix_max_trouve_vendu").html('');
					$("#listderech_article").html('');
					$("#recherche_en_cours").html('');
				}
			});
		
		});
}


function ShowTreeCateg()
{

		$("#root ul").each(function() 
		{
			var id_ul = $(this).attr('id');
			
			var id_hidden = id_ul.replace("c_", "h_");

			if ($("#" + id_hidden).attr('value') == 1)
			{
				$(this).css("display", "block");
			}

		});

		$("#root .category").click(function() {
			var childid = "#" + $(this).attr("childid");
			if ($(childid).css("display") == "none") {$(childid).css("display", "block");}
			else {$(childid).css("display", "none");}
			if ($(this).hasClass("cat_close")) {$(this).removeClass("cat_close").addClass("cat_open");}
			else{$(this).removeClass("cat_open").addClass("cat_close");}
		});

		$("#root .category2").click(function() {
			var childid = "#" + $(this).attr("childid");
			if ($(childid).css("display") == "none") {$(childid).css("display", "block");}
			else {$(childid).css("display", "none");}
			if ($(this).hasClass("cat_close2")) {$(this).removeClass("cat_close2").addClass("cat_open2");}
			else{$(this).removeClass("cat_open2").addClass("cat_close2");}
		});

}


function ShowTreeConso()
{

		$("#root_conso ul").each(function() 
		{
			var id_ul = $(this).attr('id');
			
			var id_hidden = id_ul.replace("conso_", "hidden_");

			if ($("#" + id_hidden).attr('value') == 1)
			{
				$(this).css("display", "block");
			}

		});

		$("#root_conso .conso_tete").click(function() {
			var childid = "#" + $(this).attr("childid");
			
			if ($(childid).css("display") == "none") 
			{
				$(childid).css("display", "block");
			}
			else 
			{
				$(childid).css("display", "none");
			}
			
			if ($(this).hasClass("conso_close")) 
			{
				$(this).removeClass("conso_close").addClass("conso_open");
			}
			else
			{
				$(this).removeClass("conso_open").addClass("conso_close");
			}
		});

		$("#lien_onglet_titre").click(function() {
			$("#lien_fleche_titre").click();
		});
		$("#lien_onglet_format").click(function() {
			$("#lien_fleche_format").click();
		});
		$("#lien_onglet_label").click(function() {
			$("#lien_fleche_label").click();
		});
		$("#lien_onglet_press").click(function() {
			$("#lien_fleche_press").click();
		});
		$("#lien_onglet_vendeur").click(function() {
			$("#lien_fleche_vendeur").click();
		});

}

/*function LaunchFeaturedItems()
{

	if ($('#featureditems'))
	{
		$("#featureditems").scrollable({circular: true, mousewheel: true});
	}

	if ($('#featuredsellers'))
	{
		$("#featuredsellers").scrollable({circular: true, mousewheel: true});
	}
}*/


function EventListWhat()
{
	var thelng = $("#lalng").attr('value');

	$(".headerSearchSelectList li a").click(function() {
			
		if ($(this).attr('thewhat'))
		{

			if ($(this).attr('thewhat') != "at")
			{
				$("#selectwhat").removeClass("headerSearchSelectLabelSpecif"+thelng).addClass("headerSearchSelectLabel"+thelng);
				$("#foo").removeAttr('disabled');
				$("#inputartiste").css("display", "block");
				$("#stringa").attr("value", '');
				$("#stringt").attr("value", '');
				$("#stringa").attr("disabled", 'true');
				$("#stringt").attr("disabled", 'true');
				$("#stringa").removeClass('textColor9');
				$("#stringt").removeClass('textColor9');
				$("#inputartistetitre").css("display", "none");
			}
			if ($(this).attr('thewhat') == "at")
			{
				$("#selectwhat").removeClass("headerSearchSelectLabel"+thelng).addClass("headerSearchSelectLabelSpecif"+thelng);
				$("#stringa").attr("value", $("#stringa").attr("valinfo"));
				$("#stringt").attr("value", $("#stringt").attr("valinfo"));
				$("#stringa").addClass('textColor9');
				$("#stringt").addClass('textColor9');
				$("#stringa").removeAttr('disabled');
				$("#stringt").removeAttr('disabled');
				$("#inputartistetitre").css("display", "block");
				$("#foo").attr("value", '');
				$("#foo").attr('disabled', true);
				$("#inputartiste").css("display", "none");
			}
			
			$('#what').attr('value', $(this).attr('thewhat'));
			$('#selectwhat').html($(this).attr('thevalue'));
			$("#listwhat").css("display", "none");
		}

		if ($(this).attr('thefmt'))
		{
			$('#fmt').attr('value', $(this).attr('thefmt'));
			$('#selectfmt').html($(this).html());
			$("#listfmt").css("display", "none");
		}

	});

	$("#stringa").click(function() {
		if ($("#stringa").attr('value') == $("#stringa").attr('valinfo'))
		{
			$("#stringa").attr('value', '');
		}
		if ($("#stringt").attr('value') == $("#stringt").attr('valinfo'))
		{
			$("#stringt").attr('value', '');
		}
		$("#stringa").removeClass('textColor9');
		$("#stringt").removeClass('textColor9');
	})

	$("#stringt").click(function() {
		if ($("#stringa").attr('value') == $("#stringa").attr('valinfo'))
		{
			$("#stringa").attr('value', '');
		}
		if ($("#stringt").attr('value') == $("#stringt").attr('valinfo'))
		{
			$("#stringt").attr('value', '');
		}
		$("#stringa").removeClass('textColor9');
		$("#stringt").removeClass('textColor9');
	})

	$("#selectwhat").click(function() {
		if($("#listwhat").css("display") == "none")
		{
			$("#listwhat").css("display", "block");
		}
		else
		{
			$("#listwhat").css("display", "none");
		}
	});

	$("#selectwhat_fleche").click(function() {
		if($("#listwhat").css("display") == "none")
		{
			$("#listwhat").css("display", "block");
		}
		else
		{
			$("#listwhat").css("display", "none");
		}
	});
	
  	$("#divselectwhat").mouseleave(function() {
		
		$("#listwhat").css("display", "none");

	});

	$("#selectfmt").click(function() {
		if($("#listfmt").css("display") == "none")
		{
			$("#listfmt").css("display", "block");
		}
		else
		{
			$("#listfmt").css("display", "none");
		}
	});

	$("#selectfmt_fleche").click(function() {
		if($("#listfmt").css("display") == "none")
		{
			$("#listfmt").css("display", "block");
		}
		else
		{
			$("#listfmt").css("display", "none");
		}
	});

  	$("#divselectfmt").mouseleave(function() {
		
		$("#listfmt").css("display", "none");

	});

	$(".headerSearchBtn").click(function() {
		
		if ($("#stringa").attr('value') == $("#stringa").attr('valinfo'))
		{
			$("#stringa").attr('value', '');
		}
		if ($("#stringt").attr('value') == $("#stringt").attr('valinfo'))
		{
			$("#stringt").attr('value', '');
		}

	});

}


function search_video_youtube()
{
	$("#page_produit_video_youtube").click(function(event)
		{	
			if( $("#id_videoProdContainer").html() == '')
			{
				//$("#id_photo_principale").html('<img src="http://www.cdandlp.com/images/ajax-loader.gif" height="12" width="12"/>');

				//http://www.cdandlp.com/includes/youtube/api_youtube.php?recherche=james brown&recherche_titre=sex machine&tri=relevance&mg=1&divwidth=380&divheight=380&lng=1

				$.ajax({
					type: "GET",
					url: "http://www.cdandlp.com/includes/youtube/api_youtube.php",
					data : {recherche : $('#produit_artiste').attr('value'), recherche_titre : $('#produit_titre').attr('value'), tri : 'relevance', mg : '1', divwidth : '380', divheight : '330', lng : $('#lng_titre').attr('value')},
					dataTypeString : "html",
					success: function(data) {
						
						$("#id_photoProdContainer").css("display", 'none');
						$("#id_videoProdContainer").css("display", 'block');
						$("#id_videoProdContainer").html(data);
					},
					error: function(data) {
						$("#id_photoProdContainer").css("display", 'none');
						$("#id_videoProdContainer").css("display", 'block');
						$("#id_videoProdContainer").html(data);
					}
				});
			}
			else
			{
				$("#id_photoProdContainer").css("display", 'none');
				$("#id_videoProdContainer").css("display", 'block');
			}
		
		});
}


function apply_arrondi()
{
	if ($.browser.msie)
	{

		$(".arrondis4px").each(function() {
			PIE.attach(this);
		});
		$(".arrondis8px").each(function() {
			PIE.attach(this);
		});
		$(".arrondishautgauche4px").each(function() {
			PIE.attach(this);
		});
		$(".arrondishautdroite4px").each(function() {
			PIE.attach(this);
		});
		$(".arrondishautgauche8px").each(function() {
			PIE.attach(this);
		});
		$(".arrondishautdroite8px").each(function() {
			PIE.attach(this);
		});
		$(".genericBlueBtnValidForm").each(function() {
			PIE.attach(this);
		});
		$(".genericBlueBtn").each(function() {
			PIE.attach(this);
		});

		$(".headerSearchField").each(function() {
			PIE.attach(this);
		});
		$(".headerSearchBtn").each(function() {
			PIE.attach(this);
		});
		$(".createAnAccountLink").each(function() {
			PIE.attach(this);
		});
		$(".fleche").each(function() {
			PIE.attach(this);
		});
		$(".flechePagination").each(function() {
			PIE.attach(this);
		});
		$(".searchFilters2 h3").each(function() {
			PIE.attach(this);
		});
		$(".pageProdPriceLine1Puce").each(function() {
			PIE.attach(this);
		});
		$(".pageProdSellerPic h2 span").each(function() {
			PIE.attach(this);
		});

		$(".table_type_1").each(function() {
			PIE.attach(this);
		});
		$(".table_type_3").each(function() {
			PIE.attach(this);
		});
		$(".window_valid_caddie_titre").each(function() {
			PIE.attach(this);
		});
		$(".window_valid_caddie_desc_items").each(function() {
			PIE.attach(this);
		});
		$(".zoom_image").each(function() {
			PIE.attach(this);
		});
	}

	
/*$(".headerSearchSelect").each(function() {
		$(this).css("background", 'url("../../../images/sites/cdandlp/searchSelectbg.png") left bottom repeat-x');
	});*/
	

}

function showPromoSeller()
{
	if ($("#cptpromoencours"))
	{
		interval = setInterval(function(){ 
			
			$("li[id^='promo_seller_']").each(function() 
			{
				$(this).css("display", "none");
			});

			var id_affich = $("#cptpromoencours").attr('value');
			id_affich = parseInt(id_affich) + 1;
			var id_max_cpt = $("#nbpromoseller").attr('value');

			if (parseInt(id_affich) >= parseInt(id_max_cpt))
			{
				//alert('toto');
				$("#cptpromoencours").attr('value', 1);
				var id_affich = 1;
			}
			else
			{
				$("#cptpromoencours").attr('value', id_affich);
			}

			//alert($("#nbpromoseller").attr('value'));
			
			$("#promo_seller_" + id_affich).toggle();

		}, 5000);
	}
}



function EventListWhatAdv()
{
	$("#select_what_adv").change(function() {
			
		if ($(this).attr('value'))
		{

			if ($(this).attr('value') != "artistetitre")
			{
				$("#value_adv").removeClass('textColor9');
				$("#value_adv2").removeClass('textColor9');
				$("#value_adv").attr("value", '');
				$("#value_adv2").attr("value", '');
				$("#inputartistetitreadv").css("display", "none");
			}
			if ($(this).attr('value') == "artistetitre")
			{

				$("#value_adv").addClass('textColor9');
				$("#value_adv2").addClass('textColor9');
				$("#value_adv").attr("value", $("#value_adv").attr("valinfoadv"));
				$("#value_adv2").attr("value", $("#value_adv2").attr("valinfoadv"));
				$("#inputartistetitreadv").css("display", "block");
			}
			
		}
	});

	$("#value_adv").click(function() {
		if ($("#value_adv").attr('value') == $("#value_adv").attr('valinfoadv'))
		{
			$("#value_adv").attr('value', '');
		}
		if ($("#value_adv2").attr('value') == $("#value_adv2").attr('valinfoadv'))
		{
			$("#value_adv2").attr('value', '');
		}
		$("#value_adv").removeClass('textColor9');
		$("#value_adv2").removeClass('textColor9');
	})

	$("#value_adv2").click(function() {
		if ($("#value_adv").attr('value') == $("#value_adv").attr('valinfoadv'))
		{
			$("#value_adv").attr('value', '');
		}
		if ($("#value_adv2").attr('value') == $("#value_adv2").attr('valinfoadv'))
		{
			$("#value_adv2").attr('value', '');
		}
		$("#value_adv").removeClass('textColor9');
		$("#value_adv2").removeClass('textColor9');
	})

	$("#submitbuttonwhatadv").click(function() {
		
		if ($("#value_adv").attr('value') == $("#value_adv").attr('valinfoadv'))
		{
			$("#value_adv").attr('value', '');
		}
		if ($("#value_adv2").attr('value') == $("#value_adv2").attr('valinfoadv'))
		{
			$("#value_adv2").attr('value', '');
		}

	});

}

function EventSlideFeaturedItemsSoco()
{

	if ($("#id_button_next_featured_items_soco"))
	{
		interval_soco = setInterval(function(){ 
			$("#id_button_next_featured_items_soco").click();
		}, 5000);
	}

}


function vDeleteJS()
{
	$('input').change(function(){
		$lavaleur = $(this).val();
		$(this).val(removeScript($lavaleur));		
	});
	$('textarea').change(function(){
		$lavaleur = $(this).val();
		$(this).val(removeScript($lavaleur));		
	});
	
	//$('p').ready(function(){
	//	$lavaleur = $(this).html();
		//alert($lavaleur);
	//	$(this).html(removeScript($lavaleur));		
	//});
}

function removeScript(string) {
	return string.replace(new RegExp('\\s*<script[^>]*>[\\s\\S]*?</script>\\s*','ig'),'');
}

function vAnimatePromoNoel()
{

	if ($(".slidepromonoelcdandlp"))
	{
	

		//Set Default State of each portfolio piece
		$(".paging").show();
		$(".paging a:first").addClass("active");
			
		//Get size of images, how many there are, then determin the size of the image reel.
		var imageWidth = $(".window").width();
		var imageSum = $(".image_reel img").size();
		var imageReelWidth = imageWidth * imageSum;
		
		//Adjust the image reel to its new size
		$(".image_reel").css({'width' : imageReelWidth});
		
		//Paging + Slider Function
		rotate = function(){	
			var triggerID = $active.attr("rel") - 1; //Get number of times to slide
			var image_reelPosition = triggerID * imageWidth; //Determines the distance the image reel needs to slide
	
			$(".paging a").removeClass('active'); //Remove all active class
			$active.addClass('active'); //Add active class (the $active is declared in the rotateSwitch function)
			
			//Slider Animation
			$(".image_reel").animate({ 
				left: -image_reelPosition
			}, 500 );
			
		}; 
		
		//Rotation + Timing Event
		rotateSwitch = function(){		
			play = setInterval(function(){ //Set timer - this will repeat itself every 3 seconds
				$active = $('.paging a.active').next();
				if ( $active.length === 0) { //If paging reaches the end...
					$active = $('.paging a:first'); //go back to first
				}
				rotate(); //Trigger the paging and slider function
			}, 5000); //Timer speed in milliseconds (3 seconds)
		};
		
		rotateSwitch(); //Run function on launch
		
		//On Hover
		$(".image_reel a").hover(function() {
			clearInterval(play); //Stop the rotation
		}, function() {
			rotateSwitch(); //Resume rotation
		});	
		
		//On Click
		$(".paging a").click(function() {	
			$active = $(this); //Activate the clicked paging
			//Reset Timer
			clearInterval(play); //Stop the rotation
			rotate(); //Trigger rotation immediately
			rotateSwitch(); // Resume rotation
			return false; //Prevent browser jump to link anchor
		});	
	}
}

function vAnimateMyListPicture()
{

	$(".idPictureMyList").mouseover(function() {
		
		$(this).find('a.MyListLinkPicture').removeClass('MyListLinkPicture').addClass('MyListLinkPictureMouseOver');
		$(this).find('div').show();
		
	});

	$(".idPictureMyList").mouseleave(function() {
	
		$(this).find('div').hide();
		$(this).find('a.MyListLinkPictureMouseOver').removeClass('MyListLinkPictureMouseOver').addClass('MyListLinkPicture');
	});

}


function search_video_youtube_for_mylist()
{

	if ($('#containervideoyoutube').length != 0)
	{
		$('#containervideoyoutube').css("height", jQuery(document).height());
		$('#containervideoyoutube').css("width", jQuery(document).width());
	}

	if ($('#containershowvideoyoutube').length != 0)
	{
		$('#containershowvideoyoutube').CenterIt();
		$('#containershowvideoyoutube').css("display", 'none');
	}

	$("#imgclosevideoyoutube").mouseover(function()
	{
		$(this).css('cursor','pointer');
	});

	$("#imgclosevideoyoutube").mouseleave(function()
	{
		$(this).css('cursor','auto');
	});

	$("#imgclosevideoyoutube").click(function()
	{
		$("#containervideoyoutube").css("display", 'none');
		$("#containershowvideoyoutube").css("display", 'none');
	});


	$(".MyListVideoYoutube").click(function()
	{	
	
		$.ajax({
			type: "GET",
			url: $("#url_hidden").val() + "/includes/youtube/api_youtube.php",
			data : {recherche : $(this).attr('mylist_artiste'), recherche_titre : $(this).attr('mylist_titre'), tri : 'relevance', mg : '1', divwidth : '640', divheight : '480', lng : $('#mylist_lng').attr('value')},
			dataTypeString : "html",
			success: function(data) {
				$("#containervideoyoutube").css("display", 'none');
				$("#containervideoyoutube").css("display", 'block');
				$("#containershowvideoyoutube").css("display", 'none');
				$("#containershowvideoyoutube").css("display", 'block');
				$("#showvideoyoutube").html(data);
			},
			error: function(data) {
				$("#containervideoyoutube").css("display", 'none');
				$("#containervideoyoutube").css("display", 'block');
				$("#containershowvideoyoutube").css("display", 'none');
				$("#containershowvideoyoutube").css("display", 'block');
				$("#showvideoyoutube").html(data);
			}
		});
	});
}



function validInfoRomanjiEvent()
{

	$("#thenom").change(function(event)
	{
		validInfoRomanji($(this));
	});

	$("#theprenom").change(function(event)
	{
		validInfoRomanji($(this));
	});

	$("#theadresse").change(function(event)
	{
		validInfoRomanji($(this));
	});

	$("#theville").change(function(event)
	{
		validInfoRomanji($(this));
	});

	$("#theregion").change(function(event)
	{
		validInfoRomanji($(this));
	});
	
	$("#shipnomach").change(function(event)
	{
		validInfoRomanji($(this));
	});

	$("#billnomach").change(function(event)
	{
		validInfoRomanji($(this));
	});

	$("#shippreach").change(function(event)
	{
		validInfoRomanji($(this));
	});

	$("#billpreach").change(function(event)
	{
		validInfoRomanji($(this));
	});

	$("#shipadrach").change(function(event)
	{
		validInfoRomanji($(this));
	});

	$("#billadrach").change(function(event)
	{
		validInfoRomanji($(this));
	});

	$("#shipcitach").change(function(event)
	{
		validInfoRomanji($(this));
	});

	$("#billcitach").change(function(event)
	{
		validInfoRomanji($(this));
	});

	$("#shipzipach").change(function(event)
	{
		validInfoRomanji($(this));
	});

	$("#billzipach").change(function(event)
	{
		validInfoRomanji($(this));
	});

	$("#shipstaach").change(function(event)
	{
		validInfoRomanji($(this));
	});

	$("#billstaach").change(function(event)
	{
		validInfoRomanji($(this));
	});
}


function validInfoRomanji(_theobj)
{

	var rege = /^(.)*([\u3040-\u309F])+(.)*$/;
	if(rege.test(_theobj.val()))
	{ 
		//alert('Hiragana');
		var rege = /[\u3040-\u309F]/g;
		_theobj.val(_theobj.val().replace(rege, ''));
		if ($('#obj_message'))
		{
			$('#obj_message').html("お客様は詳細を日本語で入力されました。当社はこの詳細を自動翻訳します。もし、自動翻訳が正しくない場合は翻訳をご訂正して頂きますようお願いします。");
			$('#obj_message').addClass("infobox");	
		}
	}
	
	var rege = /^(.)*([\u30A0-\u30FF])+(.)*$/;
	if(rege.test(_theobj.val()))
	{ 
		//alert('katakana');
		var rege = /[\u30A0-\u30FF]/g;
		_theobj.val(_theobj.val().replace(rege, ''));
		$('#obj_message').html("お客様は詳細を日本語で入力されました。当社はこの詳細を自動翻訳します。もし、自動翻訳が正しくない場合は翻訳をご訂正して頂きますようお願いします。");
		$('#obj_message').addClass("infobox");	
		if ($('#obj_message'))
		{
			$('#obj_message').html("お客様は詳細を日本語で入力されました。当社はこの詳細を自動翻訳します。もし、自動翻訳が正しくない場合は翻訳をご訂正して頂きますようお願いします。");
			$('#obj_message').addClass("infobox");	
		}
	}
	
	var rege = /^(.)*([\u4E00-\u9FBF])+(.)*$/;
	if(rege.test(_theobj.val()))
	{ 
		//alert('Kanji');
		var rege = /[\u4E00-\u9FBF]/g;
		_theobj.val(_theobj.val().replace(rege, ''));
		$('#obj_message').html("お客様は詳細を日本語で入力されました。当社はこの詳細を自動翻訳します。もし、自動翻訳が正しくない場合は翻訳をご訂正して頂きますようお願いします。");
		$('#obj_message').addClass("infobox");	
		if ($('#obj_message'))
		{
			$('#obj_message').html("お客様は詳細を日本語で入力されました。当社はこの詳細を自動翻訳します。もし、自動翻訳が正しくない場合は翻訳をご訂正して頂きますようお願いします。");
			$('#obj_message').addClass("infobox");	
		}
	}
	

}

