function validFormAdhesion(formAdhesion, lang){
	if(validForm(formAdhesion, lang)) {
		if($('input[name=my_categorie]:radio:checked').val()) {
			return true;
		}
		else {
			alert("Veuillez choisir une catégorie.");
			$('#1-4').focus();
			return false;
		}
	}
	else {
		return false;
	}
}

function set_name()
{
	killAjax();
	ret = function() 
	{
		if(ajaxOk())
		{
				document.getElementById('nom').value = objAjax.responseText;
				set_compagnie();

		}
	}
	callAjax('/script/ajax.php?what=set_field&field=nom',ret,null);
}
function set_compagnie()
{
	killAjax();
	ret = function() 
	{
		if(ajaxOk())
		{
				document.getElementById('entreprise').value = objAjax.responseText;

		}
	}
	callAjax('/script/ajax.php?what=set_field&field=nom_compagnie',ret,null);
}

function valid_acces(login,pass)
{
	killAjax();
	ret = function() {
		if(ajaxOk()){
			if (objAjax.responseText == '1')
			{
				document.getElementById('login_box').style.display='none';
				document.getElementById('proposer_box').style.display='';
				set_name('nom');
			}
			if (objAjax.responseText == '0')
			{
				alert('Mauvais courriel ou mot de passe');
			}
			cleanCal();
		}
	}
	callAjax('/script/ajax.php?what=login_activite&login='+login.value+'&pass='+pass.value,ret,null);
}

function login_cheque(email,pass)
{
	killAjax();
	ret = function() {
		if(ajaxOk()){
			if (objAjax.responseText == '1')
			{
				location.href='/chequier';
			}
			if (objAjax.responseText == '0')
			{
				alert('Mauvais courriel ou mot de passe');
			}
			cleanCal();
		}
	}
	callAjax('/script/ajax.php?what=login_cheque&email='+email.value+'&pass='+pass.value,ret,null);
}

function changemois(direction,mois,annee){
	killAjax();
	ret = function() {
		if(ajaxOk()){
			document.getElementById('calendarbox').innerHTML=objAjax.responseText;
			cleanCal();
		}
	}
	callAjax('/script/ajax.php?what=calendrier&dir='+direction+'&mois='+mois+'&annee='+annee,ret,null);
}

function cleanCal(){
	var a = document.getElementById('calendarbox').getElementsByTagName('td');
	for(i=0;i<a.length;i++){
		if(a[i].innerHTML=='' || a[i].innerHTML=='&nbsp;'){a[i].className='vide';}
	}
}

function addmailing(email, lang){
	if(validMail(email.value)){
		killAjax();
		ret = function() {
			if(ajaxOk()){
				document.getElementById('mailling_list').innerHTML = objAjax.responseText;
			}
		}
		callAjax('/script/ajax.php?what=mailing&courriel='+email.value+'&lang='+lang,ret,null);
	}
	else{
		email.focus();
		email.select();
		alert('Veuillez entrer une adresse de courriel valide.');
	}
}

function addcheque(nom, muni, email, lang)
{
	/*if(validMail(email.value))*/
	if(validForm(document.getElementById('form_chequier')))
	{
		killAjax();
		ret = function()
		{
			if(ajaxOk())
			{
				document.getElementById('form_chequier').innerHTML = objAjax.responseText;
			}
		}
		callAjax('/script/ajax.php?what=cheque&nom='+nom.value+'&password='+password.value+'&muni='+muni.value+'&courriel='+email.value+'&lang='+lang,ret,null);
	}
	else{
		email.focus();
		email.select();
		alert('Veuillez entrer une adresse de courriel valide.');
	}
}

function addcomment(lang, post){
	if(validForm(post)){
		killAjax();
		ret = function(){
			if(ajaxOk()){
				document.getElementById('comment_form').innerHTML = objAjax.responseText;
			}
		}
		callAjax('/script/ajax.php?what=comment&lang='+lang,ret,null,post);
	}
}

