// -------------------------------------------------------
// Fonction getXHR
// -------------------------------------------------------
function getXHR()
	{
    var xhr = null;
    if(window.XMLHttpRequest) // Firefox et autres
    xhr = new XMLHttpRequest();
    else if(window.ActiveXObject)
		{ // Internet Explorer
		try { xhr = new ActiveXObject("Msxml2.XMLHTTP"); }
		catch (e) { xhr = new ActiveXObject("Microsoft.XMLHTTP"); }
		}
     else
	 	{ // XMLHttpRequest non support� par le navigateur
        alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
        xhr = false;
        }
    return xhr;
	}


// ------------------------------------------------------
// Retaille des images
// ------------------------------------------------------
function redimImage(oImg, inMW, inMH)
{
  // Cette function recoit 3 parametres
  // inImg : Chemin relatif de l'image
  // inMW  : Largeur maximale
  // inMH   : Hauteur maximale
var maxWidth = inMW;
var maxHeight = inMH;


var nomnav = navigator.appName;
if (nomnav == "Microsoft Internet Explorer")
	{
	oImg.style.display = "inline" ; // on est oblig�s d'afficher l'image originale dans IE pour r�cup�rer les tailles
	}

// On recupere les tailles reelles
var oH = oImg.height;
var oW = oImg.width;

if (oW > maxWidth && maxWidth != "")
		{
//		h = parseInt((maxWidth / w) * h, 10); 
		oH = (maxWidth / oW) * oH ; 
		oW = maxWidth ;
		}
if (oH > maxHeight && maxHeight != "")
		{
//		w = parseInt((maxHeight / h) * w, 10) ;
		oW = (maxHeight / oH) * oW ;
		oH = maxHeight ;
		}
	

// mise en place des nouvelles dimensions de l'image
	oImg.style.display = "inline" ;
	oImg.width = oW;
	oImg.height = oH;
	
	if (inMH == 60 && inMW == 60)
		{
		oMarginTop = oMarginBottom = (65-oH) / 2;
		oImg.style.marginTop = oMarginTop + "px";
		oImg.style.marginBottom = oMarginBottom + "px";	
		}
}


// ------------------------------------------------------
// Cr�ation de la fonction getElementsByClass
// ------------------------------------------------------
function getElementsByClass(classe)
{
	var divs = document.getElementsByTagName('div');
	var resultats = new Array();
	for(var i=0; i<divs.length; i++)
		{
		if(divs[i].className == classe)
			{
			resultats.push(divs[i]);
			}
		}
	return resultats;
}


// ------------------------------------------------------
// R�cup�ration des �l�ments de formulaire pour les Regex
// ------------------------------------------------------

function initialisation_inscription ()
{
obirthday = document.getElementById("birthday");
oMotifbirthday = document.getElementById("regex_birthday");
oImgbirthday = document.getElementById("img_birthday");

omail = document.getElementById("mail");
oMotifmail = document.getElementById("regex_mail");
oImgmail = document.getElementById("img_mail");

opassword = document.getElementById("password");
oMotifpassword = document.getElementById("regex_password");
oImgpassword = document.getElementById("img_password");

opassword_r = document.getElementById("password_r");
oMotifpassword_r = document.getElementById("regex_password_r");
oImgpassword_r = document.getElementById("img_password_r");

ofirstname = document.getElementById("firstname");
oMotiffirstname = document.getElementById("regex_firstname");
oImgfirstname = document.getElementById("img_firstname");

osurname = document.getElementById("firstname");
oMotifsurname = document.getElementById("regex_surname");
oImgsurname = document.getElementById("img_surname");

ocountry = document.getElementById("country");
oMotifcountry = document.getElementById("regex_country");
oImgcountry = document.getElementById("img_country");
}

// -------------------------------------------------------
// Contr�le des champs de formulaire par rapport aux Regex
// -------------------------------------------------------

function control(champ)
{
oMotif = eval("oMotif" + champ);
o = eval("o" + champ);
oImg = eval("oImg" + champ);

if (oMotif.value == "")
	{
		if (o.value != "")
		{
			if (champ == "password_r")
				{
				if (opassword.value == opassword_r.value)
					{
					oImg.src = "../images/icons/tick.png" ;
					oImg.style.display = "inline";
					}
				else
					{
					oImg.src = "../images/icons/cross.png" ;
					oImg.style.display = "inline";
					}
				}
			else 
				{
				oImg.src = "../images/icons/tick.png" ;
				oImg.style.display = "inline";
				}
		}
		else 
			{
			oImg.src = "../images/icons/cross.png" ;
			oImg.style.display = "inline";
			}
	}

else
	{
	var er = new RegExp(oMotif.value) ;
	if (er.test(o.value)) 
		{
			oImg.src = "../images/icons/tick.png" ;
			oImg.style.display = "inline";
		}
		else 
			{
			oImg.src = "../images/icons/cross.png" ;
			oImg.style.display = "inline";
			}
	}

}

// -------------------------------------------------------
function changeCaptcha(id) 
// -------------------------------------------------------
{
var xhr = getXHR() ;
xhr.open('GET', "ajax_change_captcha.php?captcha_id="+id, true);
xhr.onreadystatechange = function() { recupChangeCaptcha(xhr, id); };
xhr.send(null);	
}

// -------------------------------------------------------
function recupChangeCaptcha(xhr, id) 
// -------------------------------------------------------
{
if(xhr.readyState == 4 && xhr.status == 200) 
	{
	document.getElementById("captcha_id").innerHTML = xhr.responseText;
	document.images["captcha_img"].src = "captcha/captcha_" + id + ".png" ;
	document.getElementById("loader_captcha").style.display = "none";
	}
else if (xhr.readyState < 4) 
	{
	document.getElementById("loader_captcha").style.display = "inline";
	}

}


// -------------------------------------------------------
function initialisation_sizes() 
// -------------------------------------------------------
{
	oMeasure1 = document.getElementById("measure_1") ; 
	oMeasure2 = document.getElementById("measure_2") ;
	oMeasure3 = document.getElementById("measure_3") ; 
	oMeasure4 = document.getElementById("measure_4") ; 
	oMeasure5 = document.getElementById("measure_5") ; 
	oMeasure6 = document.getElementById("measure_6") ; 
	oMeasure7 = document.getElementById("measure_7") ; 												
	oMeasure8 = document.getElementById("measure_8") ; 	
	oMeasure9 = document.getElementById("measure_9") ; 	
	oMeasure10 = document.getElementById("measure_10") ; 	
	oMeasure11 = document.getElementById("measure_11") ; 	
	oMeasure12 = document.getElementById("measure_12") ; 	
	oMeasure13 = document.getElementById("measure_13") ; 	
	oMeasure14 = document.getElementById("measure_14") ; 	
	oMeasure15 = document.getElementById("measure_15") ; 	
	oMeasure16 = document.getElementById("measure_16") ; 	
	oMeasure17 = document.getElementById("measure_17") ; 	
	oMeasure18 = document.getElementById("measure_18") ; 	
	oMeasure19 = document.getElementById("measure_19") ; 													
	oMeasure20 = document.getElementById("measure_20") ; 															
	
	oValuesInf1 = document.getElementById("inf_1") ; 												
	oValuesInf2 = document.getElementById("inf_2") ;							
	oValuesInf3 = document.getElementById("inf_3") ;							
	oValuesInf4 = document.getElementById("inf_4") ;							
	oValuesInf5 = document.getElementById("inf_5") ;							
	oValuesInf6 = document.getElementById("inf_6") ;							
	oValuesInf7 = document.getElementById("inf_7") ;							
	oValuesInf8 = document.getElementById("inf_8") ;							
	oValuesInf9 = document.getElementById("inf_9") ;							
	oValuesInf10 = document.getElementById("inf_10") ;							
	oValuesInf11 = document.getElementById("inf_11") ;							
	oValuesInf12 = document.getElementById("inf_12") ;							
	oValuesInf13 = document.getElementById("inf_13") ;									
	oValuesInf14 = document.getElementById("inf_14") ;							
	oValuesInf15 = document.getElementById("inf_15") ;									
	oValuesInf16 = document.getElementById("inf_16") ;							
	oValuesInf17 = document.getElementById("inf_17") ;							
	oValuesInf18 = document.getElementById("inf_18") ;							
	oValuesInf19 = document.getElementById("inf_19") ;															
	oValuesInf20 = document.getElementById("inf_20") ;																	
	
	oValuesSup1 = document.getElementById("sup_1") ; 												
	oValuesSup2 = document.getElementById("sup_2") ;							
	oValuesSup3 = document.getElementById("sup_3") ;							
	oValuesSup4 = document.getElementById("sup_4") ;							
	oValuesSup5 = document.getElementById("sup_5") ;							
	oValuesSup6 = document.getElementById("sup_6") ;							
	oValuesSup7 = document.getElementById("sup_7") ;							
	oValuesSup8 = document.getElementById("sup_8") ;							
	oValuesSup9 = document.getElementById("sup_9") ;							
	oValuesSup10 = document.getElementById("sup_10") ;							
	oValuesSup11 = document.getElementById("sup_11") ;							
	oValuesSup12 = document.getElementById("sup_12") ;							
	oValuesSup13 = document.getElementById("sup_13") ;									
	oValuesSup14 = document.getElementById("sup_14") ;							
	oValuesSup15 = document.getElementById("sup_15") ;									
	oValuesSup16 = document.getElementById("sup_16") ;							
	oValuesSup17 = document.getElementById("sup_17") ;							
	oValuesSup18 = document.getElementById("sup_18") ;							
	oValuesSup19 = document.getElementById("sup_19") ;															
	oValuesSup20 = document.getElementById("sup_20") ;
	
	oComment1 = document.getElementById("size_comment_1") ;
	oComment2 = document.getElementById("size_comment_2") ;
	oComment3 = document.getElementById("size_comment_3") ;		
	oComment4 = document.getElementById("size_comment_4") ;
	oComment5 = document.getElementById("size_comment_5") ;
	oComment6 = document.getElementById("size_comment_6") ;
	oComment7 = document.getElementById("size_comment_7") ;
	oComment8 = document.getElementById("size_comment_8") ;
	oComment9 = document.getElementById("size_comment_9") ;
	oComment10 = document.getElementById("size_comment_10") ;
	oComment11 = document.getElementById("size_comment_11") ;
	oComment12 = document.getElementById("size_comment_12") ;
	oComment13 = document.getElementById("size_comment_13") ;
	oComment14 = document.getElementById("size_comment_14") ;
	oComment15 = document.getElementById("size_comment_15") ;
	oComment16 = document.getElementById("size_comment_16") ;
	oComment17 = document.getElementById("size_comment_17") ;
	oComment18 = document.getElementById("size_comment_18") ;
	oComment19 = document.getElementById("size_comment_19") ;
	oComment20 = document.getElementById("size_comment_20") ;				
	
	for (var i=1 ; i<=20 ; i++)
		{
		recupSizesValuesInf(i);
		}		
}

