/*
* Author:      Marco Kuiper (http://www.marcofolio.net/)
*/
google.load("jquery", "1.3.1");
google.setOnLoadCallback(function()
{
	// Safely inject CSS3 and give the search results a shadow
	var cssObj = { 'box-shadow' : '#888 5px 10px 10px', // Added when CSS3 is standard
		'-webkit-box-shadow' : '#888 5px 10px 10px', // Safari
		'-moz-box-shadow' : '#888 5px 10px 10px'}; // Firefox 3.5+
	$("#suggestions").css(cssObj);
	
	// Fade out the suggestions box when not active
	 $("input").blur(function(){
	 	$('#suggestions').fadeOut();
	 });
});

function lookup(inputString) {
	if(inputString.length == 0) {
		$('#suggestions').fadeOut(); // Hide the suggestions box
	} else {
		$.post("search.php", {queryString: ""+inputString+""}, function(data) { // Do an AJAX call
			$('#suggestions').fadeIn(); // Show the suggestions box
			$('#suggestions').html(data); // Fill the suggestions box
		});
	}
}


var xhr = null; 
var erreur=0;
function getXhr(){
				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; 
				} 
			}
			
function toogle(objet){ 
if(document.getElementById(objet).style.display == "block") { 
document.getElementById(objet).style.display = "none";
}
else { 
document.getElementById(objet).style.display = "block";
} 
}

function afficher(objet){ 
document.getElementById(objet).style.display = "block";
}
function masquer(objet){ 
document.getElementById(objet).style.display = "none";
}
function alaffiche_questions() {
	toogle('alaffiche_modules_questions');
	masquer('alaffiche_modules_prevenir');
	masquer('alaffiche_modules_avertir');
	if (document.getElementById("alaffiche_lien_question").className=="alaffiche_modules_container_over") {
			document.getElementById("alaffiche_lien_question").className = "alaffiche_modules_container_normal";
			document.getElementById("alaffiche_lien_prevenir").className = "alaffiche_modules_container_normal";
			document.getElementById("alaffiche_lien_avertir").className = "alaffiche_modules_container_normal";
		}
		else {
			document.getElementById("alaffiche_lien_question").className = "alaffiche_modules_container_over";
			document.getElementById("alaffiche_lien_prevenir").className = "alaffiche_modules_container_normal";
			document.getElementById("alaffiche_lien_avertir").className = "alaffiche_modules_container_normal";
		}
}
function alaffiche_prevenir() {
	toogle('alaffiche_modules_prevenir');
	masquer('alaffiche_modules_questions');
	masquer('alaffiche_modules_avertir');
	if (document.getElementById("alaffiche_lien_prevenir").className=="alaffiche_modules_container_over") {
			document.getElementById("alaffiche_lien_prevenir").className = "alaffiche_modules_container_normal";
			document.getElementById("alaffiche_lien_question").className = "alaffiche_modules_container_normal";
			document.getElementById("alaffiche_lien_avertir").className = "alaffiche_modules_container_normal";
		}
		else {
			document.getElementById("alaffiche_lien_prevenir").className = "alaffiche_modules_container_over";
			document.getElementById("alaffiche_lien_question").className = "alaffiche_modules_container_normal";
			document.getElementById("alaffiche_lien_avertir").className = "alaffiche_modules_container_normal";
	}
}
function alaffiche_avertir() {
	toogle('alaffiche_modules_avertir');
	masquer('alaffiche_modules_questions');
	masquer('alaffiche_modules_prevenir');
	if (document.getElementById("alaffiche_lien_avertir").className=="alaffiche_modules_container_over") {
			document.getElementById("alaffiche_lien_prevenir").className = "alaffiche_modules_container_normal";
			document.getElementById("alaffiche_lien_question").className = "alaffiche_modules_container_normal";
			document.getElementById("alaffiche_lien_avertir").className = "alaffiche_modules_container_normal";
		}
		else {
			document.getElementById("alaffiche_lien_avertir").className = "alaffiche_modules_container_over";
			document.getElementById("alaffiche_lien_question").className = "alaffiche_modules_container_normal";
			document.getElementById("alaffiche_lien_prevenir").className = "alaffiche_modules_container_normal";
	}
}
function bientot_questions_1() {
	toogle('modules_bientot_1_questions');
	masquer('modules_bientot_1_avertir');
	masquer('modules_bientot_2_questions');
	masquer('modules_bientot_2_avertir');
	if (document.getElementById("modules_bientot_1_liens_questions").className=="bientot_modules_liens_over") {
			document.getElementById("modules_bientot_1_liens_questions").className = "bientot_modules_liens";
			document.getElementById("modules_bientot_2_liens_questions").className = "bientot_modules_liens";
			document.getElementById("modules_bientot_1_liens_avertir").className = "bientot_modules_liens";
			document.getElementById("modules_bientot_2_liens_avertir").className = "bientot_modules_liens";
		}
		else {
			document.getElementById("modules_bientot_1_liens_questions").className = "bientot_modules_liens_over";
			document.getElementById("modules_bientot_2_liens_questions").className = "bientot_modules_liens";
			document.getElementById("modules_bientot_1_liens_avertir").className = "bientot_modules_liens";
			document.getElementById("modules_bientot_2_liens_avertir").className = "bientot_modules_liens";
	}
}

