<?php include ("_website_init.php"); ?>
<?php $errorsAndAlerts = ""; ?>
<?php if (@$_REQUEST['save'] == 1) {
// if     (!@$_REQUEST['practice_state'] )                     { $errorsAndAlerts .= "You'll need to choose at least a State and re-submit your search to continue<br/>\n"; }	
}
// get geocoding data
  list($myLat, $myLng) = geocodeAddress( @$_REQUEST['fromAddress'] );
  $kmOrMiles           = 'miles'; // can be 'miles' or 'km'
  $geoOptions          = geocoder_getOptions($myLat, $myLng, @$_REQUEST['maxDistance'], $kmOrMiles);

  // get records
  list($addressRecords, $addressMetaData) = getRecords(array(
    'tableName'     => $GLOBALS['GEOCODER_SAMPLE_TABLENAME'],
  ) + $geoOptions);  // geoOptions WILL NOT override the above options

  // error checking
  $errorsAndAlerts = '';
  if (@$_REQUEST['search']) {
    if     (!@$_REQUEST['fromAddress']) { $errorsAndAlerts .= "No address entered!<br/>\n"; }
   // elseif (!$myLat || !$myLng)         { $errorsAndAlerts .= "Please enter a valid  5 digit zip code!<br/>\n"; }
  }

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>DBT NETWORK SERVICE PROVIDER DIRECTORY LISTINGS</title>
<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">
<meta name="viewport" content="width=device-width, target-densitydpi=device-dpi, initial-scale=1">
<link rel="shortcut icon" type="image/ico" href="/favicon.ico" />
<link href="css/dbt.css.php" rel="stylesheet" type="text/css" />
<link rel="stylesheet" type="text/css" href="css/fonts.css.php" />
<?php include ("_preload.php"); ?>
<link rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/css?family=<?php 
    $output = ''; 
    foreach ($google_font_namesRecords as $record) { $record['name'] = preg_replace("/[, ]/", "+", $record['name']);
      $output .= $record['name'] . "|"; 
    } 
    $output = rtrim($output,"|"); // remove trailing pipe 
    print $output; 
?>">
<?php function formatPhone($phone = '', $convert = false, $trim = true)
{
	// If we have not entered a phone number just return empty
	if (empty($phone)) {
		return '';
	}
 
	// Strip out any extra characters that we do not need only keep letters and numbers
	$phone = preg_replace("/[^0-9A-Za-z]/", "", $phone);
 
	// Do we want to convert phone numbers with letters to their number equivalent?
	// Samples are: 1-800-TERMINIX, 1-800-FLOWERS, 1-800-Petmeds
	if ($convert == true) {
		$replace = array('2'=>array('a','b','c'),
				 '3'=>array('d','e','f'),
			         '4'=>array('g','h','i'),
				 '5'=>array('j','k','l'),
                                 '6'=>array('m','n','o'),
				 '7'=>array('p','q','r','s'),
				 '8'=>array('t','u','v'),								 '9'=>array('w','x','y','z'));
 
		// Replace each letter with a number
		// Notice this is case insensitive with the str_ireplace instead of str_replace 
		foreach($replace as $digit=>$letters) {
			$phone = str_ireplace($letters, $digit, $phone);
		}
	}
 
	// If we have a number longer than 11 digits cut the string down to only 11
	// This is also only ran if we want to limit only to 11 characters
	if ($trim == true && strlen($phone)>11) {
		$phone = substr($phone, 0, 11);
	}						 
 
	// Perform phone number formatting here
	if (strlen($phone) == 7) {
		return preg_replace("/([0-9a-zA-Z]{3})([0-9a-zA-Z]{4})/", "$1-$2", $phone);
	} elseif (strlen($phone) == 10) {
		return preg_replace("/([0-9a-zA-Z]{3})([0-9a-zA-Z]{3})([0-9a-zA-Z]{4})/", "($1) $2-$3", $phone);
	} elseif (strlen($phone) == 11) {
		return preg_replace("/([0-9a-zA-Z]{1})([0-9a-zA-Z]{3})([0-9a-zA-Z]{3})([0-9a-zA-Z]{4})/", "$1($2) $3-$4", $phone);
	}
 
	// Return original phone if not 7, 10 or 11 digits long
	return $phone;
}
?>
</head>

