// 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 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;
}
