// Ferme les pads ERROR
function closePadError(pad_id) {
	document.getElementById('conteneur-'+pad_id).style.display = "none";
	document.getElementById(pad_id).style.display = "none";
}

//Change Zoom image product-info
function changeZoom(urlImg, img, currentPadId)
{
	var pad_img = document.getElementById('pad-img');
	
	document.getElementById(pad_img.getAttribute("rel")).style.display = "block";
	
	pad_img.setAttribute("rel", "thumb_id"+currentPadId);
	
	pad_img.innerHTML='<a href="'+urlImg+'" rel="lightbox" class="mask">&nbsp;</a><a href="'+urlImg+'" rel="lightbox"><img src="'+img+'" /></a>';
	window.addEvent('domready', Lightbox.init.bind(Lightbox));
	
	var currentPad = document.getElementById('thumb_id'+currentPadId);
	currentPad.style.display = "none";
}

//Onglets
function showOnglet(id_show,id_hide)
{
	//onglets
	document.getElementById(id_show).style.display = "block";
	document.getElementById(id_hide).style.display = "none";
	
	//liens
	document.getElementById('lk_'+id_show).className = "active";
	document.getElementById('lk_'+id_hide).className = "";
}
// Prod detail
function initReadmore()
{
	var mySlide = new Fx.Slide('desc_detail', {duration: 300});
	mySlide.hide();
	
	var btn1 = document.getElementById('btn-readmore-1');
	btn1.onclick = function(){
		mySlide.toggle();
	};
}
function initReadmore2()
{
	var mySlide2 = new Fx.Slide('ingr_detail', {duration: 300});
	mySlide2.hide();
	
	var btn2 = document.getElementById('btn-readmore-2');
	btn2.onclick = function(){
		mySlide2.toggle();
	};
}

function change_qty(variation)
{
	field_value = document.cart_quantity.quantity.value;
	new_value = eval(field_value + variation);
	if(new_value<=0)
		document.cart_quantity.quantity.value = 1;
	else	
		document.cart_quantity.quantity.value = new_value;
}

function check_text_perso()
{
	text_perso = document.cart_quantity.text_perso.value;
	
	if(text_perso == '')
	{
		alert('Veuillez saisir un texte personnalisé pour votre produit');
		return false;
	}
	else
	{
		return true;
	}
}
function check_text_perso2()
{
	text_perso = document.cart_quantity.text_perso.value;
	
	if(text_perso == '')
	{
		alert('Veuillez saisir un texte personnalisé pour votre produit');
	}
	else
	{
		document.cart_quantity.submit();
	}
}


function check_img_perso()
{
	products_screenshot = document.cart_quantity.products_screenshot.value;
	products_text1 = document.cart_quantity.products_text1.value;
	products_img1 = document.cart_quantity.products_img1.value;
		
	if(products_screenshot == '')
	{
		alert('Veuillez personnaliser votre produit');
		return false;
	}
	else
	{
		if( (products_text1 == '') && (products_img1 == '') )
		{
			alert('Veuillez saisir un texte personnalisé ou une image pour votre produit');
			return false;
		}
		else
		{
			if(document.cart_quantity.quantity.value<50)
			{
				alert("Minimum de commande pour personnalisation du message : 50 pièces");
			}
			else
			{
				return true;
			}
		}
	}
}
function check_img_perso2()
{
	products_screenshot = document.cart_quantity.products_screenshot.value;
	products_text1 = document.cart_quantity.products_text1.value;
	products_img1 = document.cart_quantity.products_img1.value;
		
	if(products_screenshot == '')
	{
		alert('Veuillez personnaliser votre produit');
	}
	else
	{
		if( (products_text1 == '') && (products_img1 == '') )
		{
			alert('Veuillez saisir un texte personnalisé ou une image pour votre produit');
		}
		else
		{
			if(document.cart_quantity.quantity.value<50)
			{
				alert("Minimum de commande pour personnalisation du message : 50 pièces");
			}
			else
			{
				document.cart_quantity.submit();
			}
		}
	}
}

function check_img2_perso()
{
	products_screenshot = document.cart_quantity.products_screenshot.value;
	products_text1 = document.cart_quantity.products_text1.value;
	products_img1 = document.cart_quantity.products_img1.value;
	products_text2 = document.cart_quantity.products_text2.value;
	products_img2 = document.cart_quantity.products_img2.value;
		
	if(products_screenshot == '')
	{
		alert('Veuillez personnaliser votre produit');
		return false;
	}
	else
	{
		if( ((products_text1 == '') && (products_img1 == '')) || ((products_text2 == '') && (products_img2 == '')) )
		{
			alert('Veuillez renseigner les 2 champs personnalisés');
			return false;
		}
		else
		{
			if(document.cart_quantity.quantity.value<50)
			{
				alert("Minimum de commande pour personnalisation du message : 50 pièces");
				return false;
			}
			else
			{
				return true;
			}
		}
	}
}
function check_img2_perso2()
{
	products_screenshot = document.cart_quantity.products_screenshot.value;
	products_text1 = document.cart_quantity.products_text1.value;
	products_img1 = document.cart_quantity.products_img1.value;
	products_text2 = document.cart_quantity.products_text2.value;
	products_img2 = document.cart_quantity.products_img2.value;
	
	if(products_screenshot == '')
	{
		alert('Veuillez personnaliser votre produit');
	}
	else
	{
		if( ((products_text1 == '') && (products_img1 == '')) || ((products_text2 == '') && (products_img2 == '')) )
		{
			alert('Veuillez renseigner les 2 champs personnalisés');
		}
		else
		{
			if(document.cart_quantity.quantity.value<50)
			{
				alert("Minimum de commande pour personnalisation du message : 50 pièces");
			}
			else
			{
				document.cart_quantity.submit();
			}
		}
	}
}