// -------------------------------------------------------
function recupSizesValuesInf(id) 
// -------------------------------------------------------
{
	// --- Suppression de tous les �l�ments de la liste des livres
	oValuesInf = eval("oValuesInf" + id);
	oMeasure = eval("oMeasure" + id);
	if(oMeasure != null)
		{
		while(oValuesInf.childNodes.length > 0 ) oValuesInf.removeChild(oValuesInf.firstChild) ;
		executerSizesRequete("ajax_list_size_values.php",oMeasure.value, oValuesInf, id);
		}
}

// -------------------------------------------------------
function recupSizesValuesSup(id) 
// -------------------------------------------------------
{
	// --- Suppression de tous les �l�ments de la liste des livres
	oValuesSup = eval("oValuesSup" + id);
	oValuesInf = eval("oValuesInf" + id);
	oMeasure = eval("oMeasure" + id);
	if(oMeasure != null)
		{
		while(oValuesSup.childNodes.length > 0 ) oValuesSup.removeChild(oValuesSup.firstChild) ;
		executerSizesRequeteSup("ajax_list_size_values_sup.php",oMeasure.value, oValuesInf.value, oValuesSup, id);
		}
}

// -------------------------------------------------------
function envoiSizesDonnees(id, uid, lang) 
// -------------------------------------------------------
{
	oMeasure = eval("oMeasure" + id);
	oValuesInf = eval("oValuesInf" + id);
	oValuesSup = eval("oValuesSup" + id);
	oComment = eval("oComment" + id);
	
	// --- Instanciation de l'objet XMLHttpRequest via la fonction getXHR()
	var xhr = getXHR() ;
	xhr.open('GET', "/profile/ajax_insert_size.php?uid=" + uid + "&size_measure_id=" + oMeasure.value + "&size_value_inf_id=" + oValuesInf.value + "&size_value_sup_id=" + oValuesSup.value + "&size_comment=" + oComment.value + 
				"&id=" + id + "&lang=" + lang, true);
	xhr.onreadystatechange = function() { recupSizesDonnees(xhr, id); };
	xhr.send(null);
}

// -------------------------------------------------------
function recupSizesDonnees(xhr, id) 
// -------------------------------------------------------
{
oSizeResult = document.getElementById("size_results_"+id);
	if(xhr.readyState == 4 && xhr.status == 200) 
		{
		oSizeResult.innerHTML = xhr.responseText ;
		document.getElementById("loader_"+id).style.display = "none";
		disappearSizeBlock(id);	
		}
	else if(xhr.readyState == 4 && xhr.status != 200) oSpResultat.innerHTML = "Code PHP introuvable" ;
	else if (xhr.readyState < 4) 
	{
		document.getElementById("loader_"+id).style.display = "inline";
	}
}

// -------------------------------------------------------
function executerSizesRequete(asUrl, asParam, aLB, id) 
// -------------------------------------------------------
{
	// --- Instanciation de l'objet XMLHttpRequest via la fonction getXHR()
	var xhr = getXHR() ;
	xhr.open('GET', asUrl + "?id=" + asParam , true) ;
	xhr.onreadystatechange=function() {recupererSizesContenu(xhr,aLB,id);};
	xhr.send(null) ;
}

// -------------------------------------------------------
function executerSizesRequeteSup(asUrl, asParam, asParam2, aLB, id) 
// -------------------------------------------------------
{
	// --- Instanciation de l'objet XMLHttpRequest via la fonction getXHR()
	var xhr = getXHR() ;
	xhr.open('GET', asUrl + "?id=" + asParam + "&inf=" + asParam2, true) ;
	xhr.onreadystatechange=function() {recupererSizesContenu(xhr,aLB,id);};
	xhr.send(null) ;
}	


// -------------------------------------------------------
function recupererSizesContenu(xhr, aLB, asParam) 
// -------------------------------------------------------
{	
	var sRetourSQL ;
	var tIdValeurs, tIdVal, nId, sValeur ;
	var nvOption ;

	
	
	if(xhr.readyState == 4 && xhr.status == 200)
	{
		document.getElementById("loader_"+asParam).style.display = "none";
		sRetourSQL = xhr.responseText ;
		// --- D�coupage de la cha�ne renvoy�e par PHP : la cha�ne a ce format-ci = 1*Proust;2*Ducharme...
		tIdValeurs = sRetourSQL.split(";") ;
		for(var i=0; i<tIdValeurs.length-1; i++)
		{
			tIdVal  = tIdValeurs[i].split("*") ;
			nId     = tIdVal[0] ;
			sValeur = tIdVal[1] ;
			nvOption = document.createElement("option") ;
			nvOption.innerHTML = unescape(sValeur) ;
			nvOption.setAttribute("value",nId) ;
			aLB.appendChild(nvOption) ;
		}
	}
	else if (xhr.readyState < 4) 
	{
		document.getElementById("loader_"+asParam).style.display = "inline";
	}
	
}


// ------------------------------------------------------
// R�cup�ration de l'id dans autocompl�tion
// ------------------------------------------------------
function ac_return(field, item)
{
        // on met en place l'expression r�guli�re
        var regex = new RegExp('user_[0-9]+', 'i');
        // on l'applique au contenu
        var nomimage = regex.exec($(item).innerHTML);
		//on r�cup�re l'id
        id = nomimage[0].replace('user_','');
		// et on l'affecte au champ cach�
        $(field.name+'_id').value = id;
}

// ------------------------------------------------------
// Suppression d'une envie cadeau (wish) - gros bloc
// ------------------------------------------------------
var wishBlock;

function deleteWish(wish_id)
{
wishBlock = document.getElementById("wish-block_" + wish_id);

// --- Instanciation de l'objet XMLHttpRequest via la fonction getXHR()
var xhr = getXHR() ;

xhr.open('GET', "/wishes/ajax_delete_wish.php?wish_id="+wish_id, true);
xhr.onreadystatechange = function() { resultDeleteWish(xhr, wish_id); };
xhr.send(null);
}

// ------------------------------------------------------
// R�sultat de la suppression de l'envie cadeau (wish)
// ------------------------------------------------------

function resultDeleteWish(xhr, wish_id)
{
		if(xhr.readyState == 4 && xhr.status == 200) 
			{
			document.getElementById("loader_"+wish_id).style.display = "none";
			wishBlock.style.display = "none";
			}
		else if(xhr.readyState == 4 && xhr.status == 404) wishBlock.innerHTML = "Code PHP introuvable" ;
		else if (xhr.readyState < 4) 
			{
			document.getElementById("loader_"+wish_id).style.display = "inline";
			}
}	

// ------------------------------------------------------
// Suppression d'une envie cadeau (wish) - bloc type item
// ------------------------------------------------------
var itemWishBlock;

