function update_widget(id)
{
	$('code_genere').value = '<script type="text/javascript" src="http://www.mistercote.com/matche_ajax.php?id_equipe='+id+'&utilite=export"></script>';
}

//defilement bookmaker

var x = 0;
function makeHighlight()
{
	var bookmakers = $$('#section_bookmakers .bookmakerdiv');
	theLength = bookmakers.length;
	
	if (x == theLength) x = 0;
	if (x == 0) var exX = theLength-1;
	else var exX = x-1;
	
	bookmakers[exX].style.backgroundColor = '';
	bookmakers[x].style.backgroundColor = '#c1dbf9';
	x++;
	setTimeout(function() { makeHighlight(); }, 3000);
}

//menu des sports
function showHide()
{
	$$('#sports_filtre .sport').each(function(element)
	{
		element.observe('click', function()
		{ 
			if (navigator.userAgent.toLowerCase().indexOf("msie") != -1)var div = element.nextSibling.id;
			else var div = element.nextSibling.nextSibling.id;
			if($(div).visible() == true)
			{
				$(div).style.marginBottom = '0px';
				$(div).hide();
				// element.style.backgroundImage = "url('site/css/sports_fleche.png')";
			}
			else
			{
				$(div).style.marginBottom = '10px';
				$(div).show();
				// element.style.backgroundImage = "url('site/css/sports_fleche_over.png')";
			}
		})
	})
	
	$$('#sports_filtre .sport_pays').each(function(element)
	{
		element.observe('click', function()
		{
			var sibling = element.nextSibling;
			var div = sibling.id;
			if($(div).visible() == true)
			{
				$(div).hide();
				element.className = "sport_pays";
			}
			else
			{
				$(div).show();
				element.className = "sport_pays_on";
			}
		})
	})
}

//Paris
function updateWinnings() 
{
	var total = $('mise').value * $('cote_finale').value
	var winnings = Math.round(total*100) /100;
	$('towin').innerHTML = '<p><strong>'+winnings+'</strong></p>';
}

//formulaire


	
function verification_mail(mail, ico) 
{
	var filtre = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (!filtre.test(mail.value)) 
	{
		$(ico).innerHTML = '<img src="root/css/images/icone_pasbon.png" alt="pas bon"> Mauvais format';
		mail.focus
		return false;
	}
	else
	{
		$(ico).innerHTML = '<img src="root/css/images/icone_bon.png" alt="bon">';
		return false;
	}
}

function verification_login(a,b,c)
{
	var filtre = /^([a-zA-Z0-9_\-]{5,})$/;
	if (!filtre.test(b)) 
	{
		$(c).innerHTML = '<img src="root/css/images/icone_pasbon.png" alt="pas bon"> Plus de 5 caractère alphanumériques (-_)';
	}
	else
	{
		verification_formulaire(a,b,c);
	}
}

function verification_password()
{
	var form = document.forms['inscription'];
	
	var filtre = /^([a-zA-Z0-9]{5,})$/;
	if (!filtre.test(form.elements['password'].value)) 	
	{
		$('ico_statut_password').innerHTML = '<img src="root/css/images/icone_pasbon.png" alt="pas bon"> Plus de 5 caractères alphanumériques';
	}
	else
	{
		if (form.elements['password'].value != form.elements['cpassword'].value)
		{
			$('ico_statut_password').innerHTML = '<img src="root/css/images/icone_pasbon.png" alt="pas bon"> La confirmation n\'est pas identique';
			$('ico_statut_cpassword').innerHTML = '<img src="root/css/images/icone_pasbon.png" alt="pas bon"> Le mot de passe n\'est pas identique';
		}
		else
		{
			$('ico_statut_password').innerHTML = '<img src="root/css/images/icone_bon.png" alt="bon">';
			$('ico_statut_cpassword').innerHTML = '<img src="root/css/images/icone_bon.png" alt="bon">';
		}
	}
}

function verification_formulaire(a,b,c) 
{
	AjaxRequete(Object.toQueryString({utilisation: a, donnee: b}), c, root+'/ajaxs.php', 'POST'); 
}



