function ShowHide(id)
{
 var itm = null;
 if (document.getElementById) itm = document.getElementById(id);
 else if (document.all) itm = document.all[id];
 else if (document.layers) itm = document.layers[id];
 
 if (itm.style)
 {
  if (itm.style.display == "none" ) itm.style.display = "block";
  else itm.style.display = "none";
  
  if (itm.style.visibility == "hidden" ) itm.style.visibility = "visible";
  else itm.style.visibility = "hidden";
 }
 
 return false
}

////////////////////

function SendComment(form)
{
 var mattajaxrequest = new MakeNewAjaxRequest();
 
 mattajaxrequest.onreadystatechange = function()
 {
  document.getElementById('commentedit').innerHTML = "Commentaire en cours d'envoi ...";
  
  if (mattajaxrequest.readyState == 4)
  {
   if (mattajaxrequest.status == 200) document.getElementById('commentedit').innerHTML = "Commentaire recu, merci de votre participation ! Il va etre relu par un administrateur avant son affichage sur le site.";
   else document.getElementById('commentedit').innerHTML = "Erreur d'envoi du commentaire !";
  }
 };
 
 mattajaxrequest.open("GET", "/sendcomment.php?randy="+Math.random()+"&video="+encodeURIComponent(form.video.value)+"&email="+encodeURIComponent(form.email.value)+"&pseudo="+encodeURIComponent(form.pseudo.value)+"&comment="+encodeURIComponent(form.comment.value), true);
 mattajaxrequest.send(null);
 
 return false
}

////////////////////

function createCookie(name, value, hours)
{
 if (hours)
 {
  var date = new Date();
  date.setTime(date.getTime()+(hours*60*60*1000));
  var expires = "; expires="+date.toGMTString();
 }
 else var expires = "";
 document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name)
{
 var nameEQ = name + "=";
 var ca = document.cookie.split(';');
 for(var i=0;i < ca.length;i++)
 {
  var c = ca[i];
  while (c.charAt(0)==' ') c = c.substring(1,c.length);
  if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
 }
 return null;
}

function eraseCookie(name)
{
 createCookie(name,"",-1);
}

////////////////////

function MakeNewAjaxRequest()
{
 var activexmodes = ["Msxml2.XMLHTTP", "Microsoft.XMLHTTP"];
 if (window.ActiveXObject)
 {
  for (var i=0; i<activexmodes.length; i++)
  {
   try { return new ActiveXObject(activexmodes[i]); }
   catch(e) { }
  }
 }
 else if (window.XMLHttpRequest) return new XMLHttpRequest();
 else return false;
}

////////////////////

function trade_counter()
{
 var mattajaxrequest = new MakeNewAjaxRequest();
 mattajaxrequest.open("GET", "/index.php?traderef=1", true);
 mattajaxrequest.send(null);
}

////////////////////

function click_video()
{
 var clicks = ((readCookie("clicks") == undefined) ? 0 : parseInt(readCookie("clicks"))) + 1;
 createCookie("clicks", clicks, 24);
 
 if ((clicks == 2) || ((clicks > 5) && ((clicks % 3) == 0)))
 {
  var viewWzz = 950;
  var viewHzz = 550;
  var winw = 0; w = viewWzz;
  var winh = 0; h = viewHzz;
  
  thegogogo = window.open("/index.php?boost=1","","scrollbars=yes,toolbar=yes,location=yes,status=yes,menubar=yes,resizable=yes,dependent=no,width="+w+",height="+h+",top="+winh+",left="+winw);
  thegogogo.blur();
  window.focus();
 }
 
 return true;
}

////////////////////

function JSParseUrl(url)
{
 var loc = { 'href' : url };
 var parts = url.replace('//', '/').split('/');
 loc.protocol = parts[0];
 loc.host = parts[1];
 parts[1] = parts[1].split(':');
 loc.hostname = parts[1][0];
 loc.port = parts[1].length > 1 ? parts[1][1] : '';
 parts.splice(0, 2);
 loc.pathname = '/' + parts.join('/');
 loc.pathname = loc.pathname.split('#');
 loc.hash = loc.pathname.length > 1 ? '#' + loc.pathname[1] : '';
 loc.pathname = loc.pathname[0];
 loc.pathname = loc.pathname.split('?');
 loc.search = loc.pathname.length > 1 ? '?' + loc.pathname[1] : '';
 loc.pathname = loc.pathname[0];
 return loc;
}

////////////////////