var currMenu = null;
function mainmenu(sender,classe){
	sender = document.getElementById(sender);
	if(sender){
		sender = (sender.tagName=="UL") ? sender : sender.childNodes[0];
		sender = (sender && sender.tagName=="UL") ? sender : sender.nextSibling;
		if(sender){
			if(sender.tagName=="UL"){
				if(classe!=""){
					var uls = sender.getElementsByTagName("UL");
					for(i=0;i<uls.length;i++){
						if(uls[i].className==classe) currMenu = uls[i].parentNode;
					}
					if(currMenu) currMenu.className+=" shover";
				}
				var lis = sender.getElementsByTagName("LI");
				for(i=0;i<lis.length;i++){
					if(lis[i].className!="vide"){
						lis[i].onmouseover=function() {
							if(currMenu) currMenu.className=currMenu.className.replace("shover", "");
							this.className+=" shover";
							//if(document.all) this.style.zIndex=100;
						}
						lis[i].onmouseout=function() {
							this.className=this.className.replace("shover", "");
							if(currMenu) if(currMenu.className.indexOf("shover")==-1) currMenu.className+=" shover";
							//if(document.all) this.style.zIndex=1;
						}
					}
				}
			}else{
				alert("Le sender n\'est pas un UL");
			}
		}
	}
}

$(function(){
	$("a[rel^=activite]").fancybox({
		'frameHeight': 500,
		'showNavArrows' : false,
		'hideOnContentClick': false,
		'overlayOpacity': 0.7
	});
	$("a[rel^=news]").fancybox({
		'frameHeight': 500,
		'showNavArrows' : false,
		'hideOnContentClick': false,
		'overlayOpacity': 0.7
	});
});

var temp_photo=new Array(); 
function image_preload(id,name)
{
	temp_photo[id] = new Image(1998,300);
	temp_photo[id].src="/images/photos2011/"+name; 
}

Array.prototype.shuffle = function() {
var s = [];
while (this.length) s.push(this.splice(Math.random() * this.length, 1)[0]);
while (s.length) this.push(s.pop());
return this;
} 

var p_aImgs = null;
var p_aLink = null;
var p_aImg = null;
var p_theInt = null;
var p_speed = 10000;
var list_photo=new Array(); 
list_photo[0]="header-1.jpg";       
list_photo[1]="header-3.jpg";
list_photo[2]="header-4.jpg";
list_photo[3]="header-5.jpg";
list_photo[4]="header-6.jpg";
list_photo[5]="header-7.jpg";
list_photo[6]="header-8.jpg";
list_photo[7]="header-9.jpg";
list_photo[8]="header-11.jpg";
list_photo[9]="header-12.jpg";
list_photo[10]="header-13.jpg";
list_photo[11]="header-14.jpg";
list_photo[12]="header-15.jpg";
list_photo[13]="header-17.jpg";
list_photo[14]="header-18.jpg";
list_photo[15]="header-19.jpg";
list_photo[16]="header-20.jpg";
list_photo[17]="header-21.jpg";
list_photo[18]="header-22.jpg";
list_photo[19]="header-23.jpg";
list_photo[20]="header-24.jpg";
list_photo[21]="header-25.jpg";
list_photo[22]="header-26.jpg";
list_photo[23]="header-27.jpg";
list_photo[24]="header-28.jpg";
srt = Math.round(Math.random())-0.5;
list_photo.shuffle();

var p_curpos = Math.floor(Math.random()*13)

for(i = 0; i < list_photo.length; i++)
{
	image_preload(i,list_photo[i]);
}


function p_changePic()
{
	/* 		<div id="main_photo" class="photo" style="background-image: url(/images/photos/maison.jpg);">	
*/
	if (p_curpos >= list_photo.length)
		p_curpos = 0;
	$('#main_photo').css({ backgroundImage : "url(/images/photos2011/"+list_photo[p_curpos]+")" });
	p_runInt(p_speed);
}

function p_runInt(s){
	clearInterval(p_theInt);
	p_theInt = setInterval(function(){
		p_curpos++;
		p_changePic();
	}, s);
}


var aImgs = null;
var aLink = null;
var aImg = null;
var theInt = null;
var curclicked = 0;
var speed = 1000;

function scrollNews(s){
	if($("#ntext")){
		speed = s;
		$("#news a").bind('mouseover',function(){
			curclicked = $("#news a").index(this);
			changePic();
		});
		changePic();
	}
}
function changePic(){
	$("#news a").removeClass("selected");
	$("#news a").eq(curclicked).addClass("selected");
	$("#ntext .item").css("display","none");
	$("#ntext .item").eq(curclicked).css("display","");
	runInt(speed);
}
function runInt(s){
	clearInterval(theInt);
	theInt = setInterval(function(){
		curclicked++;
		if(curclicked>=$("#news a").length) curclicked = 0;
		changePic();
	}, s);
}