function AjaxRequete(datas, id_bloc, page, method) 
{
	$(id_bloc).innerHTML = '<img align="center" src="root/css/images/ajax-loader.gif">';
	
	new Ajax.Request(
		page,
		{
			method: method,
			parameters: datas,

			onComplete: function(transport) 
			{
			    var rep = transport.responseText;

			    while( $(id_bloc).firstChild ) 
				{
					$(id_bloc).removeChild($(id_bloc).firstChild );
			    }
				$(id_bloc).innerHTML+= rep;
			},

			onFailure: function() 
			{
			    $(id_bloc).innerHTML = 'Un problème technique est survenu lors de la requete';
			}
		}
	);
}


function rechercher_widget(a,b) 
{
	AjaxRequete(Object.toQueryString({utilisation: 'recherche_widget', donnee: a}), b, root+'/ajaxs.php', 'POST');
	
}

function gotochx(a) 
{
	AjaxRequete(Object.toQueryString({page: a}), 'ajax_categorie', 'root/ajax/ajax_pages.php', 'GET'); 
}

function changeFlux(a) 
{
	AjaxRequete(Object.toQueryString({fil: a}), 'infos', 'root/ajax/flux.php', 'GET'); 
}

function add(a, b, c, d) 
{
	dirPari(Object.toQueryString({id: a, idtype: b, intitule: c, odd: d, to: 'add'})); 
}

function del(a) 
{
	dirPari(Object.toQueryString({id: a, to: 'del'}));
}

function initParis()
{
		dirPari();
}

function dirPari(datas) 
{
	
	var couponID = 'selection';
	$$('#coupon_loader .loader')[0].innerHTML = '<img align="center" src="../root/css/images/ajax-loader.gif">';
	new Ajax.Updater(
		couponID,
		root+'/root/ajax/paris.php',
		{
			method: 'GET',
			parameters: datas,
			insertion: Insertion.Bottom,

			onComplete: function(transport) 
			{
			    var rep = transport.responseText;
				$(couponID).innerHTML = rep;
				$$('#coupon_loader .loader')[0].innerHTML = '';
			},

			onFailure: function() 
			{
			    $(couponID).innerHTML = 'Un problème technique est survenu lors de la requete';
			}
		}
	);
}




Effect.OpenUp = function(element, id) 
{
	element = $(element);
	if (element.appear())
	{
		if (new Effect.BlindDown(element, arguments[1] || {}))
		{
			if (id != 0)
			{
				detailsMatch(id);
			}
		}
	}
}



Effect.CloseDown = function(element) 
{
	element = $(element);
	if (element.fade())
	{
		new Effect.BlindUp(element, arguments[1] || {});
	}
}



Effect.Combo = function(element, id) 
{
	element = $(element);
	if(element.style.display == 'none') 
	{ 
		new Effect.OpenUp(element, id, arguments[1] || {}); 
	}
	else 
	{ 
		new Effect.CloseDown(element, arguments[1] || {}); 
	}
}
 
function detailsMatch(a) 
{
	AjaxRequete(Object.toQueryString({id: a}), a, '../matche_ajax.php', 'GET'); 
}


function OuvrirPop(url,nom,haut,Gauche,largeur,hauteur,options) 
{
	ouvpop=window.open(url,nom,"scrollbars,top="+haut+",left="+Gauche+",width="+largeur+",height="+hauteur+","+options);
}


var compteurMatches = 0;

function dynamiqueNbMatchs()
{
	compteurMatches++;
	if (compteurMatches < nombreMatchs)
	{
		$('nombre_matchs').innerHTML = compteurMatches;
		setTimeout(dynamiqueNbMatchs, 1);
	}
}

 


function confirmation(question, url) 
{
	var answer = confirm(question)
	if (answer)
	{
		window.location = url;
	}
}

var nb_mail = 0;

function creer_champ(div, partir) {

if (nb_mail == 0) {
	nb_mail = partir;
}
else {
	nb_mail++;
}
document.getElementById(div).innerHTML+= '<div class="mails_filleuls"> Mail '+nb_mail+' <input type="text" class="text" name="mail[]"></div>';


}


window.onload = function() {
	initParis();
 	makeHighlight();
	showHide();
};

