	var strDefaultLastName = "Last Name";
	var strDefaultCity = "City";
	var strDefaultZip = "Zip";			
	
	String.prototype.trim = function () {
 		return this.replace(/^\s*/, "").replace(/\s*$/, "");
	}
				
	function physdir_toggle(x) {
		if (document.getElementById('divPhysDir' + x).style.display == 'none') {
			document.getElementById('divPhysDir' + x).style.display = 'block';
			document.images['imgPhysDir' + x].src="images/template/v2/arrow_indicator_minus.gif";
		} else {
			document.getElementById('divPhysDir' + x).style.display = 'none';
			document.images['imgPhysDir' + x].src="images/template/v2/arrow_indicator_plus.gif";
		}
	}	
				
	function validateform_search_FAD(myform) {
		var lastname = document.getElementById('limit_lastname').value;
		var city = document.getElementById('limit_city').value;
		var zip = document.getElementById('limit_zip').value;
		zip = zip.trim();
		if(lastname == strDefaultLastName) lastname = '';
		if(city == strDefaultCity) city = '';
		if(zip == strDefaultZip) zip = '';	
		if (lastname == '' &&
			myform.limit_specialty.selectedIndex == 0 &&
			(myform.limit_hospital.value == '' || myform.limit_hospital.selectedIndex == 0) &&
			city == '' &&
			zip == '' &&
			myform.limit_firstname.value == '' &&
			myform.limit_gender[2].checked &&
			myform.limit_language.value == '' &&
			myform.limit_practicename.value == '' &&
			myform.limit_interest.value == '') {
			alert("You must fill out at least one element of the search form\n - such as entering a name or choosing a specialty -\nbefore you search.\n");
			return false;
		} else if (zip != '' && (zip.length !=5 || isNaN(zip))) {
			alert("Please enter a valid 5-digit ZIP Code.\n");
			return false;
		}
		return true;
	}
			
			
	/*  file js/jquery.template.js  calls this function via beforeSubmit: validateForm, */
	function jquery_validateForm (formData, jqForm, options){
		var fields = [
			{
				limit_lastname:		strDefaultLastName,
				limit_specialty:	"",
				limit_hospital:		"",
				limit_city:			strDefaultCity,
				limit_zip:			strDefaultZip,
				limit_firstname:	"",
				limit_gender:		"",
				limit_language:		"",
				limit_practicename:	"",
				limit_interest:		"",
				curpage: "",
				nTotalPages: ""
			}
		];
		var field = {};
		var field_defined = false;	
		var validate_pagination = false;				
		$.each(fields,function(index,names){
			$.each(names,function(name,default_value){
				var nameOfField = $(jqForm).find('[name='+name+']');
				if(nameOfField.length > 0){
					if (name == "curpage") {
					 	validate_pagination = true;	
					}
					if (name == "limit_gender") { 
						field[name]=$(jqForm).find('[name='+name+']:checked').val();
				   	} else {
						field[name]=$(jqForm).find('[name='+name+']').val().trim();
					}								
				}else{
					field[name]='';
				}
				/* dap testing 
				if (name == 'limit_specialty') {
					alert('name=' + name + ' val=' + field[name]);
				}  */
				if (field[name]==default_value){
					field[name]='';
				}else{
					if(field[name]!=''){
						field_defined = true;
					}
				}
			});
		});
			
		if (validate_pagination) {
			if (isNaN(field['curpage']) || field['curpage'] == '') { 
				alert("Please enter a number from 1 to " + field['nTotalPages']); 
				return false;
			} else if (parseInt(field['curpage']) < 1 || parseInt(field['curpage']) > parseInt(field['nTotalPages'])) { 
				alert("Please enter a number from 1 to " + field['nTotalPages']);  
				return false;
			} 
			return true;
		}
		
		if(!field_defined){
			alert('You must fill out at least one element of the search form\n - such as entering a name or choosing a specialty -\nbefore you search.\n');
			return false;
		}
		
		if(field['limit_zip'] != '' && (field['limit_zip'].length !=5 || isNaN(field['limit_zip']))){
			alert("Please enter a valid 5-digit ZIP Code.\n");
			return false;
		}
	
		/*
		var queryString = $.param(formData); 
		alert('Validation checks PASS SUBMIT FORM: \n\n' + queryString);
		*/
		return true;
	}
			

