function duplicateChars(text, character){

   text = Replace(text, character + character,character);

   len = text.length;
   pos=0;
   while (pos < len){
      mychar = text.charAt(pos);
      cDep = text.charAt(pos+1);
      if ((mychar == character) && (cDep != mychar)){
         parte1 = text.substring(0, pos+1);
         parte2 = text.substring(pos + 1 , text.length);
         text = parte1 + character + parte2;
         pos++;
      }
      pos++;
      len = text.length;
   }
   return text;
}

function Replace( texto, procurar, novo ){
   len = procurar.length;
   pos = texto.indexOf(procurar);
   while (pos > -1){
      parte1 = texto.substring(0, pos);
      parte2 = texto.substring(pos + len , texto.length);
      texto = parte1 + novo + parte2;
      pos = texto.indexOf(procurar);
   }
   return texto;
}