function display_zone(id_to_dis){
	$('#'+id_to_dis).slideDown();
}
function hide_zone(id_to_dis){
	$('#'+id_to_dis).slideUp();
}
function toggle_zone(id_to_dis){
	$('#'+id_to_dis).slideToggle();
}
// affichage des éléments d'un object
var deep=5;
function listObject(object, maxdeep) {
    var decal = '-- ';
    var textObject = "";
    for (var i in object) {
        // création de l'indentation
        var indent = "";
        for (var y = 0; y < deep; y++) indent += decal;
        // nom de la propriété
        textObject += "deep = " + deep + " : " + indent + "<b>" + i + "</b> : ";
        if (typeof(object[i]) == ("object") && deep < maxdeep) {
            deep++;
            textObject += "<br />" + listObject(object[i],  maxdeep);
            deep--;
        }
        else {
            // valeur de la propriété
            textObject += object[i] + "<br />";
        }
    }
    return (textObject);
}

function VerifMail(a){
	valide1 = false;
	
	for(var j=1;j<(a.length);j++){
		if(a.charAt(j)=='@'){
			if(j<(a.length-4)){
				for(var k=j;k<(a.length-2);k++){
					if(a.charAt(k)=='.') valide1=true;
				}
			}
		}
	}
	return valide1;
}

// Affichage dans le div des éléments d'un object
function retourObj (object, deep) {
    var evalObject = eval(object);
    document.getElementById('infoObject').style.display = "";
    document.getElementById('infoObject').innerHTML = (object) ? listObject(evalObject, deep) : "Ce n'est pas un object";
}
function Remplace(str,find,rep){
	if(str=="undefined" || str==undefined || str==''){
		return '';
	}
	else if(str!=null){
		x = str.length;
		if(x>4){
			var reg = new RegExp(find,"gi")
			return(str.replace(reg,rep));
		}else return str;
	}else return '';	
}
function is_numeric(input){
     return (input - 0) == input && input.length > 0;
 }
function redir(url){
	window.location.href=url;
}
function display_help(title,text,idguide,url){
	if(help_statut){
		$('#header_help h3').html(title);
		$('#content_help').html(text);
		if(idguide!='' && url!=''){
			$('#'+idguide).click(function(){
				popupWindow(url, 'Aide', 640, 700, 1);
			});
		}
		$('#help_zone').slideDown();
		
	}
}
function hide_help(){
	$('#help_zone').slideUp();
}
function toggle_help(){

	if(help_statut){// si l'aide est en place
		$.post("toggle_help.php",{help_stat:help_statut},
		function success(data){
			hide_help();
			help_statut=0;
			$('#desactive_help').html("Activer l'aide");
		}, "json");
	}else{
		$.post("toggle_help.php",{help_stat:help_statut},
		function success(data){			
			help_statut=1;
			$('#desactive_help').html("Désactiver l'aide");
		}, "json");
	}
	
}

/**
* Pops up a new window in the middle of the screen
*/
function popupWindow(mypage, myname, w, h, scroll) {
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable';
	win = window.open(mypage, myname, winprops);
	if(!win || win.closed || typeof win.closed=='undefined'){
		alert('La fenêtre que vous souhaitiez lancer a été bloquée par votre navigateur, veuillez autoriser l\'ouverture de pop up pour ce site');
	}
	if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
	
}

function sign_up_newsletter(){
	var email_to_sign=jQuery('#newsletter').val();
	if(VerifMail(email_to_sign)){
		jQuery.post(url_dir+"/sign_up_newsletter.php",{email:email_to_sign},
			function success(data){
				if(data.succes=='2'){
					alert('Email déjà présent dans la base de données');
				}else{
					alert('Vous êtes bien inscrit à la newsletter');
				}
			}
		, "json");
	}else{
		alert('Veuillez saisir un email valide');
	}
}