<body >
<p>&nbsp;</p>
<table class="shadow3" bgcolor="#<?php echo $dbt_colorsRecord['main_box_background_color'] ?>" width="55%" border="0" align="center" cellpadding="0">
  <tr>
    <td  colspan="2" bgcolor="#<?php echo $dbt_colorsRecord['masthead_background_color'] ?>"><div class="under round-corner" align="left">
        <?php foreach ($common_informationRecord['masthead'] as $index => $upload): ?>
        <a href="index.php"><img src="<?php echo $upload['thumbUrlPath3'] ?>"   alt="DBT Masthead" /></a>
        <?php endforeach ?>
      </div></td>
  </tr>
  <tr>
    <td class="shadow3"  width="20%" rowspan="4" align="right" valign="top" bgcolor="#<?php echo $dbt_colorsRecord['menu_background_color'] ?>" ><?php include ("_mainnavmenu.php"); ?></td>
    <td width="82%"></td>
  </tr>
  <tr>
    <td align="center" ><br />
      <br />
      <div align="center" style="width:80%; text-align:left">
      
      <!-- Insert Active Code Here --> 
      
      <span class="heading_font"><b>SERVICE PROVIDER DIRECTORY LISTINGS </b><br />
      <br />
      <a href="directory_searchB.php"><span class="sub_heading_font"><br />
      &lt;&lt; <u>Change Your Directory Search Criteria</u></span></a> <br />
      <br />
      </span><span class="text_font">
      <table align="left" width="90%" border="0" cellspacing="0" cellpadding="2">
        <tr>
          <td colspan="2"><?php
		//Start Levels Of Care
		  @$levelsOfCaresearchCriteria = "";  // set default value
		  if  ((@$_REQUEST['save'] == 1) && @$_REQUEST['levels_of_care_keyword']) {
		   @$levelsOfCaresearchCriteria = "<b>Levels of Care: </b>";  // set default value 
		   // cycle through each level of care selected
		   foreach ($_REQUEST['levels_of_care_keyword'] as $levelOfCare) {
			 
			 // lookup level of care number in database
			 $levelOfCareRecord = mysql_get("levels_of_care_categories", $levelOfCare);
			 
			 if ($levelOfCareRecord) {
			   // add "level of care" value to output
			   @$levelsOfCaresearchCriteria .= $levelOfCareRecord['category'] .", ";
			 }
			 
		   }
		   
		  }
		  //End Levels Of Care
		  //Start Age Group
		  @$generalTargetPopulationsearchCriteria = "";  // set default value
		  if  ((@$_REQUEST['save'] == 1) && @$_REQUEST['general_target_population_keyword']) {
		   @$generalTargetPopulationsearchCriteria = "<b>Age Group: </b>";  // set default value 
		   // cycle through each general target population selected
		   foreach ($_REQUEST['general_target_population_keyword'] as $generalTargetPopulation) {
			 
			 // lookup general target population number in database
			 $general_target_populationRecord = mysql_get("general_target_population_categories", $generalTargetPopulation);
			 
			 if ($general_target_populationRecord) {
			   // add "general target population" value to output
			   @$generalTargetPopulationsearchCriteria .= $general_target_populationRecord['category'] .", ";
			 }
		   }
		  }
		  //End Age Group
		 
		 // Start Services Offered
		    @$servicesOfferedsearchCriteria = "";  // set default value
		  if  ((@$_REQUEST['save'] == 1) && @$_REQUEST['services_offered_keyword']) {
		   @$servicesOfferedsearchCriteria = "<b>Services Offered: </b>";  // set default value 
		   // cycle through each services offered selected
		   foreach ($_REQUEST['services_offered_keyword'] as $servicesOffered) {
			 
			 // lookup services offered number in database
			 $servicesOfferedRecord = mysql_get("services_offered_categories", $servicesOffered);
			 
			 if ($servicesOfferedRecord) {
			   // add "services offered" value to output
			   @$servicesOfferedsearchCriteria .= $servicesOfferedRecord['category'] .", ";
			 }
		   }
		  } 
		  // End Services Offered
		  
		
		 	  
		  if ((@$_REQUEST['save'] == 1) && @$_REQUEST['public_transportation_nearby'] && @$_REQUEST['public_transportation_nearby'] == 1) { @$publicTransportationNearbysearchCriteria .= "<b>Public Transportation Nearby:</b> Yes"; }

