// JavaScript Document
l = 0;
w = 0;
opp = 0;
boxsize = 280;

function construct(){
	
	if(window.XMLHttpRequest) // FIREFOX
			return new XMLHttpRequest();
		else if(window.ActiveXObject) // IE
			return new ActiveXObject("Microsoft.XMLHTTP");
		else
			return(false);
}
function getPageSizeWithScroll(){
	if (window.innerHeight && window.scrollMaxY) {// Firefox
		yWithScroll = window.innerHeight + window.scrollMaxY;
		xWithScroll = window.innerWidth + window.scrollMaxX;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		yWithScroll = document.body.scrollHeight;
		xWithScroll = document.body.scrollWidth;
	} else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari
		yWithScroll = document.body.offsetHeight;
		xWithScroll = document.body.offsetWidth;
  	}
	arrayPageSizeWithScroll = new Array(xWithScroll,yWithScroll);
	//alert( 'The height is ' + yWithScroll + ' and the width is ' + xWithScroll );
	return arrayPageSizeWithScroll;
}
function getScrollPosition(){
    return Array((document.documentElement && document.documentElement.scrollLeft) || window.pageXOffset || self.pageXOffset || document.body.scrollLeft,(document.documentElement && document.documentElement.scrollTop) || window.pageYOffset || self.pageYOffset || document.body.scrollTop);
}
function alertbx(data){
	
	scroller2 = getScrollPosition();

	//pos = scroller2[1]+((document.body.clientHeight-boxsize)/2);
	pos = scroller2[1]+((haut_s-250)/2);
	
	document.getElementById('alert_fond').style.height = haut+'px';
	document.getElementById('alert_fond').style.width = larg+'px';
	document.getElementById('alert_fond').style.display = 'block';
	
	document.getElementById('alert_cont').style.height = '0px';
	document.getElementById('alert_cont').style.width = '0px';
	document.getElementById('alert_cont').style.marginTop = pos+'px';

	document.getElementById('alert_data').innerHTML = data;
	timer = setInterval("showbox()", 1);

}
function showbox(){
	
	if(l < boxsize){
		l += 16;
		w += 30;
		
		if(opp < 100){
			opp += 4;
		}
		
		document.getElementById('alert_cont').style.height = l+'px';
		document.getElementById('alert_cont').style.width = w+'px';
	}
	else{
		document.getElementById('alert_data').style.display = 'block';
		clearInterval(timer);
		
		var allscript = document.getElementById('alert_data').getElementsByTagName('script');
    	for(var i=0;i< allscript.length;i++){
     		 global.eval(allscript[i].text);
   		}
	}
	
}
function clearbx(){
	document.getElementById('alert_fond').style.display = 'none';
	document.getElementById('alert_data').style.display = 'none';
	l = 0;
	w = 0;
	opp = 0;
}
function boxloader(url){ // loader ajax asynchrone
	xhr_object = construct();
	xhr_object.onreadystatechange = function(){
		if(this.readyState == 4){
			if(this.status == 200){
				res = this.responseText;
				alertbx(res);
			}
			else{
				alert('Erreur lors de la recherche');
			}
		}
	};
	xhr_object.open("GET", url, true);
	xhr_object.send(null);
}
function warnprod(email,id){
	
	xhr_object = construct();
	xhr_object.onreadystatechange = function(){
		if(this.readyState == 4){
			if(this.status == 200){
				
			}
			clearbx();
		}
	};
	xhr_object.open("GET", '/services.php?mode=warnprod&id='+id+'&email='+email, true);
	xhr_object.send(null);
	
}
function recover_pass(email){
	
	xhr_object = construct();
	xhr_object.onreadystatechange = function(){
		if(this.readyState == 4){
			if(this.status == 200){
				alert('Demande prise en compte !');
			}
			clearbx();
		}
	};
	xhr_object.open("GET", '/services.php?mode=recover&email='+email, true);
	xhr_object.send(null);
}
function rebour(conteneur,limit){
	id = setInterval("uprebour('"+conteneur+"','"+limit+"')", 1000);
}
function showflash(){
	document.getElementById('flashrecap').style.visibility = "visible";
}
function hideflash(){
	document.getElementById('flashrecap').style.visibility = "hidden";
}
function uprebour(conteneur,limit){
	
	var now = Math.floor((new Date()).getTime() / 1000);
	var rest = limit-now;
	
	if(rest > 0){
		
		jour = Math.floor(rest/86400);
		heure = Math.floor(rest/3600)-jour*24;
		minute = Math.floor(rest/60)-jour*1440-heure*60;
		
		second = rest-jour*86400-heure*3600-minute*60;
		var texte = '<span style="font-size:10px; color:#333">Temps restant avant la fin de la vente :</span><br> <span style="color:#FF0000; font-size:14px"><b>';
		
		if(jour > 0){
			texte += jour+" jours ";
		}
		if(heure > 0){
			texte += heure+" h ";
		}
		if(minute >= 0){
			texte += minute+" min ";
		}
		if(second >= 0){
			texte += second+" s";
		}
		
		texte += "</b></span>";
		document.getElementById(conteneur).innerHTML = texte;
		
	}
	else{
		document.getElementById(conteneur).innerHTML = "Vente flash terminée";
	}
	
}
