
function partager_interact(type, elem_no, action, arg)
    {
	// type: 1 ou 'rubr' pour partager une rubrique; 2 ou 'sites' pour partager un site
	// elem_no: N° de la rubrique ou du site
	// arg = 'url' ou '0'

	// rubriques
	if (type==1) { var interact_dial_id='rubr_interact_dial'; }
	// sites
	else if (type==2) { var interact_dial_id='site_interact_dial_'+elem_no; }

	document.getElementById(interact_dial_id).style.display='block';

	httpRequest=ajax_requete_init();

    httpRequest.onreadystatechange = function() {
		if (httpRequest.readyState == 4)
			{
			if (httpRequest.status == 200)
				{ document.getElementById(interact_dial_id).innerHTML=httpRequest.responseText; }
			else { document.getElementById(interact_dial_id).innerHTML='Problème... :-('; }
			}
		//else { document.getElementById(interact_dial_id).innerHTML='Traitement de votre demande en cours...'; }
		};

	if (type==1)
		{
		if (action==1) // Recommandation par mail
			{
			var url='/contact/interact/part-ajax.php';
			//var arg='type=1&elem_no='+elem_no+'&action=mail&rubr_url='+arg;
			var arg='type=1&elem_no='+elem_no+'&action=mail&'+arg;
			}
		else if (action==2) // Réseaux sociaux
			{
			var url='/contact/interact/part-ajax.php';
			var arg='type=1&elem_no='+elem_no+'&action=soc&rubr_url='+arg;
			}
		}
	else if (type==2)
		{
		if (action==1) // Recommandation par mail
			{
			var url='/contact/interact/part-ajax.php';
			var arg='type=2&elem_no='+elem_no+'&action=mail&'+arg;
			}
		}

	httpRequest.open('POST', url, true);
	httpRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	httpRequest.send(arg);
	}


function recomm_envoyer(type,elem_no)
	{
	if (mail_verif(document.getElementById('dest_mail_'+type+'_'+elem_no).value)!=false)
		{
		arg='exp_nom='+document.getElementById('exp_nom_'+type+'_'+elem_no).value+'&dest_mail='+document.getElementById('dest_mail_'+type+'_'+elem_no).value;
		partager_interact(type,elem_no,1,arg);
		}
	else
		{
		document.getElementById('dest_mail_'+type+'_'+elem_no).value='Adresse mail non valide!';
		document.getElementById('dest_mail_'+type+'_'+elem_no).focus();
		document.getElementById('dest_mail_'+type+'_'+elem_no).select();
		}
	}


function interact_dial_fermer(type,elem_no)
    {
	if (type==1) { document.getElementById('rubr_interact_dial').style.display='none'; }
	else if (type==2) { document.getElementById('site_interact_dial_'+elem_no).style.display='none'; }
	}

function mail_verif(emailAddr)
	{
	var i;
	
	// Recherche de @
	i=emailAddr.indexOf('@');
	if (i==-1) { return false; }
	
	// Séparation du nom de l'utilisateur et du nom de domaine.
	var username=emailAddr.substring(0, i);
	var domain=emailAddr.substring(i + 1, emailAddr.length);

	// Recherche des espaces au début du nom de l'utilisateur.
	i = 0;
	while ((username.substring(i,i+1)==' ')&&(i<username.length)) { i++; }
	// Les enlève s'il en trouve.
	if (i > 0) { username = username.substring(i, username.length); }

	// Recherche d'espaces à la fin du nom de domaine.
	i=domain.length-1;
	while ((domain.substring(i, i + 1) ==' ')&&(i>=0)) { i--; }
	// Les enlève s'il en trouve.
	if (i < (domain.length - 1)) { domain = domain.substring(0,i+1); }

	// Vérifie que le nom de l'utilisateur et du domaine ne soit pas vide.
	if ((username=='')||(domain=='')) { return false; }
	
	// Vérifie s'il n'y a pas de caractères interdits dans le nom de l'utilisateur.
	var ch;
	for (i = 0; i < username.length; i++)
		{
		ch = (username.substring(i, i + 1)).toLowerCase();
		if (!(((ch >= 'a') && (ch <= 'z')) || 
			((ch >= '0') && (ch <= '9')) ||
			(ch == '_') || (ch == '-') || (ch == '.')))
			{ return false; }
		}
	
	// Vérifie s'il n'y a pas de caractères interdits dans le nom de domaine
	for (i = 0; i < domain.length; i++) {
		ch = (domain.substring(i, i + 1)).toLowerCase();
		if (!(((ch >= 'a') && (ch <= 'z')) || 
			((ch >= '0') && (ch <= '9')) ||
			(ch == '_') || (ch == '-') || (ch == '.')))
			{ return false; }
		}

	var aSuffix = new Array('com','net','int','aero','biz','museum','name','info','coop','pro','eu','edu','org','gov','mil','bj','dz','de','ad','be','ca','bf','bi','cm','cf','cg','cd','ci','dj','fr','ga','gp','gf','lu','mg','ml','ma','mq','mr','mc','nc','pf','re','pm','sn','ch','td','tf','tn');
	var bFoundSuffix = false;
	i = 0;
	while (i < aSuffix.length)
		{
		if (('.' + aSuffix[i]) == domain.substring(domain.length - aSuffix[i].length - 1, domain.length))
			{ return true; }
		i++;
		}
	return false;
	}	
	

