javascript to check if element visible and set "setInterval" accordingly
<p><strong>LE2. Any other ideas on how to fix this?</strong></p>

<p>I have this code and can't figure why is not working properly:</p>

<pre><code>$(function autorun() {

if ($("#contactForm").is(":visible")){
setInterval( "refreshAjax();", 150000000000 );
 }
 else {
setInterval( "refreshAjax();", 15000 );
 }
setTimeout("autorun();", 2000)
});
</code></pre>

<p>...</p>

<pre><code>&lt;body onLoad="autorun()"&gt;
</code></pre>

<p>Right now it keep refreshing the page every 2 secs, even if the "contactForm" is visible.</p>

<p>My logic is: if the "contactForm" is visible, delay the refresh or stop it, keep checking that, but in the mean time refresh the page accordingly to the other statement.</p>

<p>LE.</p>

<pre><code>$(function() {
refreshAjax = function(){$("#flex1").flexReload();
}
 });
</code></pre>

<p>LE2. Final solution provided <a href="http://stackoverflow.com/questions/4062466/javascript-script-not-working-and-crashing-ie">here</a> by @Nick Craver </p>

<pre><code>$(function () {
  var ajaxTimeout;
  function autorun() {
    if ($("#contactForm").is(":visible")){
      if(ajaxTimeout) {
        clearInterval(ajaxTimeout);
        ajaxTimeout = false;
      }
    }
    else if(!ajaxTimeout) {
      ajaxTimeout = setInterval(refreshAjax, 15000);
    }
  }
  setInterval(autorun, 2000);
});
</code></pre>

<p>Thanks,
Cristian.</p>
