var popNewsletter = function(){
	return {
		addToLoadEvent : function() {
			var f = function() { popNewsletter.init() };
			if (window.addEventListener)
	 			window.addEventListener('load', f, false);
	  		else if (window.attachEvent)
				window.attachEvent('onload', f);
		},
		init : function() {
			if(!popNewsletter.cookies.read("cyr_pushnewslight"))
			{
				var newsletterTextbox = document.getElementById("hp_newsletter_champ_inscription_textbox");
				this.defaultTextboxValue = "Saisissez ici votre adresse e-mail";
				this.display();
				// Evenements divers
				var thisPopNewsletter = this;
				newsletterTextbox.onfocus = function() {
					if(this.value == thisPopNewsletter.defaultTextboxValue) {
						this.value = "";
					}
					thisPopNewsletter.clearTimeout();
				};
				newsletterTextbox.onblur = function() {
					if(this.value == "") {
						this.value = thisPopNewsletter.defaultTextboxValue;
					}
					thisPopNewsletter.setTimeout();
				};
				document.getElementById("hp_newsletter_btn_close").onclick = function() {
					thisPopNewsletter.hide();
				};
				document.getElementById("hp_newsletter_btn_valid_inscription").onclick = function() {
					thisPopNewsletter.submitForm();
				};
			}
			else
			{
				this.hide();
			}
		},
		display : function() {
			this.cookies.create("cyr_pushnewslight","dejavu",1);
			document.getElementById("PopNewsletter").style.display = "block";
		},
		hide : function() {
			document.getElementById("PopNewsletter").style.display = "none";
		},
		setTimeout : function() {
			this.timeout = window.setTimeout(popNewsletter.hide, 5000, true);
		},
		clearTimeout : function() {
			clearTimeout(this.timeout);
		},
		submitForm : function() {
			var emailValue = document.getElementById("hp_newsletter_champ_inscription_textbox").value;
			if(emailValue != "" && emailValue != this.defaultTextboxValue)
				location.href = "/views/compteclient/inscriptionnewsletterlight.aspx?a="+emailValue;
		},
		cookies : function() {
			return {
				create : function(name,value,days) {
					if (days) 
					{
						var date = new Date();
						date.setTime(date.getTime()+(days*24*60*60*1000));
						var expires = "; expires="+date.toGMTString();
					}
					else var expires = "";
					document.cookie = name+"="+value+expires+"; path=/";
				},
				read : function(name) {
					var nameEQ = name + "=";
					var ca = document.cookie.split(';');
					for(var i=0;i < ca.length;i++) {
						var c = ca[i];
						while (c.charAt(0)==' ') c = c.substring(1,c.length);
						if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
					}
					return null;
				},
				erase : function(name) {
					this.create(name,"",-1);
				}
			};
		}()
	};
}();
popNewsletter.addToLoadEvent();
