// JavaScript Document
var isIE, isIE6 = false, isIE7 = false,
 isFIREFOX2 = false, isFIREFOX = false,
 isNETSCAPE7 = false, isNETSCAPE = false,
 isOPERA9 = false, isOPERA = false,
 isGGChrome = false,
 isUNKNOWN = false; 

var strChUserAgent = navigator.userAgent;
 var intSplitStart = strChUserAgent.indexOf("(",0);
 var intSplitEnd = strChUserAgent.indexOf(")",0);
 var strChStart = strChUserAgent.substring(0,intSplitStart);
 var strChMid = strChUserAgent.substring(intSplitStart, intSplitEnd);
 var strChEnd = strChUserAgent.substring(strChEnd);

 if(strChMid.indexOf("MSIE 7") != -1)
 isIE7 = true;
 else if(strChMid.indexOf("MSIE 6") != -1)
 isIE6 = true;
 else if(strChEnd.indexOf("Firefox/2") != -1)
 isFIREFOX2 = true;
 else if(strChEnd.indexOf("Firefox") != -1)
 isFIREFOX = true;
 else if(strChEnd.indexOf("Netscape/7") != -1)
 isNETSCAPE7 = true;
 else if(strChEnd.indexOf("Netscape") != -1)
 isNETSCAPE = true;
 else if(strChStart.indexOf("Opera/9") != -1)
 isOPERA9 = true;
 else if(strChStart.indexOf("Opera") != -1)
 isOPERA = true;
 else if(navigator.userAgent.toLowerCase().indexOf('chrome') > -1) 
 isGGChrome = true ;
 else
 isUNKNOWN = true;
 
 if (isIE6 || isIE7)  isIE = true ;


var windowWidth, windowHeight ;

if (isIE) {
	if (document.documentElement) 
		 windowWidth = parseInt(document.documentElement.clientWidth)
	else windowWidth = parseInt(document.body.clientWidth) ;        
}
else  windowWidth = parseInt(window.innerWidth) ;        


if (isIE) {
	if (document.documentElement) 
		  windowHeight = parseInt(document.documentElement.clientHeight)
	else  windowHeight = parseInt(document.body.clientHeight) ;        
}
else  windowHeight = parseInt(window.innerHeight) ; 