function deleteItemWish(wish_id)
{
itemWishBlock = document.getElementById("itemwish-block_" + wish_id);
// --- Instanciation de l'objet XMLHttpRequest via la fonction getXHR()
var xhr = getXHR() ;

xhr.open('GET', "/wishes/ajax_delete_wish.php?wish_id=" + wish_id, true);
xhr.onreadystatechange = function() { resultDeleteItemWish(xhr, wish_id); };
xhr.send(null);
}

// --------------------------------------------------------------------
// R�sultat de la suppression de l'envie cadeau (wish) - bloc type item
// --------------------------------------------------------------------

function resultDeleteItemWish(xhr, wish_id)
{
		if(xhr.readyState == 4 && xhr.status == 200) 
			{
			document.getElementById("loader_"+wish_id).style.display = "none";
			itemWishBlock.style.display = "none";
			}
		else if(xhr.readyState == 4 && xhr.status == 404) itemWishBlock.innerHTML = "Code PHP introuvable" ;
		else if (xhr.readyState < 4) 
			{
			document.getElementById("loader_"+wish_id).style.display = "inline";
			}
}	



// ------------------------------------------------------
// Suppression d'une id�e cadeau (idea)
// ------------------------------------------------------
var ideaBlock;

function deleteIdea(idea_id)
{
ideaBlock = document.getElementById("idea-block_" + idea_id);

// --- Instanciation de l'objet XMLHttpRequest via la fonction getXHR()
var xhr = getXHR() ;

xhr.open('GET', "/ideas/ajax_delete_idea.php?idea_id="+idea_id, true);
xhr.onreadystatechange = function() { resultDeleteIdea(xhr, idea_id); };
xhr.send(null);
}

// ------------------------------------------------------
// R�sultat de la suppression de l'id�e cadeau (idea)
// ------------------------------------------------------

function resultDeleteIdea(xhr, idea_id)
{
		if(xhr.readyState == 4 && xhr.status == 200) 
			{
			document.getElementById("loader_"+idea_id).style.display = "none";
			ideaBlock.style.display = "none";
			}
		else if(xhr.readyState == 4 && xhr.status == 404) ideaBlock.innerHTML = "Code PHP introuvable" ;
		else if (xhr.readyState < 4) 
			{
			document.getElementById("loader_"+idea_id).style.display = "inline";
			}
}

// ------------------------------------------------------
// Suppression d'un ami
// ------------------------------------------------------
var friendBlock;

function removeFriend(uid, friend_id)
{
friendBlock = document.getElementById("friend_" + friend_id);

// --- Instanciation de l'objet XMLHttpRequest via la fonction getXHR()
var xhr = getXHR() ;

xhr.open('GET', "/members/ajax_remove_friend.php?friend_id="+friend_id+"&uid="+uid, true);
xhr.onreadystatechange = function() { resultRemoveFriend(xhr, friend_id); };
xhr.send(null);
}

// ------------------------------------------------------
// R�sultat de la suppression de l'id�e cadeau (idea)
// ------------------------------------------------------

function resultRemoveFriend(xhr, friend_id)
{
		if(xhr.readyState == 4 && xhr.status == 200) 
			{
			document.getElementById("loader_"+friend_id).style.display = "none";
			friendBlock.style.display = "none";
			}
		else if(xhr.readyState == 4 && xhr.status == 404) friendBlock.innerHTML = "Code PHP introuvable" ;
		else if (xhr.readyState < 4) 
			{
			document.getElementById("loader_"+friend_id).style.display = "inline";
			}
}


// ------------------------------------------------------
// Affiche la Div 'Ecrire un commentaire'
// ------------------------------------------------------
function addComment(wish_id)
{
Effect.Appear("wish-comment-write_" + wish_id);
}

// ------------------------------------------------------
// Soumission du commentaire (sur envie cadeau)
// ------------------------------------------------------
var oComment;

function submitComment(wish_id, lang, uid)
{
oComment = document.getElementById("comment_" + wish_id);

// --- Instanciation de l'objet XMLHttpRequest via la fonction getXHR()
var xhr = getXHR() ;

xhr.open('GET', "/wishes/ajax_submit_comment.php?wish_id=" + wish_id + "&comment=" + oComment.value + "&lang=" + lang + "&uid=" + uid, true);
xhr.onreadystatechange = function() { resultSubmitComment(xhr, wish_id); };
xhr.send(null);
}

// -----------------------------------------------------------
// R�sultat de la soumission du commentaire (sur envie cadeau)
// -----------------------------------------------------------

function resultSubmitComment(xhr, wish_id)
{
	if(xhr.readyState == 4 && xhr.status == 200) 
		{
		document.getElementById("loader_comment_"+wish_id).style.display = "none";
		oComment.value = "";
		document.getElementById("wish-comments-text_" + wish_id).innerHTML = xhr.responseText ;
		document.getElementById("wish-comment-write_" + wish_id).style.display = "none" ;
		}
	else if (xhr.readyState == 4 && xhr.status == 404) 
		{
		document.getElementById("wish-comment-write" + wish_id).innerHTML = "Code PHP introuvable" ;
		document.getElementById("loader_comment_"+wish_id).style.display = "none";
		}
	else if (xhr.readyState < 4) 
		{
		document.getElementById("loader_comment_"+wish_id).style.display = "inline";
		}
}

// ------------------------------------------------------
// Affiche la Div 'Ecrire un avis sur un produit'
// ------------------------------------------------------
function addReview(item_id)
{
document.getElementById("product-review-write_" + item_id).style.display = "inline" ;
}

// ------------------------------------------------------
// Soumission d'un avis sur un produit
// ------------------------------------------------------
var oReview;

function submitReview(item_id, lang, uid)
{
oReview = document.getElementById("review_" + item_id);
review = oReview.value.replace(/([\n])/g,"<br />") ;

// --- Instanciation de l'objet XMLHttpRequest via la fonction getXHR()
var xhr = getXHR() ;

xhr.open('GET', "/root/ajax_submit_review.php?item_id=" + item_id + "&review=" + review + "&lang=" + lang + "&uid=" + uid, true);
xhr.onreadystatechange = function() { resultSubmitReview(xhr, item_id); };
xhr.send(null);
}

// -----------------------------------------------------------
// R�sultat de la soumission d'un avis sur un produit
// -----------------------------------------------------------

function resultSubmitReview(xhr, item_id)
{
	if(xhr.readyState == 4 && xhr.status == 200) 
		{
		document.getElementById("loader_review_"+item_id).style.display = "none";
		oReview.value = "";
		document.getElementById("product-reviews-text_" + item_id).innerHTML = xhr.responseText ;
		document.getElementById("product-review-write_" + item_id).style.display = "none" ;
		}
	else if (xhr.readyState == 4 && xhr.status == 404) 
		{
		document.getElementById("product-review-write" + item_id).innerHTML = "Code PHP introuvable" ;
		document.getElementById("loader_review_"+item_id).style.display = "none";
		}
	else if (xhr.readyState < 4) 
		{
		document.getElementById("loader_review_"+item_id).style.display = "inline";
		}
}

// -------------------------------------------------------------
// Affiche la Div 'Ecrire un commentaire' (sur historique achat)
// -------------------------------------------------------------
function addGiftComment(gift_id)
{
Effect.Appear("gift-comment-write_" + gift_id);
}

// ------------------------------------------------------
// Soumission du commentaire (sur historique achat)
// ------------------------------------------------------
var oComment;

function submitGiftComment(gift_id, lang, uid)
{
oComment = document.getElementById("comment_" + gift_id);

// --- Instanciation de l'objet XMLHttpRequest via la fonction getXHR()
var xhr = getXHR() ;

xhr.open('GET', "/gifts/ajax_submit_gift_comment.php?gift_id=" + gift_id + "&comment=" + oComment.value + "&lang=" + lang + "&uid=" + uid, true);
xhr.onreadystatechange = function() { resultSubmitGiftComment(xhr, gift_id); };
xhr.send(null);
}

// ---------------------------------------------------------------
// R�sultat de la soumission du commentaire (sur historique achat)
// ---------------------------------------------------------------

function resultSubmitGiftComment(xhr, gift_id)
{
	if(xhr.readyState == 4 && xhr.status == 200) 
		{
		document.getElementById("loader_comment_"+gift_id).style.display = "none";
		oComment.value = "";
		document.getElementById("tab_comment_" + gift_id).innerHTML = xhr.responseText ;
		document.getElementById("gift-comment-write_" + gift_id).style.display = "none" ;
		}
	else if (xhr.readyState == 4 && xhr.status == 404) 
		{
		document.getElementById("gift-comment-write" + gift_id).innerHTML = "Code PHP introuvable" ;
		document.getElementById("loader_comment_"+gift_id).style.display = "none";
		}
	else if (xhr.readyState < 4) 
		{
		document.getElementById("loader_comment_"+gift_id).style.display = "inline";
		}
}

// ------------------------------------------------------
// Confirmation d'achat d'une envie cadeau
// ------------------------------------------------------

