
// -------------------------------------- Positionner les flagbox ------------------------------
var ns4 = (document.layers)? true:false;
var ie4 = (document.all)? true:false;
var dom = (document.getElementById)? true:false;

function setToAnchor(ID_Anchor,Name_Anchor,ID_Div)
    {
    var DivLeft = 0;	  //Position du Div par rapport au côté gauche de la page
    var DivTop = 0;	  //Position du Div par rapport au haut de la page
        if (dom)
            {
            pos = document.getElementById(ID_Anchor);
            DivLeft = getLeft(pos);
            DivTop = getTop(pos);
            document.getElementById(ID_Div).style.left = DivLeft;
            document.getElementById(ID_Div).style.top = DivTop;
            }
        else if (ie4)
            {
            pos = document.all[ID_Anchor];
            DivLeft = getLeft(pos);
            DivTop = getTop(pos);
            document.all[ID_Div].style.posLeft = DivLeft;
            document.all[ID_Div].style.posTop = DivTop;
            }
        else if (ns4)
            {
            pos = document.anchors[Name_Anchor];
            DivLeft = pos.x;
            DivTop = pos.y;
            document.layers[ID_Div].pageX = DivLeft;
            document.layers[ID_Div].pageY = DivTop;
            }
    }
function getLeft(MyObject)
    {
    if (MyObject.offsetParent)
        return (MyObject.offsetLeft + getLeft(MyObject.offsetParent));
    else
        return (MyObject.offsetLeft);
    }
function getTop(MyObject)
    {
    if (MyObject.offsetParent)
        return (MyObject.offsetTop + getTop(MyObject.offsetParent));
    else
        return (MyObject.offsetTop);
    }

//-------------- Input : vérifier maxlength --------------------------

function verifMax(input, max) {
  max = max - 4;
  str = input.value;
  for (i=0; i<str.length; i++) {
    if (str.charAt(i) == '<') {
      max = max - 4;
    } else if (str.charAt(i) == '>') {
      max = max - 4;
    } else if (str.charAt(i) == '&') {
      max = max - 5;
    }
  }
  input.maxLength = max;
}

//-------------- AJAX : clic sur une case de vote --------------------
function clic(id) {
  document.getElementById('nbclic'+id).innerHTML = '<img src="img/ajax.gif">';
  new Ajax.Updater('nbclic'+id, 'clic_entry.php?id_entry='+id, {asynchronous:true, evalScripts:true,
    onComplete: function(){new Effect.Pulsate('nbclic'+id, {duration:0.8});}});
}

//-------------- AJAX : clic sur un flag --------------------
function flag(id) {
  setToAnchor('flag'+id,'flagbox'+id,'flagbox'+id)
  document.getElementById('flagbox'+id).innerHTML = '<img src="img/ajax.gif">';
  document.getElementById('flagbox'+id).style.visibility="visible";
  new Ajax.Updater('flagbox'+id, 'flag.php?id_entry='+id, {asynchronous:true, evalScripts:true});
}
function deflag(id) {document.getElementById('flagbox'+id).style.visibility="hidden";}