document.observe('dom:loaded', function() {
	
	$$("#lang a").each(function(el) {
		if(el.hasClassName("current")) {
			el.down("img").src = "/images/lang_"+el.id+"_on.gif"
		} else {
			el.observe("mouseover", function() {
				el.down("img").src = "/images/lang_"+el.id+"_hover.gif"
			});
			el.observe("mouseout", function() {
				el.down("img").src = "/images/lang_"+el.id+"_off.gif"
			});
		}
	});
	
	$$(".btn_ok_pop_message").each(function(el){
		el.observe("click", function() {
			el.up("#pop_message").hide()	
		});
	})
	
	$$(".dropdown").each(function(el){
		el.hide();
	})
	
	$$(".dropdown a").each(function(el){
		el.observe("click", function() {
			el.up(".dropdown").toggle()
		});
	})
	
	cote_init();
	
})

function toggleDropDown(id) {
	$(id).toggle();
}

var cote_selected = 0;
function cote_init() {
	$$(".cote_etoile", ".cote_star").each(function(el){
		el.observe("mouseover", function() {
			value = this.id.substr(this.id.length-1, 1)
			cote_show(Number(value))
		});
		el.observe("mouseout", function() { cote_show()	});
		el.observe("click", function() {
			value = this.id.substr(this.id.length-1, 1)
			cote_set(Number(value))			
		});
	})
}
function cote_close(el) { 
	$(el).up().hide();
	cote_selected = 0;
	$('score').value = 0;
	$('star').value = 0;
	cote_show(); 
}
function cote_set(value) { 
	cote_selected = value;
	$('score').value = value;
	$('star').value = value;
}
function cote_show(value) {
	inValue = (value != undefined) ? value : cote_selected ;
	for(i=1; i<=5; i++) {
		if(i<=inValue) { 
			$("star_"+i).src = "/images/star_on.gif";
			$("cote_"+i).src = "/images/cote_etoile_hover.gif";
		} else {
			$("star_"+i).src = "/images/star_off.gif";
			$("cote_"+i).src = "/images/cote_etoile.gif";
		}
	}
	$("indice").innerHTML = cote_labels[inValue]
}

function alerter(msg)
{
	 contenant = $("pop_message");
	 if(contenant){
			contenant.style.top = document.viewport.getScrollOffsets()[1]+'px';
	 	 	contenant.select("p").first().innerHTML = msg;
			new Effect.Appear(contenant, {duration:0.2});
			document.observe('scroll', function(){hide_alerter();});
			setTimeout(function(){hide_alerter();}, 5000); 
	 }
	 else{
		alert(msg);
	}
}

function hide_alerter()
{
//	new Effect.Fade("pop_message", {duration:0.2})
//	document.stopObserving('scroll')
}

function validate_subscribe_form(obj_field, default_message, locale)
{
	email_adr = obj_field.value
	if(email_adr == default_message){
		if(locale=='fr')
			alert('Vous devez entrer une adresse de courriel')
		else
			alert('You must enter an email address')
		return false;
	}else{
		if(email_adr.match(/^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/gi)){
			return true;
		}else{
			if(locale == 'fr')
				alert("L'adresse de courriel n'est pas valide");
			else
				alert("Invalid email address");
			
			obj_field.value = default_message;
			return false
		}
	}
}

function set_invitations_labels()
{
	invitations_count = $$('.invitation').length;
	new_invitation = $$('.invitation').last().down('input');
	if (invitations_count > 5){
		new_invitation.value = "Adresse de courriel";
	}
	else{
		new_invitation.value = "Une chance supplémentaire de gagner";
	}
}

function remove_invitation(bt_invitation){
	bt_invitation.up('.invitation').remove();
}

function validate_checkbox(){
	if($('rights_confirm').checked){
		return true
	}else{
		alerter('Vous devez accepter les conditions.');
		new Effect.Highlight('rights_confirm_block');
		return false
	}
}