 var geocoder;
	  var map;
	  var errorMsg='';
	  var errorsNum=0;
	
	  function codeAddress(street,city,state,zip) {
		errorMsg='';
	    //var address = document.getElementById("address").value;
	    geocoder = new google.maps.Geocoder();
		if (geocoder) {
	      var sure = geocoder.geocode( { 'address': street+' '+city+' '+state+' '+zip}, function(results, status) {
	        if (status == google.maps.GeocoderStatus.OK) {
			//alert(results.length+' results');
			if(results.length > 0){
			  for(i=0;i<1;i++){
			  	//alert(results[i].formatted_address);
				var found_street_number = '';
				var found_street_name = '';
				var found_city = '';
				var found_state = '';
				var found_zip = '';
				for(c=0;c<results[i].address_components.length;c++){
					if(results[i].address_components[c].types=='street_number') found_street_number=results[i].address_components[c].long_name;
					if(results[i].address_components[c].types=='route') found_street_name=results[i].address_components[c].long_name;
					if(results[i].address_components[c].types=='locality,political') found_city=results[i].address_components[c].long_name;
					if(results[i].address_components[c].types=='administrative_area_level_1,political') found_state=results[i].address_components[c].long_name;
					if(results[i].address_components[c].types=='postal_code') found_zip=results[i].address_components[c].long_name;
				}
				if((found_street_number!=''||found_street_name!='')&&(street.toLowerCase() != found_street_number+' '+found_street_name.toLowerCase())){
					errorMsg +='<strong>Street Mismatch!</strong> You entered <i>'+street+'</i> - Did you mean? <strong>'+found_street_number+' '+found_street_name+'</strong><br />';
				}
				if(found_city!=''&&(found_city.toLowerCase() != city.toLowerCase())){
					errorMsg += '<strong>City Mismatch!</strong> You entered <i>'+city+'</i> - Did you mean? <strong>'+found_city+'</strong><br />';
				}
				//if(found_state!=''&&(found_state != state)){
					//alert('state mismatch.. you: '+state+' found: '+found_state);
				//}
				if(found_zip!=''&&(found_zip != zip)){
					errorMsg += '<strong>Zip Code Mismatch!</strong> You entered <i>'+zip+'</i> - Did you mean? <strong>'+found_zip+'</strong><br />';
				}
				
			  }
			}
	        } else {
	          //alert("Geocode was not successful for the following reason: " + status);
	        }
			
			if(errorMsg !=''){
				//alert(errorMsg);
				document.getElementById('errorDiv').innerHTML+=errorMsg;
				errorsNum++;
				return false;
			}else{
				return true;
			}
			 });
	    }
		
		//alert(sure);
	  }
	  
	  
	  /*function checkInput(){
		codeAddress(document.forms['callToAction'].street_address.value,document.forms['callToAction'].city.value,document.forms['callToAction'].state.value,document.forms['callToAction'].zip_code.value);

	  }*/




function validateMe(myForm){
	document.getElementById('errorDiv').innerHTML='';
	var theErrors="";

	if (myForm.practice_name.value == "") {
		errorsNum +=1;
		theErrors += "Please enter your practice name.<br>";
	}
	
	/*if (myForm.contact_name.value > ""){
		var contactNameEx = /[^a-zA-Z\-\(\)\.\s\&]/;
		if(myForm.contact_name.value.match(contactNameEx)){
			errorsNum +=1;
			theErrors += "The name appears to be invalid.<br>";
		}
	}*/
	
	if (myForm.street_address.value == "") {
		errorsNum +=1;
		theErrors += "Please enter your address.<br>";
	}
	
	if (myForm.city.value == "") {
		errorsNum +=1;
		theErrors += "Please enter your city.<br>";
	}

	if (myForm.state.value == "") {
		errorsNum +=1;
		theErrors += "Please enter your state.<br>";
	}
	
	
	if (myForm.zip_code.value == "") {
		errorsNum +=1;
		theErrors += "Please enter your zip code.<br>";
	}
	
	if (myForm.main_number.value == "") {
		errorsNum +=1;
		theErrors += "Please enter your main phone number.<br>";
	} else{
		var phoneEx = /[^0-9\-\(\)\.\s]/;
		if(myForm.main_number.value.match(phoneEx)){
			errorsNum +=1;
			theErrors += "The phone number appears to be invalid.<br>";
		} else if(myForm.main_number.value.replace(/[^0-9]/g,'').length != 10){
			errorsNum +=1;
			theErrors += "The phone number appears to be invalid.<br>";
		}
	}
	

	if (myForm.fax_number.value > "") {
		var faxEx = /[^0-9\-\(\)\.\s]/;
		if(myForm.fax_number.value.match(faxEx)){
			errorsNum +=1;
			theErrors += "The fax number appears to be invalid.<br>";
		} else if(myForm.fax_number.value.replace(/[^0-9]/g,'').length != 10){
			errorsNum +=1;
			theErrors += "The fax number appears to be invalid.<br>";
		}
	}

	var tfld = myForm.email_address.value.replace(/^\s+|\s+$/, '');  
	
    var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;

	if (myForm.email_address.value == "") {
    errorsNum +=1;
    theErrors += "Please enter your e-mail address.<br>";
	} else if (!emailFilter.test(tfld)) {              
    errorsNum +=1;
    theErrors += "Please enter a valid email address (Example: joe@example.com).<br>";
	} else if (myForm.email_address.value.match(illegalChars)) {
    errorsNum +=1;
    theErrors += "The email address you provided contains illegal characters.<br>";
	} 


	if (myForm.website.value > "") {
		theURL = myForm.website.value;
		var validURL = true;
		urlSplit = theURL.split('.');
		var illegalURLChars= /[\<\>\,\;\:\\\"\'\@\(.)]/ ;

		if(urlSplit.length < 2){
			validURL = false;
		}

		if(urlSplit[eval(urlSplit.length-1)].length > 4){
			validURL = false;	
		};

		if(theURL.match(illegalURLChars)){
			validURL = false;	
		}

		if(validURL = false){
			errorsNum +=1;
			theErrors += "The website doesn't appear valid.<br>";
		}
	}



/*if(codeAddress(myForm.street_address.value,myForm.city.value,myForm.state.value,myForm.zip_code.value)){
} else{
	errorsNum+=1;
}*/


	//geocode
	//var moreErrors = codeAddress(myForm.street_address.value,myForm.city.value,myForm.state.value,myForm.zip_code.value);

	//theErrors += moreErrors;
	document.getElementById('errorDiv').innerHTML = theErrors + document.getElementById('errorDiv').innerHTML;


	if(errorsNum > 0){
		//alert(theErrors);
		return false;
	} else {
		myForm.main_number.value = myForm.main_number.value.replace(/[^0-9]/g,'');
		myForm.fax_number.value = myForm.fax_number.value.replace(/[^0-9]/g,'');
		return true;
	}


}

