$(document).ready(function(){
   // Change the image of hoverable images
   $(".imgHoverable").hover( function() {
       var hoverImg = HoverImgOf($(this).attr("src"));
       $(this).attr("src", hoverImg);
     }, function() {
       var normalImg = NormalImgOf($(this).attr("src"));
       $(this).attr("src", normalImg);
     }
   );
});

function HoverImgOf(filename)
{
   var re = new RegExp("(.+)\\.(gif|png|jpg)", "g");
   return filename.replace(re, "$1_hover.$2");
}
function NormalImgOf(filename)
{
   var re = new RegExp("(.+)_hover\\.(gif|png|jpg)", "g");
   return filename.replace(re, "$1.$2");
}


function formCheck() {
  if (document.contact.forename.value.replace(/ */ig, '') === '') {
    window.alert('Please enter a forename.');
    return false; 
  }
  if (document.contact.surname.value.replace(/ */ig, '') === '') {
    window.alert('Please enter a surname.');
    return false;
  }
  if (document.contact.email.value.replace(/ */ig, '') === '') {
    window.alert('Please enter your email address.');
    return false;
  }
  if (document.contact.tel.value.replace(/ */ig, '') === '') {
    window.alert('Please enter a phone number.');
    return false;
  }
    document.contact.comment.value = document.contact.comment.value.replace(/<\/?\w+((\s+\w+(\s*=\s*(?:".*?"|'.*?'|[^'">\s]+))?)+\s*|\s*)\/?>/ig, '');
}

function commentsCheck() {
  if (document.comments.name.value.replace(/ */ig, '') === '') {
    window.alert('Please enter your name.');
    return false;
  }
  if (document.comments.email.value.replace(/ */ig, '') === '') {
    window.alert('Please enter your email address.');
    return false;
  }
  if (document.comments.comment.value.replace(/ */ig, '') === '') {
    window.alert('Please enter a comment.');
    return false;
  }
  document.comments.comment.value = document.comments.comment.value.replace(/<\/?\w+((\s+\w+(\s*=\s*(?:".*?"|'.*?'|[^'">\s]+))?)+\s*|\s*)\/?>/ig, '');
}

function signupCheck() {
  if (document.signup.signup.value.replace(/ */ig, '') === '') {
    window.alert('Please enter an email.');
    return false;
  }
  window.alert("Thank you for registering.");
}


