function SubmitForm() {

	document.form_identification.submit();
}

function AddDate() {
	var dates = clean(document.getElementById('tabNouvChronokifDate2')).firstChild;

	var espaceTr = dates.childNodes[0].cloneNode(true);
	var newTr = dates.childNodes[dates.childNodes.length-1].cloneNode(true);
	
	var inputs = newTr.getElementsByTagName('input');
	
	for(var i = 0; i<inputs.length; i++) {
		inputs[i].value = "";
	}
	
	var selects = newTr.getElementsByTagName('select');
	
	for(var i = 0; i<selects.length; i++) {
		selects[i].options[0].selected = true;
	}

	/*
	var spans = newTr.getElementsByID('numeroPhoto');
	spans[0].firstChild.nodeValue = parseInt(spans[0].firstChild.nodeValue) + 1;
	*/
	dates.appendChild(espaceTr);
	dates.appendChild(newTr);
	
}

function AddMedia(souvenir) {
	
	var medias1 = clean(document.getElementById('tableauMedias1')).firstChild;
	var medias2 = clean(document.getElementById('tableauMedias2')).firstChild;
	
	var tr1 = medias1.getElementsByTagName('tr');
	var tr2 = medias2.getElementsByTagName('tr');

	var newTr = medias2.childNodes[medias2.childNodes.length-1].cloneNode(true);
	
	var inputs = newTr.getElementsByTagName('input');
	
	if(souvenir == 5)
		var nbPhoto = (10 - (tr1.length/2));
	else
		var nbPhoto = 4;
	//alert(tr1.length);
	if(tr2.length < nbPhoto) {
		for(var i = 0; i<inputs.length; i++) {
			inputs[i].value = "";
			
		}
		medias2.appendChild(newTr);
		
		if(tr2.length == nbPhoto)
		{
			document.getElementById('photo_3').style.display="none";
			document.getElementById('warningPhoto').style.display="";
		}
	} 
	else {
		document.getElementById('photo_3').style.display="none";
		document.getElementById('warningPhoto').style.display="";
	}

}

function SupprimerDate(elem)
{
	var dates = clean(document.getElementById('tabNouvChronokifDate2')).firstChild;
	var trASupprimer = elem.parentNode.parentNode;
	if(dates.childNodes.length > 1)
		dates.removeChild(trASupprimer);
}

function RetirerMedia(elem)
{
	var media = clean(document.getElementById('tableauMedias2')).firstChild;
	var trASupprimer = elem.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode;
	if(media.childNodes.length > 1) {
		media.removeChild(trASupprimer);
		document.getElementById('warningPhoto').style.display="none";
	} else {
		AfficherMedia(1);	
	}
	
}

function SupprimerMedia(idChronokif, idMedia) {
	
	document.location.href = 'index.php?module=front&cont=chronokif&action=supprimermedia&idc=' + idChronokif + '&idm=' + idMedia ;
}

function SupprimerChronokif(idChronokif, idEtat) {
	
	document.location.href = 'index.php?module=front&cont=chronokif&action=supprimerchronokif&idc=' + idChronokif + '&ide=' + idEtat;
}
		
function ChoixDate(choix) {
	
	if(choix == 1) { document.getElementById('explicationCK').style.display="none"; }
	else { document.getElementById('explicationCK').style.display=""; }
	document.getElementById('date_1').style.display="none";
	document.getElementById('date_2').style.display="none";
	document.getElementById('date_3').style.display="none";
	document.getElementById('date_4').style.display="none";
	document.getElementById('explicationCK2').style.display="none";
	document.getElementById('explicationCK3').style.display="none";
	document.getElementById('explicationCK4').style.display="none";
	
	document.getElementById('date_' + choix).style.display="";
	
	if(choix != 1) { document.getElementById('explicationCK' + choix).style.display=""; }
}

function ChoixPartage(choix) {
		
	if(choix == 1) {
		document.getElementById('infos_public').style.display="";
	}
	else {
		document.getElementById('infos_public').style.display="none";	
	}
	
	if(choix == 2) {
		document.getElementById('tribu').style.display="";
	}
	else {
		document.getElementById('tribu').style.display="none";	
	}
}

function ChoixFrequence(choix) {
	
	if (document.getElementById('chbxFrequence').checked) {
		document.getElementById('frequenceDate1').style.display="";
	}
	else {
		document.getElementById('frequenceDate1').style.display="none";	
	}
	
}

