// JavaScript Document
function include(file)
{
	_head = document.getElementsByTagName('head')[0];
	including = document.createElement('script');
	including.src = file;
	_head.appendChild(including);
}
function toDay(oObj)
{
	Today = new Date;
	destination = (document.all?document.all(oObj):document.getElementById(oObj));
	var mydate=new Date();
	var year=mydate.getYear();
	if (year < 1000)
	year+=1900;
	var day=mydate.getDay();
	var month=mydate.getMonth();
	var daym=mydate.getDate();
	if (daym<10)
		daym="0"+daym;
	dayarray=["Dimanche","Lundi","Mardi","Mercredi","Jeudi","Vendredi","Samedi"];
	montharray=["Janvier","F&eacute;vrier","Mars","Avril","Mai","Juin","Juillet","Ao&ucirc;t","Septembre","Octobre","Novembre","D&eacute;cembre"];
	destination.innerHTML = "<font color='#006600' size='1' face='arial'>"+dayarray[day]+" "+daym+" "+montharray[month]+"  "+year+"</font><br />";
	var Heure = Today.getHours();
	var Min = Today.getMinutes();
	var Sec = Today.getSeconds();
	if(Sec<10)
		Sec='0'+Sec;
	if (Min<10)
		Min="0"+Min;
	destination.innerHTML += "<font color='#006600' size='1' face='arial'>"+Heure+":"+Min+":"+Sec;

	setTimeout("toDay('"+oObj+"')",1000);
}
function popupcentree(page,largeur,hauteur,options)
{
	var top=(screen.height-hauteur)/2;
	var left=(screen.width-largeur)/2;
	popup = window.open(page,"","top="+top+",left="+left+",width="+largeur+",height="+hauteur+","+options);
}
function reloadPage(strSelect,url)
{
	oSelect = (document.all?document.all(strSelect):document.getElementById(strSelect));
	oOptionS = oSelect.options.selectedIndex;
	direction = oSelect.options[oOptionS].value;
	if(direction!='NULL'&&direction!='Tout')
		document.location.href = (url!=undefined&&url!=null?url:'')+'?c='+direction;
	else
		document.location.href = './';
}
function calendSet(ochange)
{
	oFilter = (document.all?document.all('filter_type'):document.getElementById('filter_type'));
	oFilter.value = 'date';
	oYear = (document.all?document.all('search_year'):document.getElementById('search_year'));
	oMonth = (document.all?document.all('search_month'):document.getElementById('search_month'));
	oDay = (document.all?document.all('search_day'):document.getElementById('search_day'));
	today = new Date();
	thisYear = today.getFullYear();
	thisMonth = today.getMonth();
	thisDay = today.getDate();
	switch(ochange)
	{
		case 'year':
			iSelYear = oYear.options.selectedIndex;
			oSelYear = oYear.options[iSelYear];
			SelYear = oSelYear.value;
			if(oMonth.length>0)
			{
				for(i=oMonth.length;i>0;i--)
				{
					oMonth.removeChild(oMonth.options[i-1]);
				}
			}
			if(SelYear==thisYear)
			{
				mStart = thisMonth;
			}
			else
				mStart = 0;
			startOption = document.createElement('option');
			startOption.value = 'NULL';
			oMonth.appendChild(startOption);
			startOption.selected = "selected";
			startOption.innerHTML = '...';
			for(a=mStart;a<12;a++)
			{
				newOption = document.createElement('option');
				newOption.value = a+1;
				oMonth.appendChild(newOption);
				newOption.innerHTML = a+1;
			}
			oMonth.disabled = false;
			break;
		case 'month':
			iSelMonth = oMonth.options.selectedIndex;
			oSelMonth = oMonth.options[iSelMonth];
			SelMonth = oSelMonth.value;
			firstDate = new Date(SelYear,SelMonth,1,0,0,0);
			secondDate = new Date(SelYear,(Number(SelMonth)+1),1,0,0,0);
			firstTsp = firstDate.getTime();
			secondTsp = secondDate.getTime();
			difTsp = secondTsp - firstTsp;
			nbDays = (difTsp/86400)/1000;
			
			if(oDay.length>0)
			{
				for(i=oDay.length;i>0;i--)
				{
					oDay.removeChild(oDay.options[i-1]);
				}
			}
			if(SelMonth == thisMonth && SelYear == thisYear)
			{
				dStart = Number(thisDay)-1;
			}
			else
			{
				dStart = 0;
			}
			startOption = document.createElement('option');
			startOption.value = 'NULL';
			oDay.appendChild(startOption);
			startOption.selected = "selected";
			startOption.innerHTML = '...';
			for(d=dStart;d<nbDays;d++)
			{
				newOption = document.createElement('option');
				newOption.value = d+1;
				oDay.appendChild(newOption);
				newOption.innerHTML = d+1;
			}
			oDay.disabled = false;
			break;
	}
}
function launchFilter(type)
{
	oFilter = (document.all?document.all('filter_type'):document.getElementById('filter_type'));
	oFilter.value = type;
	oForm = (document.all?document.all('filter_form'):document.getElementById('filter_form'));
	oForm.submit();
}
function launchOrderBy(type)
{
	oOrder = (document.all?document.all('order_type'):document.getElementById('order_type'));
	oOrderDir = (document.all?document.all('order_dir'):document.getElementById('order_dir'));
	actOrder = oOrder.value;
	if(actOrder!=type)
	{
		oOrder.value = type;
		switch(type)
		{
			case 'date':
				oOrderDir.value = 'DESC';
				break;
			default:
				oOrderDir.value = 'ASC';
				break;
		}
	}
	else
	{
		if(oOrderDir.value!='DESC')
			oOrderDir.value = 'DESC';
		else
			oOrderDir.value = 'ASC';
	}
	oForm = (document.all?document.all('filter_form'):document.getElementById('filter_form'));
	oForm.submit();
}
function newsletterInscr()
{
	var bW = document.body.scrollWidth;
	var bH = document.body.scrollHeight;
	var am = '';
	winlocs = window.location.search;
	winlocs = (winlocs!=''?winlocs.substring(1):'');
	oInput = (document.all?document.all('newsletter'):document.getElementById('newsletter'));
	re = /^[\w](([_\.\-\+]?[\w]+)*)@([\w]+)(([\.-]?[\w]+)*)\.([a-z]{2,})$/
	if(oInput!=null&&oInput!=undefined&&oInput.value.match(re)) am = oInput.value;
	//alert(oInput.constructor);
	oIFrame = document.createElement('iframe');
	oIFrame.id = 'form_newsletter';
	oIFrame.border = 0;
	oIFrame.frameBorder = 0;
	oIFrame.style.position = 'absolute';
	oIFrame.style.border = '1px solid #000000';
	oIFrame.style.top = '200px';
	oIFrame.style.left = (((bW-380)/2)-10)+'px';
	oIFrame.style.width = '380px';
	oIFrame.style.height = '520px';
	oIFrame.src = _web_folder+'lib/get_form_newsletter.php?e='+am+(winlocs!=''?'&'+winlocs:'');
	document.getElementsByTagName('body')[0].appendChild(oIFrame);
	/*
	document.onmousedown = function()
	{
		document.getElementsByTagName('body')[0].removeChild(oIFrame);
		document.onmousedown = '';
	}*/
}
function showDiv(idObject)
{
	oDiv = (document.all?document.all(idObject):document.getElementById(idObject));
	oDiv.style.display = 'block';
}
function launchMedia(e)
{
	if (!e) var e = window.event;
	if (e.target) targ = e.target;
	else if (e.srcElement) targ = e.srcElement;
	if (targ.nodeType == 3)
		targ = targ.parentNode;
	type = targ.getAttribute('type');
	txt = targ.getAttribute('txt');
	file = targ.getAttribute('media');
	oDiv = (document.all?document.all('view_media'):document.getElementById('view_media'));
	oDesc = (document.all?document.all('description'):document.getElementById('description'));
	oHiddenText = (document.all?document.all(file):document.getElementById(file));
	if(oHiddenText.innerHTML != '')
	{
		descTxt = oHiddenText.innerHTML;
		while(descTxt.match(/\\/))
		{
			descTxt = descTxt.replace(/\\/,'');
		}
		oDesc.innerHTML = descTxt
	}
	else oDesc.innerHTML = '';
	oDiv.style.display = 'block';
	oDiv.style.left = '250px';
	oDiv.style.top = '0px';
	
	oTitle = (document.all?document.all('media_title'):document.getElementById('media_title'));
	oTitle.innerHTML = txt;
	
	oTitle.onmousedown = beginDrag;
	oTitle.onmousemove = drag;
	oTitle.onmouseup = endDrag;
	
	switch(type)
	{
		case 'audio':
			var FO = {movie:"/lib/mp3player.swf",width:"300",height:"70",majorversion:"7",build:"0",bgcolor:"#e9f0c1",
						flashvars:"file="+file+"&backcolor=0x008B4D&frontcolor=0xffffff&lightcolor=0x008B4D&autostart=true&showeq=true" };
			UFO.create(	FO, "media");
			oMedia = (document.all?document.all('media'):document.getElementById('media'));
			oMedia.className = 'audio';
			break;
		case 'video':
			var FO = {movie:"/lib/flvplayer.swf",width:"320",height:"275",majorversion:"7",build:"0",bgcolor:"#e9f0c1",
						flashvars:"file="+file+"&showdigits=false&autostart=true&repeat=true&backcolor=0x008B4D&frontcolor=0xffffff&lightcolor=0x008B4D" };
			UFO.create(	FO, "media");
			oMedia = (document.all?document.all('media'):document.getElementById('media'));
			oMedia.className = 'tv';
			break;
	}
	if (navigator.appName=="Microsoft Internet Explorer")
	{
		x = e.x + document.body.scrollLeft;
		y = e.y + document.body.scrollTop;
	}
	else
	{
		//if(!evt) evt = window.event;
		x = parseInt(e.clientX);
		dh = (type=='audio'?70:275);//oDiv.offsetHeight;
		if((e.pageY+parseInt(dh))>document.body.scrollHeight)
			y = document.body.scrollHeight-(parseInt(dh)+15);
		else if(e.pageY>e.clientY)
			y = parseInt(e.pageY);
		else y = parseInt(e.clientY);
		
		//alert('e.pageY:'+e.pageY+' - y:'+y+' - e.clientY:'+e.clientY+' - ('+e.pageY+'+'+parseInt(dh)+')');
	}
	oDiv.style.left = (x)+'px';
	oDiv.style.top = (y)+'px';
}
function closeMedia()
{
	oTitle = (document.all?document.all('media_title'):document.getElementById('media_title'));
	oTitle.innerHTML = '';
	oMedia = (document.all?document.all('media'):document.getElementById('media'));
	cChildren = oMedia.childNodes;
	nbChildren = cChildren.length;
	for(a=(nbChildren-1);a>-1;a--)
	{
		oMedia.removeChild(cChildren[a]);
	}
	oDiv = (document.all?document.all('view_media'):document.getElementById('view_media'));
	oDiv.style.display = 'none';
}
function viewFile(file,clkObj)
{
	oModWin = document.createElement('div');
	oModWin.id = 'ModalDialog';
	document.getElementsByTagName('body')[0].appendChild(oModWin);
	oModWinTitle = document.createElement('h1');
	oModWinTitle.innerHTML = clkObj.getAttribute('txt');
	oModWin.appendChild(oModWinTitle);
	oCloseBt = document.createElement('a');
	oCloseBt.href = 'javascript:void(0)';
	oCloseBt.title = 'Fermer';
	oCloseBt.onclick = closeModalDialog;
	oCloseBt.className = 'closeButton';
	oCloseBt.innerHTML = 'X';
	oModWin.appendChild(oCloseBt);
	oIframe = document.createElement('iframe');
	oModWin.appendChild(oIframe);
	oModWin.style.position = 'absolute';
	oModWin.style.width = '800px';
	oModWin.style.height = '600px';
	oModWin.style.top = '100px';
	oModWin.style.left = '50px';
	
	oModWinTitle.onmousedown = beginDrag;
	oModWinTitle.onmousemove = drag;
	oModWinTitle.onmouseup = endDrag;
	
	oIframe.src = '/lib/get_File.lib.php?file='+file;
	oIframe.style.width = '796px';
	oIframe.style.height = '576px';
}
function closeModalDialog(e)
{
	if (!e) var e = window.event;
	if (e.target) targ = e.target;
	else if (e.srcElement) targ = e.srcElement;
	if (targ.nodeType == 3)
		targ = targ.parentNode;
	oParent = targ.parentNode;
	oContener = oParent.parentNode;
	oContener.removeChild(oParent);
}
$(document).ready(function() {
	nb_recipient = 1;
	$('input#nb_recipient').val(nb_recipient);
});
function addRecipient()
{
	nb_recipient = 1;
	nb_recipient = parseInt($('input#nb_recipient').val());
	if(nb_recipient<5)
	{
		tpl = $('div.recipient:eq(0)').clone();
		$('input',tpl).each(function() {
			str_id = $(this).attr('id');
			str_name = $(this).attr('name');
			str_id = str_id.substring(0,str_id.length-1);
			str_name = str_name.substring(0,str_name.length-1);
			$(this).attr('id',str_id+nb_recipient).attr('name',str_name+nb_recipient).val('');
		});
		$('label',tpl).each(function() {
			str_for = $(this).attr('for');
			str_for = str_for.substring(0,str_for.length-1);
			$(this).attr('for',str_for+nb_recipient);
		});
		$('div.newsletter_first_col',tpl).text((nb_recipient+1)+'.');
		$('input#nb_recipient').val(nb_recipient+1);
		$('#recipients_list').append(tpl);
	}
}
function closeRecipient(lnk)
{
	nb_recipient = 1;
	nb_recipient = parseInt($('input#nb_recipient').val());
	if(nb_recipient>1)
	{
		recipient = $(lnk).parents('div.recipient');
		recipient.empty().remove();
		$('input#nb_recipient').val(nb_recipient-1);
		a = 0;
		$('div.recipient').each(function() {
			$('input',this).each(function() {
				str_id = $(this).attr('id');
				str_name = $(this).attr('name');
				str_id = str_id.substring(0,str_id.length-1);
				str_name = str_name.substring(0,str_name.length-1);
				$(this).attr('id',str_id+a).attr('name',str_name+a);
			});
			$('label',this).each(function() {
				str_for = $(this).attr('for');
				str_for = str_for.substring(0,str_for.length-1);
				$(this).attr('for',str_for+a);
			});
			$('div.newsletter_first_col',this).text((a+1)+'.');
			a++;
		});
	}
}
function checkEmail(em)
{
	var reg = /^[a-z0-9._-]+@[a-z0-9.-]{2,}[.][a-z]{2,3}$/
	return (reg.exec(em)!=null)
}
function checkSendForm()
{
	$('.input_error').removeClass('input_error');
	nb_recipient = 1;
	nb_recipient = parseInt($('#nb_recipient').val());
	email_array = new Array();
	$('div.recipient').each(function() {
		a = 0;
		$('input',this).each(function() {
			if(a==2) { email_array.push(checkEmail($(this).val())); }
			a++;
		});
	});
	bError = false;
	for(b=0;b<email_array.length;b++)
	{
		if(!email_array[b])
		{
			bError=true;
			$('#recipient_email_'+b).addClass('input_error');
		}
	}
	if($('#sender_info').is('fieldset'))
	{
		if($('#sender_name').val()=='') { $('#sender_name').addClass('input_error'); bError = true; }
		if($('#sender_firstname').val()=='') { $('#sender_firstname').addClass('input_error'); bError = true; }
		if(!checkEmail($('#sender_email').val())) { $('#sender_email').addClass('input_error'); bError = true; }
	}
	if(!bError)
	{
		$('#share_newsletter_form').attr('action',document.location.href);
		$('#share_newsletter_form').submit();
	}
	else
	{
	//	alert(bError);
	}
}
include('/js/dnd.js');
function goToNews(index)
{
	var rindex = index-1;
	if($('.actuslider:eq('+rindex+')').is('div'))
	{
		var ncoll = $('div.actuslider');
		var pag = $('div#pagination_actus');
		$('a span',pag).each(function() {
			$(this).removeClass('pag_select').removeClass('pag_nonselect');
			$(this).addClass('pag_nonselect');
		});
		$('a span:eq('+rindex+')',pag).removeClass('pag_nonselect').addClass('pag_select');
		$('div.actuslider').each(function() {
			$(this).css('display','none');
		});
		$('div.actuslider:eq('+rindex+')').css('display','');
	}
}
var i = 1;
function changeAgendaRegion(reg,to)
{
	if(to==undefined||to==null) to = 6000;
	if(reg==undefined&&reg==null)
	{
		var max = $('.component_agenda .region_table td').length;
		if(i>=max) i = 0;
		$('.component_agenda .regions').each(function() {
			$(this).css('display','none');
		});
		$('.component_agenda .region_table td').each(function() {
			$(this).removeClass('region_nonselect').addClass('region_nonselect');
		});
		$('.component_agenda .regions:eq('+i+')').css('display','');
		var cls = $('.component_agenda .regions:eq('+i+') div#barre_region').attr('class');
		$('.component_agenda .region_table td.'+cls).removeClass('region_nonselect');
		i++;
	}
	else
	{
		var max = $('.component_agenda .region_table td').length;
		$('.component_agenda .regions').each(function() {
			$(this).css('display','none');
		});
		$('.component_agenda .region_table td').each(function() {
			$(this).removeClass('region_nonselect').addClass('region_nonselect');
		});
		$('.component_agenda .regions:eq('+reg+')').css('display','');
		var cls = $('.component_agenda .regions:eq('+reg+') div#barre_region').attr('class');
		$('.component_agenda .region_table td.'+cls).removeClass('region_nonselect');
		i=reg+1;
	}
	gto = setTimeout('changeAgendaRegion();',to);
}
gto = '';
$(document).ready(function() {
	var pag = $('div#pagination_actus');
	var a = 0;
	$('a span',pag).each(function() {
		if(!$('.actuslider:eq('+a+')').is('div'))
		{
			$('a span:eq('+a+')',pag).removeClass('pag_select').removeClass('pag_nonselect')
				.css({backgroundColor: '#aaa',borderColor:'#888',cursor:'default'});
		}
		a++;
	});
	if($('.component_agenda .regions').length>0)
	{
		$('.component_agenda .region_table td').click(function() {
			clearTimeout(gto);
			var id = $(this).attr('class');
			id = id.replace(/region_nonselect/,'').replace(/\s/,'');
			changeAgendaRegion($('.component_agenda .region_table td').index(this),12000);
		});
		$('.component_agenda .regions:gt(0)').each(function() {
			$(this).css('display','none');
		});
		gto = setTimeout('changeAgendaRegion();',6000);
	}
	goToNews(1);
});