function PreloadImg() {
    var args_len = arguments.length;
    for (var i = args_len; i--;) {
      var cacheImage = document.createElement('img');
      cacheImage.src = arguments[i];
    }
};

function functionName(fn)
{
	var name=/\W*function\s+([\w\$]+)\(/.exec(fn);
	if(!name)return 'No name';
	return name[1];
}
function RendreElementUnique(elt){
    var dialogs = elt;
    for (var i=1; i<dialogs.length; i++)
        dialogs.eq(i).remove();

}
function LimitToDecimal(field) {
	
	var val = field.value;
	val = val.replace(/,/g, '.');
	val = val.replace(/[^0-9\.]/g, '');
	field.value = val;
	
}


function comaField(champ) {
	var valeur = champ.value;
	pos = valeur.indexOf(",");
	if (pos >= 0) {
		valeur = valeur.substr(0, pos) + "." + valeur.substr(pos+1);
	}
	champ.value = valeur;
}

function DateFrToDate(date) {
	date = date.replace(/^0+/g,"");
	date = date.replace(/\/0+/g,"/");
	var s = date.split('/');
	return new Date(parseInt(s[2]), parseInt(s[1])-1, parseInt(s[0]));
}

function DateFrToSql(date) {
	var s = date.split('/');
	return s[2]+"-"+s[1]+"-"+s[0];
}

function DateSqlToFr(date) {
	var s = date.split('-');
	return s[2]+"/"+s[1]+"/"+s[0];
}

function DateDiffDays(date1, date2) {
	diff = date('z', date2) - date('z', date1);
	for (year=date('Y', date1); year<date('Y', date2);year++) {
		diff += EstBisextile(year)?366:365;
	}
	return diff;
}

function EstBisextile(year) {
	return (year % 4 == 0 && (year%100 != 0 || year%400==0));
}
function TimeMinuteToSql(hm) {
	var hmpos = hm;
	if (hmpos < 0) hmpos = -hmpos;
	var h = Math.floor(hmpos/60);
	var m = hmpos%60;
	if (h < 10) h = '0' + h;
	if (m < 10) m = '0' + m;
	return (hm<0?'-':'') + h + ':' + m;
}

function DateToFr(date) {
	var day = (date.getDate()).toString();
	var month = (date.getMonth()+1).toString();
	var year = (date.getFullYear()).toString();
	if (day.length < 2) day = '0' + day;
	if (month.length < 2) month = '0' + month;
	return day + '/' + month + '/' + year;
}

function TimeSqlToMinute(t) {
	var s = t.split(':');
	return parseInt(s[0].replace(/^0/g,""))*60 + parseInt(s[1].replace(/^0/g,""));
}


function urlRemoveVariable(url, variable) {
	return url.replace(new RegExp(variable + '=[^&]*', 'g'), '').replace(new RegExp('&+', 'g'), '&').replace(new RegExp('&$', 'g'), '');
}
function urlRemoveVariables(url, variables) {
	for(var variable in variables)
		url = urlRemoveVariable(url, variable);
	
	return url;
}
function urlAddVariable(url, variable, value) {	
	url = urlRemoveVariable(url, variable);	
	if (url.indexOf('?',0) === false) return url + '?' + variable + '=' + value;
	else	return url + '&' + variable + '=' + value;
}

function Post(url, args, attributes) {
	if (attributes == undefined) attributes = [];
	var id = 'frmpostid' + Math.random();
	var html = '<form action="'+url+'" method="post" id="'+id+'"';
	for (key in attributes) {
		html += ' ' + key + '="'+attributes[key]+'"';
	}
	html += '>';
	for (key in args) {
		html += '<input type="hidden" name="'+key+'" value=\''+args[key]+'\' />';
	}
	html += '</form>';
	$('body').append(html);
	document.getElementById(id).submit();
}

function formise(jQueryObject){
    	jQueryObject.find("a.ajaxFormTrigger").click(submitForm);
		jQueryObject.find("button.ajaxFormTrigger").click(submitForm);
    	jQueryObject.find("input[type=text].ajaxFormTrigger").change(submitForm);
    	jQueryObject.find("input.ajaxFormTrigger").not("[type=text]").click(submitForm);    
    	jQueryObject.find("select.ajaxFormTrigger").change(submitForm);
    	jQueryObject.find("button[action]").click(submitForm);
    }

function submitForm(){
	var jQueryObject = $(this);
	//var jQueryParentObject = $(this).parent();//l'element HTML declencheur doit etre seul dans sa balise parente
	var method = jQueryObject.attr("method") != undefined ? jQueryObject.attr("method"): "POST";
	var action = jQueryObject.attr("action");
	var ajax = jQueryObject.attr('ajax');
    var myForm = jQueryObject.attr('formId');
    var type = jQueryObject.attr('typeOfData') != undefined ? jQueryObject.attr('typeOfData') : '';

    if (myForm != undefined) {
        var fields = '{';
        $('#' + myForm + ' .field').each(function() {
            if ($(this).hasClass('fckeditor')) {
                var editor = FCKeditorAPI.GetInstance($(this).attr('id'));
                var value = editor.GetHTML();
            } else {
                var value = $(this).val();
            }

            value = value.replace(/\"/g,"\\\"");

            var key = $(this).attr('name');
            if (fields != '{') fields += ',';
            fields += '"' + key + '":' + '"' + value + '"';
        });
        fields += '}';
    } else {
        fields = jQueryObject.attr("fields");
    }

    eval("var fields = " + fields);

	jQueryObject.trigger('beforeformpost');

	if(ajax != undefined){
		switch(method){
			case "POST":
				$.post(action, fields, function(data){
                    jQueryObject.trigger('afterformpost', data);
				}, type);
				break;
			case "GET":
				$.get(action, fields, function(data){
                    jQueryObject.trigger('afterformpost', data);
				}, type);
				break;
		}
	}else{
		switch(method){
			case "POST":
				Post(action, fields);
				break;
			case "GET":
				Get(action, fields);
				break;
		}
	}

    return false;
}

function changeOnEnter(jQueryObject){
	jQueryObject.find("input[type=text]").keydown(function(key){
		if(key.keyCode == 13 && $(this).attr("changeOnEnter") != undefined)	$(this).trigger('change');
	});
}

function initCommandElement(jQueryObject) {
    jQueryObject.find('[command]').click(function(e) {
        switch($(this).attr('command')) {
            case 'hideShow':
                if ($(this).attr('hide')) {
                    $('#' + $(this).attr('hide')).hide();
                }
                if ($(this).attr('show')) {
                    $('#' + $(this).attr('show')).show();
                }
            break;
        }

        e.stopPropagation();
        return false;
    });
}


function initFckEditorField(jQueryObject) {
    jQueryObject.find('.fckeditor').each(function() {
        var oFCKeditor = new FCKeditor($(this).attr('id'));
        oFCKeditor.BasePath = "/fckeditor/";
        oFCKeditor.Width = 700;
        oFCKeditor.Height = 300;
        oFCKeditor.Config["ToolbarCanCollapse"] = false;
        oFCKeditor.ToolbarSet = $(this).attr('toolbar');

        oFCKeditor.ReplaceTextarea();
    });

    return false;
}

function date ( format, timestamp ) {
    // Format a local date/time
    //
    // version: 910.813
    // discuss at: http://phpjs.org/functions/date
    // +   original by: Carlos R. L. Rodrigues (http://www.jsfromhell.com)
    // +      parts by: Peter-Paul Koch (http://www.quirksmode.org/js/beat.html)
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: MeEtc (http://yass.meetcweb.com)
    // +   improved by: Brad Touesnard
    // +   improved by: Tim Wiel
    // +   improved by: Bryan Elliott
    // +   improved by: Brett Zamir (http://brett-zamir.me)
    // +   improved by: David Randall
    // +      input by: Brett Zamir (http://brett-zamir.me)
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Brett Zamir (http://brett-zamir.me)
    // +   improved by: Brett Zamir (http://brett-zamir.me)
    // +  derived from: gettimeofday
    // +      input by: majak
    // +   bugfixed by: majak
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   input by: Alex
    // +   bugfixed by: Brett Zamir (http://brett-zamir.me)
    // +   bugfixed by: Thomas Beaucourt (http://www.webapp.fr/)
    // %        note 1: Uses global: php_js to store the default timezone
    // *     example 1: date('H:m:s \\m \\i\\s \\m\\o\\n\\t\\h', 1062402400);
    // *     returns 1: '09:09:40 m is month'
    // *     example 2: date('F j, Y, g:i a', 1062462400);
    // *     returns 2: 'September 2, 2003, 2:26 am'
    // *     example 3: date('Y W o', 1062462400);
    // *     returns 3: '2003 36 2003'
    // *     example 4: x = date('Y m d', (new Date()).getTime()/1000); // 2009 01 09
    // *     example 4: (x+'').length == 10
    // *     returns 4: true
    // *     example 5: date('W', 1104534000);
    // *     returns 5: '53'

    var that = this;
    var jsdate=(
        (typeof(timestamp) == 'undefined') ? new Date() : // Not provided
        (typeof(timestamp) == 'object') ? new Date(timestamp) : // Javascript Date()
        new Date(timestamp*1000) // UNIX timestamp (auto-convert to int)
    ); // , tal=[]
    var pad = function (n, c){
        if ( (n = n + "").length < c ) {
            return new Array(++c - n.length).join("0") + n;
        } else {
            return n;
        }
    };
    var _dst = function (t) {
        // Calculate Daylight Saving Time (derived from gettimeofday() code)
        var dst=0;
        var jan1 = new Date(t.getFullYear(), 0, 1, 0, 0, 0, 0);  // jan 1st
        var june1 = new Date(t.getFullYear(), 6, 1, 0, 0, 0, 0); // june 1st
        var temp = jan1.toUTCString();
        var jan2 = new Date(temp.slice(0, temp.lastIndexOf(' ')-1));
        temp = june1.toUTCString();
        var june2 = new Date(temp.slice(0, temp.lastIndexOf(' ')-1));
        var std_time_offset = (jan1 - jan2) / (1000 * 60 * 60);
        var daylight_time_offset = (june1 - june2) / (1000 * 60 * 60);

        if (std_time_offset === daylight_time_offset) {
            dst = 0; // daylight savings time is NOT observed
        } else {
            // positive is southern, negative is northern hemisphere
            var hemisphere = std_time_offset - daylight_time_offset;
            if (hemisphere >= 0) {
                std_time_offset = daylight_time_offset;
            }
            dst = 1; // daylight savings time is observed
        }
        return dst;
    };
    var ret = '';
    var txt_weekdays = ["Sunday", "Monday", "Tuesday", "Wednesday",
        "Thursday", "Friday", "Saturday"];
    var txt_ordin = {1: "st", 2: "nd", 3: "rd", 21: "st", 22: "nd", 23: "rd", 31: "st"};
    var txt_months =  ["", "January", "February", "March", "April",
        "May", "June", "July", "August", "September", "October", "November",
        "December"];

    var f = {
        // Day
            d: function (){
                return pad(f.j(), 2);
            },
            D: function (){
                var t = f.l();
                return t.substr(0,3);
            },
            j: function (){
                return jsdate.getDate();
            },
            l: function (){
                return txt_weekdays[f.w()];
            },
            N: function (){
                //return f.w() + 1;
                return f.w() ? f.w() : 7;
            },
            S: function (){
                return txt_ordin[f.j()] ? txt_ordin[f.j()] : 'th';
            },
            w: function (){
                return jsdate.getDay();
            },
            z: function (){
				var m = f.n();
				var z = 0;
				for (i=1; i<m; i++) z+= f.t(i);
				return z + f.j();
                //return (jsdate - new Date(jsdate.getFullYear() + "/1/1")) / 864e5 >> 0;
            },

        // Week
            W: function (){

                var a = f.z(), b = 364 + f.L() - a;
                var nd2, nd = (new Date(jsdate.getFullYear() + "/1/1").getDay() || 7) - 1;

                if (b <= 2 && ((jsdate.getDay() || 7) - 1) <= 2 - b){
                    return 1;
                }
                if (a <= 2 && nd >= 4 && a >= (6 - nd)){
                    nd2 = new Date(jsdate.getFullYear() - 1 + "/12/31");
                    return that.date("W", Math.round(nd2.getTime()/1000));
                }

                var w = (1 + (nd <= 3 ? ((a + nd) / 7) : (a - (7 - nd)) / 7) >> 0);

                return (w ? w : 53);
            },

        // Month
            F: function (){
                return txt_months[f.n()];
            },
            m: function (){
                return pad(f.n(), 2);
            },
            M: function (){
                var t = f.F();
                return t.substr(0,3);
            },
            n: function (){
                return jsdate.getMonth() + 1;
            },
            t: function (n){
                if (n == undefined) n = jsdate.getMonth() + 1;
                if ( n == 2 ){
                    return 28 + f.L();
                }
                if ( n & 1 && n < 8 || !(n & 1) && n > 7 ){
                    return 31;
                }
                return 30;
            },

        // Year
            L: function (){
                var y = f.Y();
                return (!(y & 3) && (y % 1e2 || !(y % 4e2))) ? 1 : 0;
            },
            o: function (){
                if (f.n() === 12 && f.W() === 1) {
                    return jsdate.getFullYear()+1;
                }
                if (f.n() === 1 && f.W() >= 52) {
                    return jsdate.getFullYear()-1;
                }
                return jsdate.getFullYear();
            },
            Y: function (){
                return jsdate.getFullYear();
            },
            y: function (){
                return (jsdate.getFullYear() + "").slice(2);
            },

        // Time
            a: function (){
                return jsdate.getHours() > 11 ? "pm" : "am";
            },
            A: function (){
                return f.a().toUpperCase();
            },
            B: function (){
                // peter paul koch:
                var off = (jsdate.getTimezoneOffset() + 60)*60;
                var theSeconds = (jsdate.getHours() * 3600) +
                                 (jsdate.getMinutes() * 60) +
                                  jsdate.getSeconds() + off;
                var beat = Math.floor(theSeconds/86.4);
                if (beat > 1000) {
                    beat -= 1000;
                }
                if (beat < 0) {
                    beat += 1000;
                }
                if ((String(beat)).length == 1) {
                    beat = "00"+beat;
                }
                if ((String(beat)).length == 2) {
                    beat = "0"+beat;
                }
                return beat;
            },
            g: function (){
                return jsdate.getHours() % 12 || 12;
            },
            G: function (){
                return jsdate.getHours();
            },
            h: function (){
                return pad(f.g(), 2);
            },
            H: function (){
                return pad(jsdate.getHours(), 2);
            },
            i: function (){
                return pad(jsdate.getMinutes(), 2);
            },
            s: function (){
                return pad(jsdate.getSeconds(), 2);
            },
            u: function (){
                return pad(jsdate.getMilliseconds()*1000, 6);
            },

        // Timezone
            e: function () {
/*                var abbr='', i=0;
                if (this.php_js && this.php_js.default_timezone) {
                    return this.php_js.default_timezone;
                }
                if (!tal.length) {
                    tal = this.timezone_abbreviations_list();
                }
                for (abbr in tal) {
                    for (i=0; i < tal[abbr].length; i++) {
                        if (tal[abbr][i].offset === -jsdate.getTimezoneOffset()*60) {
                            return tal[abbr][i].timezone_id;
                        }
                    }
                }
*/
                return 'UTC';
            },
            I: function (){
                return _dst(jsdate);
            },
            O: function (){
               var t = pad(Math.abs(jsdate.getTimezoneOffset()/60*100), 4);
               t = (jsdate.getTimezoneOffset() > 0) ? "-"+t : "+"+t;
               return t;
            },
            P: function (){
                var O = f.O();
                return (O.substr(0, 3) + ":" + O.substr(3, 2));
            },
            T: function () {
/*                var abbr='', i=0;
                if (!tal.length) {
                    tal = that.timezone_abbreviations_list();
                }
                if (this.php_js && this.php_js.default_timezone) {
                    for (abbr in tal) {
                        for (i=0; i < tal[abbr].length; i++) {
                            if (tal[abbr][i].timezone_id === this.php_js.default_timezone) {
                                return abbr.toUpperCase();
                            }
                        }
                    }
                }
                for (abbr in tal) {
                    for (i=0; i < tal[abbr].length; i++) {
                        if (tal[abbr][i].offset === -jsdate.getTimezoneOffset()*60) {
                            return abbr.toUpperCase();
                        }
                    }
                }
*/
                return 'UTC';
            },
            Z: function (){
               return -jsdate.getTimezoneOffset()*60;
            },

        // Full Date/Time
            c: function (){
                return f.Y() + "-" + f.m() + "-" + f.d() + "T" + f.h() + ":" + f.i() + ":" + f.s() + f.P();
            },
            r: function (){
                return f.D()+', '+f.d()+' '+f.M()+' '+f.Y()+' '+f.H()+':'+f.i()+':'+f.s()+' '+f.O();
            },
            U: function (){
                return Math.round(jsdate.getTime()/1000);
            }
    };

    return format.replace(/[\\]?([a-zA-Z])/g, function (t, s){
        if ( t!=s ){
            // escaped
            ret = s;
        } else if (f[s]){
            // a date function exists
            ret = f[s]();
        } else {
            // nothing special
            ret = s;
        }
        return ret;
    });
}

function strtotime (str, now) {
    // Convert string representation of date and time to a timestamp
    //
    // version: 909.322
    // discuss at: http://phpjs.org/functions/strtotime
    // +   original by: Caio Ariede (http://caioariede.com)
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +      input by: David
    // +   improved by: Caio Ariede (http://caioariede.com)
    // +   improved by: Brett Zamir (http://brett-zamir.me)
    // +   bugfixed by: Wagner B. Soares
    // +   bugfixed by: Artur Tchernychev
    // %        note 1: Examples all have a fixed timestamp to prevent tests to fail because of variable time(zones)
    // *     example 1: strtotime('+1 day', 1129633200);
    // *     returns 1: 1129719600
    // *     example 2: strtotime('+1 week 2 days 4 hours 2 seconds', 1129633200);
    // *     returns 2: 1130425202
    // *     example 3: strtotime('last month', 1129633200);
    // *     returns 3: 1127041200
    // *     example 4: strtotime('2009-05-04 08:30:00');
    // *     returns 4: 1241418600

    var i, match, s, strTmp = '', parse = '';

    strTmp = str;
    strTmp = strTmp.replace(/\s{2,}|^\s|\s$/g, ' '); // unecessary spaces
    strTmp = strTmp.replace(/[\t\r\n]/g, ''); // unecessary chars

    if (strTmp == 'now') {
        return (new Date()).getTime()/1000; // Return seconds, not milli-seconds
    } else if (!isNaN(parse = Date.parse(strTmp))) {
        return (parse/1000);
    } else if (now) {
        now = new Date(now*1000); // Accept PHP-style seconds
    } else {
        now = new Date();
    }

    strTmp = strTmp.toLowerCase();

    var __is =
    {
        day:
        {
            'sun': 0,
            'mon': 1,
            'tue': 2,
            'wed': 3,
            'thu': 4,
            'fri': 5,
            'sat': 6
        },
        mon:
        {
            'jan': 0,
            'feb': 1,
            'mar': 2,
            'apr': 3,
            'may': 4,
            'jun': 5,
            'jul': 6,
            'aug': 7,
            'sep': 8,
            'oct': 9,
            'nov': 10,
            'dec': 11
        }
    };

    var process = function (m) {
        var ago = (m[2] && m[2] == 'ago');
        var num = (num = m[0] == 'last' ? -1 : 1) * (ago ? -1 : 1);

        switch (m[0]) {
            case 'last':
            case 'next':
                switch (m[1].substring(0, 3)) {
                    case 'yea':
                        now.setFullYear(now.getFullYear() + num);
                        break;
                    case 'mon':
                        now.setMonth(now.getMonth() + num);
                        break;
                    case 'wee':
                        now.setDate(now.getDate() + (num * 7));
                        break;
                    case 'day':
                        now.setDate(now.getDate() + num);
                        break;
                    case 'hou':
                        now.setHours(now.getHours() + num);
                        break;
                    case 'min':
                        now.setMinutes(now.getMinutes() + num);
                        break;
                    case 'sec':
                        now.setSeconds(now.getSeconds() + num);
                        break;
                    default:
                        var day;
                        if (typeof (day = __is.day[m[1].substring(0, 3)]) != 'undefined') {
                            var diff = day - now.getDay();
                            if (diff == 0) {
                                diff = 7 * num;
                            } else if (diff > 0) {
                                if (m[0] == 'last') {diff -= 7;}
                            } else {
                                if (m[0] == 'next') {diff += 7;}
                            }
                            now.setDate(now.getDate() + diff);
                        }
                }
                break;

            default:
                if (/\d+/.test(m[0])) {
                    num *= parseInt(m[0], 10);

                    switch (m[1].substring(0, 3)) {
                        case 'yea':
                            now.setFullYear(now.getFullYear() + num);
                            break;
                        case 'mon':
                            now.setMonth(now.getMonth() + num);
                            break;
                        case 'wee':
                            now.setDate(now.getDate() + (num * 7));
                            break;
                        case 'day':
                            now.setDate(now.getDate() + num);
                            break;
                        case 'hou':
                            now.setHours(now.getHours() + num);
                            break;
                        case 'min':
                            now.setMinutes(now.getMinutes() + num);
                            break;
                        case 'sec':
                            now.setSeconds(now.getSeconds() + num);
                            break;
                    }
                } else {
                    return false;
                }
                break;
        }
        return true;
    };

    match = strTmp.match(/^(\d{2,4}-\d{2}-\d{2})(?:\s(\d{1,2}:\d{2}(:\d{2})?)?(?:\.(\d+))?)?$/);
    if (match != null) {
        if (!match[2]) {
            match[2] = '00:00:00';
        } else if (!match[3]) {
            match[2] += ':00';
        }

        s = match[1].split(/-/g);

        for (i in __is.mon) {
            if (__is.mon[i] == s[1] - 1) {
                s[1] = i;
            }
        }
        s[0] = parseInt(s[0], 10);

        s[0] = (s[0] >= 0 && s[0] <= 69) ? '20'+(s[0] < 10 ? '0'+s[0] : s[0]+'') : (s[0] >= 70 && s[0] <= 99) ? '19'+s[0] : s[0]+'';
        return parseInt(this.strtotime(s[2] + ' ' + s[1] + ' ' + s[0] + ' ' + match[2])+(match[4] ? match[4]/1000 : ''), 10);
    }

    var regex = '([+-]?\\d+\\s'+
        '(years?|months?|weeks?|days?|hours?|min|minutes?|sec|seconds?'+
        '|sun\.?|sunday|mon\.?|monday|tue\.?|tuesday|wed\.?|wednesday'+
        '|thu\.?|thursday|fri\.?|friday|sat\.?|saturday)'+
        '|(last|next)\\s'+
        '(years?|months?|weeks?|days?|hours?|min|minutes?|sec|seconds?'+
        '|sun\.?|sunday|mon\.?|monday|tue\.?|tuesday|wed\.?|wednesday'+
        '|thu\.?|thursday|fri\.?|friday|sat\.?|saturday))'+
        '(\\sago)?';

    match = strTmp.match(new RegExp(regex, 'g'));
    if (match == null) {
        return false;
    }

    for (i = 0; i < match.length; i++) {
        if (!process(match[i].split(' '))) {
            return false;
        }
    }

    return (now.getTime()/1000);
}

function ajaxDialog(objectParams, callBack) {	
    
        /*Bloque de retro compatibilite*/
        if(typeof objectParams == "string"){//nous sommes en mode ajaxDialog(url, dialogOptions)
            var temp = objectParams;
            objectParams = new Object();
            objectParams.url = temp;
            $.extend(objectParams, callBack);
        }
        
        var dialogOptions = new Object();                
        var url = "";
        
        dialogOptions.title         = "";
        dialogOptions.width         = "auto";
        dialogOptions.height        = "auto";
        dialogOptions.modal         = true;
        dialogOptions.resizable     = false;
        dialogOptions.closeOnEscape = false;
        dialogOptions.position      = "center";
        dialogOptions.close         = function(){$(this).remove()};        
        
        var dialogClass = "";        
        
        if(typeof objectParams == "object" && objectParams.jquery != undefined){
            if(objectParams.attr('args')) {
				var args = $.parseJSON(objectParams.attr('args'));
				for (var i in args) objectParams.attr(i, args[i]);
			}
            if(objectParams.attr('popupTitle'))
                dialogOptions.title = objectParams.attr('popupTitle');
            if(objectParams.attr('width'))
                dialogOptions.width = objectParams.attr('width');
            if(objectParams.attr('height'))
                dialogOptions.height = objectParams.attr('height');
            if(objectParams.attr('modal'))
                dialogOptions.modal = objectParams.attr('modal');
            if(objectParams.attr('resizable'))
                dialogOptions.resizable = objectParams.attr('resizable');
            if(objectParams.attr('closeOnEscape'))
                dialogOptions.closeOnEscape = objectParams.attr('closeOnEscape'); 
            if(objectParams.attr('position'))
                dialogOptions.position = objectParams.attr('position');                     
            if(objectParams.attr('dialogClass'))
                dialogClass = objectParams.attr('dialogClass');        
            if(objectParams.attr('url'))
                url = objectParams.attr('url');                    
            else if(objectParams.attr('href'))
                url = objectParams.attr('href');                    
            
        }else{
            $.extend(dialogOptions, objectParams);
            url = objectParams.url;
        }                       
        
        if(url == ""){
            alert("Erreur n°1 dans global.ajaxDialog();");
            return false;
        }
        $("body").append('<div class="ajaxdialog ' + dialogClass + '" style="display:none;"><img src="img/ajax-loader-FFFFFF.gif" alt="Chargement en cours..." /></div>');        
        var divToDialog = $("div.ajaxdialog:last");
        
	divToDialog.dialog(dialogOptions);
        
	divToDialog.load(url, function() {
		divToDialog.dialog("option", "height", dialogOptions.height);
		divToDialog.dialog("option", "position", dialogOptions.position);
		divToDialog.dialog("open");
		afterLoad(divToDialog);
		if (callBack != undefined) callBack();                
	});
}


function printr(e, whereDisplay){        
    
    var html = '';
    for (var i in e)
        if(typeof e[i] != "function"){
            html += i + ' = ' + e[i];
            switch(whereDisplay){
                case undefined:
                    html += '\n';
                break;
                default:
                    html += '</br></br>';
                break;                
            }
        }
            
    var style = "";
    switch(whereDisplay){
        case undefined:
            alert(html); 
            break;
        case "body":
            style = "bottom:50px; position:absolute;";
        default:
            $(whereDisplay).append("<div style='" + style + "'>" + html + "</div>"); 
            break;
        
    }
    
}

function nl2br (str) {    
    var breakTag = '<br/>'; 
    return (str + '').replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, '$1' + breakTag + '$2');
}

$(".loadingdialog").live('click', function(){
            
	var href = $(this).attr("href");
	
	var title = "";
	if($(this).attr("title"))
		title = $(this).attr("title");
	
	var height = $(window).height()-50;
	if($(this).attr("height"))
		height = $(this).attr("height");
	
	var width = $(window).width()-50;
	if($(this).attr("width"))
		width = $(this).attr("width");
	
	$("body").append('<div class="loadindialog" style="display:none;"></div>');
	var divToDialog = $("body div.loadindialog:last");
	$.ajax({
		url:href,
		success:function(data){
			divToDialog.html(data);
			divToDialog.dialog({ 
				autoOpen:true, 
				closeOnEscape:false, 
				height:height, 
				width:width, 
				modal:true, 
				resizable: false, 
				title:title, 
				draggable:false,
				close:function(){
					divToDialog.remove();
				}                                    
			});
		}
	});            
	return false;
	
});

function ToogleLoadingBar(activeTestFeature){  
    if(activeTestFeature != undefined){
        $('div.main div.loading div.ui-progressbar-value').live("dblclick", function(){
            ToogleLoadingBar();
        });
        return false;
    }
    
    if($("div.maincontent.hideuntilload").is(":visible")){
        $('div.main div.hideuntilload').fadeOut(10, function(){
           $('div.main > div.loading').fadeIn(10); 
        });        
    }
    else{
        $('div.main > div.loading').fadeOut(10, function(){
           $('div.main div.hideuntilload').fadeIn(10); 
        });
    }    
}

function basevalueFocus(){                       
    if($(this).val() == $(this).attr("basevalue")){
        $(this).val("");
        if($(this).hasClass("tobasevalue_password")){
            var rand = "change_input_type_rand_"+Math.ceil(Math.random()*100);
            $(this).removeClass("tobasevalue");            
            $("<input basevalue='" + $(this).attr("basevalue") + "' style='display:none;'type='password' class='" + $(this).attr("class") + " " + rand + "' value='" + $(this).val() + "'/>").insertAfter($(this));            
            var newObject = $(this).siblings("input[type='password']." + rand);                          
            $(this).removeClass("tobasevalue").remove();               
            newObject.show().focus();
            newObject.addClass("tobasevalue");
        }
                    
    }
}
function basevalueFocusout (){
    if($(this).val() == ""){
        $(this).val($(this).attr("basevalue"));
        if($(this).hasClass("tobasevalue_password")){
            var rand = "change_input_type_rand_"+Math.ceil(Math.random()*100);
            $(this).removeClass("tobasevalue");            
            $("<input basevalue='" + $(this).attr("basevalue") + "' style='display:none;'type='text' class='" + $(this).attr("class") + " " + rand + "' value='" + $(this).val() + "'/>").insertAfter($(this));            
            var newObject = $(this).siblings("input[type='text']." + rand);  
            $(this).removeClass("tobasevalue").remove();               
            newObject.show();
            newObject.addClass("tobasevalue");
        }
                    
    }		
}
$(".tobasevalue").live('focus', basevalueFocus);
$(".tobasevalue").live('focusout', basevalueFocusout)
    