function AfficherMedia(choix) {
	
	document.getElementById('photo_1').style.display="none";	
	document.getElementById('photo_2').style.display="none";
	document.getElementById('photo_3').style.display="none";
	if( choix == 1) {
		document.getElementById('photo_1').style.display="";
		
		var media = clean(document.getElementById('tableauMedias')).firstChild;
		
		for(var i = media.childNodes.length-1; i > 0; i--) {
			var trASupprimer = media.childNodes[1];
			media.removeChild(trASupprimer);
		}

		var newTr = media.childNodes[0];
		var inputs = newTr.getElementsByTagName('input');
		for(var i = 0; i<inputs.length; i++) {
			inputs[i].value = "";
		}
	}
	else {
		document.getElementById('photo_2').style.display="";
		document.getElementById('photo_3').style.display="";
	}
	
}

function TriCategorie() {
	
	var choix = document.getElementById('typoListeTri').options[document.getElementById('typoListeTri').selectedIndex].value;
	document.location.href = 'index.php?module=front&cont=home&idcat=' + choix;
}

function TriSouvenirs() {
	
	var choix = document.getElementById('typoListeTri').options[document.getElementById('typoListeTri').selectedIndex].value;
	document.location.href = 'index.php?module=front&cont=chronokif&action=souvenirs&tri=' + choix;
}

function TriMesChronokifs() {
	
	var choix = document.getElementById('typoListeTri').options[document.getElementById('typoListeTri').selectedIndex].value;
	var idMembre = document.getElementById('idMembreFiche').value;
	
	if(document.location.href.indexOf('meschronokifs') >= 0){ 
		document.location.href = 'index.php?module=front&cont=chronokif&action=meschronokifs&idm=' + idMembre + '&tri=' + choix;
	}
	else {
		document.location.href = 'index.php?module=front&cont=chronokif&action=fichemembre&idm=' + idMembre + '&tri=' + choix;
	}
}

function TriChronokifsTribu() {
	
	var choix = document.getElementById('typoListeTri').options[document.getElementById('typoListeTri').selectedIndex].value;
	document.location.href = 'index.php?module=front&cont=tribus&action=fiche&tri=' + choix;
}

function AddTag(choix) {

	document.getElementById('inputMotCle').value = choix;
	
	document.getElementById('rechercheTag').submit();
}

function RechercheTop() {
	
	document.getElementById('barreRecherche').submit();

}

// Dfilement 4 directions multiple
function Defilant(id, pos_init, pos_min, pos_max, delta, direction) {
   this.id          = id;
   this.element     = document.getElementById(id);
   this.pos_init    = pos_init;
   this.pos_min     = pos_min;
   this.pos_max     = pos_max;
   this.pos_current = pos_init;
   this.delta       = delta;
   this.direction   = direction;
}
       
Defilant.prototype.defile = function() {
   
	if (!this.element) 
	{
		this.element = document.getElementById(this.id);
	}
	
	if (this.element) 
	{
		if(this.pos_current < this.pos_min || this.pos_current > this.pos_max)
		{
			this.delta = -this.delta;
		} 
	
		this.pos_current += this.delta;
	
		if(this.direction == 'vertical')
		{
			this.element.style.top = this.pos_current+"px";
		} 
		else if(this.direction == 'horizontal') 
		{
			this.element.style.left = this.pos_current+"px";
		}
	}
}


