<?
	include("config/connect.php");
	include("session.php");
	include("functions.php");

	$uid = $_SESSION["userid"];
	
	$fname = $_POST["name"];
	$add1 = $_POST["address1"];
	$add2 = $_POST["address2"];
	$city = $_POST["city"];
	$state = $_POST["state"];
	$country = $_POST["country"];
	$zip = $_POST["zip"];
	$phone = $_POST["phone"];
	
	if($_POST["del_confirm"]!="")
	{
		$qryupd = "update registration set delivery_name='$fname',  delivery_addressline1='$add1', delivery_addressline2='$add2', delivery_city='$city', delivery_state='$state', delivery_country='$country', delivery_postcode='$zip', delivery_phone='$phone' where id=$uid";		
		mysql_query($qryupd) or die(mysql_error());
		$msg = 1;
	}

	if($_POST["edit_confirm"]!="")
	{
		$qryselcou = "select * from countries where countryId='".$country."'";
		$resselcou = mysql_query($qryselcou);
		$objselcou = mysql_fetch_object($resselcou);
		$fullmobileno = "+".$objselcou->countrycode.$_POST["mobileno"];
		
		$qryupd = "update registration set firstname='$fname', addressline1='$add1', addressline2='$add2', city='$city', state='$state', country='$country', postcode='$zip', phone='$phone',full_mobileno='$fullmobileno',can_send_gift='1' where id=$uid";
		mysql_query($qryupd) or die(mysql_error());
		$msg = 1;
		
		$qryupd = "update ";
		mysql_query($qryupd) or die(mysql_error());
	}

	$qr = "select * from registration r left join countries c on r.country=c.countryId where r.id=".$uid."";
	$rs = mysql_query($qr);
	$total = mysql_num_rows($rs);
	$row = mysql_fetch_object($rs);
?>
<!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=<?=$lng_characset;?>" />
<title><?=$AllPageTitle;?></title>
<link href="css/style_youbid.css" rel="stylesheet" type="text/css" />
<link href="css/menu.css" rel="stylesheet" type="text/css" />
<!--[if lte IE 6]>
<link href="css/menu_ie.css" rel="stylesheet" type="text/css" />
<![endif]-->
<script language="javascript" type="text/javascript" src="function.js"></script>
<script language="javascript" src="basic.js"></script>
<script language="javascript">
function HideDisplay(edit)
{
	var ed = edit;
	if(ed==1)
	{
		obj1 = document.getElementById('edit_address');
		obj1.style.display = 'block';
		document.getElementById('billing_address').style.display = 'none';
	}
	else
	{
		obj = document.getElementById('delivery_address');
		if(obj.style.display=='none')
		{
			obj.style.display='block';
		}
		else
		{
			obj.style.display='none';
		}
	}
}

function HideDisplayDeliveryAddress(edit)
{
	var ed = edit;
	if(ed==1)
	{
		obj1 = document.getElementById('delivery_address_exp1');
		obj1.style.display = 'block';
		document.getElementById('delivery_address_exp').style.display = 'none';
	}
	else
	{
		obj = document.getElementById('delivery_address');
		if(obj.style.display=='none')
		{
			obj.style.display='block';
		}
		else
		{
			obj.style.display='none';
		}
	}
}

function check()
{
	if(document.address.name.value=="")
	{
		alert("<?=$lng_plsentername;?>");
		document.address.name.focus();
		return false;
	}
	if(document.address.address1.value=="")
	{
		alert("<?=$lng_plsenteradd;?>");
		document.address.address1.focus();
		return false;
	}
	/*
	if(document.address.city.value=="")
	{
		alert("<?=$lng_plsentercity;?>");
		document.address.city.focus();
		return false;
	}	
	if(document.address.state.value=="")
	{
		alert("请输入省!!!");
		document.address.state.focus();
		return false;
	}*/
	if(document.address.zip.value=="")
	{
		alert("<?=$lng_plsenterpostcode;?>");
		document.address.zip.focus();
		return false;
	}
	if(document.address.phone.value=="")
	{
		alert("<?=$lng_plsenterphoneno;?>");
		document.address.phone.focus();
		return false;
	}
}

