var is_popup_showed = false;
var begin_popup_url = false;
var begin_script_url = false;
function show_begin_popup(is_gold, adjust_size)
{
     if (is_gold)
     {
          return;
     }
     if (is_popup_showed)
     {
          return;
     }

     if (begin_popup_url && begin_popup_url != '')
     {
          if (show_begin_popup.arguments.length == 1)
          {
               adjust_size = false;
          }
          var params = 'toolbar=1,location=1,status=1, menubar=1,scrollbars=1,resizable=1';
          if(adjust_size)
          {
               var width = screen.width/2;
               var height = screen.height/2;
               var left = screen.width - screen.width*0.75;
               var top = screen.height - screen.height*0.75;
               params = 'height='+height+',width='+width+',left='+left+',top='+top+',toolbar=0,status=0,menubar=0,status=0,menubar=0,resizable=1,scrollbars=1';
          }
          pop = window.open(begin_popup_url, '_blank', params);
          window.focus();
          is_popup_showed = true;
     }
     else if(begin_script_url)
     {
          if (document.getElementById("exit_script_block"))
          {
               setTimeout('document.getElementById("exit_script_block").innerHTML="<iframe src=\''+begin_script_url+'\' height=0 width=0 frameboder=0></iframe>";', 1000);
          }
          //window.open(popunder_url');
          //is_popup_showed = true;google-analytics.com
     }
}
var show_url_start_time = false;
var show_url_first = true;
function show_url(delay)
{
     var remain = 0;

     if (show_url_first)
     {
          /*cache_img_code();*/
          show_url_first = false;
     }

     if (delay>0)
     {
          var d = new Date();
          if (!show_url_start_time)
          {
               document.getElementById('download_waiter').style.display = '';
               show_url_start_time = d.getTime();
          }
          remain =  show_url_start_time + delay*1000 - d.getTime();
     }
     if (remain<=100)
     {
          document.getElementById('download_url').style.display = '';

          if(document.getElementById('download_waiter'))
               document.getElementById('download_waiter').style.display = 'none';

          if(document.getElementById('img_code_block'))
          {
               /*refresh_img_code();*/
               document.getElementById('img_code_block').style.display="";
          }
     }
     else
     {
          remain = remain/1000;
          if(document.getElementById('download_waiter_remain'))
          {
               document.getElementById('download_waiter_remain').innerHTML = Math.round(remain);
          }
          setTimeout('show_url('+(delay)+')', 1000);
     }
}
var img_code_form_submitted = false;
function submit_img_code()
{
     var img_code_form = document.getElementById('img_code_form');
     if(img_code_form)
     {
          img_code_form.submit();
          img_code_form_submitted = true;
          if(document.getElementById('img_code_block'))
               document.getElementById('img_code_block').style.display = 'none';
          if(document.getElementById('invalid_code_msg_block'))
               document.getElementById('invalid_code_msg_block').style.display = 'none';
     }
}
function img_code_form_onsubmit()
{
     if(img_code_form_submitted)
     {
          return false;
     }
     return false;
}
function on_event(func)
{
     if (window.oe_hash && oe_hash[func])
     {
          oe_hash[func]();
     }
}
function number_format(num, prec)
{
     num = num.toString();
     pos = num.indexOf('.');
     if (pos >=0)
     {
          return num.substr(0,pos+prec+1);
     }
     return num+".0";
}
var img_code_cached = false;
var img_code_icid = false;
function cache_img_code()
{
     if (img_code_cached)
     {
          return;
     }
     if (!img_code_icid)
     {
          return;
     }
     img_code_cached = new Image();
     var date = new Date();
     img_code_cached.src = http_abs_path + '/get_download_img_code.php?icid='+img_code_icid+'&rnd='+date.getTime();
}
function refresh_img_code()
{
     cache_img_code();
     if (!img_code_cached)
     {
          return;
     }
     document.getElementById('img_code_img').src = img_code_cached.src;
     img_code_cached = false;
}

function open_img_code_page()
{
     if(!img_code_icid)
     {
          return false;
     }
     var width = 121;
     var height = 61;
     var left = screen.width - screen.width*0.75;
     var top = screen.height - screen.height*0.75;
     params = 'height='+height+',width='+width+',left='+left+',top='+top+',toolbar=0,status=0,menubar=0,status=0,menubar=0,resizable=1,scrollbars=0';
     var date = new Date();
     pop = window.open(http_abs_path + '/get_download_img_code_page.php?icid='+img_code_icid+'&rnd='+date.getTime(), 'df_img_code', params);
     pop.focus();
}

function addBookmark(url, title)
{
  if (!url) url = location.href;
  if (!title) title = document.title;

  //Gecko
  if ((typeof window.sidebar == "object") && (typeof window.sidebar.addPanel == "function")) window.sidebar.addPanel (title, url, "");
  //IE4+
  else if (typeof window.external == "object") window.external.AddFavorite(url, title);
  //Opera7+
  else if (window.opera)
  {
    return true;
  }
  return false;
}


var is_download_started = false;
function download_started()
{
     is_download_started = true;
     var tags = new Array('div','span','a','table')

     for(j=0;j<tags.length;j++)
     {
          var coll = document.getElementsByTagName(tags[j]);
          for(i=0;i<coll.length;i++)
          {
               if(coll[i].className.indexOf('show_download_started') >= 0)
               {
                    coll[i].style.display='';
               }
               if(coll[i].className.indexOf('hide_download_started') >= 0)
               {
                     coll[i].style.display='none';
               }
          }
     }

}