// OUVERTURE DU POPUP

function envoyer(type,dest,che,pays) {
	
	installBackground();
	cont = document.getElementById('contenu');
	cont.innerHTML = '<div id="bloc_envoyer_ami_bg"></div><div id="bloc_envoyer_ami"><div id="close_envoyer_ami" onclick="close_envoyer_ami();"></div><img style="margin:184px 0 0 184px;" src="'+che+'style/wait.gif"></div>'+cont.innerHTML;
	
	c = document.getElementById('bloc_envoyer_ami');
	bg = document.getElementById('bloc_envoyer_ami_bg');
	
	h_tr = getVisibleHeightPage();
	c_top = getScrollTop();
	aaa = c_top+((parseInt(h_tr)-c.offsetHeight)/2);
	aaa2 = aaa-20;
	c.style.top=aaa+'px';
	c.style.display='block';
	bg.style.top=aaa2+'px';
	bg.style.display='block';
	
	var xhr;
	if (window.XMLHttpRequest) {
		xhr = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		xhr = new ActiveXObject('Microsoft.XMLHTTP');
	}
	xhr.open('POST',che+'envoyer.php?dest='+dest,true);
	xhr.onreadystatechange = function() {
		if (xhr.readyState == 4) {
			if(type=='calculateur') {
				tab = xhr.responseText.split('|||');
				c.innerHTML = tab[2];
				calculette(1,tab[0],tab[1],document.getElementById('chrono1'));
			} else {
				c.innerHTML = xhr.responseText;
			}
		} 
	}
	xhr.setRequestHeader('Content-type','application/x-www-form-urlencoded');			
	xhr.send(type+'=1&che='+che+'&pays='+pays);

}
// FERMETURE POPUP
function close_envoyer_ami() {
	c = document.getElementById('bloc_envoyer_ami');
	bg = document.getElementById('bloc_envoyer_ami_bg');
	c.style.display = 'none';
	bg.style.display = 'none';
	desinstallBackground();
}
// ENVOYER LE MESSAGE A UN AMI
function verif_envoyer(che) {
	b = document.getElementById('button_envoyer');
	b.style.display = 'none';
	n = document.getElementById('nom').value;
	e = document.getElementById('email').value;
	a1 = document.getElementById('mail_ami1').value;
	a2 = document.getElementById('mail_ami2').value;
	a3 = document.getElementById('mail_ami3').value;
	a4 = document.getElementById('mail_ami4').value;
	m = document.getElementById('message').value;
	if(n=='' || e=='' || (a1=='' && a2=='' && a3=='' && a4=='') || m=='') {
		alert('Veuillez remplir tous les champs');
		b.style.display = 'inline';
	} else {
		var xhr;
		if (window.XMLHttpRequest) {
			xhr = new XMLHttpRequest();
		} else if (window.ActiveXObject) {
			xhr = new ActiveXObject('Microsoft.XMLHTTP');
		}
		xhr.open('POST',che+'envoyer.php',true);
		xhr.onreadystatechange = function() {
			if (xhr.readyState == 4) {
				alert(xhr.responseText);
			} 
		}
		xhr.setRequestHeader('Content-type','application/x-www-form-urlencoded');			
		xhr.send('verif=1&n='+n+'&e='+e+'&a1='+a1+'&a2='+a2+'&a3='+a3+'&a4='+a4+'&m='+m);
	}
}
// INSCRIPTION NEWSLETTER
function verif_newsletter(che) {
	s = document.getElementById('newsletter_societe');
	if(s.checked==true) {
		s = '1';
	} else {
		s = '0';
	}
	p = document.getElementById('newsletter_page').value;
	e = document.getElementById('newsletter_email').value;
	d = document.getElementById('newsletter_dest').value;
	
	var regex = new RegExp(/^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+.[a-zA-Z]{2,4}$/);
	if(!regex.test(e)) {
		alert('Veuillez indiquer un email valide');
		return;
	}
	document.getElementById('bandeau_bas_btn').style.backgroundPosition = '0 -18px';
	var xhr;
	if (window.XMLHttpRequest) {
		xhr = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		xhr = new ActiveXObject('Microsoft.XMLHTTP');
	}
	xhr.open('POST',che+'envoyer.php',true);
	xhr.onreadystatechange = function() {
		if (xhr.readyState==4) {
			alert(xhr.responseText);
		} 
	}
	xhr.setRequestHeader('Content-type','application/x-www-form-urlencoded');			
	xhr.send('inscription_newsletter=1&e='+e+'&p='+p+'&s='+s+'&d='+d);
	
}

// AJOUTER AU FAVORI
function addToFavorites(clip) {	
	if (navigator.appName != 'Microsoft Internet Explorer' ) {
		window.sidebar.addPanel('Avec Téléfuté, j\'appelle sans me ruiner','http://www.telefute.com','');
	} else {
		window.external.AddFavorite('http://www.telefute.com','Avec Téléfuté, j\'appelle sans me ruiner');
	}
}
// OUVRIR L'EXEMPLE DE FACTURE
function open_facture(che) {
	window.open (che+'style/exemple_facture_grand.gif','facture', config='height=160, width=640, toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=yes, directories=no, status=no');
}
// DESTINATIONS PHARES
function ap_dest(type) {
	c1 = document.getElementById('dest_phares');
	c2 = document.getElementById('dest_phares_liste');
	if(type=='on') {
		c1.style.color='#fff';
		c1.style.borderColor='#cccccc';
		c1.style.backgroundColor='#649949';
		c1.style.backgroundPosition='148px -15px';
		c2.style.display='block';
	} else {	
		c1.style.color='#333';
		c1.style.backgroundColor='#ffffff';
		c1.style.borderColor='#ffffff';
		c1.style.backgroundPosition='148px 5px';
		c2.style.display='none';
	}
}
// HAUTEUR TOTALE DE LA PAGE
function getTotalHeightPage() {
	var h = document.documentElement.scrollHeight;
	if(document.documentElement.clientHeight > h ) {
		h  = document.documentElement.clientHeight;
	}
	if(document.body.scrollHeight > h) {
		h = document.body.scrollHeight;
	}
	return h;
}

// HAUTEUR VISIBLE DE LA PAGE
function getVisibleHeightPage() {
	if (self.innerHeight) {
		h = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { 
		h = document.documentElement.clientHeight;
	} else if (document.body) {
		h = document.body.clientHeight;
	}
	return h;
}

// HAUTEUR DU SCROLL
function getScrollTop() {
	if (document.documentElement && document.documentElement.scrollTop){
		c_top = document.documentElement.scrollTop;
	} else if (document.body) {
		c_top = document.body.scrollTop;
	}
	return c_top;
}
// BACKGROUND TRANSPARENT
function installBackground() {
	document.body.innerHTML += '<div id="background"></div>';
	h = getTotalHeightPage();
	c = document.getElementById('background');
	c.style.height = h+'px';
	c.style.display = 'block';
}
function desinstallBackground() {
	document.getElementById('background').style.display = 'none';
}

