<?php

$newby=8;
require("includes/.htconfig.php");
require("includes/dbcon.php");
$err_msg="";

$enrolleeQuery="select * from enrollee where enrollee_id=$enrollee_id";
$enrollee=mysql_fetch_array(mysql_query($enrolleeQuery));
$activeValue=$enrollee["activFlag"];


if( !empty($_POST) )
{	
	$father_name=trim($_REQUEST['father_name']);
	$mother_m_name=trim($_REQUEST['mother_m_name']);
  $name_born=trim($_REQUEST['name_born']);
	$dob=trim($_REQUEST['dob']);
  $city_born=trim($_REQUEST['city_born']);
  $state_born=trim($_REQUEST['state_born']);
	$country_born=trim($_REQUEST['countryBorn']);
  $state_id=getStateId($state_born,$country_born);
  $city_id=getCityId($city_born,$state_id,$country_born);
  $sex=trim($_REQUEST['sex']);

  if (is_null($enrollee["sex"]) || $enrollee["sex"] != $sex)
  {
    $update_enrollee_sql="update enrollee set gender='$sex' where enrollee_id=$enrollee_id";
    if (!mysql_query($update_enrollee_sql))
      $err_msg.=addMessage(reporterror("updating sex in enrollee",$update_enrollee_sql));
	}

	$insert_foundationalInfo_sql="insert into foundational_info set 
		enrollee_id=".$enrollee_id.",
		country_born=".$country_born.",
    city_born=$city_id,
		mothers_m_name='".mysql_escape_string($mother_m_name)."',
		fathers_name='".mysql_escape_string($father_name)."',
    date_of_birth='".mysql_escape_string($dob)."',
    name_born='".mysql_escape_string($name_born)."'";
		if (mysql_query($insert_foundationalInfo_sql))
    {
      header("location:userDetails3.php");
      exit();
	  }
    $err_msg.=addMessage(reporterror("inserting foundational_info for enrollee $enrollee_id",$insert_foundationalInfo_sql));
    $err_msg.=addMessage("We couldn't record your data.  Could you look it over and try again, please?");
}
?>
<!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>
<link href="./style/design.css" rel="stylesheet" type="text/css" />

<style type="text/css">
<!--
.style1 {font-size: 0.8em}
-->
</style>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Birth Record Page</title>
<script language="JavaScript" src="includes/js/common.js"></script>
<link rel="stylesheet" type="text/css" media="all" href="cal/calendar-win2k-cold-1.css" title="win2k-cold-1"><!-- main calendar program -->  
  <script type="text/javascript" src="cal/calendar.js"></script><!-- language for the calendar -->  
  <script type="text/javascript" src="cal/calendar-en.js"></script><!-- the following script defines the Calendar.setup helper function, which makes
       adding a calendar a matter of 1 or 2 lines of code. -->  
  <script type="text/javascript" src="cal/calendar-setup.js"></script>
<script language="JavaScript">
  function validate()
  {
  var is_valid=true
  is_valid = blank_check( document.frm.father_name.value, "PLEASE INPUT YOUR FATHER'S NAME" )
  if( is_valid == false ) { document.frm.father_name.focus(); return is_valid }

  is_valid = blank_check( document.frm.mother_m_name.value, "PLEASE INPUT YOUR MOTHER'S NAME AT BIRTH" )
  if( is_valid == false ) { document.frm.mother_m_name.focus(); return is_valid }

  is_valid = blank_check( document.frm.name_born.value, "PLEASE INPUT YOUR NAME AT BIRTH" )
  if( is_valid == false ) { document.frm.name_born.focus(); return is_valid }

  is_valid = blank_check( document.frm.dob.value, "PLEASE INPUT DATE OF BIRTH" )
  if( is_valid == false ) { document.frm.dob.focus(); return is_valid }

  ##is_valid = blank_check( document.frm.ssn.value, "PLEASE INPUT SSN" )
  ##	if( is_valid == false ) { document.frm.ssn.focus(); return is_valid }

  is_valid = chosen_check( document.frm.countryBorn.value, "PLEASE SELECT THE COUNTRY WHERE YOU WERE BORN" )
  if( is_valid == false ) { document.frm.countryBorn.focus(); return is_valid }

  is_valid = chosen_check( document.frm.cityBorn.value, "PLEASE SELECT THE CITY WHERE YOU WERE BORN" )
  if( is_valid == false ) { document.frm.cityBorn.focus(); return is_valid }

  return is_valid
  }
</script>
</head>
<body>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
	<tr>
		<td align="center" valign="top">

