<?php include ("_website_init.php"); ?>
<?php // load records from 'accounts'
  list($accountsRecords, $accountsMetaData) = getRecords(array(
    'tableName'   => 'accounts',
    'loadUploads' => true,
    'allowSearch' => true,

  ));

 // error checking
  if (!@$GLOBALS['GEOCODER_PLUGIN']) { die("You must activate the Geocoder plugin before you can access this page."); }

  // set default values (not required)
  if (!array_key_exists('fromAddress', $_REQUEST)) { $_REQUEST['fromAddress'] = 'Please Enter A Zip/Postal Code'; }      // this is the default address/postalcode if none entered

  // 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 = '';
  $action = '' ;
  
  if (@$_REQUEST['save']) {

     @$count = '';
     @$count = mb_strlen($_REQUEST['fromAddress']  );

     if     (!@$_REQUEST['fromAddress'])                    { $errorsAndAlerts .= "No zip/postal code entered.<br/>\n"; }
     elseif (@$count < 5 )                                  { $errorsAndAlerts .= "Your zip/postal code must be at least 5 digits long.<br/>It is currently under 5 digits.<br/>\n"; }
}

elseif ((!@$myLat || !@$myLng))                             { $errorsAndAlerts .= "Please enter a valid zip/postal code.<br/>\n"; @$_REQUEST['save'] = ''; }

if (!@$errorsAndAlerts && @$count > 4 && @$count <= 12)     { $action .= "http://dbtproviders.com/directory_resultsC.php"; }

