function Dump(d,l) {
    if (l == null) l = 1;
    if (l > 4) return s;
    if (typeof(d) == "object") {
        s += typeof(d) + " {\n";
        for (var k in d) {
            for (var i=0; i<l; i++) s += "  ";
            s += k+": " + Dump(d[k],l+1);
        }
        for (var i=0; i<l-1; i++) s += "  ";
        s += "}\n"
    } else {
        s += "" + d + "\n";
    }
    return s;
}

function get_size_str(bytes_cnt)
{
     if (bytes_cnt < 1024)
     {
          return bytes_cnt + 'Bytes';
     }

     if (bytes_cnt > 1024*1024)
     {
          return Math.round(bytes_cnt/(1024.0*1024.0)*100)/100 + 'Mb';
     }
     return Math.round(bytes_cnt/(1024.0)*100)/100 + 'Kb';
}

function zero_pad(str)
{
     if (str.length < 2)
     {
          return '0' + str;
     }
     return str;
}

function get_time_str(seconds_cnt)
{
     hours = Math.floor(seconds_cnt/3600);
     minutes = Math.floor((seconds_cnt % 3600)/60);
     seconds = Math.floor((seconds_cnt % 3600)%60);
     return zero_pad(hours.toString())+':'+zero_pad(minutes.toString())+':'+zero_pad(seconds.toString());
}

function progress_bar_parse_str(str)
{
     result = new Object();
     strings = str.split(":");
     for (i = 0; i < strings.length; i++)
     {
          if (strings[i].length < 3)
          {
               continue;
          }
          components = strings[i].split('=');
          result[components[0]] = Math.floor(components[1]);
     }
     return result;
}
////////////////////////////////////////////////////////////////////////////

var on_done_func = function(text) {alert(text)};
var g_script_span = null;
function req_send(url, on_done)
{
     on_done_func = on_done;
     with (document)
     {
            var span = null;
            // Oh shit! Damned stupid fucked Opera 7.23 does not allow to create SCRIPT 
            // element over createElement (in HEAD or BODY section or in nested SPAN - 
            // no matter): it is created deadly, and does not respons on href assignment.
            // So - always create SPAN.
            span = body.appendChild(createElement("SPAN"));
            span.style.display = 'none';
            span.innerHTML = 'Text for stupid IE.<s'+'cript></' + 'script>';
            setTimeout(function() 
               {
                    var s = span.getElementsByTagName("script")[0];
                    s.language = "JavaScript";
                    if (s.setAttribute) s.setAttribute('src', url); else s.src = url;
               }, 10);
            g_script_span = span;
      }
}

function req_clear()
{
     // Remove last used script element (clean memory).
     var span = g_script_span;
     if (span) 
     {
          g_script_span = null;
          setTimeout(function() 
               {
                    // without setTimeout - crash in IE 5.0!
                    span.parentNode.removeChild(span);
               }, 50);
     }
     return false;
}
