trying to replace all \n inside textarea to '\n (4 spaces) ' and viceversa but only one \n is found
<p>here's the link where I'm trying this:</p>

<p><a href="http://jsbin.com/ajirim/2/edit#source" rel="nofollow">http://jsbin.com/ajirim/2/edit#source</a></p>

<p>the js code:</p>

<pre><code>$(function(){
    $('button').click(dao);
    });

   function dao()            {
   var x = $('textarea').val();

   if(x.substring(0,4) == '    ')
   {
      x = x.replace('\n    ','\n').substr(4);
   }
   else
   {
      x = '    '+ x.replace('\n', '\n    ');
   }

   $('textarea').val(x);
}
</code></pre>
