// fonction utilitaires de chaines de caractères
function getFront(mainStr, searchStr) {
  foundOffset = mainStr.indexOf(searchStr);
  if (foundOffset == -1) {
    return null;
  }
  return mainStr.substring(0,foundOffset);
}

function getEnd(mainStr, searchStr) {
  foundOffset = mainStr.indexOf(searchStr);
  if (foundOffset == -1) {
    return null;
  }
  return mainStr.substring(foundOffset+searchStr.length, mainStr.length);
}

function replaceString(mainStr, searchStr, replaceStr) {
  var front = getFront(mainStr, searchStr);
  var end   = getEnd(mainStr, searchStr);
  
  while (front != null && end != null) {
    mainStr = front + replaceStr + end;
    front = getFront(mainStr, searchStr);
    end   = getEnd(mainStr, searchStr); 
  }
  return mainStr;
}

// Ajax
function obtenirAsync(url, datas, callback, method, typeReturn) {

  try {
    $.ajax( {
             type        : method,
             url         : url,
             data        : datas,
             dataType    : typeReturn,
             success     : function( returnData ) {
                             callback ( returnData ); 
                           },
             error       : function( o, s, e ) {
                             //alert( "ERREUR XMLHttpRequest !\n" + url + "\n" + datas + "\n" + s );
                           } 
            } );
  } catch (e) {
    alert(e.message);
  }
  
}
