/*
 * All the various functions for handling the order form
 *
 */

// try stopping the enter key forcing a form submit
var mouse_in_use = false;

function MouseDetected() 
{ mouse_in_use = true; }

function MouseLost() 
{ mouse_in_use = false; }

function MouseUsed() 
{ return( mouse_in_use == true ); }
 
 
function ValidateAddress()
{
  // called on submit of the delivery address form
  
  // firstly only allow mouse clicks to submit 
  // (stop those annoying enter key accidental submits
  if( ! MouseUsed() ) return false;

  // see if they chose a different country to the order form
  // move this to a field specific onclick function

  // check that each of the fields is non-null
  if ( document.orderform.name.value == '' )
  {
    alert('Please enter your name');
    return false;
  }
  
  if ( (document.orderform.address.value == '') ||
       (document.orderform.postcode.value == '')
     )
  {
    alert('Please give us your FULL address and postcode');
    return false;
  }
  
  if ( document.orderform.email.value != document.orderform.emailconfirm.value  )
  {
    alert('Your email addresses don\'t match\nplease correct one or the other');
    return false;
  }
  
  if ( (document.orderform.emailconfirm.value == '') ||
       (document.orderform.email.value == '')
     )
  {
    alert('Please give us your email address \nin case of problems with your order');
    return false;
  }
  
  // made it!
  return true;
}

function ValidateJoinAddress()
{
  // called on submit of the "join mailing list" form
  
  // firstly only allow mouse clicks to submit 
  // (stop those annoying enter key accidental submits
  if( ! MouseUsed() ) return false;

  // check that each of the fields is non-null
  if ( document.joinform.name.value == '' )
  {
    alert('Please enter your name');
    return false;
  }
    
  if ( document.joinform.email.value == '' )
  {
    alert('Please give us your email address');
    return false;
  }
  
  // made it!
  return true;
}