function confirmBuy(wish_id, item_id, uid)
{
// --- Instanciation de l'objet XMLHttpRequest via la fonction getXHR()
var xhr = getXHR() ;

xhr.open('GET', "/wishes/ajax_confirm_buy.php?wish_id=" + wish_id + "&item_id=" + item_id + "&uid=" + uid, true);
xhr.onreadystatechange = function() { resultSubmitConfirmBuy(xhr, wish_id); };
xhr.send(null);
}

// ------------------------------------------------------
// R�sultat de la confirmation d'achat
// ------------------------------------------------------

function resultSubmitConfirmBuy(xhr, wish_id)
{
	if(xhr.readyState == 4 && xhr.status == 200) 
		{
		document.getElementById("loader_confirm_buy_"+wish_id).style.display = "none";
		window.location = "../gifts/mybuyings.php?wish_id=" + wish_id ;
		}
	else if (xhr.readyState == 4 && xhr.status == 404) 
		{
		document.getElementById("boxtitle_buy_online_"+wish_id).innerHTML = "Code PHP introuvable" ;
		document.getElementById("loader_confirm_buy_"+wish_id).style.display = "none";
		}
	else if (xhr.readyState < 4) 
		{
		document.getElementById("loader_confirm_buy_"+wish_id).style.display = "inline";
		}
}	

// ------------------------------------------------------
// Confirmation d'achat hors ligne d'une envie cadeau
// ------------------------------------------------------

function confirmBuyOut(wish_id, item_id, uid)
{
// --- Instanciation de l'objet XMLHttpRequest via la fonction getXHR()
var xhr = getXHR() ;

xhr.open('GET', "/wishes/ajax_confirm_buyout.php?wish_id=" + wish_id + "&item_id=" + item_id + "&uid=" + uid, true);
xhr.onreadystatechange = function() { resultSubmitConfirmBuyOut(xhr, wish_id); };
xhr.send(null);
}

// ------------------------------------------------------
// R�sultat de la confirmation d'achat
// ------------------------------------------------------

function resultSubmitConfirmBuyOut(xhr, wish_id)
{
	if(xhr.readyState == 4 && xhr.status == 200) 
		{
		document.getElementById("loader_confirm_buy_out_"+wish_id).style.display = "none";
		//window.location.reload()
		window.location = "../gifts/mybuyings.php?wish_id=" + wish_id ;
		}
	else if (xhr.readyState == 4 && xhr.status == 404) 
		{
		document.getElementById("boxtitle_buy_out_"+wish_id).innerHTML = "Code PHP introuvable" ;
		document.getElementById("loader_confirm_buy_out_"+wish_id).style.display = "none";
		}
	else if (xhr.readyState < 4) 
		{
		document.getElementById("loader_confirm_buy_out_"+wish_id).style.display = "inline";
		}
}	

// ------------------------------------------------------
// Poser une option sur une envie cadeau
// ------------------------------------------------------

function putOption(wish_id, uid)
{
// --- Instanciation de l'objet XMLHttpRequest via la fonction getXHR()
var xhr = getXHR() ;

xhr.open('GET', "/wishes/ajax_put_option.php?wish_id=" + wish_id + "&uid=" + uid, true);
xhr.onreadystatechange = function() { resultPutOption(xhr, wish_id); };
xhr.send(null);
}

// ------------------------------------------------------
// R�sultat de la confirmation d'option
// ------------------------------------------------------

function resultPutOption(xhr, wish_id)
{
	if(xhr.readyState == 4 && xhr.status == 200) 
		{
		document.getElementById("loader_"+wish_id).style.display = "none";
		window.location.reload()
		}
	else if (xhr.readyState < 4) 
		{
		document.getElementById("loader_"+wish_id).style.display = "inline";
		}
}	

// ------------------------------------------------------
// Supprimer une option sur une envie cadeau
// ------------------------------------------------------

function deleteOption(wish_id, uid)
{
// --- Instanciation de l'objet XMLHttpRequest via la fonction getXHR()
var xhr = getXHR() ;

xhr.open('GET', "/wishes/ajax_delete_option.php?wish_id=" + wish_id + "&uid=" + uid, true);
xhr.onreadystatechange = function() { resultDeleteOption(xhr, wish_id); };
xhr.send(null);
}

// ------------------------------------------------------
// R�sultat de la confirmation d'option
// ------------------------------------------------------

function resultDeleteOption(xhr, wish_id)
{
	if(xhr.readyState == 4 && xhr.status == 200) 
		{
		document.getElementById("loader_"+wish_id).style.display = "none";
		window.location.reload();
		}
	else if (xhr.readyState < 4) 
		{
		document.getElementById("loader_"+wish_id).style.display = "inline";
		}
}	


// ------------------------------------------------------
// Liaison 2 listes d�roulantes cat�gories
// ------------------------------------------------------

function linkCategs(lang, in_items)
{

var l1    = document.getElementById("main_categs");
var l2    = document.getElementById("sub_categs");
var categ = l1.value ;

while(l2.childNodes.length > 0 ) l2.removeChild(l2.firstChild) ;

// --- Instanciation de l'objet XMLHttpRequest via la fonction getXHR()
var xhr = getXHR() ;
if (in_items == "1")
	{
	xhr.open('GET', '/wishes/ajax_link_categs_initems.php?categ_id=' + categ + "&lang=" + lang, true) ;
	}
else
	{
	xhr.open('GET', '/wishes/ajax_link_categs.php?categ_id=' + categ + "&lang=" + lang, true) ;
	}		
xhr.onreadystatechange=function() {resultLinkCategs(xhr, l2);};
xhr.send(null) ;
}

function recupSubCateg()
{
document.getElementById("sub_categs_hidden").value = document.getElementById("sub_categs").options[document.getElementById("sub_categs").selectedIndex].value ;
}

// -------------------------------------------------------
// R�sultat liaison 2 listes d�roulantes cat�gories
// -------------------------------------------------------
function resultLinkCategs(xhr, l2)
{	
var sRetourSQL ;
var tIdValeurs, tIdVal, nId, sValeur ;
var nvOption ;

if(xhr.readyState == 4 && xhr.status == 200)
	{
	document.getElementById("loader").style.display = "none";
	sRetourSQL = xhr.responseText ;
	tIdValeurs = sRetourSQL.split(";") ;

	nvOption = document.createElement("option") ;
	nvOption.innerHTML = unescape(" ") ;
	nvOption.setAttribute("value",0) ;
	document.getElementById("sub_categs").appendChild(nvOption)

	for(var i=0; i<tIdValeurs.length-1; i++)
		{
		tIdVal  = tIdValeurs[i].split("*") ;
		nId     = tIdVal[0] ;
		sValeur = tIdVal[1] ;
		nvOption = document.createElement("option") ;
		nvOption.innerHTML = unescape(sValeur) ;
		nvOption.setAttribute("value",nId) ;
		document.getElementById("sub_categs").appendChild(nvOption) ;
		}
	}
else if (xhr.readyState < 4) 
		{
		document.getElementById("loader").style.display = "inline";
		}

}

// ------------------------------------------------------
// Tout cocher / d�cocher dans les mails
// ------------------------------------------------------

function mail_select_all ()
{
oSelect = document.getElementById("mail_check_all");
var temp = document.getElementsByTagName("input").length ;

if (oSelect.checked == 1)
	{ // si la case est coch�e
	for (i=1; i < temp; i++)
		{ // on coche toutes les autres
		document.getElementsByTagName("input")[i].checked=1;
		}
	}
else
	{
	for (i=1; i < temp; i++)
		{ // on d�coche tout
		document.getElementsByTagName("input")[i].checked=0;
		}
	} 
}

function mail_verif_check (check_number)
{
oCheckNumber = "mail_check_" + check_number ;
oSelect = document.getElementById(oCheckNumber) ;
if (oSelect.checked == 0)
	{
	document.getElementById("mail_check_all").checked=0;
	}
}

// ------------------------------------------------------
// Gestion des cases � cocher dans la box "View"
// ------------------------------------------------------
function view_check (block)
{
oViewAll = document.getElementById("check_all" + block);
oViewNone = document.getElementById("check_none" + block);
oViewFriends = document.getElementById("check_friends");
oViewNone.checked = 0 ;
oViewAll.checked = 0 ;
oViewFriends.checked = 0 ;
}


function view_check_none (block)
{
oViewAll = document.getElementById("check_all" + block);
oViewNone = document.getElementById("check_none" + block);
oViewFriends = document.getElementById("check_friends");
var temp = document.getElementsByTagName("input").length ;

for (i=1; i < temp; i++)
	{ // on d�coche tout
	document.getElementsByTagName("input")[i].checked = 0;
	}
oViewNone.checked = 1 ;	
}

function view_check_friends (block)
{
oViewAll = document.getElementById("check_all" + block);
oViewNone = document.getElementById("check_none" + block);
oViewFriends = document.getElementById("check_friends");
var temp = document.getElementsByTagName("input").length ;

for (i=1; i < temp; i++)
	{ // on coche toutes les cases sauf les cases ViewAll et ViewNone
	document.getElementsByTagName("input")[i].checked = 1;
	}				
oViewNone.checked = 0 ;
oViewAll.checked = 0 ;
}

