// JavaScript Document
// Start the Form Validation /////////////////////
// I Believe you can't have numbers in the fiedl name for this script
//
//global variable for error flag
var errfound = false;
//function to validate by length
function ValidLength(item, len) {
   return (item.length >= len);
}
//function to validate an email address
function ValidEmail(item) {
   if (!ValidLength(item, 1)) return false;
   if (item.indexOf ('@', 0) == -1) return false;
   return true;
}
// display an error alert
function error(elem, text) {
// abort if we already found an error
   if (errfound) return;
   window.alert(text);
   elem.select();
   elem.focus();
   errfound = true;
}

// Start Phone Number Validation Part 1 /////////////
//
//
// Declaring required variables
var digits = "0123456789";
// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "()- ";
// characters which are allowed in international phone numbers
// (a leading + is OK)
var validWorldPhoneChars = phoneNumberDelimiters + "+";
// Minimum no of digits in an international phone no.
var minDigitsInIPhoneNumber = 10;

function isInteger(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++)
    {
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function checkInternationalPhone(strPhone){
s=stripCharsInBag(strPhone,validWorldPhoneChars);
return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}
//
//
// End Phone Number Validation Part 1 /////////////
// main validation function
// Change the Form and Field Name  document.FORM_NAME.FIELD_NAME.value
function Validate() {
	// pNum is for the Radio Button check
	var pNum
   errfound = false;

  	var FirstName=document.reqAdoptForm.first_name

	if ((FirstName.value==null)||(FirstName.value=="")){
		alert("Please Enter your First Name")
		FirstName.value=""
		FirstName.focus()
		pNum = false;
		return false
	}

if(errfound == false) {
  	var LastName=document.reqAdoptForm.last_name

	if ((LastName.value==null)||(LastName.value=="")){
		alert("Please Enter your Last Name")
		LastName.value=""
		LastName.focus()
		pNum = false;
		return false
	}
}

if(errfound == false) {
   if (!ValidLength(document.reqAdoptForm.email.value,6))
      error(document.reqAdoptForm.email,"Invalid Email Address ");
		pNum = false;
// Phone section
//
}

if(errfound == false) {

  	var Company=document.reqAdoptForm.company

	if ((Company.value==null)||(Company.value=="")){
		alert("Please Enter your Company Name")
		Company.value=""
		Company.focus()
		pNum = false;
		return (false);
	}
} 

if(errfound == false) {
  	var Address=document.reqAdoptForm.street

	if ((Address.value==null)||(Address.value=="")){
		alert("Please Enter your Address")
		Address.value=""
		Address.focus()
		pNum = false;
		return false
	}
}

if(errfound == false) {
  	var city=document.reqAdoptForm.city

	if ((city.value==null)||(city.value=="")){
		alert("Please Enter your City")
		city.value=""
		city.focus()
		pNum = false;
		return false
	}
}

/*if(errfound == false) {
  	var state=document.reqAdoptForm.state

	if ((state.value==null)||(state.value=="")){
		alert("Please Enter your State")
		state.value=""
		state.focus()
		pNum = false;
		return false
	}
}
	
*/

if(errfound == false) {
  	var ZipCode=document.reqAdoptForm.zip

	if ((ZipCode.value==null)||(ZipCode.value=="")){
		alert("Please Enter your Zip Code.")
		ZipCode.value=""
		ZipCode.focus()
		pNum = false;
		return false
	}
}

if(errfound == false) { 
//00N80000003AL9I
   	var Country=document.reqAdoptForm.country

	if ((Country.value==null)||(Country.value=="")){
		alert("Please Enter your Country")
		Country.value=""
		Country.focus()
		pNum = false;
		return (false);
	}
}
	
if(errfound == false) {	
if (document.reqAdoptForm.iAgree.checked == false )  {
	alert ('Please confirm that you have read the terms of use and agree!');
	return false;
	}

}
	 // return true
     return !errfound; /* true if there are no errors */
}