// Client side validation with javascript, for various fields. 

// Checks that the login table fields are valid.
function login_validate()
{
  var no_error=true;
  //
  if (document.getElementById('cellphone').value=='')
  {
    // If cellphone is empty, alert & make text red.
    alert('You must enter your cellphone number.');
    document.getElementById('cell_error').style.color='#ff0000';
    no_error=false;
  }
  else
  {
    document.getElementById('cellphone').value=removeSpaces(document.getElementById('cellphone').value);
    if (isNaN(document.getElementById('cellphone').value))
    { 
      // If cellphone is invalid, alert & make text red.
      alert('You can only enter a number into the cellphone field.');
      document.getElementById('cell_error').style.color='#ff0000';
      no_error=false;
    }
    else
    {
      // Else, make text black.
      document.getElementById('cell_error').style.color='#000000';
    }
  }
  //
  // If all are valid, post data to [login.php]
  event.returnValue=no_error;
}

function removeSpaces(string)
{
	var tstring = "";
	string = '' + string;
	splitstring = string.split(" ");
	for(i = 0; i < splitstring.length; i++)
	tstring += splitstring[i];
	return tstring;
}