function view_check_all (block)
{
oViewAll = document.getElementById("check_all" + block);
oViewNone = document.getElementById("check_none" + block);
oViewFriends = document.getElementById("check_friends");
var temp = document.getElementsByTagName("input").length ;
for (i=1; i < temp; i++)
	{ // on coche toutes les autres
	document.getElementsByTagName("input")[i].checked = 0;
	}
oViewAll.checked = 1 ;
}

// ------------------------------------------------------
// Suppression d'un groupe
// ------------------------------------------------------
var groupBlock;

function deleteGroup(group_id)
{
groupBlock = document.getElementById("list-group_" + group_id);

// --- Instanciation de l'objet XMLHttpRequest via la fonction getXHR()
var xhr = getXHR() ;

xhr.open('GET', "/members/ajax_delete_group.php?group_id="+group_id, true);
xhr.onreadystatechange = function() { resultDeleteGroup(xhr, group_id); };
xhr.send(null);
}

// ------------------------------------------------------
// R�sultat de la suppression du groupe
// ------------------------------------------------------

function resultDeleteGroup(xhr, group_id)
{
		if(xhr.readyState == 4 && xhr.status == 200) 
			{
			document.getElementById("loader_"+group_id).style.display = "none";
			groupBlock.style.display = "none";
			}
		else if(xhr.readyState == 4 && xhr.status == 404) groupBlock.innerHTML = "Code PHP introuvable" ;
		else if (xhr.readyState < 4) 
			{
			document.getElementById("loader_"+group_id).style.display = "inline";
			}
}	

// ------------------------------------------------------
// Suppresion d'un �v�nement
// ------------------------------------------------------

var eventBlock;

function deleteEvent(event_id)
{
eventBlock = document.getElementById("event-block_" + event_id);

// --- Instanciation de l'objet XMLHttpRequest via la fonction getXHR()
var xhr = getXHR() ;

xhr.open('GET', "/events/ajax_delete_event.php?event_id="+event_id, true);
xhr.onreadystatechange = function() { resultDeleteEvent(xhr, event_id); };
xhr.send(null);
}

// ------------------------------------------------------
// R�sultat de la suppression d'un �v�nement
// ------------------------------------------------------

function resultDeleteEvent(xhr, event_id)
{
		if(xhr.readyState == 4 && xhr.status == 200) 
			{
			document.getElementById("loader_"+event_id).style.display = "none";
			eventBlock.style.display = "none";
			}
		else if(xhr.readyState == 4 && xhr.status == 404) eventBlock.innerHTML = "Code PHP introuvable" ;
		else if (xhr.readyState < 4) 
			{
			document.getElementById("loader_"+event_id).style.display = "inline";
			}
}	

// ------------------------------------------------------
// Gestion de l'alarme cadeau
// ------------------------------------------------------
var eventReminderBlock;

function alarmManager(event_id, alarm_action, lang)
{
eventReminderBlock = document.getElementById("event-reminder_" + event_id);

// --- Instanciation de l'objet XMLHttpRequest via la fonction getXHR()
var xhr = getXHR() ;

xhr.open('GET', "/events/ajax_alarm.php?event_id="+event_id+"&alarm="+alarm_action+"&lang="+lang, true);
xhr.onreadystatechange = function() { resultAlarmManager(xhr, event_id); };
xhr.send(null);
}

// ------------------------------------------------------
// R�sultat de la gestion de l'alarme cadeau
// ------------------------------------------------------

function resultAlarmManager(xhr, event_id)
{
		if(xhr.readyState == 4 && xhr.status == 200) 
			{
			document.getElementById("loader_"+event_id).style.display = "none";
			eventReminderBlock.innerHTML = xhr.responseText ;
			}
		else if(xhr.readyState == 4 && xhr.status == 404) eventReminderBlock.innerHTML = "Code PHP introuvable" ;
		else if (xhr.readyState < 4) 
			{
			document.getElementById("loader_"+event_id).style.display = "inline";
			}
}	


// ------------------------------------------------------
// Suppression d'une cat�gorie favorite
// ------------------------------------------------------
var categBlock;

function deleteFavCateg(categ_id, user_id)
{
categBlock = document.getElementById("categ_block_" + categ_id);

// --- Instanciation de l'objet XMLHttpRequest via la fonction getXHR()
var xhr = getXHR() ;

xhr.open('GET', "/profile/ajax_delete_favcateg.php?categ_id="+categ_id+"&user_id="+user_id, true);
xhr.onreadystatechange = function() { resultDeleteFavCateg(xhr, categ_id); };
xhr.send(null);
}

// ------------------------------------------------------
// R�sultat de la suppression d'une cat�gorie favorite
// ------------------------------------------------------

function resultDeleteFavCateg(xhr, categ_id)
{
		if(xhr.readyState == 4 && xhr.status == 200) 
			{
			document.getElementById("loader_"+categ_id).style.display = "none";
			categBlock.style.display = "none";
			}
		else if(xhr.readyState == 4 && xhr.status == 404) categBlock.innerHTML = "Code PHP introuvable" ;
		else if (xhr.readyState < 4) 
			{
			document.getElementById("loader_"+categ_id).style.display = "inline";
			}
}	


// ------------------------------------------------------
// Affichage des 5 items suivants
// ------------------------------------------------------
function printNextItems(block_type, categ, lang)
{
oLimit = document.getElementById("limit_" + block_type).innerHTML ;

// --- Instanciation de l'objet XMLHttpRequest via la fonction getXHR()
var xhr = getXHR() ;


xhr.open('GET', "ajax_nextitems.php?limit=" + oLimit + "&lang=" + lang + "&categ=" + categ + "&block_type=" + block_type, true);
xhr.onreadystatechange = function() { resultPrintItems(block_type, xhr); };
xhr.send(null);
}

// ------------------------------------------------------
// Affichage des 5 items pr�c�dents
// ------------------------------------------------------
function printPrevItems(block_type, categ, lang)
{
oLimit = document.getElementById("limit_"  + block_type).innerHTML ;

// --- Instanciation de l'objet XMLHttpRequest via la fonction getXHR()
var xhr = getXHR() ;

xhr.open('GET', "ajax_previtems.php?limit=" + oLimit + "&lang=" + lang + "&categ=" + categ + "&block_type=" + block_type, true);
xhr.onreadystatechange = function() { resultPrintItems(block_type, xhr); };
xhr.send(null);
}

// ------------------------------------------------------
// R�sultat de l'affichage des items
// ------------------------------------------------------

function resultPrintItems(block_type, xhr)
{
		if(xhr.readyState == 4 && xhr.status == 200) 
			{
			document.getElementById("loader_" + block_type).style.display = "none";
			document.getElementById("item-bigblock_" + block_type).innerHTML = "" ;
			document.getElementById("item-bigblock_" + block_type).innerHTML = xhr.responseText ;
			}
		else if(xhr.readyState == 4 && xhr.status == 404) document.getElementById("loader_" + block_type).innerHTML = "Code PHP introuvable" ;
		else if (xhr.readyState < 4) 
			{
			document.getElementById("loader_" + block_type).style.display = "inline";
			}
}	

// ------------------------------------------------------
// Ajout et suppresion d'un lien entre une id�e et un user
// ------------------------------------------------------
function addIdeaForWhom(idea_id, lang)
{
// --- Instanciation de l'objet XMLHttpRequest via la fonction getXHR()
var xhr = getXHR() ;

oUser = document.getElementById("select_idea_for_whom_"+idea_id).value ;
xhr.open('GET', "/ideas/ajax_idea_for_whom.php?idea_id=" + idea_id + "&user_id=" + oUser + "&lang=" + lang + "&action=add", true);
xhr.onreadystatechange = function() { resultIdeaForWhom(xhr, idea_id); };
xhr.send(null);
}

function removeIdeaForWhom(idea_id, user_id, lang)
{
// --- Instanciation de l'objet XMLHttpRequest via la fonction getXHR()
var xhr = getXHR() ;

xhr.open('GET', "/ideas/ajax_idea_for_whom.php?idea_id=" + idea_id + "&user_id=" + user_id + "&lang=" + lang + "&action=remove", true);
xhr.onreadystatechange = function() { resultIdeaForWhom(xhr, idea_id); };
xhr.send(null);
}

// -------------------------------------------------------
// R�sultat de l'ajout d'un lien entre une id�e et un user
// -------------------------------------------------------
function resultIdeaForWhom(xhr, idea_id)
{
		if(xhr.readyState == 4 && xhr.status == 200) 
			{
			document.getElementById("loader_"+idea_id).style.display = "none";
			document.getElementById("idea_for_whom_result_"+idea_id).innerHTML = xhr.responseText ;
			document.getElementById("idea_for_whom_"+idea_id).style.display = "none" ;
			}
		else if(xhr.readyState == 4 && xhr.status == 404) document.getElementById("loader_"+idea_id).innerHTML = "Code PHP introuvable" ;
		else if (xhr.readyState < 4) 
			{
			document.getElementById("loader_"+idea_id).style.display = "inline";
			}
}


