$sql = "UPDATE fbJewishDates SET Birthday='{$Birthday}' WHERE uid={$user}";
        mysql_query($sql) or die("You must un-install and re-install this app");
        $success = 2;
    }
}
$results = mysql_query("SELECT BornAtNight, Birthday, style, displayCurrent, displayLink FROM fbJewishDates WHERE uid={$user}");
if (!($rs = mysql_fetch_assoc($results))) {
    die("<h1 style='margin:30px 30px 30px 30px;'>You have the Alpha 1.0 version of this app installed on your profile. <br /> You must un-install and re-install this app!</h1>");
}
$bBornAfterSunset = $rs['BornAtNight'];
$profileDesign = $rs['style'];
$displayCurrent = $rs['displayCurrent'];
$displayLink = $rs['displayLink'];
$Birthday = date("M d, Y", strtotime($rs['Birthday']));
mysql_close();
$fbml = printJewishBirthday($Birthday, $bBornAfterSunset, $profileDesign, $displayCurrent, $displayLink);
$facebook->api_client->profile_setFBML($fbml);
?>
 <?php 
include_once 'inc/header.php';
?>
<div class="everything" style="clear:both;">
<div class="wide">
    <?php 
if ($success != 0) {
    ?>
            <fb:success>
                <fb:message>You have
                	<?php 
    if ($success == 1) {
        ?>
echo printJewishBirthday($birthday, $bBornAfterSunset, 3, $displayCurrent, $displayLink);
?>
          </div></div>
        </label>

        <label for="pd4"><div class="profileDesign">
       	  <div align="center">
          	<input type="radio" name="profileDesign" id="pd4" value="4" <?php 
if ($profileDesign == 4) {
    echo "checked";
}
?>
 />
            <br />
              <?php 
echo printJewishBirthday($birthday, $bBornAfterSunset, 4, $displayCurrent, $displayLink);
?>
              <br />    
              <br />
            </div>
        </div>
      	</label>
		<br clear="all" />
      </div>
      <br clear="all" />
    <div class="section">
        <h3>More Options</h3>
        	<input type="checkbox" name="chkToday" <?php 
if ($displayCurrent) {
    ?>
checked="checked"<?php 
?>
        <?php 
if ($rs['displayLink']) {
    ?>
and <b>a link</b> to an explanation about Jewish Birthdays. <?php 
}
?>
        (<a href="settings.php">change</a>).<br />
        Your profile is using style <b>#<?php 
echo $rs['style'];
?>
</b>(<a href="settings.php">change</a>).<br />
        Methods of receiving notifications about your friends birthdays: <a href="messageSettings.php"><b>none</b></a>. <br /><br />
    </div>
    <div id="currentDisplay"><?php 
echo printJewishBirthday($rs['Birthday'], $rs['BornAtNight'], $rs['style'], $rs['displayCurrent'], $rs['displayLink']);
?>
</div>
	<div id="upcomingList">
    	<b><u>Your friends with birthdays in the coming week:</u></b>
        <table>
            <tr><th>Name</th><th>Hebrew Birthday</th><th>Next Occurance</th></tr>
        <?php 
$birthdays = getFriendsBirthdays();
foreach ($birthdays as $friend) {
    if (strtotime($friend["dateThisYear"]) > strtotime('+1 week')) {
        break;
    }
    ?>
<tr>
                	<td  width='200'>
function updateJDateProfile($updateDB = true)
{
    global $facebook;
    global $bBornAfterSunset, $profileDesign, $displayCurrent, $displayLink, $birthday, $success;
    dbConnect();
    if (isset($_POST["Submit"]) && $_POST["Submit"] == "Submit" && $updateDB) {
        $strBornAfterSunset = "";
        if (isset($_POST["chkSunset"]) && $_POST["chkSunset"] == "on") {
            $strBornAfterSunset = "true";
        } else {
            $strBornAfterSunset = "false";
        }
        $profileDesign = isset($_POST["profileDesign"]) ? $_POST["profileDesign"] : 1;
        $displayCurrent = isset($_REQUEST["chkToday"]);
        $displayLink = isset($_REQUEST["chkExplanation"]);
        $sql = "UPDATE fbJewishDates SET BornAtNight={$strBornAfterSunset}, style={$profileDesign}, displayLink='{$displayLink}', displayCurrent='{$displayCurrent}' WHERE uid={$facebook->user}";
        mysql_query($sql) or die("You must un-install and re-install this app");
        $success = true;
    }
    $sql = "SELECT BornAtNight, Birthday, style, displayCurrent, displayLink FROM fbJewishDates WHERE uid='{$facebook->user}'";
    $results = mysql_query($sql);
    if (!($rs = mysql_fetch_assoc($results))) {
        addBirthdayRecord();
        $results = mysql_query($sql);
        $rs = mysql_fetch_assoc($results);
    }
    mysql_close();
    $bBornAfterSunset = $rs['BornAtNight'];
    $profileDesign = $rs['style'];
    $displayCurrent = $rs['displayCurrent'];
    $displayLink = $rs['displayLink'];
    $birthday = date("M d, Y", strtotime($rs['Birthday']));
    //$userInfo = $facebook->api_client->fql_query("SELECT birthday FROM user WHERE uid=$user");
    //$birthday = $userInfo[0]['birthday'];
    $fbml = printJewishBirthday($birthday, $bBornAfterSunset, $profileDesign, $displayCurrent, $displayLink);
    $mobileFBML = $fbml;
    $mainFBML = $fbml;
    $ahebdate = explode("/", strGregToHeb($birthday, false, $bornAtNight));
    $info_fields = array(array('field' => 'My Hebrew Birthday', 'items' => array(array('label' => strGregToHeb($birthday, true, $bBornAfterSunset), 'description' => 'A kabbalisticly powerful day.', 'link' => 'http://apps.facebook.com/jewishdates/'))), array('field' => 'Next Occurence', 'items' => array(array('label' => dateThisYear($ahebdate), 'description' => 'The next gregorian date that will corespond with my Hebrew Birthday', 'link' => 'http://apps.facebook.com/jewishdates/'))));
    $moreFBML = '<b><u>Special Dates</u></b><br />';
    $specialDays = DateRecord::findByWhere('DateRecord', "uid={$facebook->user}");
    foreach ($specialDays as $friend) {
        $moreFBML .= '<div><b>' . $friend->data['title'] . ':</b>' . $friend->getHebrewDate('longeng') . ' - ' . $friend->getNextOccurance() . '</div>';
        $info_fields[] = array('field' => $friend->data['title'], 'items' => array(array('label' => $friend->getHebrewDate('longeng'), 'description' => 'Hebrew Date', 'link' => 'http://apps.facebook.com/jewishdates/'), array('label' => 'Next Occurance: ' . $friend->getNextOccurance(), 'description' => 'Gregorian Date this coming year', 'link' => 'http://apps.facebook.com/jewishdates/')));
    }
    $facebook->api_client->profile_setFBML($fbml . $moreFBML, $facebook->profileID, $fbml . $moreFBML, NULL, $mobileFBML, $mainFBML);
    $facebook->api_client->profile_setInfo('Jewish Dates', 1, $info_fields, $user);
    $refValue = "Todays Hebrew Date is:<br />" . strGregToHeb(date("M d, Y"), true);
    $facebook->api_client->fbml_setRefHandle("Today_H", $refValue);
    $facebook->api_client->fbml_setRefHandle("Message", "<fb:subtitle><a href='http://apps.facebook.com/jewishdates/'>Add this to my profile.</a></fb:subtitle>");
    //<div style='text-align:center;color:red;'>Help 'Jewish Dates'.<br />Support <a href='http://apps.facebook.com/jewishdates/supportChabadOfNewPaltz'>Chabad of New Paltz</a><hr /></div>
    $facebook->api_client->fbml_setRefHandle("Explanation", "<a href='http://www.chabad.org/library/article.asp?AID=144345'>What is a Jewish Birthday?</a>");
}