/* ---------------------------- */
/* XMLHTTPRequest Enable */
/* ---------------------------- */
function createObject() {
var request_type;
var browser = navigator.appName;
if(browser == "Microsoft Internet Explorer"){
request_type = new ActiveXObject("Microsoft.XMLHTTP");
}else{
request_type = new XMLHttpRequest();
}
return request_type;
}

var http = createObject();

/* -------------------------- */
/* LOGIN */
/* -------------------------- */
/* Required: var nocache is a random number to add to request. This value solve an Internet Explorer cache issue */
var nocache = 0;
function login() {
// Optional: Show a waiting message in the layer with ID ajax_response
document.getElementById('login_response').innerHTML = "Chargement en cours..."
// Required: verify that all fileds is not empty. Use encodeURI() to solve some issues about character encoding.
var email = encodeURI(document.getElementById('emailLogin').value);
var psw = encodeURI(document.getElementById('pswLogin').value);
// Set te random number to add to URL request
nocache = Math.random();
// Pass the login variables like URL variable
http.open('get', 'valid_login.php?email='+email+'&psw='+psw+'&nocache = '+nocache);
http.onreadystatechange = loginReply;
http.send(null);
}
function loginReply() {
if(http.readyState == 4){
var response = http.responseText;
//alert(response);
if(response == 0){
// if login fails
document.getElementById('login_response').innerHTML = 'Votre authentification à échouée, veuillez vérifier votre email et mot de passe';
// else if login is ok show a message: "Welcome + the user name".
} else {
		window.location.href = "nouveau_post.php"
//document.getElementById('login_response').innerHTML = 'Identitication réussie';
}
}
}

function sendemail() {
document.getElementById('login_response').innerHTML = "Chargement en cours..."
var email = encodeURI(document.getElementById('emailLogin').value);
nocache = Math.random();
http.open('get', 'send_email.php?email='+email+'&nocache = '+nocache);
http.onreadystatechange = sendemailReply;
http.send(null);
}
function sendemailReply() {
if(http.readyState == 4){
var response = http.responseText;

if(response == 0){
// if login fails
document.getElementById('login_response').innerHTML = 'Vous n êtes pas autorisé à utiliser ce service ou la saisie de votre adresse mail était erronée.';
// else if login is ok show a message: "Welcome + the user name".
} else {
document.getElementById('login_response').innerHTML = 'Votre mot de passe vous a été envoyé sur boite mail.';
}
}
}

function $RF(radioName){ 
  array=$$('input'); 
  var value=""; 
   
  array.each( 
    function (radio){ 
      if (radio.hasAttribute("name") && radio.readAttribute("name")==radioName) 
        if (radio.checked=="true" || radio.checked) value=radio.getValue();  
    } 
  );//End of each() 
  return value;  
} 

function liste_post(id_theme) {

var checkbox_choices = 0;
id_theme = 0;
// Loop from zero to the one minus the number of checkbox button selections
for (counter = 0; counter < document.getElementsByName("id_theme").length; counter++)
{

// If a checkbox has been selected it will return true
// (If not it will return false)
if (document.getElementsByName("id_theme")[counter].checked)
{ id_theme = (document.getElementsByName("id_theme")[counter].value) ; }

}


		var listeCheckBox = document.getElementsByName("type_support[]");
		var nb = 0;
		var filtre = " and id_theme = " + id_theme;
		for(var i= 0 , l = listeCheckBox.length;i <l ; i++){
			if(listeCheckBox[i].checked){
				if ( nb >0) {
					filtre += " or post.id_support = " + listeCheckBox[i].value;										
				}else{
					filtre += " and (post.id_support = " + listeCheckBox[i].value;								
				}
				nb = nb +1;				
			}
		}
		if ( nb > 0) {
			filtre += " )";									
		}

//alert(filtre);

document.getElementById('liste_post').innerHTML = "Chargement en cours..."
//var email = encodeURI(document.getElementById('emailLogin').value);
nocache = Math.random();
http.open('get', 'detail_liste_post.php?id_theme='+id_theme+'&filtre='+filtre+'&nocache = '+nocache);
http.onreadystatechange = detail_liste_post;
http.send(null);
}

function detail_liste_post() {
if(http.readyState == 4){
var response = http.responseText;

document.getElementById('liste_post').innerHTML = response; 
}
}