// ------------------------------------------------------
// Affichage d'une div
// ------------------------------------------------------

function printADiv(div_id)
{
oDiv = document.getElementById(div_id) ;
oDiv.style.display = "block";
}

// ------------------------------------------------------
// Fermeture d'une div
// ------------------------------------------------------

function closeADiv(div_id)
{
oDiv = document.getElementById(div_id) ;
oDiv.style.display = "none";
}

// -------------------------------------------------------
// Affichage des div Alphabet (pour affichage des marques)
// -------------------------------------------------------

function printAlphaDivs()
{
var filterAlphaClass = getElementsByClass("filter_brand_alpha") ;
for (i = 0 ; i < filterAlphaClass.length; i++)
	{
	filterAlphaClass[i].style.display = "inline";
	}
}

// -------------------------------------------------------
// Fermeture des div Alphabet (pour affichage des marques)
// -------------------------------------------------------

function closeAlphaDivs()
{
var filterAlphaClass = getElementsByClass("filter_brand_alpha") ;
for (i = 0 ; i < filterAlphaClass.length; i++)
	{
	filterAlphaClass[i].style.display = "none";
	}
}

// -------------------------------------------------------
// Fermeture des div Alphabet (pour affichage des marques)
// -------------------------------------------------------

function disableLink(link_id)
{
oLink = document.getElementById(link_id) ;
oLink.removeAttribute("href");
oLink.onmouseover = function() { this.style.textDecoration = 'none'; this.style.color = 'black' ; };
oLink.onclick = function() { };
}

// -------------------------------------------------------
function appearSizeBlock(id) 
// -------------------------------------------------------
{
Effect.BlindUp("button_" + id);
Effect.BlindDown("size-block-modif_" + id);
}

// -------------------------------------------------------
function disappearSizeBlock(id) 
// -------------------------------------------------------
{
Effect.BlindUp("size-block-modif_" + id);
Effect.BlindDown("button_" + id);
}

// -------------------------------------------------------
function printPwd()
// -------------------------------------------------------
{
oShareType = document.getElementById("sharetype").options[document.getElementById("sharetype").selectedIndex].value ;
if (oShareType == 1)
	{
	document.getElementById("sharewishes_pwd").style.display = "inline";
	}
else
	{
	document.getElementById("sharewishes_pwd").style.display = "none";
	}
}

// -------------------------------------------------------
function checkPwdSharedWishes(wish_share_id)
// -------------------------------------------------------
{
oPwd = document.getElementById('pwd').value ;

// --- Instanciation de l'objet XMLHttpRequest via la fonction getXHR()
var xhr = getXHR() ;

xhr.open('GET', "/wishes/ajax_checkpwd_sharedwishes.php?pwd=" + oPwd + "&share_id=" + share_id, true);
xhr.onreadystatechange = function() { resultCheckPwd(xhr); };
xhr.send(null);
}

// ------------------------------------------------------
// R�sultat de l'affichage des items
// ------------------------------------------------------

function resultCheckPwd(xhr)
{
		if(xhr.readyState == 4 && xhr.status == 200) 
			{
			document.getElementById("loader").style.display = "none";
			if (xhr.responseText == "ok")
				{
				document.getElementById("pwd_block").style.display = "none";
				document.getElementById("sharedwishes-block").style.display = "inline-block";
				}
			else 
				{
				document.getElementById("loader").innerHTML = "Mot de passe erron�"	;
				}
			}
		else if(xhr.readyState == 4 && xhr.status == 404) document.getElementById("loader").innerHTML = "Code PHP introuvable" ;
		else if (xhr.readyState < 4) 
			{
			document.getElementById("loader").style.display = "inline";
			}
}	

// ------------------------------------------------------
// Affichage d'une div de type Popup
// ------------------------------------------------------

function printPopUp(div_id)
{
oDiv = document.getElementById(div_id) ;
oDiv.style.display = "inline-block";
new Effect.Opacity(div_id, { from: 1.0, to: 0.0, duration: 5.0 });
}

// ------------------------------------------------------
// Ajout d'un vote 
// ------------------------------------------------------
function addVote(item_id, user_id, likeness)
{
// --- Instanciation de l'objet XMLHttpRequest via la fonction getXHR()
var xhr = getXHR() ;

oVotes = document.getElementById("product-votes_"+item_id) ;
xhr.open('GET', "/root/ajax_addvote.php?item_id=" + item_id + "&user_id=" + user_id + "&likeness=" + likeness, true);
xhr.onreadystatechange = function() { resultAddVote(xhr, item_id); };
xhr.send(null);
}

// -------------------------------------------------------
// R�sultat de l'ajout d'un vote
// -------------------------------------------------------
function resultAddVote(xhr, item_id)
{
	if(xhr.readyState == 4 && xhr.status == 200) 
		{
		oVotes.innerHTML = xhr.responseText ;
		}
	else if(xhr.readyState == 4 && xhr.status == 404) oVotes.innerHTML = "Code PHP introuvable" ;
	else if (xhr.readyState < 4) 
		{
		//document.getElementById("loader_"+idea_id).style.display = "inline";
		}
}


// ------------------------------------------------------
// S�lection / D�selection d'une id�e pour cadeau commun
// ------------------------------------------------------
function commonGiftIdeaSelect(item_price, item_id)
{
oCommonGiftPrice = document.getElementById("commongift_price") ;
oCommonGiftRest = document.getElementById("commongift_rest") ;

oPrice = oCommonGiftPrice.innerHTML ;
oRest = oCommonGiftRest.innerHTML ;

oPrice = Math.round(parseFloat(oPrice)*100)/100;
oRest = Math.round(parseFloat(oRest)*100)/100;
item_price = Math.round(parseFloat(item_price)*100)/100;

var oCheck = document.getElementById("checkbox_"+item_id).checked ;

if (oCheck == true)
	{
	oNewPrice = oPrice + item_price ;
	oNewRest = oRest + item_price ;
	}
else if (oCheck == false)
	{
	oNewPrice = oPrice - item_price ;
	oNewRest = oRest - item_price ;
	}

oNewPrice = Math.round(oNewPrice*100)/100 ;
oNewRest = Math.round(oNewRest*100)/100 ;

oCommonGiftPrice.innerHTML = oNewPrice ;
oCommonGiftRest.innerHTML = oNewRest ;
}

// -------------------------------------------------------------
// Affiche la Div 'Ajouter une id�e' (sur cadeau commun)
// -------------------------------------------------------------
function addCommonGiftIdea()
{
Effect.Appear("cgaddidea");
}

// -------------------------------------------------------------
// Affiche la Div 'Ecrire un commentaire' (sur cadeau commun)
// -------------------------------------------------------------
function addCGComment(cg_id)
{
Effect.Appear("cg-comment-write");
}

// -------------------------------------------------------------
// D�saffiche la Div 'Ecrire un commentaire' (sur cadeau commun)
// -------------------------------------------------------------
function cancelCGComment()
{
Effect.Fade("cg-comment-write");
}

// ------------------------------------------------------
// Soumission du commentaire (sur cadeau commun)
// ------------------------------------------------------
var oComment;

function submitCGComment(cg_id, uid, lang)
{
oComment = document.getElementById("cgcomment");

// --- Instanciation de l'objet XMLHttpRequest via la fonction getXHR()
var xhr = getXHR() ;

xhr.open('GET', "/gifts/ajax_submit_cg_comment.php?cg=" + cg_id + "&comment=" + oComment.value + "&uid=" + uid + "&lang=" + lang, true);
xhr.onreadystatechange = function() { resultSubmitCGComment(xhr); };
xhr.send(null);
}

// ---------------------------------------------------------------
// R�sultat de la soumission du commentaire (sur cadeau commun)
// ---------------------------------------------------------------

function resultSubmitCGComment(xhr)
{
	if(xhr.readyState == 4 && xhr.status == 200) 
		{
		document.getElementById("cg-comment-write").style.display = "none";
		document.getElementById("loader_comment").style.display = "none";
		oComment.value = "";
		document.getElementById("cg_comments").innerHTML = xhr.responseText ;
		}
	else if (xhr.readyState == 4 && xhr.status == 404) 
		{
		document.getElementById("cg_comments").innerHTML = "Code PHP introuvable" ;
		}
	else if (xhr.readyState < 4) 
		{
		document.getElementById("loader_comment").style.display = "inline";
		}
}

// ------------------------------------------------------
// Supprime une participation (sur cadeau commun)
// ------------------------------------------------------
var oComment;
var oMsg;

