function Dvb_Commune(commune_nIdCommune)
{
    dQuery = {};
    dQuery['pgl'] = 'Ajax/AjaxCommune';
    dQuery['commune_nIdCommune'] = commune_nIdCommune;
    dQuery['PHPSESSID'] = dvb.sess;

    new Ajax.Request(dvb.kHttp_Script, {
            method: 'get',
            parameters: dQuery,
            onSuccess: function(xrq) {
                    var sRet;
                    sRet = Extract_tag('ret', xrq.responseText);
                    $('Commune_Info').innerHTML = sRet;
            },
            onFailure:function() {
                    alert('echec');
            },
            onCreate: function(){
                /*
                    try {
                            Element.show('systemWorking');
                    }catch(e){}
                    */
            },
            onComplete: function() {
                /*
                try {
                            if(Ajax.activeRequestCount == 1)
                                    Element.hide('systemWorking');
                    }catch(e){}
                    */
            }
	});
}



function Extract_tag(sTag, s)
{
    var sRet = null;
    var sBalise1 = "<dvb_"+sTag+">";
    var sBalise2 = "</dvb_"+sTag+">";
    var nIndex1 = s.indexOf(sBalise1);
    var nIndex2 = s.indexOf(sBalise2);
    //alert(nIndex1+"/"+nIndex2);
    if ( (nIndex1 != -1) && (nIndex2 != -1))
    {
       n1 = nIndex1+strlen(sTag)+6;
       sRet = s.substring(n1, nIndex2);
       sRet = Decode_tag(sRet);
    }
   return sRet;
}


function Decode_tag(s)
{
	s = decodeURIComponent( escape( s));
	s = s.unescapeHTML();
	var reg=new RegExp("(\\\\n)", 'g');
	s = s.replace(reg, "\n");
	// remplacement des caractères ci dessous pour imcompatibilité entre mozilla et ie,chrome
	s = s.replace(/&nbsp;/g,' ');
	s = s.replace(/&#039;/g,"'"); // 39 27
	s = s.replace(/&quot;/g,'"'); // 34 22
	s = s.replace(/&amp;/g,'&'); // 38 26
	s = s.replace(/'/g,"'"); // 39 27
	s = s.replace(/&lt;/g,'<'); // 60 3C
	s = s.replace(/&gt;/g,'>'); // 62 3E
        return s;
}



function strlen (string) {
    var str = string+'';
    var i = 0, chr = '', lgth = 0;

    if (!this.php_js || !this.php_js.ini || !this.php_js.ini['unicode.semantics'] ||
            this.php_js.ini['unicode.semantics'].local_value.toLowerCase() !== 'on') {
        return string.length;
    }

    var getWholeChar = function (str, i) {
        var code = str.charCodeAt(i);
        var next = '', prev = '';
        if (0xD800 <= code && code <= 0xDBFF) { // High surrogate (could change last hex to 0xDB7F to treat high private surrogates as single characters)
            if (str.length <= (i+1))  {
                throw 'High surrogate without following low surrogate';
            }
            next = str.charCodeAt(i+1);
            if (0xDC00 > next || next > 0xDFFF) {
                throw 'High surrogate without following low surrogate';
            }
            return str.charAt(i)+str.charAt(i+1);
        } else if (0xDC00 <= code && code <= 0xDFFF) { // Low surrogate
            if (i === 0) {
                throw 'Low surrogate without preceding high surrogate';
            }
            prev = str.charCodeAt(i-1);
            if (0xD800 > prev || prev > 0xDBFF) { //(could change last hex to 0xDB7F to treat high private surrogates as single characters)
                throw 'Low surrogate without preceding high surrogate';
            }
            return false; // We can pass over low surrogates now as the second component in a pair which we have already processed
        }
        return str.charAt(i);
    };

    for (i=0, lgth=0; i < str.length; i++) {
        if ((chr = getWholeChar(str, i)) === false) {
            continue;
        } // Adapt this line at the top of any loop, passing in the whole string and the current iteration and returning a variable to represent the individual character; purpose is to treat the first part of a surrogate pair as the whole character and then ignore the second part
        lgth++;
    }
    return lgth;
}

