// --------------------------------------------------------
//  form ajout d'un wish
// --------------------------------------------------------
function afficheProduit(_idProduit) {
	$.get(
	"./ajax.php" , 
	{afficheProduit : 1, idProduit:_idProduit} , 
	function(data){ 
		$("#formProduit").html(data).fadeIn(); 
	}
	);        
}

// --------------------------------------------------------
//  form ajout d'un wish
// --------------------------------------------------------
function showMyList(_idListe) {
	$("#waitList").html('<img src="/images/attente_mini.gif" style="float:right; position:absolute">');
	$.get(
	"./ajax.php" , 
	{showMyList : 1, idListe : _idListe} , 
	function(data){ 
		$("#listeMesProduits").html(data).fadeIn(); 
		$("#waitList").html('');
	}
	);        
}

function addToMyList(_idProduit, _idListe) {
	$.get(
	"./ajax.php" , 
	{addToMyList : 1, idProduit : _idProduit, idListe : _idListe} , 
	function(data){ 
		showMyList(_idListe); 
	}
	);   	
}

function deleteProduit(_idProduit, _idListe) {
	if (confirm('ėtes-vous sūr de vouloir supprimer ce cadeau?')) {
		$.get(
		"./ajax.php" , 
		{deleteProduit : 1, idProduit : _idProduit, idListe:_idListe} , 
		function(data){ 
			$("#mes_prod_"+_idProduit).fadeOut('fast'); 
		}
		);       
	}
}

// --------------------------------------------------------
//  form ajout d'un wish
// --------------------------------------------------------
function addProduit(_idListe) {
	$.get(
	"./ajax.php" , 
	{addProduit : 1, idListe:_idListe} , 
	function(data){ 
		$("#formProduit").html(data).fadeIn(); 
	}
	);        
}


// --------------------------------------------------------
//  form edit d'un wish
// --------------------------------------------------------
function editProduit(_id) {
	$.get(
	"./ajax.php" , 
	{editProduit : 1, id : _id} , 
	function(data){ 
		$("#formProduit").html(data).slideDown(); 
	}
	);    	
	
}

// --------------------------------------------------------
//  buy a wish
// --------------------------------------------------------
function buyProduit(_id) {
	$.get(
	"./ajax.php" , 
	{buyProduit : 1, id : _id} , 
	function(data){ 
		$("#buy").html(data).slideDown(); 
	}
	);        
	
}

// --------------------------------------------------------
//  Email a list
// --------------------------------------------------------
function emailListe(_idListe) {

	_texte = $("#texte").val();
		
	_nom1 = $("#nom1").val();
	_nom2 = $("#nom2").val();  
	_nom3 = $("#nom3").val();  
	_nom4 = $("#nom4").val();  
	
	_prenom1 = $("#prenom1").val();
	_prenom2 = $("#prenom2").val();  
	_prenom3 = $("#prenom3").val();  
	_prenom4 = $("#prenom4").val();    	
	
	_email1 = $("#email1").val();
	_email2 = $("#email2").val();  
	_email3 = $("#email3").val();  
	_email4 = $("#email4").val();  
	
	var t = new Date();
	if (_nom1 != '' && _prenom1 != '' && _email1 != '' && _texte != '' && _idListe != '') {
		$("#confimInvitation").slideDown('fast').html("Envoi en cours ...");
		$.post(
			"./ajax.php" , 
			{emailList: 1, texte:_texte, idListe: _idListe, t: t.getTime(),nom1: _nom1, nom2: _nom2, nom3: _nom3, nom4: _nom4, prenom1: _prenom1, prenom2: _prenom2, prenom3: _prenom3, prenom4: _prenom4, email1: _email1, email2: _email2, email3: _email3, email4: _email4 } , 
			function(data){ $("#confimInvitation").html(data).fadeIn('fast'); }
		);   
	} 
	else {
		if (_nom1 == '') $('#nom1').css({'border' : '#CC0000 solid 1px'});
		else $('#nom1').css({'border' : '#CCCCCC solid 1px'});
		
		if (_prenom1 == '') $('#prenom1').css({'border' : '#CC0000 solid 1px'});
		else $('#prenom1').css({'border' : '#CCCCCC solid 1px'});
		
		if (_email1 == '') $('#email1').css({'border' : '#CC0000 solid 1px'});
		else $('#email1').css({'border' : '#CCCCCC solid 1px'});       
		
		if (_texte == '') $('#texte').css({'border' : '#CC0000 solid 1px'});
		else $('#texte').css({'border' : '#CCCCCC solid 1px'});           
	
	}
	
}


// --------------------------------------------------------
//  form ajout d'un wish
// --------------------------------------------------------
function sendProduit() {
	var _idProduit = $('#idProduit').val();
	var _titre = $('#wish_titre').val();
	//var _link1 = $('#wish_link1').val();
	//var _link2 = $('#wish_link2').val();
	var _foto = $('#wish_foto').val();

	if ((_titre != '' && _foto != '' && _idProduit == '') || (_titre != '' && _foto == '' && _idProduit > 0) || (_titre != '' && _foto != '' && _idProduit != '')) {                
		$('#wishform').submit(); 
	}
	else {
		if (_titre == '') $('#wish_titre').css({'border' : '#CC0000 solid 1px'});
		else $('#wish_titre').css({'border' : '#CCCCCC solid 1px'});
		
		if (_idProduit == ''){ 
			if (_foto == '') $('#error_foto').css({'background-color' : '#CC0000'});
			else $('#error_foto').css({'background-color' : '#F5F5F5'}); 
		}
	}
				   
}

