
function IsBlank(value) {
   for (var x = value.length - 1; x >= 0; x--) {
      if ((value.charAt(x) != " ") && (value.charAt(x) != "")) {
         return false;
      } 
   }
   return true;
}
////////////////////////////////////////////////////////////
// Checks to see whether a value contains non-numeric
// data.
////////////////////////////////////////////////////////////
function IsANumber(value){

    // Assume everything is okay
    var result = true

    // Check the all the digits,
    // so step through the inputValue one character at
    // a time and set result = false if any non-numeric
    // digits are encountered.

	for (var i=0; i<value.length; i++) {
         if (value.charAt(i) != " " && value.charAt(i) != "0") {
               if (!parseFloat(value.charAt(i))) {
                   result = false
                   break
	         }
	     }
	}

    // Return true (inputValue is a valid number) or
    // false (it's invalid).
    return result
}
////////////////////////////////////////////////////////////
// Checks to see if an input value contains 10 numbers.
////////////////////////////////////////////////////////////
function IsAValidPhoneNumber(value1,value2,value3){
    var digitsFound = 0

    // Step through each input Value to see how
    // many digits it contains
	var value = value1 + value2 + value3
    for (var i=0; i<value.length; i++) {
	   if (IsANumber(value.charAt(i))) {
          digitsFound++
	      }
    }
    // If inputValue contains at least 10
    // digits, assume it is a valid phone number
	  if (digitsFound == 10) {
	      return true
    }
    else {
	     return false
    }
}
////////////////////////////////////////////////////////////
// Checks to see whether an input value contains "@" and
// "."
////////////////////////////////////////////////////////////
function IsAValidEmail(value) {

    var foundAt = false
    var foundDot = false

    // Step through the inputValue looking for
    // "@" and "."

    for (var i=0; i<=value.length; i++) {
      if (value.charAt(i) == "@" ) {
          foundAt = true
      }
      else if (value.charAt(i) == ".") {
          foundDot = true
      }
    }

    // If both "@" and "." were found, assume
    // the e-mail address is valid; otherwise,
    // return false so the calling code knows
    // the e-mail address is invalid.

    if (foundAt && foundDot) {
        return true
    }
    else {
        return false
    }
}
function radio_button_checker()
{
// set var radio_choice to false
var radio_choice = false;

// Loop from zero to the one minus the number of radio button selections
for (counter = 0;  counter < Registration.salesman.length; counter++)
{
// If a radio button has been selected it will return true
// (If not it will return false)
if (Registration.salesman[counter].checked)
radio_choice = true; 
}

if (!radio_choice)
{
// If there were no selections made return false 
return (false);
}
return (true);
}

function ValidateForm(Registration) {
   
   if ((IsBlank(Registration.firstname.value))) {
      	alert("Please enter your First Name.");
		document.Registration.firstname.focus();
     	return false;
   }
   else if ((IsBlank(Registration.lastname.value))) {
     	alert("Please enter your Last Name.");
   		document.Registration.lastname.focus();                           
        return false;
   }
   else if ((IsBlank(Registration.companyname.value))){ 
   		alert("Please enter your Company Name.");
   		document.Registration.companyname.focus();                           
        return false;
   }   
    else if ((IsBlank(Registration.location.value))){ 
   		alert("Please enter your Location.");
   		document.Registration.location.focus();                           
        return false;
   }   
   else if ((IsBlank(Registration.areacode.value))){ 
   		alert("Please enter your Area Code.");
   		document.Registration.areacode.focus();                           
        return false;
   }  
   else if ((IsBlank(Registration.phone3.value))){ 
   		alert("Please enter your Phone Number.");
   		document.Registration.phone3.focus();                           
        return false;
   }   
   else if ((IsBlank(Registration.phone4.value))){ 
   		alert("Please enter your Phone Number.");
   		document.Registration.phone4.focus();                           
        return false;
   }   
   else if ((!IsANumber(Registration.areacode.value))){ 
   		alert("Please enter your Area Code as a number.");
   		document.Registration.areacode.focus();                           
        return false;
   }   
   else if ((!IsANumber(Registration.phone3.value))){ 
   		alert("Please enter your Phone Number as a number.");
   		document.Registration.phone3.focus();                           
        return false;
   }      
   else if ((!IsANumber(Registration.phone4.value))){ 
   		alert("Please enter your Phone Number as a number.");
   		document.Registration.phone4.focus();                           
        return false;
   }         
   else if ((!IsAValidPhoneNumber(Registration.areacode.value,Registration.phone3.value,Registration.phone4.value))){ 
   		alert("Please enter a proper Phone Number.");
   		document.Registration.areacode.focus();                           
        return false;
   }         
   else if ((IsBlank(Registration.emailaddress.value))){ 
   		alert("Please enter your e-Mail Address");
   		document.Registration.emailaddress.focus();                           
        return false;
   }   
   else if ((!IsAValidEmail(Registration.emailaddress.value))){ 
   		alert("Please enter a your e-Mail Address in a proper format.");
   		document.Registration.emailaddress.focus();                           
        return false;
   }         
   else if ((!radio_button_checker())){ 
   		alert("Please select a Trans Am Sales Rep. If you are not sure who your Sales Rep is then select Unknown.");
        return false;
   }         
   else {                              
            return true;
   }
   }                                 

