
nb_max = 0;
current_nb = 1;
function addInputFile(list_files)
{
	if(current_nb<nb_max || nb_max==0)
	{
		document.getElementById(list_files+'_div').appendChild(document.createElement('br'));
		newinput = new Element('input', {
			'name': list_files+'[]',
			'type': 'file',
			'class': 'input_3'
		});
		newinput.addEvent('change', function(){
			addInputFile(list_files)
		});
		document.getElementById(list_files+'_div').appendChild(newinput);
		current_nb++;
	}
}

function callContactForm(form) {

	s_email = form.s_email.value;
	r_id 	= form.r_id.value;
	s_name = form.s_name.value;
	subject = form.subject.value;
	message = form.message.value;
	args = 's_email='+s_email+'&s_name='+s_name+'&subject='+subject+'&message='+message+'&r_id='+r_id+'&is_post=1';
	var myAjax = new MyAjax();
	myAjax.send({url:'/contact-membre-cm216.html', method: "POST", data:args, callback:{type:"function", name:"redirectContact"}});
	return false;
}

function redirectContact(response) {
	if(response == 'is_send') {
		var form = document.getElementById('form');
		var myAjax = new MyAjax();
		myAjax.send({url:'/confirmation-envoi.html', method: "POST", data:args, callback:{type:"function", name:"redirect"}});
		return false;
	}else if( document.getElementById('MultiBoxContentContainer') != null ) {
		document.getElementById('MultiBoxContentContainer').innerHTML =  response;
		return false;
	} else {
		document.write(response);
		return false;
	}	
}

function callConnexionForm(form) {
	email = form.email.value;
	mdp = form.password.value;
	permanent = form.permanent.checked;
	if( form.permanent.checked) {
		permanent = 1;
	} else {
		permanent = 0;
	}
	args = 'email='+email+'&password='+mdp+'&permanent='+permanent;
	var myAjax = new MyAjax();
	myAjax.send({url:'/connexion.html', method: "POST", data:args, callback:{type:"function", name:"redirect"}});
	return false;
}

function callPasswordForm(form) {
	email = form.email.value;
	args = 'email='+email;
	var myAjax = new MyAjax();
	myAjax.send({url:'/oubli-passe.html', method: "POST", data:args, callback:{type:"function", name:"redirect"}});
	return false;
}

function redirect(response) {
	if(response == 'Reload') {
		if( document.getElementById('MultiBoxContentContainer') != null ) {
			if( window.location.pathname == '/') {
				document.location = '/espace-membre.html';
			} else {
				document.location = window.location.pathname ;
			}
			return false;
		} else {
			document.location = '/';
			return false;
		}
	}
	if( document.getElementById('MultiBoxContentContainer') != null ) {
		document.getElementById('MultiBoxContentContainer').innerHTML =  response;
		return false;
	} else {
		document.write(response);
		return false;
	}	
}
function redirectToProfile(){
	window.parent.contact.close();
}

function validConditions(){
	window.parent.document.getElementById('client[term_of_use][1]').checked=1;
	window.parent.t.close();
}

function redirectToPass() {
	var newAjax = new MyAjax();
	if( document.getElementById('MultiBoxContentContainer') != null ) {
		newAjax.send({url:'/oubli-passe.html', method: 'POST', callback:{type:"innerHTML", name:"MultiBoxContentContainer"}});
	} else {
		document.location = '/oubli-passe.html';
	}
}

function redirectToConnect() {
	var nwAjax = new MyAjax();
	if( document.getElementById('MultiBoxContentContainer') != null) {
		nwAjax.send({url:'/connexion.html', method: 'POST', callback:{type:"innerHTML", name:"MultiBoxContentContainer"}});
	} else {
		document.location = '/connexion.html';
	}
}

function changeHref( id) {

	var reg = new RegExp( 'connexion-membre.html', 'g');
	if( reg.test( document.getElementById( id).href)) {
		document.getElementById( id).href = '/connexion.html';
	}
}

function changeHrefTerm( id) {

	var reg = new RegExp( 'conditions-generales.html', 'g');
	if( reg.test( document.getElementById( id).href)) {
		document.getElementById( id).href = '/conditions.html';
	}
}
function changeHrefContact( id) {

	var reg = new RegExp( 'contacter-membre.html', 'g');
	if( reg.test( document.getElementById( id).href)) {
		document.getElementById( id).href = '/contact-membre.html';
	}
}

function show( divId ) {
	var div = document.getElementById( divId );
	if( div != null ){
		if( div.style.display == 'block') {
			div.style.display = 'none';
		} else {
			div.style.display = 'block';
		}
	}	
}

function hide( divId ){
	var div = document.getElementById( divId );
        if( div != null ){
                div.style.display = 'none';
        }

}

function setContent( eltId, content ){
	var elt = document.getElementById( eltId );
        if( elt != null ){
                elt.innerHTML = content;
        }
}

function showImage( divId, imgUrl ){
	setContent( divId, '<div><a href="javascript:hide(\''+divId+'\');"><img src="'+imgUrl+'" /><br/>Fermer l\'aperçu</a></div>');
	show( divId );
}

