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 setpng(img)
{
  if(document.all && (IEver=parseFloat(navigator.appVersion.split("MSIE")[1])) && (IEver>=5.5) && (IEver<7) && document.body.filters && img)
  {
	  imgName=img.src.toUpperCase();
	  if(imgName.substring(imgName.length-3,imgName.length)=="PNG")
      img.outerHTML = "<span "+(img.id?"id='"+img.id+"' ":"")+(img.className?"class='"+img.className+"' ":"")+(img.title?"title=\""+img.title+"\" ":"")+
                		  "style=\"width:"+img.width+"px;height:"+img.height+"px;"+(img.align=="left"?"float:left;":(img.align=="right"?"float:right;":""))+
                      (img.parentElement.href?"cursor:hand;":"")+"display:inline-block;"+img.style.cssText+";"+
                      "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+img.src+"',sizingMethod='scale');\"></span>";
  }
}

//******************************************************************************
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 place(evt, fenetre, largeur, hauteur)
{
  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;

  fenetre.style.left = ((larg-largeur)/2) + 'px';
  fenetre.style.top = (Ydoc-hauteur) + 'px';
}

//******************************************************************************
function showVote(evt, idSite, nomSite, show)
{
  aide = document.getElementById('bulleVote');

  if (show)
  {
    place(evt, aide, 300, 100);

    document.getElementById('nomSite').innerHTML= nomSite;
    document.getElementById('idSite').innerHTML = '<input type="hidden" id="idSiteForm" name="id" value="' + idSite + '"/>';
  }

  aide.style.visibility = show?"visible":"hidden";
}

//******************************************************************************
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;
  appelAjax(null, url);
}

//******************************************************************************
var xhr_object = null;
var lastobj = null;

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 appelAjax(obj, url)
{
  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);
  xhr_object.onreadystatechange = getNextCallback;
  xhr_object.send(null);

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

  return false;
}

//******************************************************************************
function compteClic(id)
{
  if(window.XMLHttpRequest)
    xhr_object = new XMLHttpRequest();
  else if(window.ActiveXObject)
    xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
  else
    return true;

  xhr_object.open("GET", 'ajax_clic.php?id=' + id, true);
  xhr_object.send(null);

  return true;
}