function bientot_questions_2() {
	toogle('modules_bientot_2_questions');
	masquer('modules_bientot_1_avertir');
	masquer('modules_bientot_1_questions');
	masquer('modules_bientot_2_avertir');
	if (document.getElementById("modules_bientot_2_liens_questions").className=="bientot_modules_liens_over") {
			document.getElementById("modules_bientot_1_liens_questions").className = "bientot_modules_liens";
			document.getElementById("modules_bientot_2_liens_questions").className = "bientot_modules_liens";
			document.getElementById("modules_bientot_1_liens_avertir").className = "bientot_modules_liens";
			document.getElementById("modules_bientot_2_liens_avertir").className = "bientot_modules_liens";
		}
		else {
			document.getElementById("modules_bientot_2_liens_questions").className = "bientot_modules_liens_over";
			document.getElementById("modules_bientot_1_liens_questions").className = "bientot_modules_liens";
			document.getElementById("modules_bientot_1_liens_avertir").className = "bientot_modules_liens";
			document.getElementById("modules_bientot_2_liens_avertir").className = "bientot_modules_liens";
	}
}
function bientot_avertir_1() {
	toogle('modules_bientot_1_avertir');
	masquer('modules_bientot_2_avertir');
	masquer('modules_bientot_1_questions');
	masquer('modules_bientot_2_questions');
	if (document.getElementById("modules_bientot_1_liens_avertir").className=="bientot_modules_liens_over") {
			document.getElementById("modules_bientot_1_liens_questions").className = "bientot_modules_liens";
			document.getElementById("modules_bientot_2_liens_questions").className = "bientot_modules_liens";
			document.getElementById("modules_bientot_1_liens_avertir").className = "bientot_modules_liens";
			document.getElementById("modules_bientot_2_liens_avertir").className = "bientot_modules_liens";
		}
		else {
			document.getElementById("modules_bientot_1_liens_avertir").className = "bientot_modules_liens_over";
			document.getElementById("modules_bientot_2_liens_questions").className = "bientot_modules_liens";
			document.getElementById("modules_bientot_1_liens_questions").className = "bientot_modules_liens";
			document.getElementById("modules_bientot_2_liens_avertir").className = "bientot_modules_liens";
	}
}
function bientot_avertir_2() {
	toogle('modules_bientot_2_avertir');
	masquer('modules_bientot_1_avertir');
	masquer('modules_bientot_1_questions');
	masquer('modules_bientot_2_questions');
	if (document.getElementById("modules_bientot_2_liens_avertir").className=="bientot_modules_liens_over") {
			document.getElementById("modules_bientot_1_liens_questions").className = "bientot_modules_liens";
			document.getElementById("modules_bientot_2_liens_questions").className = "bientot_modules_liens";
			document.getElementById("modules_bientot_1_liens_avertir").className = "bientot_modules_liens";
			document.getElementById("modules_bientot_2_liens_avertir").className = "bientot_modules_liens";
		}
		else {
			document.getElementById("modules_bientot_2_liens_avertir").className = "bientot_modules_liens_over";
			document.getElementById("modules_bientot_2_liens_questions").className = "bientot_modules_liens";
			document.getElementById("modules_bientot_1_liens_questions").className = "bientot_modules_liens";
			document.getElementById("modules_bientot_1_liens_avertir").className = "bientot_modules_liens";
	}
}

