function createRequestObject() {
    var ro;
    var browser = navigator.appName;
    if(browser == "Microsoft Internet Explorer"){
        ro = new ActiveXObject("Microsoft.XMLHTTP");
    }else{
        ro = new XMLHttpRequest();
    }
    return ro;
}

var http = createRequestObject();

function flagProduit(id) {
	
	if (confirm('Cette vidéo ne fonctionne vraiment plus?')){

		var theUL = document.getElementById('flag'); // the UL
		
		// switch UL with a loading div
		theUL.innerHTML = '<img src="img/layout/working.gif">';
		
		http.open('get', 'form-flagproduit.php?id='+id);
		http.onreadystatechange = mbexHandleResponse;
		http.send(null);
	}
	
}

function diggComment(id) {
	var theUL = document.getElementById('comment-'+id); // the UL
	
	// switch UL with a loading div
	theUL.innerHTML = '<img src="img/layout/working.gif">';
	http.open('get', 'form-diggcomment.php?id='+id);
	http.onreadystatechange = mbexHandleResponse;
    http.send(null);
}
function buryComment(id) {
	var theUL = document.getElementById('comment-'+id); // the UL
	
	// switch UL with a loading div
	theUL.innerHTML = '<img src="img/layout/working.gif">';
	http.open('get', 'form-burycomment.php?id='+id);
	http.onreadystatechange = mbexHandleResponse;
    http.send(null);
}

function addFav(id) {
	
	var theUL = document.getElementById(id); // the UL
	
	theUL.innerHTML = '<img src="img/layout/working.gif">';

	http.open('get', 'form-bookmark.php?id='+id);
	/*http.open('get', 'form-bookmark.php?id='+action);*/
	http.onreadystatechange = mbexHandleResponse;
    http.send(null);
	
}

function mbexHandleResponse() {
    if(http.readyState == 4){
        var response = http.responseText;
        var update = new Array();

        if(response.indexOf('|' != -1)) {
            update = response.split('|');
            document.getElementById(update[0]).innerHTML = update[1];
        }
    }
}

function mbexHandleTVResponse() {
    if(http.readyState == 4){
        var response = http.responseText;
        var update = new Array();

        if(response.indexOf('|' != -1)) {
            update = response.split('|');
            document.getElementById('screen').innerHTML = update[1];
        }
    }
}
function addToTVplaylist(id) {
	var theUL = document.getElementById('screen'); // the UL
	
	theUL.innerHTML = '<img src="img/layout/working.gif">';
	
	http.open('get', 'form-addtotvplaylist.php?id='+id);
	http.onreadystatechange = mbexHandleTVResponse;
    http.send(null);
}


function loadProgram(action) {
	http.open('get', 'loadprogram.php?id='+action);
	http.onreadystatechange = mbexHandleTVResponse;
    http.send(null);
}