// --------------------------------------------------------
//  form ajout d'un wish
// --------------------------------------------------------
function sendListe() {
	var _idListe = $('#idListe').val();
	var _titre = $('#titre_liste').val();
	var _texte = $('#texte_liste').val(); 
	var _prenom_bebe = $('#prenom_bebe').val(); 
	var _photo_bebe = $('#photo_bebe').val();

	if ((_titre != '' && _photo_bebe != '' && _idListe == '') || (_titre != '' && _photo_bebe == '' && _idListe > 0) || (_titre != '' && _photo_bebe != '' && _idListe != '')) {                
		$('#listForm').submit(); 
	}
	else {
		if (_titre == '') $('#titre_liste').css({'border' : '#CC0000 solid 1px'});
		else $('#titre_liste').css({'border' : '#CCCCCC solid 1px'});
		
		if (_texte == '') $('#texte_liste').css({'border' : '#CC0000 solid 1px'});
		else $('#texte_liste').css({'border' : '#CCCCCC solid 1px'});        
		
		if (_prenom_bebe == '') $('#prenom_bebe').css({'border' : '#CC0000 solid 1px'});
		else $('#prenom_bebe').css({'border' : '#CCCCCC solid 1px'});  		
		
		if (_idListe == ''){ 
			if (_photo_bebe == '') $('#error_photo').css({'background-color' : '#CC0000'});
			else $('#error_photo').css({'background-color' : '#F5F5F5'}); 
		}
	}
}

// --------------------------------------------------------
//  Changer de liste
// --------------------------------------------------------
function changeLink() {
	i = document.formMalist.maListe.selectedIndex;
	if (i == 0) return;
	url = document.formMalist.maListe.options[i].value;
	parent.location.href = url;
}

// --------------------------------------------------------
//  Offirir un produit
// --------------------------------------------------------
function offrir(_id) {

	var _nom = $('#nom').val();
	var _prenom = $('#prenom').val();
	var _email = $('#email').val();

	if ((_nom != '' && _prenom != '' && _email != '')) {                
		$.post(
		"./ajax.php" , 
		{offrir : 1, id : _id, nom: _nom, prenom: _prenom, email: _email} , 
		function(data){ 
			$("#formProduit").html(data).fadeIn(); 
		}
		); 
	}
	else {
		if (_nom == '') $('#nom').css({'border' : '#CC0000 solid 1px'});
		else $('#nom').css({'border' : '#CCCCCC solid 1px'});
		
		if (_prenom == '') $('#prenom').css({'border' : '#CC0000 solid 1px'});
		else $('#prenom').css({'border' : '#CCCCCC solid 1px'}); 
		
		if (_email == '') $('#email').css({'border' : '#CC0000 solid 1px'});
		else $('#email').css({'border' : '#CCCCCC solid 1px'});         
	}       
	
}

// --------------------------------------------------------
//  Offirir un produit
// --------------------------------------------------------
function formBuyProduit(_id) {
	$.get(
	"./ajax.php" , 
	{formBuyProduit : 1, id : _id} , 
	function(data){ 
		$("#formProduit").html(data).fadeIn(); 
	}
	);        
	
}

// --------------------------------------------------------
//  Vie privee
// --------------------------------------------------------
function viePrivee(_idListe) {

	var _prive_all = $('#prive_all').val();
	var _prive_invites = $('#prive_invites').val();

	$.post(
	"./ajax.php" , 
	{viePrivee : 1, idListe : _idListe, prive_all: _prive_all, prive_invites: _prive_invites} , 
	function(data){ 
		$("#confirmPrive").html(data).fadeIn();
		$("#formPrive").css('background','#d3ffce', 'border', '#4bb341 solid 1px'); 
	}
	);        
	
}

// --------------------------------------------------------
//  Supprimer une liste
// --------------------------------------------------------
function deleteList(_idListe) {
	if (confirm('ėtes-vous sūre de vouloir supprimer cette liste?')) {
		$.post(
		"./ajax.php" , 
		{deleteList : 1, idListe : _idListe} , 
		function(data){ 
			$("#confirmDelete").html(data).fadeIn();
		}
		);   
	}     
	
}

function changeCheckbox(_data) {
	if ($("#"+_data).val() == '1') $("#"+_data).val(0);
	else $("#"+_data).val(1);	
}

function signaler(_idProduit) {
	if (confirm('ėtes-vous sūre de vouloir signaler ce produit?')) {
		$.get(
		"./ajax.php" , 
		{signaler : 1, idProduit : _idProduit} , 
		function(data){ 
			$("#signaler_"+_idProduit).html('<span style="color:#CC0000">Signalé</span>');
		}
		);   
	} 
}
