function show(id){         
	eval("document.getElementById('"+id+"').style.display = 'block'");
	document.cookie = id + "=" + escape('block') + "; path=/";
}

function hide(id){  
	eval("document.getElementById('"+id+"').style.display = 'none'");
	document.cookie = id + "=" + escape('none') + "; path=/";
}
function ChargeEmbed(){  
	if(document.getElementById('pub')) {
		hide('pub');
	}
	if(document.getElementById("pub_default")) {
        hide('pub_default');
	}
	show('bgbc');
	$("#player_wrapper").show();
	hitstat("videobegin");
}
function DisplayDefaultad(){  
        hide('pub');
        //hide('bgbc') ;
        show('pub_default');
    if(document.getElementById("duree_default")){
        var duree=document.getElementById("duree_default").value;
        chronopubroll(((duree)/1000));
        document.getElementById("code_enc").value=document.getElementById("code_enc_default").value;
        hitstat(); 
    }
}

function Chargeduree_embed() {
	if(document.getElementById("duree")){
		var duree=document.getElementById("duree").value;
		chronopubroll(((duree)/1000));
         hitstat();
	}
}

function endad() {
ChargeEmbed();
}

function noad() {
	if(document.getElementById("duree_default")){
		DisplayDefaultad();
	}else{
		ChargeEmbed();
	}
}

function displaypub(){
hitstat();
}


function chronopubroll(secondepubroll){
	secondepubroll--;
	if(secondepubroll == 0){
		ChargeEmbed();
		return;
	}
	writediv(secondepubroll,'chronopubroll');
	
	toto = setTimeout('chronopubroll('+secondepubroll+')',1000);
	
}


function writediv(texte,div){
     document.getElementById(div).innerHTML = texte;
     }



function hitstat(action, code) {
	if (typeof action == 'undefined') {
		action = "adbegin";
	}
	
	if( typeof code == 'undefined' ){
		var code_enc = document.getElementById("code_enc").value;
		//alert(code_enc);
	}else{
		var code_enc = code;
	}

    var xhr;
    if(window.XMLHttpRequest || window.ActiveXObject)
    {
        if(window.XMLHttpRequest)
            xhr = new XMLHttpRequest();
        else
        {
            try   {xhr = new ActiveXObject("Msxml2.XMLHTTP");}
            catch(e)    {xhr = new ActiveXObject("Microsoft.XMLHTTP");}
        }
    }
    else
        return;
    
    xhr.onreadystatechange = function() {
        if(xhr.readyState == 4 && (xhr.status == 200 || xhr.status == 0))
        {
            reponse = xhr.responseText;
        }
    };
        
    xhr.open("GET", "/deliver/statistiques/" + action + "/code_enc/" + code_enc, true);
    xhr.send(null);
}

 function remainingTime(time)
	{
		document.getElementById('time').innerHTML = time;
	}

/*window.onload = function () {
	
	// Si la vidéo de preview existe, on lance la pub au clic dessus
	if (document.getElementById("videoPreviewLayer")) {
		document.getElementById("adOverlay").onclick = function() {
			hide("videoPreviewLayer");
			show("adWrapper");
			Chargeduree_embed();
			if (typeof VideoAdRoll != "undefined") {
				VideoAdRoll.cleanAndShow();
			}
		}
	} else {
		Chargeduree_embed();
	} 
}  */