var _overlay_  ;
function overlay() {
	
	var container = false ;
	var input_email = false ;
	var input_ico = false ;
	
	this.setCookie = function () {
	
	   var expire = new Date();
		var delay = expire.getTime() + (2 * 30 * 24  *60 * 60 * 1000);	
        
		expire.setTime(delay);
	
		EcrireCookie("Propos_Inscription",1, expire, "/")  ; 
	
	}
		
	
	this.close = function() {
		
		
		var windowWidth, windowHeight ;

		if (isIE) {
			if (document.documentElement) 
				 windowWidth = parseInt(document.documentElement.clientWidth)
			else windowWidth = parseInt(document.body.clientWidth) ;        
		}
		else  windowWidth = parseInt(window.innerWidth) ;        
		
		
		if (isIE) {
			if (document.documentElement) 
				  windowHeight = parseInt(document.documentElement.clientHeight)
			else  windowHeight = parseInt(document.body.clientHeight) ;        
		}
		else  windowHeight = parseInt(window.innerHeight) ;
		
		
		var finalTop = (windowHeight - parseInt(container.style.height)) ;
		
		var effect = new Effect.Tween(null, finalTop, windowHeight + 125, {duration:0.4}, function (top) {
			container.style.top = top + "px" ;				
		});	
		
		_overlay_.setCookie() ;
		

	}	
	
	this.inputClickHandler = function () {
		

		if (input_email.value == "Entre ton adresse email ici...") {
			input_email.value = "" ;			
			input_email.style.fontSize = "16pt" ;
			input_email.style.fontWeight = "bold" ;
			input_email.style.color = "#906" ;			
			input_email.style.fontStyle = "normal" ;
			
		}
	}
	
	this.inputOutHandler = function () {
		
		if (input_email.value == "" || input_email.value == "Entre ton adresse email ici...") {	
			input_email.value = "" ;
			input_email.style.fontSize = "12pt" ;
			input_email.style.fontWeight = "normal" ;
			input_email.style.color = "#666" ;			
			input_email.style.fontStyle = "italic" ;
			input_email.value = "Entre ton adresse email ici..." ;
		}
	}
	
	this.inputCheckMailLive = function() {
		
		if (input_email.value.length > 0) {		
			if (_overlay_.checkMail(input_email.value)) {
				input_ico.src = "/library/img/overlay/ico-valid.png" ;
			}
			else {
				input_ico.src = "/library/img/overlay/ico-error.png" ;
			}
			
			return false ;
		}
		else {
			input_ico.src = "/library/img/overlay/ico-complete.png" ;
						
			return true ;
		}
	}
	
	this.checkMail = function(email) {
		if ((email.length == 0) || 
    		((email.indexOf("@") == -1) || 
    	    (email.indexOf(".",email.indexOf("@")) == -1) || 
    	    (email.indexOf(".",email.indexOf("@")) == email.indexOf("@")+1) || 
    	    (email.lastIndexOf(".")+1 == email.length) || 
    	    (email.indexOf("..") != -1))) 		{
    	    
       		return false ;
        
		}
	    
    	return true ;
	}
	
	this.submit = function() {
		
		if (_overlay_.checkMail(input_email.value)) {
			_overlay_.setCookie() ;
			document.location.href = "/newsletter/abo_all.php?email=" + input_email.value ; 			
		}
		else {
			alert("L'adresse email que tu as saisi n'est pas correcte !\nPour t'abonner à la newsletter, tu dois saisir une adresse email valide.") ;
			return false ;
		}
	}
	
	
	

	this.show = function() {
		
		var windowWidth, windowHeight ;


		if (isIE) {
			if (document.documentElement) 
				 windowWidth = parseInt(document.documentElement.clientWidth)
			else windowWidth = parseInt(document.body.clientWidth) ;        
		}
		else  windowWidth = parseInt(window.innerWidth) ;        
		
		
		if (isIE) {
			if (document.documentElement) 
				  windowHeight = parseInt(document.documentElement.clientHeight)
			else  windowHeight = parseInt(document.body.clientHeight) ;        
		}
		else  windowHeight = parseInt(window.innerHeight) ;
		
		
		if (!container) {
			
			//conteneur
			container = new Element("div") ;
			container.style.width = windowWidth + "px";
			container.style.height = "110px" ;			
			container.style.position = "fixed" ;			
			container.style.zIndex = "300000" ;			
			container.style.top = (windowHeight - parseInt(container.style.height)) + "px";
			//container.style.top = windowHeight + "px" ;
			
			
			//background
			var background = new Element("div") ;			
			background.style.backgroundColor = "black" ;
			background.style.height = "110px" ;			
			//background.style.marginTop = (parseInt(container.style.height) - parseInt(background.style.height)) + "px" ;			
			background.setOpacity(0.65) ;			
			
			container.appendChild(background) ;		
			
			
			//fourmi
			var img = new Element("img") ;
			img.src = "/library/img/overlay/fourmi.png" ;
			img.style.width = "168px" ;
			img.style.height = "235px" ;
			img.style.top = "-235px" ;
			img.style.position = "relative" ;
			img.style.zIndex = "30001" ;
			
			container.appendChild(img) ;
			
			//btn
			var btn = new Element("img") ;
			btn.src = "/library/img/overlay/btn-close.png" ;
			btn.style.width = "133px" ;
			btn.style.height = "25px" ;
			btn.style.position = "relative" ;
			btn.style.cursor = 'pointer' ; 
			
			btn.style.top = "-" + (parseInt(img.style.height) +  parseInt(background.style.height)) + "px" ;
			btn.style.left =  (windowWidth - parseInt(btn.style.width) - parseInt(img.style.width) - 15) + "px" ;
			
			btn.setOpacity(0.65) ;
			
			btn.observe("click", _overlay_.close) ;			
			
			
			container.appendChild(btn) ;			

			//btn close
			var close_link = new Element("a") ;
			close_link.update("Fermer") ;
			close_link.style.color = "white" ;	
			close_link.style.fontSize = "12pt" ;			
			close_link.style.width = "150px" ;			
			close_link.style.position = "relative" ;
			close_link.style.cursor = 'pointer' ;
			
			close_link.style.top = "-" + (parseInt(img.style.height) +  parseInt(background.style.height) + 5) + "px" ;
			close_link.style.left =  (windowWidth - parseInt(btn.style.width) - parseInt(img.style.width) - parseInt(btn.style.width) + 10 ) + "px" ;
			
			close_link.observe("click", _overlay_.close) ;
			
			container.appendChild(close_link) ;		

			//btn close ico
			var close_ico = new Element("img") ;
			close_ico.src = "/library/img/overlay/btn-close-ico.png" ;
			close_ico.style.width = "15px" ;
			close_ico.style.height = "15px" ;
			close_ico.style.position = "relative" ;
			
			close_ico.style.top = "-" + (parseInt(img.style.height) +  parseInt(background.style.height) + 2 ) + "px" ;
			close_ico.style.left =  (windowWidth - parseInt(btn.style.width) - parseInt(img.style.width) - parseInt(btn.style.width) + 20 ) + "px" ;
			close_ico.style.cursor = 'pointer' ;
			
			close_ico.observe("click", _overlay_.close) ;		

			
			container.appendChild(close_ico) ;		
			
			
			//form container
			var div_form = new Element("div") ;
			div_form.style.width = windowWidth + "px" ;
			div_form.style.height = "110px" ;			
			div_form.style.position = "relative" ;			
			div_form.style.top = "-" + (parseInt(img.style.height) +  parseInt(background.style.height) + 5 ) + "px" ;
			
			
			//forum accroche
			var form_text = new Element("div") ;
			form_text.style.background = "url('/library/img/overlay/form-text.png') right no-repeat" ;
			form_text.style.width = ((windowWidth / 2) - 20) + "px";
			form_text.style.height = "88px" ;
			form_text.style.marginTop = "12px" ;
			
			if (!isIE) form_text.style.cssFloat = "left" ;
			else form_text.style.styleFloat = "left" ;
			
			
			div_form.appendChild(form_text) ;	
			
			var form = new Element("div") ;
			form.style.width = ((windowWidth / 2) - 20) + "px";
			form.style.height = "88px" ;
			form.style.marginTop = "12px" ;	
			
			form.style.background = "url('/library/img/overlay/form.png') left no-repeat" ;
			
			if (!isIE) 	form.style.cssFloat = "right" ;
			else form.style.styleFloat = "right" ;
			
			div_form.appendChild(form) ;
			
			
			//form input icon
			input_ico = new Element("img") ;
			input_ico.src = "/library/img/overlay/ico-complete.png" ;
			input_ico.style.width = "20px" ;
			input_ico.style.height = "19px" ;
			input_ico.style.position = "relative" ;
			input_ico.style.marginTop = "55px" ;
			input_ico.style.marginLeft = "15px" ;
			input_ico.style.marginRight = "5px" ;
			
			input_ico.style.cursor = 'pointer' ;
			
			form.appendChild(input_ico) ;	

			
			
			//form input
			var input = new Element("input") ;
			/*input.setAttribute("type", "text") ;
			input.setAttribute("id", "email") ;*/
			input.type = "text" ;
			input.value = "Entre ton adresse email ici..." ;
			
			input.style.background ="none";
			input.style.border = "0" ;
			input.style.fontSize = "12pt" ;
			//input.style.fontWeight = "bold" ;
			input.style.height = "25px" ;
			input.style.marginTop = "-10px" ;
			input.style.width = "385px" ;	
			input.style.verticalAlign = "middle" ;
			
			input.style.color = "#666" ;
			input.style.fontStyle = "italic" ;
			
			input.observe("click", _overlay_.inputClickHandler) ;
			input.observe("focus", _overlay_.inputClickHandler) ;
			input.observe("blur",  _overlay_.inputOutHandler) ;
			input.observe("keyup", _overlay_.inputCheckMailLive) ;
			input.observe("keydown", function(e) {
											   
				if (_overlay_.checkMail(input.value)) {
					if (e.keyCode == 13) {
						_overlay_.submit() ;	
					}
				}
				
		    }) ;
			
			input_email = input ;
			
			form.appendChild(input) ;	
			
			
			//form bouton
			var btn_form = new Element("div") ;
			
			btn_form.style.position = "relative" ;

			btn_form.style.width = "60px" ;
			btn_form.style.height = "30px" ;
			btn_form.style.marginLeft = "435px" ;
			btn_form.style.marginTop = "-30px" ;		
			
			btn_form.observe("click", _overlay_.submit) ;
						
			form.appendChild(btn_form) ;				
			
			container.appendChild(div_form) ;		
			document.body.appendChild(container) ;
			
			
			var finalTop = (windowHeight - parseInt(container.style.height)) ;
			
			
			/***** ACTIONS ******/ 
			
			//moving overlay (at start)
			new Effect.Tween(null, windowHeight, finalTop, {duration:0.4}, function (top) {
				container.style.top = top + "px" ;													 
			});
			
		
		}	
	}

}





Event.observe(window, 'load', function () { 
	
	if (LireCookie("Propos_Inscription") == null) {
		
		 _overlay_  = new overlay() ;
		_overlay_.show() ;
		
	}

}) ;
