﻿/*
Includes code from ryan masuga, masugadesign.com
*/

if (window.XMLHttpRequest) { // FIREFOX
	xmlhttp = new XMLHttpRequest();
} else if(window.ActiveXObject) { // IE
	xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} else {
	xmlhttp = false;
}

function post_present_friend(mail, name)
{

	xmlhttp.open('get', '/friend.php?form_DecouverteEmail='+mail+'&form_DecouverteNom='+name+'&action=submit');
	
	xmlhttp.onreadystatechange = handleResponse;
    xmlhttp.send(null);
}


function hide_friend(){
	document.getElementById("present-friend").style.display = "none";
}

function com(form,log)
{
	if(form.commentaire.value=="")
	{
		alert('Aucun commentaire n\'a été saisi');
		return false;
	}
	return true;
}

function sndReq_friend()
{
	document.getElementById("present-friend").style.display = "inline";
    xmlhttp.open('get','/friend.php');

	xmlhttp.onreadystatechange = handleResponse;
    xmlhttp.send(null);
}

function handleResponse() {
  if(xmlhttp.readyState == 4){
		if (xmlhttp.status == 200){
	        var response = xmlhttp.responseText;
	        var update = new Array();
	        if(response.indexOf('|') != -1) {
	            update = response.split('|');
				changeText(update[0], update[1]);
	        }
		}
    }
}

function changeText( div2show, text ) {
    // Detect Browser
    var IE = (document.all) ? 1 : 0;
    var DOM = 0;
    if (parseInt(navigator.appVersion) >=5) {DOM=1};
    if (DOM) {
        var viewer = document.getElementById(div2show);
        viewer.innerHTML = text;
    }  else if(IE) {
        document.all[div2show].innerHTML = text;
    }
}

