<?php
include("includes/site_info.php");
include('session_handler.inc');

$WUserID = $_SESSION['Sess_UserId'];
$WUserType = $_SESSION['Sess_UserType'];
$WUserLastVisit = $_SESSION['Sess_LastVisit'];
$WUsername = $_SESSION['Sess_UserName'];
$result=mysql_query("SELECT * FROM members LEFT JOIN adverts ON (mem_userid=adv_userid) WHERE mem_userid=$WUserID",$link);
$sql_array = mysql_fetch_object($result);

?>
<script type="text/javascript">
jQuery.noConflict();
jQuery(document).ready(function(){
    jQuery("#edit_profile").submit(function(){

	if (jQuery("#sex").val() == "")
    {
      alert("Invalid Gender");
      jQuery("#sex").focus();
      return false;
    }

	if (jQuery("#dob_day").val() == "")
    {
      alert("Invalid Day of Birth");
      jQuery("#dob_day").focus();
      return false;
    }

	if (jQuery("#dob_month").val() == "")
    {
      alert("Invalid Month of Birth");
      jQuery("#dob_month").focus();
      return false;
    }

	if (jQuery("#dob_year").val() == "")
    {
      alert("Invalid Year of Birth");
      jQuery("#dob_year").focus();
      return false;
    }

	if (jQuery("#city").val().match(/[^a-zA-Z0-9, \/_-]/))
    {
      alert("City limit to letter, number, and \"_-/\" characters only.");
      jQuery("#city").focus();
      return false;
    }

	if (jQuery("#state").val().match(/[^a-zA-Z0-9 ]/))
    {
      alert("State limit to letter, and number only.");
      jQuery("#state").focus();
      return false;
    }

	if (jQuery("#country").val() == "")
    {
      alert("Invalid Country");
      jQuery("#country").focus();
      return false;
    }

   if (jQuery("#zipcode").val().length > 0) {
    if (jQuery("#zipcode").val().match(/[^0-9+]/))
    {
       alert("Zipcode limit to digits only.");
       jQuery("#zipcode").focus();
       return false;
    }
	}

   if (jQuery("#politicalview").val().length > 0) {
    if (jQuery("#politicalview").val().match(/[^a-zA-Z0-9, \/_-]/))
    {
       alert("Political Views limit to letter, number, and \"_-/\" characters only.");
       jQuery("#politicalview").focus();
       return false;
    }
	}

	var str = 'Submit=profile_basic&' + jQuery(this).serialize();

   		jQuery.ajax({
   		type: "POST",
   		url: "profile_account_submit.php",
   		data: str,
   		success: function(result){
		jQuery("#msg_content").html(result);
		jQuery("#msg_content").fadeIn('slow');
		jQuery("#sub_content").hide();
		jQuery.get('profile_basic_result.php', function(data) {
 		jQuery("#result_content").fadeIn('slow');
 		jQuery('#result_content').html(data);
		});
		}

 });

return false;
    });
});
</script>

