<?php
#This page gathers the name so that we can write an NDA on the next page.
require("includes/.htconfig.php");

$gender="";		##I use it later in the form and don't want to be throwing an error.
if (array_key_exists("command",$_REQUEST) && $_REQUEST["command"] == "Submit")
{
	$first_name=fromRequest("first_name");
	$middle_name=fromRequest("middle_name");
	$last_name=fromRequest("last_name");
	$gender=fromRequest("gender");
	$street_line_01=fromRequest("street_line_01");
	$street_line_02=fromRequest("street_line_02");
	$street_line_03=fromRequest("street_line_03");
	$city=fromRequest("city");
	$state=fromRequest("state");
	$zipCode=fromRequest("zipCode");
	$zippy=mysql_getRow("select * from zip_code where zip_code='$zipCode'");
	$country_id=fromRequest("country_id");
	if ($country_id == 0) $country_id=NULL;
	if (is_null($first_name) && is_null($middle_name)) $errmsgs.="<BR>You need to give us your given name.";
	if (is_null($last_name)) $errmsgs.="<BR>You need to give us your surname.";
	if (strlen($errmsgs) == 0)
	{
		$query="update enrollee set ";
		if (!is_null($first_name)) $query.="first_name='".mysql_escape_string($first_name)."',";
		if (!is_null($middle_name)) $query.="middle_name='".mysql_escape_string($middle_name)."',";
		$query.="last_name='".mysql_escape_string($last_name)."'";
		if (!is_null($gender)) $query.=", gender='$gender'";
		$query.=" where enrollee_id=$enrollee_id";
		if (!mysql_query($query))
		{
			loggywoggy("error in \n$query");
			$errmsgs.=reportError("adding names to database for enrollee $enrollee_id",$query);
			$errmsgs.="We were unable to add your name to our database.  We are looking into this and you can try it again.";
		}
		$state_id=getStateId($state,$country_id);
		$city_id=getCityId($city,$state_id,$country_id);
		$query="insert into address set "
				."address_type_id='ehom', "
				."owner_id=$enrollee_id, "
				."country_id=$country_id, "
				."state_id=$state_id,"
				."city_id=$city_id, "
				."zipCode='$zipCode' ";
			if (!is_null($street_line_01)) $query.=",street_line_01='$street_line_01'";
			if (!is_null($street_line_02)) $query.=",street_line_02='$street_line_02'";
			if (!is_null($street_line_03)) $query.=",street_line_03='$street_line_03'";
			if (!is_null($zippy)) $query.=",lat=".$zippy["lat"].",lon=".$zippy["lon"];
		if (!mysql_query($query))
		{
			$errmsgs.=reportError("adding the address for enrollee $enrollee_id",$query);
			$errmsgs.="<BR>We couldn't add the address.";
		}
		if (strlen($errmsgs) == 0)
		{
			loggywoggy("start.php is done, moving on");
			advancePage($enrollee_id,$newby);
		}
	}
}
?>
<!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>What's Your Name?</title>
<script language="JavaScript" src="includes/js/common.js"></script>
<!--script language='javascript' src='datepicker/popcalendar.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.first_name.value, "Please give us your first name." )
		if( is_valid == false ) { document.frm.first_name.focus(); return is_valid }

	is_valid = blank_check( document.frm.last_name.value, "Please give us your surname." )
		if( is_valid == false ) { document.frm.last_name.focus(); 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");
?>
      <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 1: Data for the NDA</span>
              </div>
            </td>
          </tr>
        </table>
        <table width="90%" border="0" align="center" cellpadding="0" cellspacing="0" class="DarkLightBox">
          <?php
	if(strlen($errmsgs) > 0)
	{
	?>
          <tr>
            <td height="30" align="center" valign="top" colspan="8">
              <strong>
                <?=$errmsgs?>
              </strong>
            </td>
          </tr>
          <?php
	}
	?>
	<tr><td colspan=9>We have recorded your provisional certificate and now we want to construct your ValID<sup>TM</sup> certificate.
	Before we start to gather all of your personal information, we first want to enter a contract wherein you tell us what we're allowed to do with your personal information.
	To write this contract, we need your name and sex.
	When you submit this information to us, we shall send you back a contract digitally signed by our CEO in which you give us
	permission to use the information to satisfy us as to your identity.
	Beyond that use, we are not permitted to go without your further permission.
          <tr>
            <td width="65%" align="left" valign="top" colspan="8" class="TopMenu2">Personal Details</td>
          </tr>
          <tr>
            <td align="left" valign="top" colspan="8">&nbsp;</td>
          </tr>
          <tr>
            <?PHP
				$spacer="<td height=\"30\" align=\"left\" valign=\"top\" width=\"1%\">&nbsp;</td>";
				echo inputCells("First Name$redstar","first_name");
				echo $spacer.inputCells("Middle Name","middle_name");
				echo $spacer.inputCells("Surname$redstar","last_name");
			?>
          </tr>
          <tr>
            <td height="30" align="left" valign="top" class="browseEventContents">Sex:</td>
            <td height="30" align="left" valign="top">
              <select name="gender">
				<?PHP
				echo "<option value=\"m\"".if_selected($gender == "m")."Male</option>";
				echo "<option value=\"f\"".if_selected($gender == "f")."Female</option>";
				?>
              </select>
            </td>
          </tr>
          <tr>

          </tr>
          <TR valign="top">
            <td colspan="6">
              <TABLE>
                <TR>
                  <td width="65%" align="left" valign="top" colspan="8" class="TopMenu2">Residential Address</td>
                </TR>
                <TR>
				<?PHP
					echo inputCells("Street Address$redstar","street_line_01");
				?>
                </TR>
                <TR>
				<?PHP
					echo inputCells("","street_line_02");
				?>
                </TR>
                <TR>
				<?PHP
					echo inputCells("","street_line_03");
				?>
                </TR>
                
                <tr>
				<?PHP
					echo inputCells("City$redstar","city");
					echo $spacer.inputCells("State$redstar","state");
					echo $spacer.inputCells("Zip Code$redstar","zipCode");
				?>
                </tr>
                <tr>
                  <td height="30" align="left" valign="top" class="browseEventContents">
                    Country:<?=$redstar?>
                  </td>
                  <td height="30" align="left" valign="top" colspan="7">
						<select name='country_id' id='country'>
						<option value='0' >--- Select Country ---</option>
						<?php			
						$countryQuery = "select country_id, country_name from country order by country_name asc";
						echo spew_options($link,$countryQuery,"country_id","country_name",$_REQUEST['country_id'])
						?>
                    </select>
                  </td>
                </tr>
              </TABLE>
			</td>
      </TR>


          
        
      </tr>
	 <tr>
	   <td height="35" align="left" valign="bottom" colspan="7">&nbsp;</td>	   
	   <td height="35" align="left" valign="bottom"><input name="command" type="submit" value="Submit" /></td>
	 </tr>
	</table>
</form>
<?php
include_once("includes/footer.php");
?>
	   </td>
	 </tr> 	 
</table>
</body>
</html>