function isEmail2(who) {
    var email=/^[A-Za-z0-9]+([_\.-][A-Za-z0-9]+)*@[A-Za-z0-9]+([_\.-][A-Za-z0-9]+)*\.([A-Za-z]){2,4}$/i;
    return(email.test(who));
}


		/**
		* POSEZ VOS QUESTIONS
		*/
function questions(id_chat)
{
	//
	var pseudo = eval("document.getElementById('pseudo"+id_chat+"').value");
	var email = eval("document.getElementById('email"+id_chat+"').value");
	var question = eval("document.getElementById('question"+id_chat+"').value");
	var information_cc_grandialogue = eval("document.getElementById('information_questions"+id_chat+"').checked==true?'1':'0'");
	var titre_questions = eval("document.getElementById('titre_questions"+id_chat+"')");
	
	/*var id_chat = document.form_questions.id_chat.value;
	var pseudo = document.form_questions.pseudo.value;
	var email = document.form_questions.email.value;
	var question = document.form_questions.question.value;
	var information_cc_grandialogue = document.form_questions.information_cc_grandialogue.checked==true?'1':'0';*/
	titre_questions.innerHTML ='';
	if( pseudo == '') {
		titre_questions.innerHTML = 'Merci de saisir votre nom ou pseudo !';
	}
	// else if (email == '') {
	// 	titre_questions.innerHTML = 'Merci de saisir votre e-mail !';
	// }
	// else if (!isEmail2(email)){
	// 	titre_questions.innerHTML = 'Merci de vérifier votre e-mail !';
	// }
	else if (question == '') {
		titre_questions.innerHTML = 'Merci de poser une question !';
	}
	
	else {
	getXhr();
	xhr.onreadystatechange = function()
	{
		titre_questions.innerHTML = '<img src="images/spinner.gif">';
		if(xhr.readyState == 4 && xhr.status == 200)
		{
			yoyo = xhr.responseText;
			titre_questions.innerHTML = yoyo;
			eval("document.getElementById('question"+id_chat+"').value=''");
		}
	}
	xhr.open("POST","../modules/questions.php",true);
	xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xhr.send("pseudo="+pseudo+"&email="+email+"&question="+question+"&id_chat="+id_chat+"&information_cc_grandialogue="+information_cc_grandialogue);
}
}

		/**
		* PREVENIR VOS AMIES
		*/