function check1()
{
	if(document.editaddress.name.value=="")
	{
		alert("<?=$lng_plsentername;?>");
		document.editaddress.name.focus();
		return false;
	}
	if(document.editaddress.address1.value=="")
	{
		alert("<?=$lng_plsenteradd;?>");
		document.editaddress.address1.focus();
		return false;
	}/*
	if(document.editaddress.city.value=="")
	{
		alert("<?=$lng_plsentercity;?>");
		document.editaddress.city.focus();
		return false;
	}
	if(document.editaddress.state.value=="")
	{
		alert("请输入省!!!");
		document.editaddress.state.focus();
		return false;
	}*/
	if(document.editaddress.zip.value=="")
	{
		alert("<?=$lng_plsenterpostcode;?>");
		document.editaddress.zip.focus();
		return false;
	}
	if(document.editaddress.phone.value=="")
	{
		alert("<?=$lng_plsenterphoneno;?>");
		document.editaddress.phone.focus();
		return false;
	}
}
</script>
</head>


<body>
<div id="main_div">
<?
	include("d1.php");
?>
		<div id="middle_div">
			<? include("leftside.php"); ?>
			<div class="inner-container">
				<div class="titlebar">
					<div class="leftbar"></div>
					<div class="middlebar"><!--<div class="page_title_font"><?=$lng_myauctionsavenue;?> - <?=$lng_addresses;?>&nbsp;&nbsp;<div class=red>在注册会员后48小时内完善您的收货地址信息，即可获赠我们的大礼包！</div></div>!--></div> 
					<div class="rightbar"></div>
				</div>
				<div class="bodypart">	
				<div id="middle" align="left" style="margin-top: 30px; margin-left: 40px;">
						<p class="normal_text"><b><?=$lng_hereeditadd;?></b></p>
						<? if($row->delivery_addressline1==""){ ?>
						<p style="margin-top: 10px;"><a class="alink" href="javascript: HideDisplay()"><?=$lng_enternewadd;?></a></p>
						<? } ?>
				<?
					if($msg==1)
					{
				?>
					<p style="margin-top: 10px;" align="left" class="greenfont"><?=$lng_addresschanged;?></p>
				<?
					}
				?>
							<table border="0" width="600">
								<tr>
									<td width="100%" class="addressline"></td>
								</tr>
							</table>
					<? if($row->delivery_addressline1==""){ ?>
					<form name="address" action="" method="post" onsubmit="return check();">
						<div id="delivery_address" style="display: none;">
							<div style="height: 255pt;">
							<table width="70%" border="0" align="left" cellpadding="0" cellspacing="5">
								<tr>
									<td colspan="2"><select name="delivery">
										<option value="delivery"><?=$lng_deliveryaddress;?></option></select></td>
								</tr>
								<tr>
									<td>&nbsp;</td>
								</tr>
								<tr>
									<td class="normal_text" style="font-weight: 600;"><?=$lng_onlyname;?></td>
									<td><input type="text" name="name" size="20" class="textboxclas" value="<?=$row->delivery_name;?>" />  <span class="red-text-12-b">*</span></td>
								</tr>
				  			<!--tr>
									<td width="30%" class="normal_text" style="font-weight: 600;"><?=$lng_state;?></td>
									<td><input type="text" name="state" size="20" class="textboxclas" value="<?$row->delivery_state;?>" />  <span class="red-text-12-b">*</span></td>
								</tr>
								<tr>
									<td class="normal_text" style="font-weight: 600;"><?=$lng_towncity;?> : </td>
									<td><input type="text" name="city" size="20" class="textboxclas" value="<?=$row->delivery_city;?>" />  <span class="red-text-12-b">*</span></td>
								</tr-->
								<tr>
									<td class="normal_text" style="font-weight: 600;"><?=$lng_addressline1;?> : </td>
									<td><input type="text" name="address1" size="20" class="textboxclas" value="<?=$row->delivery_addressline1;?>" />  <span class="red-text-12-b">*</span></td>
								</tr>
								<!--tr>
									<td class="normal_text" style="font-weight: 600;"><?=$lng_addressline2;?> : </td>
									<td><input type="text" name="address2" size="20" class="textboxclas" value="<?=$row->delivery_addressline2;?>" /></td>
								</tr-->
								<!--tr>
									<td class="normal_text" style="font-weight: 600;"><?=$lng_country;?> : </td>
									<td>
									<select name="country" style="width: 220px;">
									<?
										$qrc1 = "select * from countries order by printable_name";
										$rsc1 = mysql_query($qrc1);
										while($v1 = mysql_fetch_array($rsc1))
										{
									?>
										<option <?=$row->country==$v1["countryId"]?"selected":"";?> value="<?=$v1["countryId"];?>"><?=$v1["printable_name"];?></option>
									<?
										}
									?>
									</select>
									</td>
								</tr-->
								<tr>
									<td class="normal_text" style="font-weight: 600;"><?=$lng_postcode;?> : </td>
									<td><input type="text" name="zip" size="20" class="textboxclas" value="<?=$row->delivery_postcode;?>" />  <span class="red-text-12-b">*</span></td>
								</tr>
								<tr>
									<td class="normal_text" style="font-weight: 600;"><?=$lng_phoneno;?> : </td>
									<td><input type="text" name="phone" size="20" class="textboxclas" value="<?=$row->delivery_phone;?>" />  <span class="red-text-12-b">*</span></td>
								</tr>
								<tr>
									<td colspan="2" class="normal_text"><span class="red-text-12-b">*</span> <?=$lng_mandatoryfield;?></td>
								</tr>
								<tr>
									<td>&nbsp;</td>
								</tr>
								<tr>
									<td colspan="2"><input type="image" name="delconfirm" value="confirm" src="<?=$lng_imagepath;?>submit_btn.png" onmouseover="this.src='<?=$lng_imagepath;?>submit_hover_btn.png'" onmouseout="this.src='<?=$lng_imagepath;?>submit_btn.png'"/>
									<input type="hidden" value="Confirm" name="del_confirm" />
									</td>
								</tr>
							</table>
						</div>
						<div class="addressline" style="clear: both;"></div>
						</div>
				</form>
					<? } ?>
						<div id="billing_address">
						<div style="height: 200pt;">
							<table border="0" width="70%" align="left" cellpadding="0" cellspacing="5">
							<tr>
								<td colspan="2"><?=$lng_billingaddress;?> : </td>
							</tr>
							<tr>
								<td>&nbsp;</td>
							</tr>
								<tr>
									<td class="normal_text" style="font-weight: 600;"><?=$lng_onlyname;?></td>
									<td class="normal_text"><?=$row->firstname;?></td>
								</tr>
								<!--tr>
									<td width="30%" class="normal_text" style="font-weight: 600;"><?=$lng_state;?> : </td>
									<td class="normal_text"><?$row->state;?></td>
								</tr>
								<tr>
									<td class="normal_text" style="font-weight: 600;"><?=$lng_towncity;?> : </td>
									<td class="normal_text"><?=$row->city;?></td>
								</tr-->
								<tr>
									<td class="normal_text" style="font-weight: 600;"><?=$lng_addressline1;?> : </td>
									<td class="normal_text"><?=$row->addressline1;?></td>
								</tr>
								<!--tr>
									<td class="normal_text" style="font-weight: 600;"><?=$lng_addressline2;?> : </td>
									<td class="normal_text"><?=$row->addressline2;?></td>
								</tr-->
								<!--tr>
									<td class="normal_text" style="font-weight: 600;"><?=$lng_country;?> : </td>
									<td class="normal_text">
										<select name="country" style="width: 220px;" disabled="disabled">
									<?
										$qrc = "select * from countries order by printable_name";
										$rsc = mysql_query($qrc);
										while($v=mysql_fetch_array($rsc))
										{
									?>
										<option <?=$row->country==$v["countryId"]?"selected":"";?> value="<?=$v["countryId"];?>"><?=$v["printable_name"];?></option>
									<?
										}
									?>
										</select></td>
								</tr-->
								<tr>
									<td class="normal_text" style="font-weight: 600;"><?=$lng_postcode;?> : </td>
									<td class="normal_text"><?=$row->postcode;?></td>
								</tr>
								<tr>
									<td class="normal_text" style="font-weight: 600;"><?=$lng_phoneno;?> : </td>
									<td class="normal_text"><?=$row->phone;?></td>
								</tr>
								<tr>
									<td>&nbsp;</td>
								</tr>
								<tr>
									<td colspan="2"><input type="image" name="edit" value="Edit" src="<?=$lng_imagepath;?>edit_hover_btn.png" onmouseover="this.src='<?=$lng_imagepath;?>edit_btn.png'" onmouseout="this.src='<?=$lng_imagepath;?>edit_hover_btn.png'" onclick="HideDisplay(1)" /></td>
								</tr>
							</table>
						</div>
						<div class="addressline" style="text-align: left;"></div>
						</div>
						<div id="edit_address" style="display: none">
							<div style="height: 240pt;">
					<form name="editaddress" action="" method="post" onsubmit="return check1();">
							<table width="70%" border="0" align="left" cellpadding="0" cellspacing="5">
							<tr>
								<td colspan="2"><?=$lng_billingaddress;?> : </td>
							</tr>
							<tr>
								<td>&nbsp;</td>
							</tr>			
								<tr>
									<td class="normal_text" style="font-weight: 600;"><?=$lng_onlyname;?></td>
									<td><input type="text" name="name" size="20" value="<?=$row->firstname;?>"  class="textboxclas"/>&nbsp;<font class="red-text-12-b">*</font></td>
								</tr>
								<!--tr>
									<td width="30%" class="normal_text" style="font-weight: 600;"><?=$lng_state;?> : </td>
									<td><input type="text" name="state" size="20" value="<?$row->state;?>" class="textboxclas" />&nbsp;<font class="red-text-12-b">*</font></td>
								</tr>
								<tr>
									<td class="normal_text" style="font-weight: 600;"><?=$lng_towncity;?> : </td>
									<td><input type="text" name="city" size="20" value="<?=$row->city;?>" class="textboxclas" />&nbsp;<font class="red-text-12-b">*</font></td>
								</tr-->
								<tr>
									<td class="normal_text" style="font-weight: 600;"><?=$lng_addressline1;?> : </td>
									<td><input type="text" name="address1" size="20" value="<?=$row->addressline1;?>" class="textboxclas" />&nbsp;<font class="red-text-12-b">*</font></td>
								</tr>
								<!--tr>
									<td class="normal_text" style="font-weight: 600;"><?=$lng_addressline2;?> : </td>
									<td><input type="text" name="address2" size="20" value="<?=$row->addressline2;?>" class="textboxclas" /></td>
								</tr-->
								<!--tr>
									<td class="normal_text" style="font-weight: 600;"><?=$lng_country;?> : </td>
									<td>
									<select name="country" style="width: 220px;">
									<?
										$qrc2 = "select * from countries order by printable_name";
										$rsc2 = mysql_query($qrc2);
										while($v2 = mysql_fetch_array($rsc2))
										{
									?>
										<option <?=$row->country==$v2["countryId"]?"selected":"";?> value="<?=$v2["countryId"];?>"><?=$v2["printable_name"];?></option>
									<?
										}			
									?>
									</select></td>
								</tr-->
								<tr>
									<td class="normal_text" style="font-weight: 600;"><?=$lng_postcode;?> : </td>
									<td><input type="text" name="zip" size="20" value="<?=$row->postcode;?>" class="textboxclas" />&nbsp;<font class="red-text-12-b">*</font></td>
								</tr>
								<tr>
									<td class="normal_text" style="font-weight: 600;"><?=$lng_phoneno;?> : </td>
									<td><input type="text" name="phone" size="20" value="<?=$row->phone;?>" class="textboxclas" />&nbsp;<font class="red-text-12-b">*</font></td>
								</tr>
								<tr>
									<td colspan="2" class="normal_text"><span class="red-text-12-b">*</span> <?=$lng_mandatoryfield;?></td>
								</tr>
								<tr>
									<td>&nbsp;</td>
								</tr>
								<tr>
									<td colspan="2"><input type="image" value="confirm" name="editconfirm" src="<?=$lng_imagepath;?>submit_btn.png" onmouseover="this.src='<?=$lng_imagepath;?>submit_hover_btn.png'" onmouseout="this.src='<?=$lng_imagepath;?>submit_btn.png'"/>
									<input type="hidden" value="<?=$row->mobile_no;?>" name="mobileno" />
									<input type="hidden" name="edit_confirm" value="Confirm" />
									</td>
								</tr>
								<tr>
									<td>&nbsp;</td>
								</tr>
							</table>
							</form>
						</div>
						<div class="addressline" style="clear: both;"></div>
					</div>
					<? if($row->delivery_addressline1!=""){ ?>
					<div id="delivery_address_exp">
						<div style="height: 200pt;">
							<table border="0" width="70%" align="left" cellpadding="0" cellspacing="5">
							<tr>
								<td colspan="2"><?=$lng_deliveryaddress;?> : </td>
							</tr>
							<tr>
								<td>&nbsp;</td>
							</tr>
								<tr>
									<td class="normal_text" style="font-weight: 600;"><?=$lng_onlyname;?> </td>
									<td class="normal_text"><?=$row->delivery_name;?></td>
								</tr>
								<!--tr>
									<td width="30%" class="normal_text" style="font-weight: 600;"><?=$lng_state;?> : </td>
									<td class="normal_text"><?$row->delivery_state;?></td>
								</tr>
								<tr>
									<td class="normal_text" style="font-weight: 600;"><?=$lng_towncity;?> : </td>
									<td class="normal_text"><?=$row->delivery_city;?></td>
								</tr-->
								<tr>
									<td class="normal_text" style="font-weight: 600;"><?=$lng_addressline1;?> : </td>
									<td class="normal_text"><?=$row->delivery_addressline1;?></td>
								</tr>
								<!--tr>
									<td class="normal_text" style="font-weight: 600;"><?=$lng_addressline2; ?> : </td>
									<td class="normal_text"><?=$row->delivery_addressline2;?></td>
								</tr-->
								<!--tr>
									<td class="normal_text" style="font-weight: 600;"><?=$lng_country;?> : </td>
									<td class="normal_text">
										<select name="country" style="width: 220px;" disabled="disabled">
									<?
										$qrc = "select * from countries order by printable_name";
										$rsc = mysql_query($qrc);
										while($v=mysql_fetch_array($rsc))
										{
									?>
										<option <?=$row->delivery_country==$v["countryId"]?"selected":"";?> value="<?=$v["countryId"];?>"><?=$v["printable_name"];?></option>
									<?
										}
									?>
										</select></td>
								</tr-->
								<tr>
									<td class="normal_text" style="font-weight: 600;"><?=$lng_postcode;?> : </td>
									<td class="normal_text"><?=$row->delivery_postcode;?></td>
								</tr>
								<tr>
									<td class="normal_text" style="font-weight: 600;"><?=$lng_phoneno;?> : </td>
									<td class="normal_text"><?=$row->delivery_phone;?></td>
								</tr>
								<tr>
									<td>&nbsp;</td>
								</tr>
								<tr>
									<td colspan="2"><input type="image" name="edit" value="Edit" src="<?=$lng_imagepath;?>edit_btn.png" onmouseover="this.src='<?=$lng_imagepath;?>edit_hover_btn.png'" onmouseout="this.src='<?=$lng_imagepath;?>edit_btn.png'" onclick="HideDisplayDeliveryAddress(1)" /></td>
								</tr>
							</table>
						</div>
						<div class="addressline" style="clear: both;"></div>
						</div>
					<form name="address" action="" method="post" onsubmit="return check();">
						<div id="delivery_address_exp1" style="display: none;">
							<div style="height: 240pt;">
							<table width="70%" border="0" align="left" cellpadding="0" cellspacing="5">
								<tr>
									<td colspan="2"><?=$lng_deliveryaddress;?> :</td>
								</tr>
								<tr>
									<td>&nbsp;</td>
								</tr>
								<tr>
									<td class="normal_text" style="font-weight: 600;"><?=$lng_onlyname;?></td>
									<td><input type="text" name="name" size="20" class="textboxclas" value="<?=$row->delivery_name;?>" />&nbsp;<span class="red-text-12-b">*</span></td>
								</tr>
								<!--tr>
									<td width="30%" class="normal_text" style="font-weight: 600;"><?=$lng_state;?> : </td>
									<td><input type="text" name="state" size="20" class="textboxclas" value="<?$row->delivery_state;?>" />  <span class="red-text-12-b">*</span></td>
								</tr>
								<tr>
									<td class="normal_text" style="font-weight: 600;"><?=$lng_towncity;?> : </td>
									<td><input type="text" name="city" size="20" class="textboxclas" value="<?=$row->delivery_city;?>" />&nbsp;<span class="red-text-12-b">*</span></td>
								</tr-->
								<tr>
									<td class="normal_text" style="font-weight: 600;"><?=$lng_addressline1; ?> : </td>
									<td><input type="text" name="address1" size="20" class="textboxclas" value="<?=$row->delivery_addressline1;?>" />&nbsp;<span class="red-text-12-b">*</span></td>
								</tr>
								<!--tr>
									<td class="normal_text" style="font-weight: 600;"><?=$lng_addressline2; ?> : </td>
									<td><input type="text" name="address2" size="20" class="textboxclas" value="<?=$row->delivery_addressline2;?>" /></td>
								</tr-->
								<!--tr>
									<td class="normal_text" style="font-weight: 600;"><?=$lng_country;?> : </td>
									<td>
									<select name="country" style="width: 220px;">
									<?
										$qrc1 = "select * from countries order by printable_name";
										$rsc1 = mysql_query($qrc1);
										while($v1 = mysql_fetch_array($rsc1))
										{
									?>
										<option <?=$row->delivery_country==$v1["countryId"]?"selected":"";?> value="<?=$v1["countryId"];?>"><?=$v1["printable_name"];?></option>
									<?
										}
									?>
									</select>
									</td>
								</tr-->
								<tr>
									<td class="normal_text" style="font-weight: 600;"><?=$lng_postcode;?>: </td>
									<td><input type="text" name="zip" size="20" class="textboxclas" value="<?=$row->delivery_postcode;?>" />  <span class="red-text-12-b">*</span></td>
								</tr>
								<tr>
									<td class="normal_text" style="font-weight: 600;"><?=$lng_phoneno;?> : </td>
									<td><input type="text" name="phone" size="20" class="textboxclas" value="<?=$row->delivery_phone;?>" />  <span class="red-text-12-b">*</span></td>
								</tr>
								<tr>
									<td colspan="2" class="normal_text"><span class="red-text-12-b">*</span> <?=$lng_mandatoryfield;?></td>
								</tr>
								<tr>
									<td>&nbsp;</td>
								</tr>
								<tr>
									<td colspan="2"><input type="image" name="delconfirm" value="confirm" src="<?=$lng_imagepath;?>submit_btn.png" onmouseover="this.src='<?=$lng_imagepath;?>submit_hover_btn.png'" onmouseout="this.src='<?=$lng_imagepath;?>submit_btn.png'"/>
									<input type="hidden" value="Confirm" name="del_confirm" />
									</td>
								</tr>
							</table>
						</div>
						<div class="addressline" style="clear: both;"></div>
						</div>
				</form>		
					<? } ?>
			</div>				
				</div>
				<div class="bottomline">
					<div class="leftsidecorner"></div>
					<div class="middlecorner"></div>
					<div class="rightsidecorner"></div>
				</div>
			</div>
		</div>
<?
	include("footer2.php");
?>		
</div>
</body>
</html>
