var time = 120; //time in seconds
var interval = time * 1000;
var timer;

function startDecount(){
	timer = setInterval("stopStream()", interval);
}

function stopStream (){
	document.getElementById("lowres").innerHTML = '<img src="img/fleche1.gif" width="446px" height="312px" />';
	clearInterval(timer);
	//document.getElementsByTagName("meta")[0].content = "96000";
	goStage2();
}


function goStage2(){
	document.getElementById("catcher").style.display = "block";
	document.getElementById("market1").style.display = "none";
	document.getElementById("confirm").style.display = "none";
	window.scrollTo(0,1);
	window.scrollTo(0,0);
}

function goStage3(mail){
	document.getElementById("email").innerHTML = mail;
	document.getElementById("catcher").style.display = "none";
	document.getElementById("market1").style.display = "none";
	document.getElementById("confirm").style.display = "block";
}

// catcher
function sendCatch()
{
    var xhr=null;
    
    if (window.XMLHttpRequest) { 
        xhr = new XMLHttpRequest();
    }
    else if (window.ActiveXObject) 
    {
        xhr = new ActiveXObject("Microsoft.XMLHTTP");
    }
    
    xhr.open("POST", "index.php", true);
    
    //on definit l'appel de la fonction au retour serveur
    xhr.onreadystatechange = function() {
        if(xhr.readyState == 4 && 200 == xhr.status){
			//alert(xhr.responseText);
			if(xhr.responseText == "0"){
				document.getElementById("contact_mail").value="mail incorrect";
				window.scrollTo(0,1);
				window.scrollTo(0,0);
			}
			else {
				goStage3(xhr.responseText);
				window.scrollTo(0,1);
				window.scrollTo(0,0);
			}
		}
	}

	xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	var data = "d=0&p=01&contact_mail="+document.getElementById("contact_mail").value;
	xhr.send(data);
}

function cookiesEnabled() {
	document.cookie = "test=cookiesEnabled";
	var pos = document.cookie.indexOf( "test=" );
	if ( pos ==  - 1 ) {
		return false;
	} return true;
}

function bookmark() {

	title = document.title; 
	url = location.href;

	if (window.sidebar) { // Mozilla Firefox Bookmark
		window.sidebar.addPanel(title, url,"");
	} else if( window.external ) { // IE Favorite
		window.external.AddFavorite( url, title); }
	else if(window.opera && window.print) { // Opera Hotlist
		return true; }
}

function startDecountIframe(time2){
	var pos = document.cookie.indexOf( "time=" );
	if ( pos ==  - 1 ) {
		document.cookie = "time="+time2;
	}
	timer2 = setInterval("majCookie()", 5000);
}

function majCookie(){
	cookies = document.cookie;
	tab = cookies.split(";"); 
	
	for (i = 0; i < tab.length; i++){
		var pos = (tab[i]).indexOf( "time=" );
		if ( pos !=  - 1 ) {
			secondes = ((tab[i]).split("=")[1])*1;
			document.cookie = "time="+(secondes - 5);
			
			if(secondes == 0){
				clearInterval(timer2);
				document.getElementById("market1").innerHTML = '&nbsp;';
				goStage2();
			}
				
			break;
		}
	}
}

function email_focus(form_name)
{
	e = document.getElementById(form_name).contact_mail;
	if (e.value == '@') e.value = '';
}
function email_blur(form_name)
{
	e = document.getElementById(form_name).contact_mail;
	if (e.value == '@' || e.value == '')
	{
		e.value = '@';
	}
}