var popupStatus = 0;
var text_timer = Array();
var text_visible = Array();
var text_tmp = Array();

var REG_MAIL = /^[\w-\.]{2,}@[\w-]{1,}\./;

function check() {
	if(!REG_MAIL.test(document.email_form.email1.value)){
		alert("Votre email doit être valable");
		document.email_form.email1.focus();
	}	else	{
		var url = 'https://secure.securitetotale.com/cb.php?module=guest_cbsys_preform&w=0&force_step1=1&action=step2&idp=1&num_facturation=1&langue=fr&e=1&synergie=hetero&oldrf=pvaST_xxx&change_step2_rf=lebangtour&id_facturation=199&id=' + id + '&tracker=' + tracker + '&email='+document.email_form.email1.value;
		window.open(url);
	}	
	return false;
}

function blink(input_id)	{
	if(typeof input_id == 'undefined') input_id = email_inputs[0].id;
	if (text_visible[input_id])	{
		text_tmp[input_id] = document.getElementById(input_id).value;
		document.getElementById(input_id).value = '';
		text_visible[input_id] = false;
	}	else	{
		document.getElementById(input_id).value = text_tmp[input_id];
		if (typeof text_tmp[input_id] == 'undefined') {
			document.getElementById(input_id).value = "@";
		}
		text_visible[input_id] = true;
	}
}

function start_blink(input_id)	{
	if(typeof input_id == 'undefined') input_id = email_inputs[0].id;
	e = document.getElementById(input_id);
	if (!text_timer[input_id] && e.value=='@')	{
		text_timer[input_id] = setInterval('blink("'+input_id+'")', 500);
	}
}

function stop_blink(input_id)	{
	if(typeof input_id == 'undefined') input_id = email_inputs[0].id;
	if (text_timer[input_id])	{
		clearInterval(text_timer[input_id]);
		text_timer[input_id] = false;
	}
}

function email_focus(input_id)	{
	if(typeof input_id == 'undefined') input_id = email_inputs[0].id;
	stop_blink(input_id);
	e = document.getElementById(input_id);
	if (e.value == '@') e.value = '';
}

function email_blur(input_id)
{
	if(typeof input_id == 'undefined') input_id = email_inputs[0].id;
	e = document.getElementById(input_id);
	if (e.value == '@' || e.value == '')	{
		e.value = '@';
		start_blink(input_id);
	}
}

function showPopup()	{
	var e = document.getElementById('bangtour_player');
	if ( e ) e.style.display = 'none';
	centerPopup();
	loadPopup();
}

function centerPopup(){
	var d				= dimension_detect();
	var windowWidth		= document.documentElement.clientWidth;
	var windowHeight	= document.documentElement.clientHeight;
	var popupHeight		= J("#popup").height();
	var popupWidth		= J("#popup").width();
	document.getElementById("popup").style.position			= 'absolute';
	//document.getElementById("popup").style.top				= d.top+(d.viewH/2-popupHeight/2) + 'px';
	//document.getElementById("popup").style.left				= (windowWidth-popupWidth)/2 + 'px';
	
	if(document.all) document.getElementById("popup").style.top=d.top-600;
	else document.getElementById("popup").style.top= d.top - 600 + 'px';
	
	document.getElementById("popup").style.left=0;
	document.getElementById("backgroundPopup").style.height	= windowHeight + 'px';
	
}

function loadPopup(){
	document.body.style.overflow = 'hidden';
	if(popupStatus==0){
		J("#backgroundPopup").css({
			"opacity": "0.7"
		});
		J("#backgroundPopup").show();//fadeIn("slow");
		J("#popup").show();//fadeIn("slow");
		popupStatus = 1;
	}
}

function hidePopup(){
	if(popupStatus==1){
		var e = document.getElementById('bangtour_player');
		if ( e ) e.style.display = 'block';
		J("#backgroundPopup").hide();//fadeOut("slow");
		J("#popup").hide();//fadeOut("slow");
		popupStatus = 0;
	}
	document.body.style.overflow = 'auto';
}

if(typeof dimension_detect == 'undefined')	{
	function dimension_detect(){
		var d={'viewW':0,'viewH':0,'docH':0,'docW':0,'left':0,'top':0};
		if (document.body.scrollHeight>document.body.offsetHeight){
			d.docW=document.body.scrollWidth;
			d.docH=document.body.scrollHeight;
		} else {
			d.docW=document.body.offsetWidth;
			d.docH=document.body.offsetHeight;
		}
		if (self.innerWidth){
			d.viewW=self.innerWidth;
			d.viewH=self.innerHeight;
			d.left=window.pageXOffset;
			d.top=window.pageYOffset;
		} else {
			var ie=(document.compatMode&&document.compatMode!='BackCompat')?document.documentElement:document.body;
			d.viewW=ie.clientWidth;
			d.viewH=ie.clientHeight;
			d.left=ie.scrollLeft;
			d.top=ie.scrollTop;
		}
		return d;
	}
}

(function () {
	var swapper =
	function (a,L,e) {
		var r = Math.floor(Math.random()*L);
		var x = a[e];
		a[e] = a[r];
		a[r] = x;
	};
	Array.prototype.shuffle =
	function () {
		var i,L
		i = L = this.length;
		while (i--) swapper(this,L,i);
	};
})(); 
