var IE4,NS4,NS6,VERSION4;
IE4 = (document.all) ? 1 : 0;
NS4 = (document.layers) ? 1 : 0;
NS6 = (document.getElementById) ? 1 : 0;
VERSION4 = (IE4 | NS4 | NS6) ? 1 : 0;

function add_scroll_position (url)
{
  if (url.indexOf ("?") == -1) url += "?";

  if (IE4)
    url = url + "&scrollX=" + document.body.scrollLeft + "&scrollY=" + document.body.scrollTop;
  else
    url = url + "&scrollX=" + window.scrollX + "&scrollY=" + window.scrollY;
  
  url = url + "&REFERER=" + escape (document.location.href);
  
  return url;
}

function add_scroll_position_without_referer (url)
{
  if (url.indexOf ("?") == -1) url += "?";

  if (IE4)
    url = url + "&scrollX=" + document.body.scrollLeft + "&scrollY=" + document.body.scrollTop;
  else
    url = url + "&scrollX=" + window.scrollX + "&scrollY=" + window.scrollY;

  return url;
}

function popup_open (url, name)
{
  url = add_scroll_position (url);
  window.open (url, 
	       name, 
	       'width=800,height=700,scrollbars=yes,resizable=yes,left=0,top=0,status=no');
}

function insert_link (url, text)
{
  text = text ? text : "Confirmez vous cet ajout ?";
  if (confirm (text))
    {
      window.location = add_scroll_position (url);
    }
  return false;
}

function append_link (url, text)
{
 return insert_link (url, text);
}

function delete_link (url, text)
{
  text = text ? text : "Confirmez vous cette suppression ?";
  if (confirm (text))
    {
      window.location = add_scroll_position (url);
    }
  return false;
}

function state_link (url, text)
{
  text = text ? text : "Confirmez vous cette modification ?";
  if (confirm (text))
    {
      window.location = add_scroll_position (url);
    }
  return false;
}

function event_link (url, text)
{
  if (!text || confirm (text))
    {
      window.location = add_scroll_position (url);
    }
  return false;
}

function select_link (url)
{
  window.location = add_scroll_position (url);
  return false;
}

function reload_opener ()
{
  window.opener.location.reload ();
}

function reload_opener_and_close ()
{
  reload_opener ();
  window.close ();
}

function scroll_page (x, y)
{
  self.scrollTo (x,y);
}

function popup_open_without_scroll (url, name)
{
  window.open (url, 
	       name, 
	       'width=700,height=700,scrollbars=yes,resizable=yes,left=0,top=0,status=no');
  return false;
}

function change_image (element, url)
{
 if (document.getElementById (element))
    {
      document.getElementById (element).src = url;
    }
}

function change_texte (element, texte)
{
 if (document.getElementById (element))
    {
      document.getElementById (element).innerHTML = texte;
    }
}

function set_class (element, className)
{
  if (document.getElementById (element))
    {
      document.getElementById (element).className = className;
    }
}

function set_class_all (prefix, className, max)
{
  max = max ? max : 100;
  for (i=0; i<max; i++)
    {
      if (document.getElementById (prefix+i))
        {
          document.getElementById (prefix+i).className = className;
        }
      else
        break;
    }
}

function show (element)
{
  if (document.getElementById (element))
    {
      document.getElementById (element).style.display = 'block';
    }
}

function taofocus (element)
{
  if (document.getElementById (element))
    {
      document.getElementById (element).focus ();
    }
}

function hide (element)
{
  if (document.getElementById (element))
    {
      document.getElementById (element).style.display = 'none';
    }
}

function toggle_visibility (element)
{
  if (document.getElementById (element))
    {
      if (document.getElementById (element).style.display == 'none')
	{
	  show (element);
	  return 1;
	}
      else
	{
	  hide (element);
	  return 0;
	}
    }
}

function hide_all (prefix, max)
{
  max = max ? max : 100;
  for (i=0; i < 20; i++)
    {
      if (document.getElementById (prefix+i))
        {
          document.getElementById (prefix+i).style.display = 'none';
        }
//      else        break;
    }
}