<div class="right mrt_5"><a href="<?=$CONST_LINK_ROOT?>/profile_update.php#add_personal" class="a_button">Next</a></div><div class="grey_12 white_back solid_line_separator pageHeading"><img src="images/icon-profile.gif" width="30" height="22" align="absmiddle"> Update Your Basic Profile </div>
<div id="middle_panel" style="width:776px;">
	<table width="100%" border="0" cellpadding="5" cellspacing="0" class="white_back_t_xb">
					<tr>
						<td valign="top" width="100%"><div id="msg_content" style="display:none"></div>
							<div id="result_content" style="display:none"></div>
							<div id="sub_content">
								<form id="edit_profile" name="edit_profile" method="post" style="padding:0; margin:0; border:0;">
									<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" class="white_back_t_xb p5">
										<tr>
											<td colspan="2" class="grey_12 orange_row_back solid_line_separator">
													<div style="background-color:#0000FF; width:10px; height:10px; float:left; margin-top:3px; margin-right:5px;"><img src="images/spacer.gif" width="10" height="10"></div>
													Basic Information</td>
										</tr>
										<tr>
											<td width="10">&nbsp;</td>
											<td><table width="100%" border="0" cellspacing="0" cellpadding="5" class="white_back_t_xb p5">
													<tr>
														<td valign="baseline">Profile Title </td>
														<td><input name="title" type="text" class="button" id="title" value="<?=$sql_array->adv_title?>" size="40" maxlength="30"/></td>
													</tr>
													<tr>
														<td width="150" valign="baseline">Gender</td>
														<td><select name="sex" size="1" class="button" id="sex">
																<option value="">- Choose -</option>
																<option value="M" <?php if('M'==$sql_array->mem_sex) {echo " SELECTED";}?>>Male</option>
																<option value="F" <?php if('F'==$sql_array->mem_sex) {echo " SELECTED";}?>>Female</option>
																<option value="C" <?php if('C'==$sql_array->mem_sex) {echo " SELECTED";}?>>Couple</option>
															</select></td>
													</tr>
													<tr>
														<td valign="baseline">Date of Birth</td>
														<td><select name="dob_day" size="1" class="button" id="dob_day">
																<option value="">- Choose -</option>
																<?
				$dob_value=explode("-",$sql_array->mem_dob);
				$dob_year=$dob_value[0];
				$dob_month=$dob_value[1];
				$dob_day=$dob_value[2];
				
                for ($i=1; $i<=31; $i++) {

                    $cur_i = sprintf("%02d", $i);

                    $selected =  ($cur_i == $dob_day) ? " SELECTED" : "";

                    echo '<option  value="'.$cur_i.'" '.$selected.'>'.$cur_i.'</option>';

                }

                ?>
															</select>
															-
															<select name="dob_month" size="1" class="button" id="dob_month">
																<option value="">- Choose -</option>
																<option value="01" <?php if('01'==$dob_month) {echo "SELECTED";}?>>Jan</option>
																<option value="02" <?php if('02'==$dob_month) {echo "SELECTED";}?>>Feb</option>
																<option value="03" <?php if('03'==$dob_month) {echo "SELECTED";}?>>Mar</option>
																<option value="04" <?php if('04'==$dob_month) {echo "SELECTED";}?>>Apr</option>
																<option value="05" <?php if('05'==$dob_month) {echo "SELECTED";}?>>May</option>
																<option value="06" <?php if('06'==$dob_month) {echo "SELECTED";}?>>Jun</option>
																<option value="07" <?php if('07'==$dob_month) {echo "SELECTED";}?>>Jul</option>
																<option value="08" <?php if('08'==$dob_month) {echo "SELECTED";}?>>Aug</option>
																<option value="09" <?php if('09'==$dob_month) {echo "SELECTED";}?>>Sep</option>
																<option value="10" <?php if('10'==$dob_month) {echo "SELECTED";}?>>Oct</option>
																<option value="11" <?php if('11'==$dob_month) {echo "SELECTED";}?>>Nov</option>
																<option value="12" <?php if('12'==$dob_month) {echo "SELECTED";}?>>Dec</option>
															</select>
															-
															<select name="dob_year" size="1" class="button" id="dob_year">
																<option value="">- Choose -</option>
																<?
                for ($i=date("Y"); $i>=1900; $i--) {

                    $cur_i = sprintf("%04d", $i);

                    $selected =  ($cur_i == $dob_year) ? " SELECTED" : "";

                    echo '<option  value="'.$cur_i.'" '.$selected.'>'.$cur_i.'</option>';

                }

                ?>
															</select>
															<div class="red_10">Format: dd-mm-yyyy E.g. 01-Jan-2010 </div></td>
													</tr>
													<tr>
														<td valign="baseline">City/Town</td>
														<td><input name="city" type="text" class="button" id="city" value="<?=$sql_array->mem_city?>" size="40"/></td>
													</tr>
													<tr>
														<td valign="baseline">State</td>
														<td><input name="state" type="text" class="button" id="state" value="<?=$sql_array->mem_state?>" size="40"/></td>
													</tr>
													<tr>
														<td valign="baseline">Country</td>
														<td><select name="country" id="country" size="1" class="button">
																<option value="">- Choose -</option>
																<?php
												$countryr=mysql_query("select * from Geo_Countries order by Country");
												while($rst= mysql_fetch_array($countryr))
												{
												?>
																<option value="<?php echo $rst["CountryId"];?>"<?php if($rst["CountryId"]==$sql_array->mem_country){ echo " SELECTED";}?> ><?php echo $rst["Country"];?></option>
																<?php
												}
												?>
															</select></td>
													</tr>
													<tr>
														<td valign="baseline">Postcode/Zipcode</td>
														<td><input name="zipcode" type="text" class="button" id="zipcode" value="<?=$sql_array->adv_zipcode?>" size="40"/></td>
													</tr>
													<tr>
														<td valign="baseline">Relationship Status</td>
														<td><select id="marital" name="marital" class="button">
																<option value="">- Choose -</option>
																<?php
												$maritalr=mysql_query("select * from dropvalue where drop_name='marital' and drop_active='Y' order by drop_order");
												while($rst= mysql_fetch_array($maritalr))
												{
												?>
																<option value="<?php echo $rst["drop_id"];?>"<?php if($rst["drop_id"]==$sql_array->adv_marital){ echo " selected";}?> ><?php echo $rst["drop_value"];?></option>
																<?php
												}
												?>
															</select></td>
													</tr>
													<tr>
														<td valign="baseline">I'm looking for</td>
														<td><?php
												$seekingr=mysql_query("select * from dropvalue where drop_name='seeking' and drop_active='Y' order by drop_order");
												while($rst= mysql_fetch_array($seekingr))
												{
												?>
															<div>
																<input name="seeking[]" id="seeking" value="<?php echo $rst["drop_id"];?>" type="checkbox" <?php if ($sql_array->adv_seeking!="") {$seeking_value=explode("|",$sql_array->adv_seeking);foreach ($seeking_value as $j){ if($rst["drop_id"]==$j){ echo "checked";} }}?> class="button"/>
																<?php echo $rst["drop_value"];?> </div>
															<?php
												}
												?>
														</td>
													</tr>
													<tr>
														<td valign="baseline">Religious Views</td>
														<td><select id="religious" name="religious" class="button">
																<option value="">- Choose -</option>
																<?php
												$religiousr=mysql_query("select * from dropvalue where drop_name='religious' and drop_active='Y' order by drop_value");
												while($rst= mysql_fetch_array($religiousr))
												{
												?>
																<option value="<?php echo $rst["drop_id"];?>"<?php if($rst["drop_id"]==$sql_array->adv_religious){ echo " selected";}?> ><?php echo $rst["drop_value"];?></option>
																<?php
												}
												?>
															</select></td>
													</tr>
													<tr>
														<td valign="baseline">Political Views</td>
														<td><input name="politicalview" type="text" class="button" id="politicalview" value="<?=$sql_array->adv_politicalview?>" size="40"/></td>
													</tr>
												</table></td>
										</tr>
										<tr>
											<td>&nbsp;</td>
											<td>&nbsp;</td>
										</tr>
										<tr>
											<td>&nbsp;</td>
											<td align="right"><input name="user_id" type="hidden" value="<?=$WUserID?>" />
												<input name="save" type="submit" class="button" id="save" value="Save Changes"/></td>
										</tr>
										<tr>
											<td>&nbsp;</td>
											<td>&nbsp;</td>
										</tr>
									</table>
								</form>
							</div></td>
					</tr>
				</table>
</div>
