function microAjax(B,A){this.bindFunction=function(E,D){return function(){return E.apply(D,[D])}};this.stateChange=function(D){if(this.request.readyState==4){this.callbackFunction(this.request.responseText)}};this.getRequest=function(){if(window.ActiveXObject){return new ActiveXObject("Microsoft.XMLHTTP")}else{if(window.XMLHttpRequest){return new XMLHttpRequest()}}return false};this.postBody=(arguments[2]||"");this.callbackFunction=A;this.url=B;this.request=this.getRequest();if(this.request){var C=this.request;C.onreadystatechange=this.bindFunction(this.stateChange,this);if(this.postBody!==""){C.open("POST",B,true);C.setRequestHeader("X-Requested-With","XMLHttpRequest");C.setRequestHeader("Content-type","application/x-www-form-urlencoded");C.setRequestHeader("Connection","close")}else{C.open("GET",B,true)}C.send(this.postBody)}};

/* ----------------------- */

function hideDhtml(){
	stop_blink();
	document.getElementById('overlay').style.display = 'none';
    document.getElementById('div_dhtml').style.display = 'none';
}

function showDhtml(){
	start_blink();
	
	if (navigator.userAgent.indexOf("MSIE 5") != -1 || navigator.userAgent.indexOf("MSIE 6") != -1) {
		document.getElementById('div_dhtml').style.position = 'absolute';
		document.getElementById('overlay').style.display = 'block';
		window.scrollTo(0,0);
	}
	else
		document.getElementById('overlay').style.display = 'block';
		
	document.getElementById('div_dhtml').style.display = 'block';
	
	track_dhtml('click');
}

function showDhtmlThumb(niche, num_th, url_path)
{
	if (typeof(er_dhtmlthumb_imgname) != 'undefined')
	{
		if (niche != '')
			if (num_th != '')
				document.images[er_dhtmlthumb_imgname].src = er_dhtmlthumb_baseurl+'/'+niche+'/'+er_dhtmlthumb_size+'/'+num_th+'.jpg';
			else
				document.images[er_dhtmlthumb_imgname].src = er_dhtmlthumb_baseurl+'/'+niche+'/'+er_dhtmlthumb_size+'/'+(Math.floor(Math.random()*99+1))+'.jpg';
		if (url_path != '')
			document.images[er_dhtmlthumb_imgname].src = er_dhtmlthumb_baseurl+'/'+url_path;
	}
	
	showDhtml();
}

function track_dhtml(typehit)
{
	if (typeof(er_pdv_popdhtml_num) != 'undefined')
		microAjax('/dhtml/tracking/index.php?ida='+er_pdv_ida+'&idpdv='+er_pdv_idtool+'&numpop='+er_pdv_popdhtml_num+'&typehit='+typehit, function(res){});
}

/* ----------------------- */

var blink_timer;
var text_visible = 1;
var text_tmp;


function blink()
{
	if (text_visible)
	{
		text_tmp = document.dhtml_form.email.value;
		document.dhtml_form.email.value = '';
		text_visible = 0;
	}
	else
	{
		document.dhtml_form.email.value = text_tmp;
		text_visible = 1;
	}
}

function start_blink()
{
	if (document.dhtml_form.email.value=='@')
		blink_timer = setInterval('blink()', 500);
}

function stop_blink()
{
	if (blink_timer)
		clearInterval(blink_timer);
}

function email_focus(this_form, blink)
{
	if (blink == 1)
		stop_blink();
	e = this_form.email;
	if (e.value == '@') e.value = '';
}

function email_blur(this_form, blink)
{
	var e = this_form.email;
	if (e.value == '@' || e.value == '')
	{
		e.value = '@';
		if (blink == 1)
			start_blink();
	}
}

/* ----------------------- */

var msg_mail_alert;

if (navigator.browserLanguage)
	var language = navigator.browserLanguage; 
else
	var language = navigator.language; 

if (language.indexOf('fr') > -1) msg_mail_alert = 'Merci d\'entrer un email valide !';
else if (language.indexOf('en') > -1) msg_mail_alert = 'Please enter a valid email !';
else if (language.indexOf('es') > -1) msg_mail_alert = 'Please enter a valid email !';
else if (language.indexOf('de') > -1) msg_mail_alert = 'Please enter a valid email !';
else if (language.indexOf('it') > -1) msg_mail_alert = 'Please enter a valid email !';
else msg_mail_alert = 'Merci d\'entrer un email valide !';

function check_email(this_form, no_track)
{
	var email = this_form.email.value;
	var filter = /^([\w-]+(?:\.[\w-_]+)*)@((?:[\w-]+\.)*\w[\w-]{0,100})\.([a-z]{2,8}(?:\.[a-z]{2})?)$/i;
	
	if (!filter.test(email))
	{
		alert(msg_mail_alert);
		return false;
	}
	
	if (no_track != 1)
		track_dhtml('form');
	
	return true;
}

/* ----------------------- */

function blink_from_element(max, color1, color2, id_form) {
	blink_from_element_core(0,0,max, color1, color2, id_form);
}

function blink_from_element_core(current_color, current_i, max_i, color1, color2, id_form) {
	if(current_i < max_i ) {
		if(current_color == 0 ) {
			document.getElementById(id_form).email.style.backgroundColor = color1;
			current_color = 1;
		} else {
			document.getElementById(id_form).email.style.backgroundColor = color2;
			current_color = 0;
		}
		current_i++;
		setTimeout("blink_from_element_core("+current_color+","+current_i+","+max_i+",'"+color1+"','"+color2+"','"+id_form+"')", 100);
	}
	else {
		document.getElementById(id_form).email.style.backgroundColor = color2;
	}
}

/* ----------------------- */