function dispatch_check_img_perso()
{
	if(	document.cart_quantity.products_type_perso.value=="1")
	{
		return check_img_perso();
	}
	else
	{
		return check_img2_perso();
	}
}

function dispatch_check_img_perso2()
{
	if(	document.cart_quantity.products_type_perso.value=="1")
	{
		check_img_perso2();
	}
	else
	{
		check_img2_perso2();
	}
}

function fill_field(txt,obj)
{
	if(obj.value=="" || obj.value==txt)
	{
		obj.value=txt;
	}
}
function empty_field(txt,obj)
{
	if(obj.value=="" || obj.value==txt)
	{
		obj.value="";
	}
}

function check_newsletter(txt1,txt2)
{
	document.getElementById("error_name").style.display="none";
	document.getElementById("error_mail").style.display="none";
	document.getElementById("error_mail_invalid").style.display="none";
	verif = /^[a-zA-Z0-9_-|.]+@[a-zA-Z0-9-]{2,}[.][a-zA-Z]{2,3}$/ 
	name=document.getElementById("form_newsletter").nom;
	mail=document.getElementById("form_newsletter").mail;
	if((name.value!=txt1 && name.value!="") && (mail.value!=txt2 && mail.value!=""))
	{
		if(verif.exec(mail.value) != null)
		{
			document.getElementById("form_newsletter").submit();
			return true;
		}
		else
		{
			document.getElementById("error_mail_invalid").style.display="block";
			return false;
		}
	}
	else
	{
		if(name.value==txt1 || name.value=="")
			document.getElementById("error_name").style.display="block";
		if(mail.value==txt2 || mail.value=="")
			document.getElementById("error_mail").style.display="block";
		return false;
	}
}

/*=== Roll prod listing ===*/
function rollOverProd(title_id, nomClass)
{
	document.getElementById(title_id).className = nomClass+" "+nomClass+"-active";
}
function rollOutProd(title_id, nomClass)
{
	document.getElementById(title_id).className = nomClass;
}

function REGLEMENT () {
	window.open ('reglement_jeu.php','reglement','width=500,height=500,scrollbars=yes');
}

// Ajax produits personnalisables
function ajax_prod_customize(pid, session_id) {
	
	var postUrl = 'ajax_prod_customize.php?osCsid='+session_id;
	var data = 'pid='+pid;
	var zone_a_charger = $('div_ajax_prod_customize');
	
	// Ajax Loader
	zone_a_charger.innerHTML = '<div class="ajax-loader"><img src="images/ajax-loader.gif" alt=""/></div>';
	
	var onSuccess = function (t)
	{		
		var el = zone_a_charger;
		el.innerHTML = t;
	}
	
	var myAjax = new Ajax(postUrl, {method:'post', data: data, onSuccess: onSuccess});
	myAjax.request();
}

function change_texte_perso(valeur)
{
	document.cart_quantity.text_perso.value = valeur;
}

function change_carte_perso(text1, img1, text2, img2, screenshot, type)
{
	if(!type)
		type = '2';
	document.cart_quantity.products_text1.value = text1;
	document.cart_quantity.products_img1.value = img1;
	document.cart_quantity.products_text2.value = text2;
	document.cart_quantity.products_img2.value = img2;
	document.cart_quantity.products_screenshot.value = screenshot;
	document.cart_quantity.products_type_perso.value = type;
	document.cart_quantity.prod_img_perso.src = "img_dyn/carte_perso/_tmp/"+screenshot;
	document.cart_quantity.prod_img_perso.width = "225";
	document.cart_quantity.prod_img_perso.height = "225";
	document.getElementById('pad-img').style.width="220px";
	document.getElementById('pad-img').style.height="222px";
	carte_perso_close();
}

function carte_perso_open()
{
	document.getElementById('overlay_flash_custom').style.display="block";
	scrollToTop();
}

function carte_perso_close()
{
	document.getElementById('overlay_flash_custom').style.display="none";
}

//Scroll la fenetre to TOP
function scrollToTop()
{
	var scrolling = new Fx.Scroll(window).toTop();
}

function showCopyright()
{
	pad  = (document.layers) ? document.layers['copyright_over'] : document.getElementById('copyright_over');
	pad.style.display = "block";
}
function hideCopyright()
{
	pad  = (document.layers) ? document.layers['copyright_over'] : document.getElementById('copyright_over');
	pad.style.display = "none";
}
