/**
 * @file: lightninbug.js
 * @author: Barbeaux Samuel
 * @company: VLS & Henrotte
 * @brief: javascript document
 */

/***********************************************/
/**************** ERROR FUNCTION ***************/
/***********************************************/

//onerror = handleErr;

function handleErr(msg,url,l)
{
  var txt="There was an error on this page.\n\n";
  txt+="Error: " + msg + "\n";
  txt+="URL: " + url + "\n";
  txt+="Line: " + l + "\n\n";
  txt+="Click OK to continue.\n\n";
  alert(txt);
  return true;
}


/***********************************************/
/**************** MOUSE FUNCTION ***************/
/***********************************************/

function reEnable()
{
  return true
}

//if IE4+
//document.onselectstart=new Function ("return false")
document.oncontextmenu=new Function ("return false")
//if NS6
if (window.sidebar)
{
  //document.onmousedown=disableselect
  document.onclick=reEnable
}


/*****************************************************/
/** ON CLICK FUNCTION                                */
/*****************************************************/

/**
 */
function on_click(module, action, phase)
{
  document.mainForm.module.value = module;
  document.mainForm.action.value = action;
  document.mainForm.phase.value= phase;
  document.mainForm.submit();
}

/**
 */
function bcolor(bcol, tcolor, d_name)
{
  document.getElementById(d_name).style.color = tcolor;
  document.getElementById(d_name).style.backgroundColor = bcol;

  return;
}

/**
 */
function swapImage(name, src)
{
  var img = document.getElementById(name);
  img.src = src;
}

/**
 */
function geolocalise(place, address)
{
  var p = window.open('geolocalise.php?place=' + place + '&addr=' + address, '', 'width=520,height=320"');
  p.focus();
}

/**
 */
function switch_display(id_view)
{
  if (document.getElementById(id_view).style.display == "none")
  {
    document.getElementById(id_view).style.display = "";
  }
  else
  {
    document.getElementById(id_view).style.display = "none";
  }
}

/**
 */
function checkWriteguest(module, action, phase)
{
  if (document.mainForm.name.value == "")
  {
   alert("Vous devez obligatoirement entrer un nom!");
   document.mainForm.name.focus();
   return false;
  }

  if (document.mainForm.mail.value == "")
  {
   alert("Vous devez obligatoirement entrer une adresse email!");
   document.mainForm.mail.focus();
   return false;
  }
  else
  {
    // check email address
    adresse = document.mainForm.mail.value;
    var place = adresse.indexOf("@",1);
    var point = adresse.indexOf(".",place+1);
    if ((place > -1)&&(adresse.length >2)&&(point > 1)) { }
    else
    {
      alert('Entrez une adresse e-mail valide! Merci.');
      document.mainForm.mail.focus();
      return false;
    }
  }
  
  if (document.mainForm.message.value == "")
  {
   alert("Vous devez obligatoirement entrer un message !");
   document.mainForm.message.focus();
   return false;
  }
  
  if (document.mainForm.code.value == "")
  {
   alert("Vous devez obligatoirement entrer un code !");
   document.mainForm.code.focus();
   return false;
  }
  
  on_click(module, action, phase);

  return true;
}

