// ###### CRYPT ######
function crypt(User){
  window.location.href="mailto:"+User+"@directam.fr";
}

// ###### VERIF ######

function verif() {
  if(document.getElementById('intitule').value == '')
  {
    alert('Please enter a label');
    return false;
  }
}

function verifPage() {
  if(document.getElementById('titre').value == '')
  {
    alert('You have to enter a title for this page');
    return false;
  }
}

// ###### CHANGE PHOTO ######

function changePhoto(e) {
  var id = e.id;
  var img = e.src;
  var intitule = e.alt;
  
  img = img.replace('75x50','320x300');
  id = id.replace('photo_','');
  
  document.getElementById('img_default').setAttribute('src',img);
  document.getElementById('img_default').setAttribute('alt',intitule);
  
  var full_img = img.replace('320x300/','');
  full_img = full_img.replace('thumbs','orig');
  
  document.getElementById('zoom').href = full_img;
  document.getElementById('zoom').onclick = function() {
    return GB_showImage(intitule, this.href);
  }
  
  if(document.getElementById('edit')) {
    document.getElementById('champ').value = intitule;
    document.getElementById('id').value = id;
  }
  else {
    var node = document.getElementById('img_default').nextSibling;
    if(node.nodeType == 3)
      var old_id = node.nextSibling.id;
    else
      var old_id = node.id;
    if(intitule == '')
      if(document.getElementById('img_default').parentNode.id)
        document.getElementById(old_id).firstChild.nodeValue = "Aucun intitulé";
      else
        document.getElementById(old_id).nodeValue = '';
    else
      document.getElementById(old_id).firstChild.nodeValue = intitule;
    document.getElementById(old_id).id = 'intitule_'+id;
  }
  if(document.getElementById('dragPhoto')) {
      var elements = $('dragPhoto').getElementsByTagName('img');
      var reg = new RegExp('changePhotoAdmin');
      for(i=0;i<elements.length;i++) {
        if(elements[i].id) {
          var eventClick = elements[i].onclick.toString();
          if(eventClick.match(reg)) {
            elements[i].onclick = function() {
              javascript:changePhoto(this);
            }
          }
        }
      }
  }
}

// ###### COORDS & ISEMAIL ######

function coords() {
  if(document.getElementById('nom').value == '')
  {
    alert('Please fill in your lastname');
    return false;
  }
  if(document.getElementById('prenom').value == '')
  {
    alert('Please fill in your firstname');
    return false;
  }
  if(document.getElementById('adresse').value == '')
  {
    alert('Please enter your address');
    return false;
  }
  if(document.getElementById('ville').value == '')
  {
    alert('Please fill in your city');
    return false;
  }
  if(document.getElementById('tel').value == '')
  {
    alert('Please fill in a telephone number');
    return false;
  }
  if(document.getElementById('email').value == '')
  {
    alert('Please fill in your email');
    return false;
  }
  if(!isEmail(document.getElementById('email').value))
  {
    alert('The email entered is invalid');
    return false;
  }
}

function isEmail(valeur) { 
	var re = /^\w+([\.\-_]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/; 
  
   	if(!re.test(valeur)) { 
      		return false; 
   	} 
   	return true; 
}

// ###### CONFIG ######

function config() {
  if(document.getElementById('index_title').value == '')
  {
    alert('Please fill in a title!');
    return false;
  }
}