?>
<!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 SEARCH</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 SEARCH FORM </b><br />
      </span> showme $_REQUEST:<br />
      <?php showme( @$_REQUEST )?>
      <br />
      <span class="text_font">
      <table align="left" width="90%" border="0" cellspacing="0" cellpadding="2">
        <tr>
          <td align="left"  colspan="2"><span class="heading_font">Use The pull down fields below to narrow your search.</span> <br />
            <span class="text_font"><b>Hint:</b> to select more than one option for any of the fields below, hold the CTRL (CMD) key and Click to highlight each of the options.</span><br />
            <font color="#FF0000">*</font> = Required Field <br />
            <br /></td>
        </tr>
      </table>
      <table align="left" width="90%" border="0" cellspacing="0" cellpadding="2">
        <?php if(@$errorsAndAlerts):?>
        <tr>
          <td colspan="2"><br />
            <span class="heading_font" style="color: #C00;"><?php echo @$errorsAndAlerts ?></span><br /></td>
        </tr>
        <?php endif ?>
        <form method="post"  action= "<?php if(!@$errorsAndAlerts):?><?php echo $action ?><?php endif ?>">
          <input type="hidden" name="save" value="1" />
          <input type="hidden" name="km_miles" value="<?php echo $kmOrMiles ?>" />
          <tr>
            <td  align="right" class="text_font"><b><font color="#FF0000">*</font>Enter A Zip/Postal Code:<font color="#FF0000">*</font><br />
              </b></td>
            <td align="left" valign="top" colspan="2"><input type="text" name="fromAddress" value="<?php echo htmlspecialchars(@$_REQUEST['fromAddress']); ?> " size="25" class="text_font" style="background-color:#<?php echo $dbt_colorsRecord['main_box_background_color'] ?>;"></td>
          </tr>
          <tr>
            <td  align="right" class="text_font"><b>How Far Away From This Zip/Postal Code?:<br />
              </b></td>
            <td align="left" valign="top" colspan="2"><select name="maxDistance" width="300" class="text_font" style="width: 300px; max-height: 50px; background-color:#<?php echo $dbt_colorsRecord['main_box_background_color'] ?>;">
                <option value="">at any distance</option>
                <option value="100" <?php selectedIf(100, @$_REQUEST['maxDistance']) ?> >within 100
                <?php if ( $kmOrMiles == 'miles'):?>
                miles
                <?php elseif ( $kmOrMiles == 'km'):?>
                km
                <?php endif ?>
                </option>
                <option value="50"  <?php selectedIf( 50, @$_REQUEST['maxDistance']) ?> >within 50
                <?php if ( $kmOrMiles == 'miles'):?>
                miles
                <?php elseif ( $kmOrMiles == 'km'):?>
                km
                <?php endif ?>
                </option>
                <option value="25"  <?php selectedIf( 25, @$_REQUEST['maxDistance']) ?> >within 25
                <?php if ( $kmOrMiles == 'miles'):?>
                miles
                <?php elseif ( $kmOrMiles == 'km'):?>
                km
                <?php endif ?>
                </option>
                <option value="10"  <?php selectedIf( 10, @$_REQUEST['maxDistance']) ?> >within 10
                <?php if ( $kmOrMiles == 'miles'):?>
                miles
                <?php elseif ( $kmOrMiles == 'km'):?>
                km
                <?php endif ?>
                </option>
                <option value="5"   <?php selectedIf( 5,  @$_REQUEST['maxDistance']) ?> >within 5
                <?php if ( $kmOrMiles == 'miles'):?>
                miles
                <?php elseif ( $kmOrMiles == 'km'):?>
                km
                <?php endif ?>
                </option>
              </select></td>
          </tr>
          <tr>
            <td  align="right" class="text_font"><b>Level of Care Required:</b><br /></td>
            <td align="left" valign="bottom" colspan="2"><select name = "levels_of_care_keyword[]"  width="300" class="text_font" style="width: 300px; max-height: 50px; background-color:#<?php echo $dbt_colorsRecord['main_box_background_color'] ?>;"  multiple>
                <?php foreach (getListOptions('accounts', 'levels_of_care') as $value => $label2): ?>
                <option value = "<?php echo $value;?>" <?php selectedIf($value, @$_REQUEST['levels_of_care']);?>> <?php echo $label2; ?></option>
                <?php endforeach ?>
              </select></td>
          </tr>
          <tr>
            <td align="right" class="text_font"><b>Services Offered:</b><br /></td>
            <td align="left" valign="bottom" colspan="2"><select name = "services_offered_keyword[]"  width="300" class="text_font" style="width: 300px; max-height: 50px; background-color:#<?php echo $dbt_colorsRecord['main_box_background_color'] ?>;"  multiple>
                <?php foreach (getListOptions('accounts', 'services_offered') as $value => $label4): ?>
                <option value = "<?php echo $value;?>" <?php selectedIf($value, @$_REQUEST['services_offered']);?>> <?php echo $label4; ?></option>
                <?php endforeach ?>
              </select></td>
          </tr>
          <tr>
            <td align="right" class="text_font"><b>Age Group:</b><br /></td>
            <td align="left" valign="bottom" colspan="2"><select name = "general_target_population_keyword[]" width="300" class="text_font" style="width: 300px; max-height: 50px; background-color:#<?php echo $dbt_colorsRecord['main_box_background_color'] ?>;" multiple>
                <?php foreach (getListOptions('accounts', 'general_target_population') as $value => $label5): ?>
                <option value = "<?php echo $value;?>" <?php selectedIf($value, @$_REQUEST['general_target_population']);?>> <?php echo $label5; ?></option>
                <?php endforeach ?>
              </select></td>
          </tr>
          <tr>
            <td align="right" class="text_font"><b>Public Transportation Near By: </b></td>
            <td align="left" valign="bottom" colspan="2"><select name = "public_transportation_nearby" width="300" class="text_font" style="width: 300px; background-color:#<?php echo $dbt_colorsRecord['main_box_background_color'] ?>;">
                <option value="">Optional</option>
                <option value="1">Yes</option>
              </select></td>
          </tr>
          <tr>
            <td align="right" class="text_font"><b>Wheelchair Accessible: </b></td>
            <td align="left" valign="bottom" colspan="2"><select name = "wheelchair_accessible" width="300" class="text_font" style="width: 300px; background-color:#<?php echo $dbt_colorsRecord['main_box_background_color'] ?>;">
                <option value="">Optional</option>
                <option value="1">Yes</option>
              </select></td>
          </tr>
          <tr>
            <td align="right" class="text_font"><b>&nbsp;</b></td>
            <td align="left" valign="bottom" colspan="2"><input type="submit" value="Submit Search Filters" ></td>
          </tr>
        </form>
        <tr>
          <td>&nbsp;</td>
          <td colspan="2"><form method="post" action="" >
              <INPUT TYPE="submit" VALUE="Cancel Search Filters">
            </form></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>
