function checkPhoneNumber(doc) {
    $('#frmTelephone .error').removeClass('error');
        
    var ok  = true;
    var num = "";
       
    $.each( $('#frmTelephone input[type="text"].phone'), function(i, n) {
        num += $(n).attr('value');
    });
    //-- check if number if 10 digits
    //--alert (num);    
    if (!num.match(/^\d{10}$/)) {
      ok = false;
      $('#frmTelephone input.phone').addClass('error');
    }
        
    $('#thePhone').attr('value', new String(num));
    
    if (num.length == 0) {
      alert("No number entered, please try again");
      clearForm();
	}
    else if (!checknumber(num)) {
       alert("Invalid number entered, please try again");
       clearForm();
    }
    else if (num.length != 10) {
      alert("Incomplete number entered, please try again");
      clearForm();
    }
    
    return ok;
}

function clearForm() {

    $('#frmTelephone input[name="phone1"]').attr('value','');	
    $('#frmTelephone input[name="phone2"]').attr('value',''); 
    $('#frmTelephone input[name="phone3"]').attr('value','');
    
    $('#frmTelephone input[name="phone1"]').focus();
}

function checknumber(x){
  
  var anum=/(^\d+$)|(^\d+\.\d+$)/
  if (anum.test(x))
    return true;
  else
    return false;
}

$(function() {
   $('#frmTelephone input.phone').keyup(function(e) {
     var len = $(this).attr('value').length;
     var max = $(this).attr('maxlength');
        
     if (len == max) {
       if ($(this).attr('name') == "phone3")
         $('#frmTelephone input[type="submit"]').focus();
       else {
         if ($(this).attr('name') == "phone1")
           $('#frmTelephone input[name="phone2"]').focus();
         else
           $(this).next().focus();
       }
     }
   });
})