function modifCGparticipation(cg_cash_id, operation, cg_id, lang)
{
oPartBlock = document.getElementById("cg-block-participations");
if (operation == "cancel") { oMsg = document.getElementById("answer-refusal_" + cg_cash_id).value ; }
if (operation == "valid") { oMsg = document.getElementById("answer-valid_" + cg_cash_id).value ; }


// --- Instanciation de l'objet XMLHttpRequest via la fonction getXHR()
var xhr = getXHR() ;

xhr.open('GET', "/gifts/ajax_cg_participations.php?cash_id=" + cg_cash_id + "&operation=" + operation + "&cg=" + cg_id + "&lang=" + lang + "&msg=" + oMsg, true);
xhr.onreadystatechange = function() { resultModifCGparticipation(xhr); };
xhr.send(null);
}

// -----------------------------------------------------------------
// R�sultat de la supression d'une participation (sur cadeau commun)
// -----------------------------------------------------------------

function resultModifCGparticipation(xhr)
{
	if(xhr.readyState == 4 && xhr.status == 200) 
		{
		document.getElementById("loader_cg_participations").style.display = "none";
		window.location.reload();
		}
	else if (xhr.readyState == 4 && xhr.status == 404) 
		{
		oPartBlock.innerHTML = "Code PHP introuvable" ;
		}
	else if (xhr.readyState < 4) 
		{
		document.getElementById("loader_cg_participations").style.display = "inline";
		}
}

// ------------------------------------------------------
// Suppression d'une id�e cadeau (sur cadeau commun)
// ------------------------------------------------------
var oIdeaBlock;

function deleteCGIdea(cg_id, item_id, uid, addcost_check, addcost_value, lang)
{
oIdeaBlock = document.getElementById("cg_block_ideas_orga");

// --- Instanciation de l'objet XMLHttpRequest via la fonction getXHR()
var xhr = getXHR() ;

xhr.open('GET', "/gifts/ajax_delete_cg_idea.php?cg=" + cg_id + "&item_id=" + item_id + "&uid=" + uid + "&addcost_check=" + addcost_check + "&addcost_value=" + addcost_value + "&lang=" + lang, true);
xhr.onreadystatechange = function() { resultDeleteCGIdea(xhr); };
xhr.send(null);
}

// ---------------------------------------------------------------
// R�sultat de la supression d'une id�e cadeau (sur cadeau commun)
// ---------------------------------------------------------------

function resultDeleteCGIdea(xhr)
{
	if(xhr.readyState == 4 && xhr.status == 200) 
		{
		document.getElementById("loader_commongiftideas").style.display = "none";
		oIdeaBlock.innerHTML = xhr.responseText ;
		}
	else if (xhr.readyState == 4 && xhr.status == 404) 
		{
		oIdeaBlock.innerHTML = "Code PHP introuvable" ;
		}
	else if (xhr.readyState < 4) 
		{
		document.getElementById("loader_commongiftideas").style.display = "inline";
		}
}

// ------------------------------------------------------
// Modification d'une id�e cadeau (sur cadeau commun)
// ------------------------------------------------------
var oIdeaBlock;

function modifyCGIdea(cg_id, item_id, uid, addcost_check, addcost_value, lang)
{
oIdeaBlock = document.getElementById("cg_block_ideas_orga");
oLib = document.getElementById("cg_idea_lib_" + item_id).value;
oPrice = document.getElementById("cg_idea_price_" + item_id).value;
// --- Instanciation de l'objet XMLHttpRequest via la fonction getXHR()
var xhr = getXHR() ;

xhr.open('GET', "/gifts/ajax_modify_cg_idea.php?cg=" + cg_id + "&item_id=" + item_id + "&uid=" + uid + "&addcost_check=" + addcost_check + "&addcost_value=" + addcost_value + "&lang=" + lang + "&lib=" + oLib + "&price=" + oPrice, true);
xhr.onreadystatechange = function() { resultModifyCGIdea(xhr); };
xhr.send(null);
}

// -----------------------------------------------------------------
// R�sultat de la modification d'une id�e cadeau (sur cadeau commun)
// -----------------------------------------------------------------

function resultModifyCGIdea(xhr)
{
	if(xhr.readyState == 4 && xhr.status == 200) 
		{
		document.getElementById("loader_commongiftideas").style.display = "none";
		oIdeaBlock.innerHTML = xhr.responseText ;
		}
	else if (xhr.readyState == 4 && xhr.status == 404) 
		{
		oIdeaBlock.innerHTML = "Code PHP introuvable" ;
		}
	else if (xhr.readyState < 4) 
		{
		document.getElementById("loader_commongiftideas").style.display = "inline";
		}
}

// ------------------------------------------------------
// Modification d'une id�e cadeau (sur cadeau commun)
// ------------------------------------------------------
var oIdeaBlock;

function modifyCGAddCost(cg_id, uid, lang)
{
oIdeaBlock = document.getElementById("cg_block_ideas_orga");
oPrice = document.getElementById("cg_addcost_value").value;
// --- Instanciation de l'objet XMLHttpRequest via la fonction getXHR()
var xhr = getXHR() ;

xhr.open('GET', "/gifts/ajax_modify_cg_addcost.php?cg=" + cg_id + "&uid=" + uid + "&addcost_value=" + oPrice + "&lang=" + lang, true);
xhr.onreadystatechange = function() { resultModifyCGIdea(xhr); };
xhr.send(null);
}

// ------------------------------------------------------
// Relance manuelle (sur cadeau commun)
// ------------------------------------------------------
var oNonAnswering;

function manualFollowUp(to_id, cg_id, lang)
{
oNonAnsweringBlock = document.getElementById("cg_non_answering");

// --- Instanciation de l'objet XMLHttpRequest via la fonction getXHR()
var xhr = getXHR() ;

xhr.open('GET', "/gifts/ajax_manual_followup.php?cg=" + cg_id + "&to=" + to_id + "&lang=" + lang, true);
xhr.onreadystatechange = function() { resultManualFollowUp(xhr); };
xhr.send(null);
}

// ------------------------------------------------------
// R�sultat relance manuelle(sur cadeau commun)
// ------------------------------------------------------

function resultManualFollowUp(xhr)
{
	if(xhr.readyState == 4 && xhr.status == 200) 
		{
		document.getElementById("loader_commongiftparticipants").style.display = "none";
		oNonAnsweringBlock.innerHTML = xhr.responseText ;
		}
	else if (xhr.readyState == 4 && xhr.status == 404) 
		{
		oNonAnsweringBlock.innerHTML = "Code PHP introuvable" ;
		}
	else if (xhr.readyState < 4) 
		{
		document.getElementById("loader_commongiftparticipants").style.display = "inline";
		}
}

// ------------------------------------------------------
// Ajout d'un participant (sur cadeau commun)
// ------------------------------------------------------
var oParticipants;

function addParticipant(list, cg_id, uid, receiver_id, lang)
{
oParticipants = document.getElementById("cg-block-participants");
if (list == "my_friends") { oParticip = document.getElementById('my_friends').options[document.getElementById('my_friends').selectedIndex].value ; }

if (list == "receiver_friends") { oParticip = document.getElementById('receiver_friends').options[document.getElementById('receiver_friends').selectedIndex].value ; }

// --- Instanciation de l'objet XMLHttpRequest via la fonction getXHR()
var xhr = getXHR() ;

xhr.open('GET', "/gifts/ajax_add_participant.php?cg=" + cg_id + "&particip=" + oParticip + "&lang=" + lang + "&receiver=" + receiver_id + "&uid=" + uid, true);
xhr.onreadystatechange = function() { resultAddParticipant(xhr); };
xhr.send(null);
}

// ------------------------------------------------------
// R�sultat de l'ajout d'un participant (sur cadeau commun)
// ------------------------------------------------------

function resultAddParticipant(xhr)
{
	if(xhr.readyState == 4 && xhr.status == 200) 
		{
		document.getElementById("loader_commongiftparticipants").style.display = "none";
		oParticipants.innerHTML = xhr.responseText ;
		}
	else if (xhr.readyState == 4 && xhr.status == 404) 
		{
		oParticipants.innerHTML = "Code PHP introuvable" ;
		}
	else if (xhr.readyState < 4) 
		{
		document.getElementById("loader_commongiftparticipants").style.display = "inline";
		}
}

// ------------------------------------------------------
// Suppression d'un participant (sur cadeau commun)
// ------------------------------------------------------
var oParticipantInSession;

function cancelParticipantInSession(to_id, uid, lang)
{
oParticipantInSession = document.getElementById("selected_" + to_id);

// --- Instanciation de l'objet XMLHttpRequest via la fonction getXHR()
var xhr = getXHR() ;

xhr.open('GET', "/gifts/ajax_cancel_participant.php?to=" + to_id + "&uid=" + uid + "&lang=" + lang, true);
xhr.onreadystatechange = function() { resultCancelParticipantInSession(xhr); };
xhr.send(null);
}

// ------------------------------------------------------
// R�sultat de l'ajout de la suppression d'un participant (sur cadeau commun)
// ------------------------------------------------------