function prevenir(id_chat)
{
	var email_exp = eval("document.getElementById('email_exp"+id_chat+"').value");
	var email_dest = eval("document.getElementById('email_dest"+id_chat+"').value");
	var message = eval("document.getElementById('message"+id_chat+"').value");
	var information_cc_grandialogue = eval("document.getElementById('information_prevenir"+id_chat+"').checked==true?'1':'0'");
	var titre_prevenir = eval("document.getElementById('titre_prevenir"+id_chat+"')");
	/*
	var id_chat = document.form_prevenir.id_chat.value;
	var email_exp = document.form_prevenir.email_exp.value;
	var email_dest = document.form_prevenir.email_dest.value;
	var message = document.form_prevenir.message.value;
	var information_cc_grandialogue = document.form_prevenir.information_cc_grandialogue.checked==true?'1':'0';
	*/
	titre_prevenir.innerHTML ='';
	if (email_exp == '') {
		titre_prevenir.innerHTML = 'Merci de saisir votre e-mail !';
	}
	else if (!isEmail2(email_exp)){
		titre_prevenir.innerHTML = 'Merci de vérifier votre e-mail !';
	}
	else if (email_dest == '') {
		titre_prevenir.innerHTML = 'Merci de saisir l\'e-mail de votre ami(e) !';
	}
	else if (!isEmail2(email_dest)){
		titre_prevenir.innerHTML = 'Merci de vérifier l\'e-mail de votre ami(e) !';
	}
	
	else {
	getXhr();
	xhr.onreadystatechange = function()
	{
		titre_prevenir.innerHTML = '<img src="images/spinner.gif">';
		if(xhr.readyState == 4 && xhr.status == 200)
		{
			yoyo = xhr.responseText;
			titre_prevenir.innerHTML = yoyo;
		}
	}
	xhr.open("POST","../modules/prevenir.php",true);
	xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xhr.send("email_exp="+email_exp+"&email_dest="+email_dest+"&message="+message+"&id_chat="+id_chat+"&information_cc_grandialogue="+information_cc_grandialogue);
}}


		/**
		* AVERTIR
		*/
function avertir(id_chat)
{
	var email_avertir = eval("document.getElementById('email_avertir"+id_chat+"').value");
	var sms = eval("document.getElementById('sms"+id_chat+"').value");
	var information_cc_grandialogue = eval("document.getElementById('information_avertir"+id_chat+"').checked==true?'1':'0'");
	var titre_avertir = eval("document.getElementById('titre_avertir"+id_chat+"')");
	//alert (document.getElementById('email_avertir').value);
	/*
	var id_chat = document.form_avertir.id_chat.value;
	var email = document.form_avertir.email.value;
	var sms = document.form_avertir.sms.value;
	var information_cc_grandialogue = document.form_avertir.information_cc_grandialogue.checked==true?'1':'0';
	*/
	if (email_avertir == '') {
		titre_avertir.innerHTML = 'Merci de saisir votre e-mail !';
	}
	else if (!isEmail2(email_avertir)){
		titre_avertir.innerHTML = 'Merci de vérifier votre e-mail !';
	}
	else if (isNaN(sms)==true){
		titre_avertir.innerHTML = 'Merci de vérifier votre numéro de téléphone !';
	}
	
	else {
	getXhr();
	xhr.onreadystatechange = function()
	{
		titre_avertir.innerHTML = '<img src="images/spinner.gif">';
		if(xhr.readyState == 4 && xhr.status == 200)
		{
			yoyo = xhr.responseText;
			titre_avertir.innerHTML = yoyo;
		}
	}
	xhr.open("POST","../modules/avertir.php",true);
	xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xhr.send("email="+email_avertir+"&sms="+sms+"&id_chat="+id_chat+"&information_cc_grandialogue="+information_cc_grandialogue);
		}

}

		/**
		* alerte
		*/
function alerte()
{

	var email = document.form_alerte.email.value;

	if (!isEmail2(email)){
		document.getElementById('titre_alerte').innerHTML = 'Merci de vérifier votre e-mail !';
	}
	else {
	getXhr();
	xhr.onreadystatechange = function()
	{
		document.getElementById('titre_alerte').innerHTML = '<img src="images/spinner.gif">';
		if(xhr.readyState == 4 && xhr.status == 200)
		{
			yoyo = xhr.responseText;
			document.getElementById('titre_alerte').innerHTML = yoyo;
			/*document.getElementById('valider_alerte').innerHTML = '<input type="button" name="valider" value="Valider" id="valider" class="alerte_valider" onclick="javascript:void(0);">';*/
		}
	}
	xhr.open("POST","../modules/alerte.php",true);
	xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xhr.send("email="+email);
}}