function InitTrombi(id, largeurCadre) {
	
	var largeurContent = parseInt(document.getElementById(id).offsetWidth);

	if(largeurContent > largeurCadre) {
	
		defilantTrombi = new Defilant(id, 0, - largeurContent + largeurCadre, 0, deltaDefilantTrombi, 'horizontal');
		timerTrombi = setInterval("defilantTrombi.defile()",30);
		
		$("#bt_trombi_prev").mouseover(
			function() {
				clearInterval(timerTrombi)
				deltaDefilantTrombi = +2
				defilantTrombi.delta = deltaDefilantTrombi;
				defilantTrombi.defile();
				timerTrombi = setInterval("defilantTrombi.defile()",30);
			}
		);
		
		$("#bt_trombi_prev").mouseout(
			function() {
				clearInterval(timerTrombi)
				deltaDefilantTrombi = +1
				defilantTrombi.delta = deltaDefilantTrombi;
				defilantTrombi.defile();
				timerTrombi = setInterval("defilantTrombi.defile()",30);
			}
		);
		
		$("#bt_trombi_next").mouseover(
			function() {
				clearInterval(timerTrombi)
				deltaDefilantTrombi = -2
				defilantTrombi.delta = deltaDefilantTrombi;
				defilantTrombi.defile();
				timerTrombi = setInterval("defilantTrombi.defile()",30);
			}
		);
		
		$("#bt_trombi_next").mouseout(
			function() {
				clearInterval(timerTrombi)
				deltaDefilantTrombi = -1
				defilantTrombi.delta = deltaDefilantTrombi;
				defilantTrombi.defile();
				timerTrombi = setInterval("defilantTrombi.defile()",30);
			}
		);
		
		$("#defilant_trombi").mouseover(
			function() {
				clearInterval(timerTrombi)
			}
		);
		
		$("#defilant_trombi").mouseout(
			function() {
				defilantTrombi.defile();
				timerTrombi = setInterval("defilantTrombi.defile()",30);
			}
		);
	}
}

function InitTrombiCalendrier(id, largeurCadre) {
	
	var vitesseDefilement = 90;
	
	var largeurContent = parseInt(document.getElementById(id).offsetHeight);

	if(largeurContent > largeurCadre) {
		
		
		defilantTrombiCalendrier = new Defilant(id, 0, - largeurContent + largeurCadre, 0, deltaDefilantTrombiCalendrier, 'vertical');
		timerTrombiCalendrier = setInterval("defilantTrombiCalendrier.defile()",vitesseDefilement);
		
		$("#bt_trombi_prev_calendrier").mouseover(
			function() {
				clearInterval(timerTrombiCalendrier)
				deltaDefilantTrombiCalendrier = +2
				defilantTrombiCalendrier.delta = deltaDefilantTrombiCalendrier;
				defilantTrombiCalendrier.defile();
				timerTrombiCalendrier = setInterval("defilantTrombiCalendrier.defile()",vitesseDefilement-20);
			}
		);
		
		$("#bt_trombi_prev_calendrier").mouseout(
			function() {
				clearInterval(timerTrombiCalendrier)
				deltaDefilantTrombiCalendrier = +1
				defilantTrombiCalendrier.delta = deltaDefilantTrombiCalendrier;
				defilantTrombiCalendrier.defile();
				timerTrombiCalendrier = setInterval("defilantTrombiCalendrier.defile()",vitesseDefilement);
			}
		);
		
		$("#bt_trombi_next_calendrier").mouseover(
			function() {
				clearInterval(timerTrombiCalendrier)
				deltaDefilantTrombiCalendrier = -2
				defilantTrombiCalendrier.delta = deltaDefilantTrombiCalendrier;
				defilantTrombiCalendrier.defile();
				timerTrombiCalendrier = setInterval("defilantTrombiCalendrier.defile()",vitesseDefilement-20);
			}
		);
		
		$("#bt_trombi_next_calendrier").mouseout(
			function() {
				clearInterval(timerTrombiCalendrier)
				deltaDefilantTrombiCalendrier = -1
				defilantTrombiCalendrier.delta = deltaDefilantTrombiCalendrier;
				defilantTrombiCalendrier.defile();
				timerTrombiCalendrier = setInterval("defilantTrombiCalendrier.defile()",vitesseDefilement);
			}
		);
		
		$("#defilant_trombi_calendrier").mouseover(
			function() {
				clearInterval(timerTrombiCalendrier)
			}
		);
		
		$("#defilant_trombi_calendrier").mouseout(
			function() {
				defilantTrombiCalendrier.defile();
				timerTrombiCalendrier = setInterval("defilantTrombiCalendrier.defile()",vitesseDefilement);
			}
		);
	}
}

