/*==============================================================================
INDEX
=============================================================================*/
//CONNEXION
function show_connexion()
{
   document.getElementById('header_connect').className = 'hover';
}
function hide_connexion(event)
{
   event = event || window.event;
   event.target = event.target || event.srcElement;

   if(event.target === this){
      this.className = '';
   }
}

//STATS
function show_stats()
{
   document.getElementById('stats_container').className = 'hover';
}
function hide_stats()
{
   document.getElementById('stats_container').className = '';
}
/*==============================================================================
TARIFS
==============================================================================*/
//DETAILS
function toggle_offer_detail(link){
   var description = link.parentNode.getElementsByTagName('p')[0];
   var visible = description.style.display == '' ? 'none' : description.style.display;
   if(visible == 'none')
   {
      visible = 'block';
      link.style.color = '#f90';
   }
   else
   {
      visible = 'none';
      link.style.color = '#333';
   }
   description.style.display = visible;
}
/*==============================================================================
FORUMS
=============================================================================*/
//CITER
function cite(link){
   var tr = link.parentNode.parentNode.parentNode.parentNode;
   var next_tr_index = parseInt(tr.rowIndex) + 1;
   var next_tr = document.getElementsByTagName('tr')[next_tr_index];
   
   var author_tag = next_tr.getElementsByTagName('td')[0].getElementsByTagName('strong')[0].getElementsByTagName('a')[0];
   var author = author_tag ? '='+author_tag.innerHTML : '';
   var txt = next_tr.getElementsByTagName('td')[1].getElementsByTagName('p')[0].innerHTML;

   var reg = new RegExp("<.[^>]*>", "gi" );
   txt = txt.replace(reg, "" );
   document.getElementById('content_message').value = '[q'+author+']'+txt+'[/q]';
   self.location.href = '#reponse_forum';
}

//SMILEYS
function display_smileys(){
   document.getElementById('smileys').style.display = 'block';
}
function hide_smileys(){
   document.getElementById('smileys').style.display = 'none';
}

/*==============================================================================
NEW WINDOW
=============================================================================*/
//_BLANK
function new_window(url){
   window.open(url);
}
/*==============================================================================
POPUP
=============================================================================*/
//URL D'INSCRIPTION
var sign_up_url = 'http://manager.doomby.com/signup';
//OPEN
function popup(type, width, height, url, classe){
   var toolbar_height = 30;

   var container_style = 'width:'+ width + 'px;height:' + (height + toolbar_height) +'px;margin-top:-'+((height + toolbar_height)/2)+'px;margin-left:-'+(width/2)+'px';
   var container = document.createElement('div');
   container.id = 'popup';                   
   container.style.cssText = container_style;

   var overlay_style = 'height:' + document.body.offsetHeight + 'px';
   var overlay = document.createElement('div');
   overlay.id = 'overlay';
   overlay.style.cssText = overlay_style;
   if(overlay.attachEvent)
   {
      overlay.attachEvent('onclick', close_popup);
   }
   else
   {
      overlay.setAttribute('onclick', 'close_popup()');
   }

   var toolbar = document.createElement('div');
   toolbar.id = 'toolbar';
   var close_button = document.createElement('a');
   close_button.href = 'javascript:void(0)';
   if(close_button.attachEvent)
   {
      close_button.attachEvent('onclick', close_popup);
   }
   else
   {
      close_button.setAttribute('onclick', 'close_popup()');
   }

   toolbar.appendChild(close_button);
   container.appendChild(toolbar);

   if(classe)
   {
      container.setAttribute((document.all ? 'className' : 'class'), classe);
      container.setAttribute('class', classe);
   }
   if(type == 'video' || type == 'iframe')
   {
      var iframe = document.createElement('iframe');
      iframe.src = url;
      iframe.width = width;
      iframe.height = height;
      iframe.frameBorder = '0';
      container.appendChild(iframe);
   }
   else if(type == 'img')
   {
      var img = document.createElement('img');
      img.src = url;
      img.width = width;
      img.height = height;
      container.appendChild(img);
   }
   document.getElementsByTagName('body')[0].appendChild(container);
   document.getElementsByTagName('body')[0].appendChild(overlay);
}
//CLOSE
function close_popup(){
   var popup = document.getElementById('popup');
   var overlay = document.getElementById('overlay');
   document.getElementsByTagName('body')[0].removeChild(popup);
   document.getElementsByTagName('body')[0].removeChild(overlay);
}
