/*var agt = navigator.userAgent.toLowerCase();
var isMac = (agt.indexOf('mac') != -1);
var isOpera = (agt.indexOf("opera") != -1);
var isIE = ((agt.indexOf('msie')!=-1 && !isOpera && (agt.indexOf('webtv')==-1)) && !isMac);*/

//******************************************************************************
function ouvrirFenetre(url, nompage, largeur, hauteur, extra)
{
  window.open(url, nompage,
              extra + ' status=no, width=' + largeur + ', height=' + hauteur);
  return false;
}

//******************************************************************************
function verifMail(email)
{
  var usr    = "([a-zA-Z0-9][a-zA-Z0-9_.-]*|\"([^\\\\\x80-\xff\015\012\"]|\\\\[^\x80-\xff])+\")";
  var domain = "([a-zA-Z0-9][a-zA-Z0-9._-]*\\.)*[a-zA-Z0-9][a-zA-Z0-9._-]*\\.[a-zA-Z]{2,5}";
  var regex  = "^" + usr + "\@" + domain + "$";

  var rgx    = new RegExp(regex);
  return rgx.exec(email) ? true : false;
}

//******************************************************************************
function showBase(evt, aide, show, largeur, hauteur)
{
  if (show)
  {
    if(!document.all && document.getElementById)
      larg = window.innerWidth;
    else
      larg = document.body.clientWidth;
    
    if (typeof( window.pageYOffset ) == 'number') //Netscape compliant
      scrOfY = window.pageYOffset;
    else if (document.body && ( document.body.scrollLeft || document.body.scrollTop )) //DOM compliant
      scrOfY = document.body.scrollTop;
    else if ( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop )) //IE6 standards compliant mode
      scrOfY = document.documentElement.scrollTop;
    else
      scrOfY = document.documentElement.scrollTop;
    Ydoc = evt.clientY + scrOfY;
  
    aide.style.left = ((larg-largeur)/2) + 'px';
    aide.style.top = (Ydoc-hauteur) + 'px';
  }
  
  aide.style.visibility = show?"visible":"hidden";
}

//******************************************************************************
function showVote(evt, show)
{
  if (show)
    showEnvoi(event, '', '', false);
  aide = document.getElementById('bulleVote');
  showBase(evt, aide, show, 300, 100);
}

//******************************************************************************
function showEnvoi(evt, show)
{
  if (show)
    showVote(event, '', '', false);
  aide = document.getElementById('bulleEnvoi');
  showBase(evt, aide, show, 300, 150)
}

//******************************************************************************
function valideVote()
{
  id = document.getElementById('idSiteForm').value;
  note = document.getElementById('noteVote');
  note = note.options[note.selectedIndex].value;

  url = 'vote_ajax.php?note=' + note + '&id=' + id;

  return appelAjax(null, url, true);
}

//******************************************************************************
function valideEnvoi()
{
  id = document.getElementById('idSiteForm').value;
  typeEnvoi = document.getElementsByName('typeEnvoi')[0].checked?1:0;
  email = document.getElementById('emailAmi').value;
  emailVisiteur = document.getElementById('emailVisiteur').value;

  url = 'envoi_ajax.php?typeEnvoi=' + typeEnvoi + '&email=' + email + '&emailVisiteur=' + emailVisiteur + '&id=' + id;

  showEnvoi(event, '', '', false)
  res = appelAjax(null, url, false);
  document.body.style.cursor = 'default';
  alert('La recette vient d\'être envoyée');
  return res;
}
  
//******************************************************************************
var xhr_object = null;
var lastobj = null;

function appelAjax(obj, url, fct)
{
  if (xhr_object == null)
    if(window.XMLHttpRequest)
      xhr_object = new XMLHttpRequest();
    else if(window.ActiveXObject)
      xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
    else
      return true;

  xhr_object.open("GET", url, true);
  
  if (fct)
    xhr_object.onreadystatechange = getNextCallback;
  /*else
    xhr_object.onreadystatechange = getNextCallback2;*/
  xhr_object.send(null);

  document.body.style.cursor = 'wait';
  if (obj != null)
    obj.style.cursor = 'wait';
  lastobj=obj;

  return false;
}

//******************************************************************************
function getNextCallback()
{
  if ((xhr_object.readyState == 4))
  {
    showVote(null, '', '', false);
    document.body.style.cursor = 'default';
    texte = xhr_object.responseText.split('#');
    if (texte[0] == '')
      document.getElementById('tnote' + texte[1]).innerHTML = texte[2];
    else
      alert(texte[0]);
  }
}

//******************************************************************************
function getNextCallback2()
{
  if ((xhr_object.readyState == 4))
  {
    alert(xhr_object.responseText);
  }
}

//******************************************************************************
function showMenu(element)
{
  menuitem = document.getElementById(element);
  menuitem.style.display = menuitem.style.display=='none'?'':'none';
}