if ((@$_REQUEST['save'] == 1) && @$_REQUEST['public_transportation_nearby'] && (@$_REQUEST['public_transportation_nearby'] == 0 || @$_REQUEST['public_transportation_nearby'] == "")) { @$publicTransportationNearbysearchCriteria .= "<b>Public Transportation Nearby:</b> No"; }
   
    if ((@$_REQUEST['save'] == 1) && @$_REQUEST['wheelchair_accessible'] && @$_REQUEST['wheelchair_accessible'] == 1) { @$wheelchairAccessiblesearchCriteria .= "<b>Wheelchair Accessible:</b> Yes"; }
 
  if ((@$_REQUEST['save'] == 1) && @$_REQUEST['wheelchair_accessible'] && (@$_REQUEST['wheelchair_accessible'] == 0 || @$_REQUEST['wheelchair_accessible'] == "")) { @$wheelchairAccessiblesearchCriteria .= "<b>Wheelchair Accessible:</b> No"; }

		 // else {
		//	$searchCriteria = "All Listings";
		//  }
		  
		  @$levelsOfCaresearchCriteria = chop(@$levelsOfCaresearchCriteria, ', '); // remove trailing , or spaces
		 @$levelsOfCaresearchCriteria = chop(@$levelsOfCaresearchCriteria, '- '); // remove trailing - or spaces
		 
		  @$generalTargetPopulationsearchCriteria = chop(@$generalTargetPopulationsearchCriteria, ', '); // remove trailing , or spaces
		 @$generalTargetPopulationsearchCriteria = chop(@$generalTargetPopulationsearchCriteria, '- '); // remove trailing - or spaces
		
		  @$servicesOfferedsearchCriteria = chop(@$servicesOfferedsearchCriteria, ', '); // remove trailing , or spaces
		 @$servicesOfferedsearchCriteria = chop(@$servicesOfferedsearchCriteria, '- '); // remove trailing - or spaces
		 
		  @$generalTargetPopulationsearchCriteria = chop(@$generalTargetPopulationsearchCriteria, ', '); // remove trailing , or spaces
		 @$generalTargetPopulationsearchCriteria = chop(@$generalTargetPopulationsearchCriteria, '- '); // remove trailing - or spaces
		 
		
		 
		 
		?></td>
        </tr>
        <tr>
          <td colspan="2"><?php if ($errorsAndAlerts) :?>
            <span class="new_sub_heading_font"><?php echo $errorsAndAlerts ?></span>
            <?php endif?>
            <div align="left"> <span class="text_font">
              <?php if (!$errorsAndAlerts) :?>
			  showme $_REQUEST:<br /><?php	showme( @$_REQUEST )?>
      <br />
              <?php $count = '' ?>
              <?php foreach ($addressRecords as $record): ?>
              <?php if(!$record['isAdmin']):?>
              <?php $count++; ?>
              <?php endif ?>
              <?php endforeach ?>
              <?php if($count >= 2 || $count == 0 ):?>
              There are
              <?php elseif($count == 1):?>
              There is
              <?php endif ?>
              <?php if ($count == 0):?>
              no
              <?php elseif (!$count == 0):?>
              <?php echo $count ?>
              <?php endif?>
              <?php if($count >= 2 || $count == 0 ):?>
              listings
              <?php elseif($count == 1):?>
              listing
              <?php endif ?>
              that
              <?php if ($count == 1):?>
              matches
              <?php else:?>
              match
              <?php endif ?>
              your search for:
              <?php if ( @$levelsOfCaresearchCriteria || @$generalTargetPopulationsearchCriteria || @$wheelchairAccessiblesearchCriteria || @$publicTransportationNearbysearchCriteria || @$servicesOfferedsearchCriteria || @$practiceStatesearchCriteria):?>
              <br />
              <?php echo @$generalTargetPopulationsearchCriteria ?> <br />
              <?php echo @$wheelchairAccessiblesearchCriteria ?> <?php echo @$publicTransportationNearbysearchCriteria ?> <br />
              <?php echo @$levelsOfCaresearchCriteria ?> <?php echo @$servicesOfferedsearchCriteria ?> <br />
              <?php else :?>
              All Listings
              <?php  endif ?>
              <?php if ($myLat):?>
              <b>Distance from <?php echo htmlspecialchars(@$_REQUEST['fromAddress']); ?>:</b> Within
              <?php if (@$_REQUEST['maxDistance']):?>
              <?php echo htmlspecialchars(@$_REQUEST['maxDistance']); ?>
              <?php else:?>
              unlimited
              <?php endif ?>
              <?php if ( @$_REQUEST['km_miles'] == 'miles'):?>
              miles
              <?php elseif (  @$_REQUEST['km_miles'] == 'km'):?>
              km
              <?php endif ?>
              <?php endif?>
              </span><br />
            </div></td>
        </tr>
        <tr>
          <td colspan="2"><hr />
            <?php foreach ($addressRecords as $record): ?>
            <?php if(!$record['isAdmin']):?>
            <br />
            (
            <?php
          if (@$record['_distance']) { print number_format($record['_distance'], 1) . " $kmOrMiles away"; }
          else                       { print "unknown distance"; }
        ?>
            ) - <a target="_blank" href="http://maps.google.com/?q=<?php echo htmlencode($record['practice_street_address']) ?>, <?php echo htmlencode($record['practice_city']) ?>, <?php echo $record['practice_state:label'] ?> <?php echo htmlencode($record['practice_zip']) ?>">CLICK/TAP FOR A MAP</a><br />
            <b><?php echo htmlencode($record['practice_name']) ?></b> <br/>
            <?php echo htmlencode($record['practice_street_address']) ?>
            <?php if($record['room_or_floor']):?>
            - <?php echo htmlencode($record['room_or_floor']) ?>
            <?php endif?>
            <br/>
            <?php echo htmlencode($record['practice_city']) ?>, <?php echo $record['practice_state:label'] ?> <?php echo htmlencode($record['practice_zip']) ?>
            <?php if($record['practice_country']):?>
            - <?php echo $record['practice_country:label'] ?>
            <?php endif?>
            <br/>
            
            <!--<?php if($record['nearby_major_cities']):?>
            <b>Nearest Major Cities:</b> <?php echo join(', ', $record['nearby_major_cities:labels']); ?><br/>
            <?php endif ?>
            <br /> -->
            
            <?php if($record['practice_phone']):?>
            <b>Practice Phone:</b> <?php echo  htmlencode(formatPhone($record['practice_phone']))?><br/>
            <?php endif ?>
            <?php if($record['practice_fax']):?>
            <b>Practice FAX:</b> <?php echo  htmlencode(formatPhone($record['practice_fax']))?><br/>
            <?php endif ?>
            <?php if($record['practice_web_site']):?>
            <b>Practice Web Site:</b> <?php echo htmlencode($record['practice_web_site']) ?><br/>
            <?php endif ?>
            <?php if($record['practice_facebook_page_url']):?>
            Practice Facebook Page URL: <?php echo htmlencode($record['practice_facebook_page_url']) ?><br/>
            <?php endif ?>
            <?php if($record['practice_linkedin_page_url']):?>
            <b>Practice Linkedin Page URL:</b> <?php echo htmlencode($record['practice_linkedin_page_url']) ?><br/>
            <?php endif ?>
            <br />
            <?php if($record['practice_license_number']):?>
            Practice License Number: <?php echo htmlencode($record['practice_license_number']) ?><br/>
            <?php endif ?>
            <?php if ($record['accepting_new_clients'] && @$record['accepting_new_clients:text'] == 'Yes'):?>
            <b>Accepting New Clients:</b> Yes<br />
            <?php elseif ($record['accepting_new_clients'] && @$record['accepting_new_clients:text'] == 'No'):?>
            <b>Accepting New Clients: No</b><br />
            <?php endif ?>
            <?php if($record['in_practice_since']):?>
            <b>In Practice Since:</b> <?php echo htmlencode($record['in_practice_since']) ?><br/>
            <?php endif ?>
            <br />
            <?php if($record['contact_last_name']):?>
            <b>Contact:</b> <?php echo htmlencode($record['contact_courtesy_title']) ?> <?php echo htmlencode($record['contact_first_name']) ?> <?php echo htmlencode($record['contact_middle_initial']) ?> <?php echo htmlencode($record['contact_last_name']) ?> <?php echo htmlencode($record['contact_title']) ?><br/>
            <?php endif ?>
            <?php if($record['contact_or_practice_email']):?>
            <b>EMAIL:</b> <?php echo htmlencode($record['contact_or_practice_email']) ?><br />
            <?php else:?>
            <b>EMAIL:</b> <?php echo htmlencode($record['email']) ?><br/>
            <?php endif ?>
            <br />
            <?php if($record['levels_of_care']):?>
            <b>Levels of Care:</b> <?php echo join(', ', $record['levels_of_care:labels']); ?><br/>
            <?php endif ?>
            <?php if($record['services_offered']):?>
            <b>Services Offered:</b> <?php echo join(', ', $record['services_offered:labels']); ?><br/>
            <?php endif ?>
            <?php if($record['general_target_population']):?>
            <b>Age Groups:</b> <?php echo join(', ', $record['general_target_population:labels']); ?><br/>
            <?php endif ?>
            <?php if($record['insurance_classes_accepted']):?>
            <b>Insurance Classes Accepted:</b> <?php echo join(', ', $record['insurance_classes_accepted:labels']); ?><br/>
            <?php endif ?>
            <?php if($record['list_of_insurance_companies_accepted']):?>
            <b>List Of Insurance Companies Accepted:</b> <?php echo htmlencode($record['list_of_insurance_companies_accepted']) ?><br/>
            <?php endif ?>
            <br />
            <?php if($record['languages_spoken']):?>
            <b>Languages Spoken:</b> <?php echo htmlencode($record['languages_spoken']) ?><br/>
            <?php endif ?>
            <?php if($record['practitioner_gender']):?>
            <b>Practitioner Gender(s):</b> <?php echo join(', ', $record['practitioner_gender:labels']); ?><br/>
            <?php endif ?>
            <?php if($record['dbt_training_support']):?>
            <b>DBT Training Support:</b> <?php echo $record['dbt_training_support:label'] ?><br/>
            <?php endif ?>
            <br />
            <?php if($record['practice_description']):?>
            <b>Practice Description:</b> <?php echo htmlencode($record['practice_description']) ?><br/>
            <?php endif ?>
            <br />
            <?php if($record['practitioner_descriptions_and_license_numbers']):?>
            <b>Practitioner Description(s):</b> <?php echo htmlencode($record['practitioner_descriptions_and_license_numbers']) ?><br/>
            <?php endif ?>
            <br />
            <?php if ($record['wheelchair_accessible:text'] && @$record['wheelchair_accessible:text'] == 'Yes'):?>
            <b>Wheelchair Accessible:</b> Yes<br />
            <?php elseif ($record['wheelchair_accessible:text'] && @$record['wheelchair_accessible:text'] == 'No'):?>
            <b>Wheelchair Accessible:</b> No<br />
            <?php endif ?>
            <?php if ($record['public_transportation_nearby:text'] && @$record['public_transportation_nearby:text'] == 'Yes'):?>
            <b>Public Transportation Nearby:</b> Yes<br />
            <?php elseif ($record['public_transportation_nearby:text'] && @$record['public_transportation_nearby:text'] == 'No'):?>
            <b>Public Transportation Nearby:</b> No<br />
            <?php endif ?>
            <?php if($record['public_transportation_description']):?>
            <b>Public Transportation Description:</b> <?php echo htmlencode($record['public_transportation_description']) ?><br/>
            <?php endif ?>
            <hr/>
            <?php endif ?>
            <?php endforeach ?>
            <?php endif ?>
            <br /></td>
        </tr>
      </table>
      </span><br /></td>
  </tr>
  <tr>
    <td colspan="2"><p>&nbsp;</p>
      <br />
      <br />
      <?php include ("_footer.php"); ?></td>
  </tr>
</table>
</body>
</html>