function showComment( ident) {
	var obj = document.getElementById( ident);
}

function openOnglet( id, link ){
	var elt = document.getElementById( id );
    if( elt != null ){
        elt.attributes["class"].value = 'open';
		var l = document.getElementById( link );
		if( l != null ){
			l.attributes["onclick"].value = "closeOnglet('"+id+"','"+link+"');return false;";
			l.src = 'skins/default/bul-tree-1_close.gif';
		}
    }
}

function closeOnglet( id, link ){
	var elt = document.getElementById( id );
	if( elt != null ){
		elt.attributes["class"].value = 'close';
		var l = document.getElementById( link );
		if( l != null ){
			l.attributes["onclick"].value = "openOnglet('"+id+"','"+link+"');return false;";
			l.src = 'skins/default/bul-tree-1_open.gif';
		}
	}
}

function openList( id, link ){
	var elt = document.getElementById( id );
    if( elt != null ){
		elt.style.display = 'block';
		var l = document.getElementById( link );
        if( l != null ){
			l.attributes["onclick"].value = "closeList('"+id+"','"+link+"');return false;";
			l.innerHTML = '(-)';
		}
	}
}

function closeList( id, link ){
    var elt = document.getElementById( id );
    if( elt != null ){
        elt.style.display = 'none';
		var l = document.getElementById( link );
        if( l != null ){
			l.attributes["onclick"].value = "openList('"+id+"','"+link+"');return false;";
			l.innerHTML = '(+)';
		}		
    }
}

function dump(obj) 
{ 
	var text = ''; 
	for(idd in obj) text += idd+' : '+obj[idd]+"\n"; 
	alert(text); 
}

function articlePrint( article_id) {

	new Ajax( '/print-pages.php', {
		method: 'post',
		data: 'article_id='+article_id,
		evalScripts: false,
		onComplete: function( response) {
			var pages = eval('(' + response + ')');
			if( pages != '') {
				var container = new Element('div').addClass('printPages').injectAfter( 'paging');
				for( page in pages) {
					var bloc = new Element( 'div').addClass( 'p').injectInside( container);
					var h = new Element( 'h4').injectInside( bloc);
					var span = new Element( 'span').injectInside( h);
					span.setHTML( page + '. ' + pages[page]['title']);
				
					var content = new Element('div').addClass( 'articleContent').injectInside( bloc);
						content.setHTML( pages[page]['content']);
					content.setStyle('margin-bottom', '10px');
				}
			}
			window.print();
		}
	}).request();
}

function getNeighbour(id)
{
	new Ajax( '/googlemap.php', {
        method: 'post',
        data: 'id='+id,
        evalScripts: false,
        onComplete: function(response) {
            var list = eval('(' + response + ')');
			gmap.clear();
			list.each(function(item, index) {
				gmap.createMarker(gmap.makeMarker(item));
			});
			gmap.focusMap();
        }
    }).request();
}


/**
 * updateHCalendar : navigation du calendrier agenda 
 * 
 * @param id $id 
 * @access public
 * @return void
 * @date 2009-06-19
 * @author guillaume <	g.nouet@hegyd.com
>
 */
function updateHCalendar(evt, id, month, year){

	new Event(evt).stop();

	new Ajax( '/ajax/update-hcalendar', {
        method: 'post',
        data: 'id='+id+'&m='+month+'&y='+year,
        evalScripts: false,
        onComplete: function(response) {
			$(id).getParent().innerHTML = response;
        }
    }).request();
}



function callBookmark(evt, id, url, title, desc){

	new Event(evt).stop();

	if(id == 'twitter')		u = 'http://twitter.com/home?status=';
	if(id == 'delicious')	u = 'http://del.icio.us/post?url=';
	if(id == 'facebook')	u = 'https://www.facebook.com/share.php?u=';
	if(id == 'netvibes')	u = 'http://www.netvibes.com/subscribe.php?url=';
	if(id == 'newsgator')	u = 'http://www.newsgator.com/ngs/subscriber/subext.aspx?url=';
	if(id == 'technorati')	u = 'http://technorati.com/faves?add=';
	if(id == 'viadeo')		u = 'http://www.viadeo.com/shareit/share/?title='+title+'&urllanguage=fr&urlaffiliate=32003&encoding=UTF-8&overview='+desc+'&url=';
	if(id == 'google')		u = 'http://www.google.com/bookmarks/mark?op=add&title='+title+'&bkmk=';
	if(id == 'digg')		u = 'http://www.digg.com/submit?title='+title+'&url=';
	if(id == 'wikio')		u = 'http://www.wikio.com/sharethis?title='+title+'&url=';
	if(id == 'yahoo')		u = 'http://myweb2.search.yahoo.com/myresults/bookmarklet?u=';
	if(id == 'live')		u = 'https://favorites.live.com/quickadd.aspx?marklet=1&amp;mkt=en-us&amp;top=1&amp;url=';

	u = u+url;	

	window.open(u);
}