<?php
include_once("includes/header.php");
$redstar="<font color=\"red\"><strong>*</strong></font>";
?>
<?php
if( $activeValue['activFlag']== 0 )
{
?>
<form name="frm" method="post" action="" enctype="multipart/form-data" onSubmit="return validate()">	
	<table width="90%" border="0" align="center" cellpadding="0" cellspacing="0">	 
	 <tr>
	   <td width="30%" valign="top">
		<div class="bodySubHeader">
		<span class="bsht03">Step 2: Birth Record</span>		
		</div>
		</td>
	 </tr> 
	</table>		
	<table width="90%" border="0" align="center" cellpadding="0" cellspacing="0" class="DarkLightBox">	 
	 <tr>
	   <td height="30" align="center" valign="top" colspan="8"><strong><?=$err_msg?></strong></td>	   
	 </tr> 	 	
	 <tr>
	   <td height="30" align="left" valign="top" class="browseEventContents">Father's Name:<?=$redstar?></td>	   
	   <td height="30" align="left" valign="top"><input name="father_name" type="text" class="textField"/></td>
	   <td height="30" align="left" valign="top" width="1%">&nbsp;</td>
	   <td height="30" align="left" valign="top" class="browseEventContents">Mother's Birth Name:<?=$redstar?>
   </td>
	   <td height="30" align="left" valign="top"><input name="mother_m_name" type="text" class="textField"/></td>
     <td height="30" align="left" valign="top">&nbsp;</td>
     <td height="30" align="left" valign="top" class="browseEventContents">Name at birth:<?=$redstar?></td>
     <td height="30" align="left" valign="top">
       <input name="name_born" id="name_born" type="text" class="textField"/>     
     </td>
   </tr>
    <tr>
      <td height="30" align="left" valign="top" class="browseEventContents">Sex:</td>
      <td height="30" align="left" valign="top">
        <select name="sex">
          <option value="m" Selected="">Male</option>
          <option value="f">Female</option>
        </select>
      </td>
      <td height="30" align="left" valign="top">&nbsp;</td>
      <td height="30" align="left" valign="top" class="browseEventContents">
        Date of birth:<?=$redstar?>
      </td>
      <td height="30" align="left" valign="top">
        <input name="dob" id="dob" type="text" class="textField"/>&nbsp;<img src="cal/img.gif" id="f_trigger_c" style="border: 1px solid red; cursor: pointer;" title="Date selector" onMouseOver="this.style.background='red';" onMouseOut="this.style.background=''">
     
      </td>
    </tr> 
	 <tr>
	   <td height="30" align="left" valign="top" class="browseEventContents">Country of Birth:<font color="red"><strong>*</strong></font></td>	   
	   <td height="30" align="left" valign="top" colspan="7">
			<select name='countryBorn' id='countryBorn'>
			<option value='0' Selected >--- Select Country ---</option>
			<?php
      if (!is_null($enrollee["city_born"]))
      {
        $city=mysql_getRow("select * from city where city_id=".$enrollee["city_born"]);
        $state_born=mysql_getOne("select state_name from state where state_id=".$city["state_id"]);
      }
      if (!is_null($_REQUEST["countryBorn"])) $country=$_REQUEST["countryBorn"];
      else if (!is_null($city["country_code"])) $country=$city["country_code"];
      else $country=0;
      echo spew_options($link,"select country_id, country_name from country order by country_name asc","country_id","country_name",$country);
			?>
			</select>
	   </td>	   
	 </tr>
    <tr>
      <td height="30" align="left" valign="top" class="browseEventContents">
        State of Birth:<?=$redstar?>
      </td>
      <td height="30" align="left" valign="top">
        <input name="state_born" type="text" class="textField" value="<?=$state_born?>"/>
      </td>
    </tr>
    <tr>
      <td height="30" align="left" valign="top" class="browseEventContents">
        City of Birth:<?=$redstar?>
      </td>
      <td height="30" align="left" valign="top">
        <input name="city_born" type="text" class="textField" id="cityBorn"
        <?PHP
        if (!is_null($city))
        {
          echo "value='".$city["city_name"]."'";
        }
        ?>
               />
      </td>
    </tr>
	 <tr>
	   <td height="35" align="left" valign="bottom" colspan="7">&nbsp;</td>	   
	   <td height="35" align="left" valign="bottom"><input name="Submit" type="submit" value="Next" /></td>
	 </tr>
	</table>
</form>
      <script type="text/javascript">
        Calendar.setup({
        inputField     :    "dob",     // id of the input field
        ifFormat       :    "%Y-%m-%e",      // format of the input field
        button         :    "f_trigger_c",  // trigger for the calendar (button ID)
        align          :    "Tl",           // alignment (defaults to "Bl")
        singleClick    :    true
        });
      </script>
<?php
}
else
{
	$msg="You are already activated";
?>
	<table width="80%" border="0" align="center" cellpadding="0" cellspacing="0">		 
	 <tr>
	   <td height="30" align="center" valign="top"><strong><?=$msg?></strong></td>	   
	 </tr>
	</table>
<?php
}
?>
<?php
include_once("includes/footer.php");
?>
	   </td>
	 </tr> 	 
</table>
</body>
</html>