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 (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 (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=700,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 check_email (email)
{
  var valid = true;
  var AtSymbolAt = email.indexOf('@');
  var LastDotAt = email.lastIndexOf('.');
  var SpaceAt = email.indexOf(' ');
  var Length = email.length;


  // au moins un @ doit ?tre pr?sent et pas avant position 2
  if (AtSymbolAt < 1 )
    {valid = false}

  // au moin un . (point) apr?s le @

  if (LastDotAt < AtSymbolAt)
    {valid = false}

  // au moind deux caracteres [com, uk, fr, ...] apres le dernier point
  if (Length - LastDotAt <= 2)
    {valid = false}

  // pas d'espace
  if (SpaceAt != -1)
    {valid = false}

  if (valid != true)
    {alert("Veuillez entrer un email valide SVP")}

  return valid;
}

