function format(valeur,decimal,separateur) {
	var deci=Math.round( Math.pow(10,decimal)*(Math.abs(valeur)-Math.floor(Math.abs(valeur)))) ; 
	var val=Math.floor(Math.abs(valeur));
	if ((decimal==0)||(deci==Math.pow(10,decimal))) {val=Math.floor(Math.abs(valeur)); deci=0;}
	var val_format=val+"";
	var nb=val_format.length;
	for (var i=1;i<4;i++) {
		if (val>=Math.pow(10,(3*i))) {
			val_format=val_format.substring(0,nb-(3*i))+separateur+val_format.substring(nb-(3*i));
		}
	}
	if (decimal>0) {
		var decim=""; 
		for (var j=0;j<(decimal-deci.toString().length);j++) {decim+="0";}
		deci=decim+deci.toString();
		val_format=val_format+"."+deci;
	}
	if (parseFloat(valeur)<0) {val_format="-"+val_format;}
	return val_format;
}

function formatFloat(valeur, separateur){
	if (separateur == ".")
		return valeur.replace(/,/g, "\.");
	else
		return valeur.replace(/\./g, ",");
}

function empty(mixed_var) {
    // empty(null); => true
    // empty(undefined); => true
    // empty([]); => true
    // empty({}); => true
    // empty({'aFunc' : function () { alert('humpty'); } }); => false
    
    var key;
    
    if (mixed_var === ""
        || mixed_var === 0
        || mixed_var === "0"
        || mixed_var === null
        || mixed_var === false
        || mixed_var === undefined
    ){
        return true;
    }
 
    if (typeof mixed_var == 'object') {
        for (key in mixed_var) {
            return false;
        }
        return true;
    }
 
    return false;
}

function join(glue, pieces) {
    // implode(' ', ['Kevin', 'van', 'Zonneveld']); => 'Kevin van Zonneveld'
    return ((pieces instanceof Array) ? pieces.join(glue) : pieces);
}

function http_build_query(formdata, numeric_prefix, arg_separator) {
    // http_build_query({foo: 'bar', php: 'hypertext processor', baz: 'boom', cow: 'milk'}, '', '&amp;');
    // => 'foo=bar&amp;php=hypertext+processor&amp;baz=boom&amp;cow=milk'
    // http_build_query({'php': 'hypertext processor', 0: 'foo', 1: 'bar', 2: 'baz', 3: 'boom', 'cow': 'milk'}, 'myvar_');
    // => 'php=hypertext+processor&myvar_0=foo&myvar_1=bar&myvar_2=baz&myvar_3=boom&cow=milk'
 
    var key, use_val, use_key, i = 0, j=0, tmp_arr = [];
 
    if (!arg_separator) {
        arg_separator = '&';
    }
 
    for (key in formdata) {
        use_val = urlencode(formdata[key].toString());
        use_key = urlencode(key);
 
        if (numeric_prefix && !isNaN(key)) {
            use_key = numeric_prefix + j;
            j++;
        }
        tmp_arr[i++] = use_key + '=' + use_val;
    }
 
    return tmp_arr.join(arg_separator);
}

function urlencode(str) {
    // urlencode('Kevin van Zonneveld!'); => 'Kevin+van+Zonneveld%21'
    // urlencode('http://kevin.vanzonneveld.net/'); => 'http%3A%2F%2Fkevin.vanzonneveld.net%2F'
    // urlencode('http://www.google.nl/search?q=php.js&ie=utf-8&oe=utf-8&aq=t&rls=com.ubuntu:en-US:unofficial&client=firefox-a'); => 'http%3A%2F%2Fwww.google.nl%2Fsearch%3Fq%3Dphp.js%26ie%3Dutf-8%26oe%3Dutf-8%26aq%3Dt%26rls%3Dcom.ubuntu%3Aen-US%3Aunofficial%26client%3Dfirefox-a'
                             
    var histogram = {}, tmp_arr = [];
    var ret = str.toString();
    
    var replacer = function(search, replace, str) {
        var tmp_arr = [];
        tmp_arr = str.split(search);
        return tmp_arr.join(replace);
    };
    
    // The histogram is identical to the one in urldecode.
    histogram["'"]   = '%27';
    histogram['(']   = '%28';
    histogram[')']   = '%29';
    histogram['*']   = '%2A';
    histogram['~']   = '%7E';
    histogram['!']   = '%21';
    histogram['%20'] = '+';
    
    // Begin with encodeURIComponent, which most resembles PHP's encoding functions
    ret = encodeURIComponent(ret);
    
    for (search in histogram) {
        replace = histogram[search];
        ret = replacer(search, replace, ret) // Custom replace. No regexing
    }
    
    // Uppercase for full PHP compatibility
    return ret.replace(/(\%([a-z0-9]{2}))/g, function(full, m1, m2) {
        return "%"+m2.toUpperCase();
    });
    
    return ret;
}

function toggle(id){
	var element = document.getElementById(id);
	if(typeof(element) != "undefined") {
		if (element.style.display == "")
			element.style.display = "none";
		else
			element.style.display = "";
	}	
}

function show(id){
	var element = document.getElementById(id);
	if(typeof(element) != "undefined")
		element.style.display = "";
}

function hide(id){
	var element = document.getElementById(id);
	if(typeof(element) != "undefined")
		element.style.display = "none";
}