function postComment(){
	
	var idCreation = $F('idCreation');
	var idMember = $F('idMember');
	var cname = $F('name');
	var email = $F('email');
	var description = document.forms['formpost'].elements['description'].value;
	if (description == ''){
		 alert ("Attention ! Vous n'avez pas rentré de message.");
		return -1;
	}
	var opt = {
	    // Use POST
	    method: 'post',
	    // Send this lovely data
	    postBody: 'action=post' + '&idCreation=' + idCreation + '&idMember=' + idMember + '&name=' + escape(cname) + '&description=' + escape(description) + '&email=' + escape(email),
	    // Handle successful response
	    onSuccess: function(t) {
	    	reloadCommentList();
	    	document.getElementById('div-form').style.display='block';
	    	document.getElementById('loading-div').style.display='none';     
	    },
	    // Handle 404
	    on404: function(t) {
	        alert('Error 404: location "' + t.statusText + '" was not found.');
	    },
	    // Handle other errors
	    onFailure: function(t) {
	        alert('Error ' + t.status + ' -- ' + t.statusText);
	    }
	}
	document.getElementById('div-form').style.display='none';
   	document.getElementById('loading-div').style.display='block';     
	new Ajax.Request('/comment/af-comment.php', opt);
}

// Static variable
checkLogin.result = true;
function checkLogin(login){
	
	var opt = {
	    // Use POST
	    method: 'post',
	    // Send this lovely data
	    postBody: 'action=chk_login&login=' + escape(login),
	    // Not Asynchronous
	    asynchronous: false,
	    // Handle successful response
	    onSuccess: function(t) {
	    	checkLogin.result = t.responseText;
	    },
	    // Handle 404
	    on404: function(t) {
	        alert('Error 404: location "' + t.statusText + '" was not found.');
	    },
	    // Handle other errors
	    onFailure: function(t) {
	        alert('Error ' + t.status + ' -- ' + t.statusText);
	    }
	}
	
	new Ajax.Request('/controler/shop/af-shop.php', opt);
	return checkLogin.result;
}

function showPswd(){
	$('pswd-div').style.display = 'block';
	return false;
}

function chgPassword(){
	var msg = '';
	  var error = false;
	if($('b_password').value == "") {
	  	msg += "Vous n'avez pas renseigné votre mot de passe\n";
	  	error = true;
	    // les données sont ok, on peut envoyer le formulaire    
	  }
	  if($('b_password').value != $('b_c_password').value) {
	  	msg += "Les mots de passe que vous avez entré sont différents\n";
	  	error = true;
	    // les données sont ok, on peut envoyer le formulaire    
	  }
	  if (error) {
	  	// sinon on affiche un message
	    alert(msg);
	    // et on indique de ne pas envoyer le formulaire
	    return false;
	
	  }
	var opt = {
	    // Use POST
	    method: 'post',
	    // Send this lovely data
	    postBody: 'action=chg_password&password=' + escape($('b_password').value) + '&id=' + $('b_id').value,
	    // Handle successful response
	    onSuccess: function(t) {
	    	$('pswd-form').style.display = 'block';
	    	$('pswd-div').style.display = 'none';
	    	$('pswd-onload').style.display = 'none';
	    },
	    onLoading: function(t){
	    	$('pswd-onload').style.display = 'block';
	    	$('pswd-form').style.display = 'none';
	    },
	    // Handle 404
	    on404: function(t) {
	        alert('Error 404: location "' + t.statusText + '" was not found.');
	    },
	    // Handle other errors
	    onFailure: function(t) {
	        alert('Error ' + t.status + ' -- ' + t.statusText);
	    }
	}
	
	new Ajax.Request('/controler/shop/af-shop.php', opt);
}

function postShop(){
	
	var id = $F('id');
	var login = $F('login');
	var password = $F('password');
	var sname = $F('name');
	var address = $F('address');
	var city = $F('city');
	var zip = $F('zip');
	var country = $F('country');
	var phone = $F('phone');
	var hours = $F('hours');
	var siren = $F('siren');
	var ape = $F('ape');
	var description = $F('description');
	
	var opt = {
	    // Use POST
	    method: 'post',
	    // Send this lovely data
	    postBody: 'action=post' 
	    + '&id=' + id 
	    + '&login=' + escape(login) 
	    + '&password=' + escape(password) 
	    + '&name=' + escape(sname) 
	    + '&address=' + escape(address)
	    + '&city=' + escape(city)
	    + '&zip=' + escape(zip)
	    + '&country=' + escape(country)
	    + '&phone=' + escape(phone)
	    + '&hours=' + escape(hours)
	    + '&siren=' + escape(siren)
	    + '&ape=' + escape(ape)
	    + 'description=' + escape(description),
	    // Handle successful response
	    onSuccess: function(t) {
	    	reloadCommentList();
	    	//document.getElementById('div-form').style.display='block';
	    	document.getElementById('loading-div').style.display='none';     
	    },
	    // Handle 404
	    on404: function(t) {
	        alert('Error 404: location "' + t.statusText + '" was not found.');
	    },
	    // Handle other errors
	    onFailure: function(t) {
	        alert('Error ' + t.status + ' -- ' + t.statusText);
	    }
	}
	//document.getElementById('div-form').style.display='none';
   	document.getElementById('loading-div').style.display='block';     
	new Ajax.Request('/shop/af-shop.php', opt);
}

function reloadCommentList(){
	var idCreation = $F('idCreation');
	var opt = {
	    // Use POST
	    method: 'post',
	    // Send this lovely data
	    postBody: 'action=reload' + '&idCreation=' + idCreation,
	    // Handle successful response
	    onSuccess: function(t) {
	    	$('af-comment').innerHTML = t.responseText;
	    	  
	    },
	    // Handle 404
	    on404: function(t) {
	        alert('Error 404: location "' + t.statusText + '" was not found.');
	    },
	    // Handle other errors
	    onFailure: function(t) {
	        alert('Error ' + t.status + ' -- ' + t.statusText);
	    }
	}
	new Ajax.Request('/comment/af-comment.php', opt);
}
