// JavaScript Document

var ajax_http;
var ajax_id;

function createRequestObject(){
    var http;
	
    if(window.XMLHttpRequest){ 
		// Mozilla, Safari, ...
        http = new XMLHttpRequest();
    }
    else if(window.ActiveXObject){ 
		// Internet Explorer
        http = new ActiveXObject("Microsoft.XMLHTTP");
    }
    return http;
}

function sendRequest(url, id){
	ajax_id = id;
	ajax_http = createRequestObject();
	ajax_http.open('get', url, true);
	ajax_http.onreadystatechange = handleAJAXReturn;
	ajax_http.send(null);
}

function handleAJAXReturn(){
    if(ajax_http.readyState == 4){
        if(ajax_http.status == 200){
            // Utilisation du résultat
			document.getElementById(ajax_id).innerHTML = ajax_http.responseText;
			
			/*var contentElement = document.getElementById('fc');
			var contentHeight = contentElement.offsetHeight;
			
			var windowHeight = getWindowHeight();
			
			var footerElement = document.getElementById('footer');
			var footerHeight = footerElement.offsetHeight;
			
			footerElement.style.marginTop = (windowHeight - contentHeight - footerHeight - 95) +"px";*/
			//setTimeout('test();', 500);
			test();
        }
		else document.getElementById(ajax_id).innerHTML = "Error";
    }
	else document.getElementById(ajax_id).innerHTML = '<div style="text-align:center;"><img src="../IMG/ajax-loader.gif" /></div>';
}

function test(){
	var footerElement = document.getElementById('footer');
	var footerHeight = 41;
	footerElement.style.marginTop = "0px";
	
	var contentElement = document.getElementById('fc');
	var contentHeight = contentElement.offsetHeight;
	
	var windowHeight = getWindowHeight();

	if(contentHeight + footerHeight + 85 <= windowHeight){
		tmp = windowHeight - contentHeight - footerHeight - 85;
		footerElement.style.marginTop = tmp+"px";
	}
	else{
		footerElement.style.marginTop = "10px";
	}
}
