function setBodyStyle()
{
  var cWidth    = document.documentElement.clientWidth;
  var bodyClass = '';
  if ( cWidth < 800 ) bodyClass += 'small';
  if ( cWidth < 480 ) bodyClass += ' smaller';
  document.body.className = bodyClass;
}

window.onload   = setBodyStyle;
window.onresize = setBodyStyle;

function newSpanStuff(target){
var allSpans = document.getElementById('navigation').getElementsByTagName('span');
var targetSpan = allSpans[target];
if ('navgt' == targetSpan.className){
targetSpan.className = 'navgthover';
}
}

function oldSpanStuff(target){
var allSpans = document.getElementById('navigation').getElementsByTagName('span');
var targetSpan = allSpans[target];
if ('navgthover' == targetSpan.className){
targetSpan.className = 'navgt';
}
}

/***************************************************************************
* Function:  validateForm(pasval), surname(passval), Email(passval),       *
*            Phone(passval), Enquiry(passval)                              *
* Parameter: passval (value of corresponding form field)                   *
* Purpose:   Validate user form fields against regular expressions and     *
*            provide error feedback                                        *
*                                                                          *
* Author:    Chris Reeve                                                   *
* Date:      July 2007                                                     *
***************************************************************************/

function validateForm(passval)
{
  if (!surname(passval)) return false;  //if entered data fails validation, return false and stop submission until corrected
  if (!firstname(passval)) return false;
	if (!Email(passval)) return false;
  if (!Phone(passval)) return false;
	if (!organisation(passval)) return false;
  if (!Enquiry(passval)) return false;
  return true;
}

function surname(passval)
{
  if (passval.surname.value == '') //if no surname has been entered, flash an alert
  {
  //get the current style of the 'blanksurname' div and change the display property to block to show error message
  var blankfield = document.getElementById('blanksurname').style;
  blankfield.display = "block";
  return false;
  }
  else
  {
  //if no errors or errors corrected hide error message containing divs by changing display property to none
  var blankfield = document.getElementById('blanksurname').style;
  blankfield.display = "none";
  return true;
  }
}

function firstname(passval)
{
  if (passval.firstname.value == '') //if no firstname has been entered, flash an alert
  {
  //get the current style of the 'blankfirstname' div and change the display property to block to show error message
  var blankfield = document.getElementById('blankfirstname').style;
  blankfield.display = "block";
  return false;
  }
  else
  {
  //if no errors or errors corrected hide error message containing divs by changing display property to none
  var blankfield = document.getElementById('blankfirstname').style;
  blankfield.display = "none";
  return true;
  }
}

function Email(passval)
{
  //define regular expression to test for email address abcdef@bleah.co.uk or abcdef@bleah.com
  var validemail = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
  if (passval.email.value == '') //if no email address has been entered, flash an alert
  {
  //get the current style of the 'blankemail' div and change the display property to block to show error message
  var blankfield = document.getElementById('blankemail').style;
  blankfield.display = "block";
  return false;
  }
  else
  {
  if (!validemail.test(passval.email.value))//perform email check, if not required format, flash an alert
  {
  //get the current style of the 'blankemail' div and change the display property to none to hide error message
  //display wrongemail div
  var blankfield = document.getElementById('blankemail').style;
  blankfield.display = "none";
  var blankfield = document.getElementById('wrongemail').style;
  blankfield.display = "block";
  return false;
  }
  else
  {
  //if no errors or errors corrected hide error message containing divs by changing display property to none
  var blankfield = document.getElementById('blankemail').style;
  blankfield.display = "none";
  var wrongfield = document.getElementById('wrongemail').style;
  wrongfield.display = "none";
  return true;
  }
  }
}

function Phone(passval)
{
  if (passval.telephone.value == '') //if no phone number has been entered, flash an alert
  {
  //get the current style of the 'blankphone' div and change the display property to block to show error message
  var blankfield = document.getElementById('blankphone').style;
  blankfield.display = "block";
  return false;
  }
  else
  {
  return true;
  }
}

function organisation(passval)
{
  if (passval.company.value == '') //if no company or organisation name has been entered, flash an alert
  {
  //get the current style of the 'blanksurname' div and change the display property to block to show error message
  var blankfield = document.getElementById('blankcompany').style;
  blankfield.display = "block";
  return false;
  }
  else
  {
  //if no errors or errors corrected hide error message containing divs by changing display property to none
  var blankfield = document.getElementById('blankcompany').style;
  blankfield.display = "none";
  return true;
  }
}

function Enquiry(passval)
{
  if (passval.requirements.value == '' || passval.requirements.value == 'Please provide a few details about the requirements of your web site') //if no enquiry text has been entered, flash an alert
  {
  //get the current style of the 'blankmessage' div and change the display property to block to show error message
  var blankfield = document.getElementById('blankenquiry').style;
  blankfield.display = "block";
  return false;
  }
  else
  {
  //if no errors or errors corrected hide error message containing divs by changing display property to none
  var blankfield = document.getElementById('blankenquiry').style;
  blankfield.display = "none";
  return true;
  }
}

