function showHidePostContent(id)
{
    if ($(id).style.display == "none") {
        $(id).setStyle('display: block;');
    } else {
        $(id).setStyle('display: none;');
    }
}

function showCategPost(idCategToDisplay, nameCategEltToHide)
{
    $$('div[name="'+nameCategEltToHide+'"]').each(function (el){
        el.setStyle('display: none;');
    });
    $(idCategToDisplay).setStyle('display: block;');
}

function selectCategLink(idLinkToSelect, nameLinkToUnselect)
{
    $$('p[name="'+nameLinkToUnselect+'"]').each(function (el){
        el.className = el.id+"_n";
    });
    $(idLinkToSelect).className = idLinkToSelect+"_o";
}

function getNewsDivChild(child)
{
  if (child == null) {
    child = $('newsContent').firstChild;
  }

  if ((child.nodeType == 1) && (child.nodeName == 'DIV')){
    return child;
  } else {
    return getNewsDivChild(child.nextSibling);
  }
}

function rotatorFadeOut(previousChild)
{
  if (previousChild != null)
  {
    new Effect.Opacity(previousChild.id, { from: 1.0, to: 0.0, duration: 3.0 });
  }
}

function rotatorFadeIn(child, previousChild)
{
  if (previousChild != null) {
    $(previousChild.id).setStyle({visibility :"hidden"});
  }
  $(child.id).setStyle({opacity:0.1, visibility :"visible"});
  new Effect.Opacity(child.id, { from: 0.1, to: 1.0, duration: 3.0 });
  previousChild = child;
  child = getNewsDivChild(child.nextSibling);

  setTimeout(function () {rotatorNews(child, previousChild)}, 5000);
}

function rotatorNews(child, previousChild) {
  rotatorFadeOut(previousChild);
  setTimeout(function () {rotatorFadeIn(child, previousChild)}, 3000);
}

function isEmail(email) {
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   if(reg.test(email) == false) {
      return false;
   }
   return true;
}

function IsBlank(theString)
{
    if (theString.length > 0)
    {
        for (i = 0; i < theString.length; i++)
        {
            if (theString.charAt(i) != ' ')
            {
                return (false);
            }
        }
    }
    return (true);
}

function validateFormMail(email)
{
  email.style.border = "";

  var boolReturn = true;
  var msg = "This field is required : "
  if (IsBlank(email.value))
  {
    msg += "\n    - Email Address";
    boolReturn = false;
    email.style.border = "1px solid red";
  }

  if ((!IsBlank(email.value)) && (!isEmail(email.value)))
  {
    msg += "\n    - Email Address (bad email format)";
    boolReturn = false;
    email.style.border = "1px solid red";
  }


  if (boolReturn === false)
  {
    alert(msg);
  }
  
  return boolReturn;
}

function validateFormCabos(theForm)
{
  theForm.email.style.border = "";

  var boolReturn = true;
  var msg = "This field is required : "
  if (IsBlank(theForm.email.value))
  {
    msg += "\n    - Email Address";
    boolReturn = false;
    theForm.email.style.border = "1px solid red";
  }

  if ((!IsBlank(theForm.email.value)) && (!isEmail(theForm.email.value)))
  {
    msg += "\n    - Email Address (bad email format)";
    boolReturn = false;
    theForm.email.style.border = "1px solid red";
  }
  if (IsBlank(theForm.firstname.value))
  {
    msg += "\n    - First name";
    boolReturn = false;
    theForm.firstname.style.border = "1px solid red";
  }
  
  if (IsBlank(theForm.lastname.value))
  {
    msg += "\n    - Last name";
    boolReturn = false;
    theForm.lastname.style.border = "1px solid red";
  }
  
  if (IsBlank(theForm.affiliation.value))
  {
    msg += "\n    - Affiliation";
    boolReturn = false;
    theForm.affiliation.style.border = "1px solid red";
  }
  
  if (IsBlank(theForm.city.value))
  {
    msg += "\n    - City";
    boolReturn = false;
    theForm.city.style.border = "1px solid red";
  }
  
  if (IsBlank(theForm.country.value))
  {
    msg += "\n    - Country";
    boolReturn = false;
    theForm.email.style.border = "1px solid red";
  }
  
  if (IsBlank(theForm.phone.value))
  {
    msg += "\n    - Phone";
    boolReturn = false;
    theForm.email.style.border = "1px solid red";
  }
  
  if (IsBlank(theForm.fax.value))
  {
    msg += "\n    - Fax";
    boolReturn = false;
    theForm.email.style.border = "1px solid red";
  }


  if (boolReturn === false)
  {
    alert(msg);
  }
  
  return boolReturn;
}

function validateFormContact(theForm)
{
  theForm.email.style.border = "";

  var boolReturn = true;
  var msg = "This field is required : "
  if (IsBlank(theForm.email.value))
  {
    msg += "\n    - Email Address";
    boolReturn = false;
    theForm.email.style.border = "1px solid red";
  }

  if ((!IsBlank(theForm.email.value)) && (!isEmail(theForm.email.value)))
  {
    msg += "\n    - Email Address (bad email format)";
    boolReturn = false;
    theForm.email.style.border = "1px solid red";
  }

  if (IsBlank(theForm.comment.value))
  {
    msg += "\n    - Comment";
    boolReturn = false;
    theForm.comment.style.border = "1px solid red";
  }         

  if (boolReturn === false)
  {
    alert(msg);
  }
  
  return boolReturn;
}