function resultCancelParticipantInSession(xhr)
{
	if(xhr.readyState == 4 && xhr.status == 200) 
		{
		document.getElementById("loader_selectedparticipants").style.display = "none";
		oParticipantInSession.style.display = "none" ;
		}
	else if (xhr.readyState == 4 && xhr.status == 404) 
		{
		oParticipantInSession.innerHTML = "Code PHP introuvable" ;
		}
	else if (xhr.readyState < 4) 
		{
		document.getElementById("loader_selectedparticipants").style.display = "inline";
		}
}

// ------------------------------------------------------
// Refus de participer (sur cadeau commun)
// ------------------------------------------------------
var oMyPart;

function refuseParticipation(cg_id, uid, lang)
{
oMyPart = document.getElementById("cg_mypart");

// --- Instanciation de l'objet XMLHttpRequest via la fonction getXHR()
var xhr = getXHR() ;

xhr.open('GET', "/gifts/ajax_refuse_participation.php?cg=" + cg_id + "&uid=" + uid + "&lang=" + lang, true);
xhr.onreadystatechange = function() { resultRefuseParticipation(xhr); };
xhr.send(null);
}

// ------------------------------------------------------
// R�sultat du refus de participer (sur cadeau commun)
// ------------------------------------------------------

function resultRefuseParticipation(xhr)
{
	if(xhr.readyState == 4 && xhr.status == 200) 
		{
		document.getElementById("loader_mypart").style.display = "none";
		oMyPart.innerHTML = xhr.responseText ;
		}
	else if (xhr.readyState == 4 && xhr.status == 404) 
		{
		oMyPart.innerHTML = "Code PHP introuvable" ;
		}
	else if (xhr.readyState < 4) 
		{
		document.getElementById("loader_mypart").style.display = "inline";
		}
}

// ------------------------------------------------------
// Ajout d'une envie cadeau g�n�rique
// ------------------------------------------------------
var oGeneralWish;

function addGeneralWish(uid, lang)
{
oGeneralWish = document.getElementById("general_wish_block");
oWishLib = document.getElementById("general_wish").value ;
// --- Instanciation de l'objet XMLHttpRequest via la fonction getXHR()
var xhr = getXHR() ;

xhr.open('GET', "/wishes/ajax_add_general_wish.php?uid=" + uid + "&wishlib=" + oWishLib + "&lang=" + lang, true);
xhr.onreadystatechange = function() { resultAddGeneralWish(xhr); };
xhr.send(null);
}

// ------------------------------------------------------
// R�sultat de l'ajout d'une envie cadeau g�n�rique
// ------------------------------------------------------

function resultAddGeneralWish(xhr)
{
	if(xhr.readyState == 4 && xhr.status == 200) 
		{
		document.getElementById("loader_general_wish").style.display = "none";
		oGeneralWish.innerHTML = xhr.responseText ;
		}
	else if (xhr.readyState == 4 && xhr.status == 404) 
		{
		oGeneralWish.innerHTML = "Code PHP introuvable" ;
		}
	else if (xhr.readyState < 4) 
		{
		document.getElementById("loader_general_wish").style.display = "inline";
		}
}

// ------------------------------------------------------
// Suppression d'une envie g�n�rique
// ------------------------------------------------------
function deleteGeneralWish(wish_general_id, uid, lang)
{
oGeneralWish = document.getElementById("general_wish_block");

// --- Instanciation de l'objet XMLHttpRequest via la fonction getXHR()
var xhr = getXHR() ;
xhr.open('GET', "/wishes/ajax_delete_general_wish.php?wish_general_id=" + wish_general_id + "&uid=" + uid + "&lang=" + lang, true);
xhr.onreadystatechange = function() { resultDeleteGeneralWish(xhr); };
xhr.send(null);
}

// ---------------------------------------------------------------
// R�sultat de la supression d'une envie g�n�rique
// ---------------------------------------------------------------

function resultDeleteGeneralWish(xhr)
{
	if(xhr.readyState == 4 && xhr.status == 200) 
		{
		document.getElementById("loader_general_wish").style.display = "none";
		oGeneralWish.innerHTML = xhr.responseText ;
		}
	else if (xhr.readyState == 4 && xhr.status == 404) 
		{
		oGeneralWish.innerHTML = "Code PHP introuvable" ;
		}
	else if (xhr.readyState < 4) 
		{
		document.getElementById("loader_general_wish").style.display = "inline";
		}
}

// ------------------------------------------------------
// Modification d'un label (tag) sur page produit
// ------------------------------------------------------
function modifyLabel(item_id, label_id, label_type_id, label_lib, lang, user_id, change)
{
// --- Instanciation de l'objet XMLHttpRequest via la fonction getXHR()
var xhr = getXHR() ;

oLabel = document.getElementById("label_"+label_id) ;
xhr.open('GET', "/Wishes/ajax_modif_label.php?item_id=" + item_id + "&user_id=" + user_id + "&label_id=" + label_id + "&label_type_id=" + label_type_id + "&label_lib=" + label_lib + "&lang=" + lang + "&change=" + change, true);
xhr.onreadystatechange = function() { resultModifyLabel(xhr, label_id); };
xhr.send(null);
}

// -------------------------------------------------------
// R�sultat de la modification d'un label (tag) sur page produit
// -------------------------------------------------------
function resultModifyLabel(xhr, label_id)
{
	if(xhr.readyState == 4 && xhr.status == 200) 
		{
		oLabel.innerHTML = xhr.responseText ;
		}
	else if(xhr.readyState == 4 && xhr.status == 404) oLabel.innerHTML = "Code PHP introuvable" ;
	else if (xhr.readyState < 4) 
		{
		//document.getElementById("loader_"+idea_id).style.display = "inline";
		}
}

// ------------------------------------------------------
// Modification d'un label (tag) sur page links
// ------------------------------------------------------
function modifyLinksLabel(links_id, label_id, label_type_id, label_lib, lang, user_id, change)
{
// --- Instanciation de l'objet XMLHttpRequest via la fonction getXHR()
var xhr = getXHR() ;

oLabel = document.getElementById("label_"+links_id+"_"+label_id) ;
xhr.open('GET', "/root/ajax_modif_links_label.php?links_id=" + links_id + "&user_id=" + user_id + "&label_id=" + label_id + "&label_type_id=" + label_type_id + "&label_lib=" + label_lib + "&lang=" + lang + "&change=" + change, true);
xhr.onreadystatechange = function() { resultModifyLinksLabel(xhr, links_id, label_id); };
xhr.send(null);
}

// -------------------------------------------------------
// R�sultat de la modification d'un label (tag) sur page links
// -------------------------------------------------------
function resultModifyLinksLabel(xhr, links_id, label_id)
{

	if(xhr.readyState == 4 && xhr.status == 200) 
		{
		document.getElementById("loader_"+links_id).style.display = "none";
		oLabel.innerHTML = xhr.responseText ;
		}
	else if(xhr.readyState == 4 && xhr.status == 404) oLabel.innerHTML = "Code PHP introuvable" ;
	else if (xhr.readyState < 4) 
		{
		document.getElementById("loader_"+links_id).style.display = "inline";
		}
}

// ------------------------------------------------------
// R�init du moteur de recherche
// ------------------------------------------------------
function searchengine_reinit()
{
var temp = document.getElementsByTagName("input").length ;

for (i=1; i < temp; i++)
	{ // on d�coche tout
	document.getElementsByTagName("input")[i].checked = 0;
	}
}


// ------------------------------------------------------
// Fonctions LightBox
// ------------------------------------------------------
function gradient(id, level)
{
	var box = document.getElementById(id);
	box.style.opacity = level;
	box.style.MozOpacity = level;
	box.style.KhtmlOpacity = level;
	box.style.filter = "alpha(opacity=" + level * 100 + ")";
	box.style.display="block";
	return;
}

function fadein(id) 
{
	var level = 0;
	while(level <= 1)
	{
		setTimeout( "gradient('" + id + "'," + level + ")", (level* 1000) + 10);
		level += 0.01;
	}
}

// Open the lightbox
function openbox(formtitle, fadin, filter_id, box_id, boxtitle_id)
{
	scrollTo(0,0);
  
  var box = document.getElementById(box_id); 
  document.getElementById(filter_id).style.display='block';

  var btitle = document.getElementById(boxtitle_id);
  btitle.innerHTML = formtitle + '<div style="float:right;margin-right:10px;"><a href="#" onClick="closelightboxes()">X</a></div>' ;
  
  if(fadin)
  {
	 gradient(box_id, 0);
	 fadein(box_id);
  }
  else
  { 	
    box.style.display='block';
  }  	
  
}

// Close the lightbox

function closebox(filter_id, box_id)
{
   document.getElementById(filter_id).style.display='none';
   document.getElementById(box_id).style.display='none';
}

function closelightboxes()
{
var lightboxFilterClass = getElementsByClass("lightbox-filter") ;
var lightboxBoxClass = getElementsByClass("lightbox-box") ;

for (i = 0 ; i < lightboxFilterClass.length; i++)
	{
	lightboxFilterClass[i].style.display='none';
	}

for (i = 0 ; i < lightboxBoxClass.length; i++)
	{
	lightboxBoxClass[i].style.display='none';
	}
}

