//$frm_user ='fest_user';
//$frm_pwd ='fest_pass';
var frm_user = 'fest_user';
var frm_pwd = 'fest_pass';

function createXmlHttpRequest() {
	try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {}
	try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {}
	try { return new XMLHttpRequest(); } catch(e) {}
	alert("XMLHttpRequest not supported");
	return null;
}
var xhrLogin = createXmlHttpRequest();
function processLogin(dest, username, password) {
	xhrLogin.abort();

	dest.innerHTML = '<img src="/img/loading.gif" /> Connexion en cours';

	var url = "http://www.festivalsfrancais.com/Ajax/login.php";
	var parameters = frm_user + "=" + encodeURIComponent(username);
	parameters += "&" + frm_pwd + "=" + encodeURIComponent(password);

	xhrLogin.open( "POST", url );

	xhrLogin.onreadystatechange = function () {
		if (xhrLogin.readyState == 4) {
			if( xhrLogin.status == 200 ) {
				if (xhrLogin.responseText == 'Login OK') {
					window.location.replace(window.location.href);
				}
				else {
					dest.innerHTML = xhrLogin.responseText;
				}
			}
		}
	}
	xhrLogin.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xhrLogin.send( parameters );
}
function processLogout(dest) {
	xhrLogin.abort();
	
	dest.innerHTML = '<img src="/img/loading.gif" /> Déconnexion en cours';

	var url = "http://www.festivalsfrancais.com/Ajax/login.php?logout=1";
	xhrLogin.open( "GET", url, true );

	xhrLogin.onreadystatechange = function () {
		if (xhrLogin.readyState == 4) {
			if( xhrLogin.status == 200 ) {
				if (xhrLogin.responseText == 'Logout OK') {
					//window.location.reload();
					window.location.replace(window.location.href);
				}
				else {
					dest.innerHTML = xhrLogin.responseText;
				}
			}
		}
	}
	xhrLogin.send( null );
}
