function validate_required(field,alerttxt) {
with (field)  {
  if (value==null||value=="")    {
    alert(alerttxt);return false;
    }
	else    {
    return true;
    }
  }
}

function validate_radio_button(rbtn) {
	// 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 < rbtn.length; counter++) {
		// If a radio button has been selected it will return true
		// (If not it will return false)
		if (rbtn[counter].checked)
			radio_choice = true; 
	}

	//if (!radio_choice) {
		// If there were no selections made display an alert box 
		//alert("Please select a letter.")
		//return (false);
	//}

	return (radio_choice);
}

function isValidEmail(str) {
   return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
}

function isValidPhoneNumber(fld) {
   if(fld.value.search(/\d{3}\-\d{3}\-\d{4}/)==-1)   {
	return false;
   }
}

function isValidMonth(fld) {
   var month = fld.value.substr(2,2);
   if ((month < 0) || (month > 12)) {
	return false;
   }
}

function isValidZip(fld) {
   if(fld.value.search(/\d{5}/)==-1)   {
	return false;
   }
   // var zipCodePattern = /^\d{5}$|^\d{5}-\d{4}$/;
   //  return zipCodePattern.test(fld);
}







function validate_form(thisform){
with (thisform)  {
  if (validate_required(name,"Please fill out 'Your Name'!")==false) {
	name.focus();return false;
	}
  
  if (validate_required(email,"Please fill out 'Your Email'!")==false) {
	email.focus();return false;
  }
  
  if (isValidEmail(email.value)==false) {
	alert("Please fill in valid email address!");
	email.focus();return false;
  }
  
  if (validate_required(phone,"Please fill out 'Contact Phone'!")==false) {
	phone.focus();return false;
  }
  
  if (isValidPhoneNumber(phone)==false) {
	alert("The phone number you entered is not valid.\n\nPlease enter a phone number with the format xxx-xxx-xxxx.");
	phone.focus();return false;
  }

   if (validate_required(zip,"Please fill out 'Zip Code'!")==false) {
	zip.focus();return false;
	}
	
   if (isValidZip(zip)==false) {
	alert("The zip code you entered is not valid.\n\nPlease enter a valid zip code.");
	zip.focus();return false;
  }

  
  if (validate_radio_button(type)==false) {
	alert("Please select your choice for 'Animal Type'!");
	//type.focus();
	return false;
  }
  if (validate_radio_button(sex)==false) {
	alert("Please select your choice for 'Animal Gender'!");
	//type.focus();
	return false;
  }

  if (validate_required(petname,"Please fill out 'Pet Name'!")==false) {
	petname.focus();return false;
  }
  if (validate_required(weight,"Please fill out 'Pet Weight'!")==false) {
	weight.focus();return false;
  }
//  if (validate_required(ageyears,"Please fill out 'Pet Age - Years'!")==false) {
//	ageyears.focus();return false;
//  }
//  if (validate_required(agemonths,"Please fill out 'Pet Age - Months'!")==false) {
//	agemonths.focus();return false;
// }
  if (isValidMonth(agemonths)==false) {
	alert("Please fill in valid month: range is 1 - 12!");
	agemonths.focus();return false;
  }

  
 }
}

