(function ($) {

// $.jsHttpQuery
$.jsHttpQuery = {
  // launch_query
  launch_query: function (o) {
    var file = ( o.file ) ? o.file : ''; // 'filename'
    var data = ( o.data ) ? o.data : ''; // '&do=toto&pif=paf'
    if ( iz_data.root && file ) return this.hqi(iz_data.root+'js_php_bg.php?file='+file+data);
    return 'jsHttpQuery error';
  },
  
  // hqi
  hqi: function (zeFile) {
    var xhr_object = null;
    if ( window.XMLHttpRequest ) xhr_object = new XMLHttpRequest(); // FIREFOX
    else if ( window.ActiveXObject ) xhr_object = new ActiveXObject("Microsoft.XMLHTTP"); // IE
    if ( typeof xhr_object != 'object' ) { alert('Your browser does not support this action.'); return; }
    xhr_object.open("GET", zeFile, false);
    xhr_object.send(null);
    
    var html = '';
    if ( xhr_object.readyState==4 ) {
      html = ( xhr_object.responseText && typeof xhr_object.responseText !='undefined' && xhr_object.responseText!='undefined' ) ? xhr_object.responseText : '';
      html = this.replace_in_html(html);
    }
    return html;
  },
  
  // replace_in_html
  replace_in_html: function (str) {  
    if ( !str ) return '';
    
    str = str.replace(/&amp;/g, '&');
    
    // special (euros, trade, ..)
    str = str.replace(/(&circ;)/g, '');
    str = str.replace(/(&lsquo;)/g, '');
    str = str.replace(/(&rsquo;)/g, '');
    str = str.replace(/(&ldquo;)/g, '');
    str = str.replace(/(&rdquo;)/g, '');
    //str = str.replace(/(&bull;)/g, '');
    str = str.replace(/(&rsaquo;)/g, '');
    str = str.replace(/(&ndash;)/g, '');
    str = str.replace(/(&ndash;)/g, '');
    str = str.replace(/(&mdash;)/g, '');
    str = str.replace(/(&cedil;)/g, '');
    str = str.replace(/(&oelig;)/g, 'oe');
    str = str.replace(/(&#382;)/g, 'Z');
    str = str.replace(/(&#039;)/g, "'");
    str = str.replace(/(\[TRADE\])/g, '&trade;');
    str = str.replace(/(\[EUROS\])/g, '&euro;');
    
    // maj accents
    str = str.replace(/(&Agrave;)/g, 'A');
    str = str.replace(/(&Aacute;)/g, 'A');
    str = str.replace(/(&Acirc;)/g, 'A');
    str = str.replace(/(&Atilde;)/g, 'A');
    str = str.replace(/(&Auml;)/g, 'A');
    str = str.replace(/(&Aring;)/g, 'A');
    str = str.replace(/(&AElig;)/g, 'AE');
    str = str.replace(/(&Ccedil;)/g, 'C');
    str = str.replace(/(&Egrave;)/g, 'E');
    str = str.replace(/(&Eacute;)/g, 'E');
    str = str.replace(/(&Ecirc;)/g, 'E');
    str = str.replace(/(&Euml;)/g, 'E');
    str = str.replace(/(&Igrave;)/g, 'I');
    str = str.replace(/(&iacute;)/g, 'I');
    str = str.replace(/(&Icirc;)/g, 'I');
    str = str.replace(/(&Iuml;)/g, 'I');
    str = str.replace(/(&ETH;)/g, 'D');
    str = str.replace(/(&Ntilde;)/g, 'N');
    str = str.replace(/(&Ograve;)/g, 'O');
    str = str.replace(/(&Oacute;)/g, 'O');
    str = str.replace(/(&Ocirc;)/g, 'O');
    str = str.replace(/(&Otilde;)/g, 'O');
    str = str.replace(/(&Ouml;)/g, 'O');
    str = str.replace(/(&Oslash;)/g, 'O');
    str = str.replace(/(&Ugrave;)/g, 'U');
    str = str.replace(/(&Uacute;)/g, 'U');
    str = str.replace(/(&Ucirc;)/g, 'U');
    str = str.replace(/(&Uuml;)/g, 'U');
    str = str.replace(/(&Yacute;)/g, 'Y');
    str = str.replace(/(&Yuml;)/g, 'Y');
    
    // mini accents
    str = str.replace(/(&aacute;)/g, 'á');
    str = str.replace(/(&agrave;)/g, 'à');
    str = str.replace(/(&acirc;)/g, 'â');
    str = str.replace(/(&atilde;)/g, 'ã');
    str = str.replace(/(&auml;)/g, 'ä');
    str = str.replace(/(&aring;)/g, 'å');
    str = str.replace(/(&aelig;)/g, 'æ');
    str = str.replace(/(&ccedil;)/g, 'ç');
    str = str.replace(/(&egrave;)/g, 'è');
    str = str.replace(/(&eacute;)/g, 'é');
    str = str.replace(/(&ecirc;)/g, 'ê');
    str = str.replace(/(&euml;)/g, 'ë');
    str = str.replace(/(&igrave;)/g, 'ì');
    str = str.replace(/(&iacute;)/g, 'í');
    str = str.replace(/(&icirc;)/g, 'î');
    str = str.replace(/(&iuml;)/g, 'ï');
    str = str.replace(/(&eth;)/g, 'ð');
    str = str.replace(/(&ntilde;)/g, 'ñ');
    str = str.replace(/(&ograve;)/g, 'ò');
    str = str.replace(/(&oacute;)/g, 'ó');
    str = str.replace(/(&ocirc;)/g, 'ô');
    str = str.replace(/(&otilde;)/g, 'õ');
    str = str.replace(/(&ouml;)/g, 'ö');
    str = str.replace(/(&oslash;)/g, 'ø');
    str = str.replace(/(&ugrave;)/g, 'ù');
    str = str.replace(/(&uacute;)/g, 'ú');
    str = str.replace(/(&ucirc;)/g, 'û');
    str = str.replace(/(&uuml;)/g, 'ü');
    str = str.replace(/(&yacute;)/g, 'ý');
    str = str.replace(/(&yuml;)/g, 'ÿ');
    
    // misc
    str = str.replace(/(&quot;)/g, '"');
    str = str.replace(/(&lt;)/g, '<');
    str = str.replace(/(&gt;)/g, '>');
    str = str.replace(/(&nbsp;)/g, ' ');
    str = str.replace(/(&iexcl;)/g, '¡');
    str = str.replace(/(&THORN;)/g, 'Þ');
    str = str.replace(/(&thorn;)/g, 'þ');
    str = str.replace(/(&brvbar;)/g, 'Š');
    str = str.replace(/(&sect;)/g, '§');
    str = str.replace(/(&uml;)/g, 'š');
    str = str.replace(/(&ordf;)/g, 'ª');
    str = str.replace(/(&not;)/g, '¬');
    str = str.replace(/(&shy;)/g, '­');
    str = str.replace(/(&copy;)/g, '©');
    str = str.replace(/(&reg;)/g, '®');
    str = str.replace(/(&macr;)/g, '¯');
    str = str.replace(/(&deg;)/g, '°');
    str = str.replace(/(&plusmn;)/g, '±');
    str = str.replace(/(&acute;)/g, 'Ž');
    str = str.replace(/(&micro;)/g, 'µ');
    str = str.replace(/(&para)/g, '¶');
    str = str.replace(/(&middot;)/g, '·');
    str = str.replace(/(&ordm;)/g, 'º');
    str = str.replace(/(&sup1;)/g, '¹');
    str = str.replace(/(&sup2;)/g, '²');
    str = str.replace(/(&sup3;)/g, '³');
    str = str.replace(/(&laquo;)/g, '«');
    str = str.replace(/(&raquo;)/g, '»');
    str = str.replace(/(&frac14;)/g, 'Œ');
    str = str.replace(/(&frac12;)/g, 'œ');
    str = str.replace(/(&frac34;)/g, 'Ÿ');
    str = str.replace(/(&iquest;)/g, '¿');
    str = str.replace(/(&times;)/g, '×');
    str = str.replace(/(&szlig;)/g, 'ß');
    str = str.replace(/(&divide;)/g, '÷');
    str = str.replace(/(&cent;)/g, '¢');
    str = str.replace(/(&pound;)/g, '£');
    str = str.replace(/(&curren;)/g, '€');
    str = str.replace(/(&yen;)/g, '¥');
    
    return str;
  }
};

})(jQuery);