function Souvenir(){
	
	var date;
	var jour;
	var mois;
	var annee;
	var heure;
	var minute;
	
	date = document.getElementById('dateDebut').value ;
	
	jour = date.substr(0,2);
	mois = date.substr(3,2);
	annee = date.substr(6,4);
	heure = document.getElementById('heureDebut').options[document.getElementById('heureDebut').selectedIndex].value ;
	minute = document.getElementById('minuteDebut').options[document.getElementById('minuteDebut').selectedIndex].value ;
	
	date = mois +"/"+jour+"/"+annee+" "+heure+":"+minute;
	
	d_actuel=new Date();
	date_actuel=(d_actuel.getMonth()+1)+"/" + d_actuel.getDate()+"/"  +d_actuel.getFullYear()+" "+d_actuel.getHours()+":"+d_actuel.getMinutes();

	/*alert(date);
	alert(date_actuel);*/

	date_actuel = Date.parse(date_actuel); 
	date = Date.parse(date); 
	
	var diff = date - date_actuel;
	if (diff < 0){
		document.getElementById('souvenirsouvenir').style.display="";
		// alert(" Attention, le Chronokif cre est un Souvenir...");
		}
	else
		document.getElementById('souvenirsouvenir').style.display="none";

}


function EnvoyerPopUp(idChronokif){
	//alert(idChronokif);
	$.post(
		"index.php?module=front&cont=chronokif&action=formpopenvoi", { 'idc' : idChronokif },
		function(data) { 
				
			$(data).dialog({
				autoOpen : true,
				height : 'auto',
				width : 430,
				modal : false,
				resizable : true,
				zIndex : 9999
			});
			
		},
		"html"
	)
}

function AnnulerEnvoiPopUp() 
{ 
	$("#envoiPopUp").dialog("close"); 
	$("#envoiPopUp").dialog("destroy"); 
	$("#envoiPopUp").remove();
}

function EnvoiPopUpSave()
{	
	var expediteur =  $("#destinataire").val();
	$.post(
		"index.php?module=front&cont=chronokif&action=envoisave", { 'idc' : $("#idc").val(), 'expe' : $("#expediteur").val(),  'dest' : $("#destinataire").val(), 'mail' : $("#adresse").val() },
		function(data) { 
			$("#envoiPopUp").dialog("close"); 
			$("#envoiPopUp").dialog("destroy"); 
			$("#envoiPopUp").remove();
			
			var message = '<div title="' + data + '">Le ChronoKif <span style="color:#fea31a; font-style:italic"> ' + data + ' </span> a bien &eacute;t&eacute; partag&eacute; avec ' + expediteur + ' !</div>';
			$(message).dialog({width: 430});
			
		}
	)
	
}	

function PopupAPI(idChronokif){
	//alert(idChronokif);
	$.post(
		"index.php?module=front&cont=chronokif&action=showAPI", { 'idc' : idChronokif },
		function(data) { 
				
			$(data).dialog({
				autoOpen : true,
				height : 'auto',
				width : 550,
				modal : false,
				resizable : true,
				zIndex : 9999,
				open: function()
				{
					$("#showWidget").click(function() {
						
            $("#apiDemo").show();
            $("#showCode").show();
						PopupMAJCodeAPI();
            $(this).remove();

					});
					
					$("#showCode").click(function() {
						
						$("#apiCode").show();
            PopupMAJCodeAPI();            
						$(this).remove();

					});
				},
				close: function()
				{
					$("#apiParams").remove();
					$("#apiCode").remove();
					$("#apiDemo").remove();
				}
			});
			
		},
		"html"
	)
}

function PopupLienAPI(idChronokif){
	
	$.post(
		"index.php?module=front&cont=chronokif&action=showlienapi", { 'idc' : idChronokif },
		function(data) {
			$(data).dialog({
				autoOpen : true,
				height : 401,
				width : 541,
				modal : true,
				resizable : false
			});
			
		},
		"html"
	)
	return false;
}

function PopupGeolocalisation()
{
	$.post(
		"index.php?module=front&cont=membre&action=popupGeo", { },
		function(data) { 
				
			$(data).dialog({
				autoOpen : true,
				height : 'auto',
				width : 550,
				modal : true,
				resizable : true,
				zIndex : 9999,
				open: function() { 
					
					$("#geo_confirmation").hide();
					$("#geo_save").click(function() { 
					
						$.post(
							"index.php?cont=membre&action=saveGeo", 
							{ geo_code_postal: $("#geo_code_postal").val(), geo_ville: $("#geo_ville").val(), geo_pays: $("#geo_pays").val() },
					 		function(data) {
						 		
								$("#geo_form").hide();
								$("#geo_confirmation").show();
								
					 		}
						);
					});
					
				}
			});
			
		},
		"html"
	)
}
