<form method="post" action="{url x="shop" r="uc_account#save"}" name="modify">
<div class="inc">
	<div class="inc_top">{$page_title}</div>
	<div class="inc_main">
		
								<table width="100%">
									<tr>
										<td>
											
											<div class="field email">
											<label for="settings-email-address">Email</label>
											<input type="text" value="{$user_info.email}" {if $user_info.email neq ''}readonly="readonly"{/if} class="f-input {if $user_info.email neq ''}readonly{/if}" id="settings-email-address" name="email" size="30">
											</div>
											<div class="blank"></div>
											<div class="field username">
												<label for="settings-username">{$LANG.USER_TITLE_USER_NAME}</label>
												<input type="text" value="{$user_info.user_name}" readonly="readonly" class="f-input readonly" id="settings-username" name="user_name" size="30">
											</div>
											<div class="blank"></div>
											<div class="field password">
												<label for="settings-password">{$LANG.USER_TITLE_USER_NEW_PWD}</label>
												<input type="password" class="f-input" id="settings-password" name="user_pwd" size="30">
												<span class="hint">{$LANG.USER_TITLE_USER_NEW_PWD_TIP}</span> 
											</div>
											<div class="blank"></div>
											<div class="field password">
												<label for="settings-password-confirm">{$LANG.USER_TITLE_USER_CONFIRM_PWD}</label>
												<input type="password" class="f-input" id="settings-password-confirm" name="user_pwd_confirm" size="30">
											</div>
											<div class="blank"></div>											
											
			
											{foreach from=$field_list item=field_item}
											<div class="field {$field_item.field_name}">
													<label for="{$field_item.field_name}">{$field_item.field_show_name}</label>
													{if $field_item.input_type eq 0}
													<input type="text" value="{$field_item.value}" class="f-input" id="settings-{$field_item.field_name}" name="{$field_item.field_name}" size="30">
													{else}
													<select name ="{$field_item.field_name}" id="settings-{$field_item.field_name}">
														{foreach from=$field_item.value_scope item=value_item}
														<option value="{$value_item}" {if $value_item eq $field_item.value}selected="selected"{/if}>{$value_item}</option>
														{/foreach}
													</select>
													{/if}
											</div>
											<div class="blank"></div>
											{/foreach}
											
											
										</td>
										<td valign="top" style="width:180px;">
										
											
												<img id="avatar" src="{function name="get_user_avatar" uid=$user_info.id type="middle"}" />
												<div class="blank"></div>
												<label class="fileupload" onclick="upd_file(this,'avatar_file',{$user_info.id});">
												<input type="file" class="filebox" name="avatar_file" id="avatar_file"/>
												
												</label>
												<label class="fileuploading hide" ></label>
											
																				
										</td>
									</tr>
								</table>
								
							
							<div class="blank"></div>	
	</div>
	<div class="inc_foot"></div>
</div>
<div class="blank"></div>
<div class="inc">
	<div class="inc_top">{$LANG.MORE_USER_INFO}</div>
	<div class="inc_main">
		
								<table width="100%">
									<tr>
										<td>
											
																					
											
											<div class="field mobile">
												<label for="settings-mobile">{$LANG.USER_TITLE_MOBILE}</label>
												<input type="text" value="{$user_info.mobile}" class="f-input" id="settings-mobile" name="mobile" size="30">
												<span class="hint">{$LANG.USER_TITLE_MOBILE_TIP}</span> 
											</div>
											<div class="blank"></div>
											<script type="text/javascript" src="{$APP_ROOT}/system/region.js"></script>		
											<div class="field">
																							
												<label for="settings-region">{$LANG.USER_REGION}</label>
												
												{$LANG.USER_PROVINCE}：<select name="province_id">
														<option value="0">={$LANG.SELECT_PLEASE}=</option>
														{foreach from=$region_lv2 item=lv2}
														<option {if $lv2.selected eq 1}selected="selected"{/if} value="{$lv2.id}">{$lv2.name}</option>
														{/foreach}
													  </select>
																		
												{$LANG.USER_CITY}：<select name="city_id">
														<option value="0">={$LANG.SELECT_PLEASE}=</option>		
														{foreach from=$region_lv3 item=lv3}
														<option {if $lv3.selected eq 1}selected="selected"{/if} value="{$lv3.id}">{$lv3.name}</option>
														{/foreach}
													 </select>
												
											</div>
											<div class="blank"></div>
											<div class="field clearfix">
												<label for="settings-birthday">{$LANG.USER_BIRTHDAY}</label>
												<div class="f_l">
													<select name="byear">
														<option value="0">{$LANG.PLEASE_SELECT}</option>
														<?php for($i = date("Y") - 100 ;$i<=date("Y"); $i++){ ?>
														<option value="<?php echo $i; ?>" <?php if($i==$GLOBALS['user_info']['byear']){echo 'selected="selected"';} ?>><?php echo $i; ?></option>
														<?php
														}
														?>
													</select>
													{$LANG.SUPPLIER_YEAR}
													<select name="bmonth">
														<option value="0">{$LANG.PLEASE_SELECT}</option>
														<?php for($i = 1 ;$i<=12; $i++){ ?>
														<option value="<?php echo $i; ?>"  <?php if($i==$GLOBALS['user_info']['bmonth']){echo 'selected="selected"';} ?>><?php echo $i; ?></option>
														<?php
														}
														?>
													</select>
													{$LANG.SUPPLIER_MON}
													<select name="bday">
														<option value="0">{$LANG.PLEASE_SELECT}</option>
														<?php for($i = 1 ;$i<=31; $i++){ ?>
														<option value="<?php echo $i; ?>" <?php if($i==$GLOBALS['user_info']['bday']){echo 'selected="selected"';} ?>><?php echo $i; ?></option>
														<?php
														}
														?>
													</select>
													{$LANG.SUPPLIER_DAY}
												</div>
											</div>
											<div class="blank"></div>
											
											<div class="field">
												<label>{$LANG.USER_SEX}</label>
												<select name="sex">
													<option value="-1" {if $user_info.sex eq -1}selected="selected"{/if}>{$LANG.USER_SEX_NULL}</option>
													<option value="0" {if $user_info.sex eq 0}selected="selected"{/if}>{$LANG.USER_SEX_0}</option>
													<option value="1" {if $user_info.sex eq 1}selected="selected"{/if}>{$LANG.USER_SEX_1}</option>
												</select>
											</div>
											<div class="blank"></div>
											
											<div class="field">
												<label>{$LANG.USER_MY_INTRO}</label>
												<textarea name="my_intro" cols="10" style="width:250px; height:100px; border:#ccc solid 1px;">{$user_info.my_intro}</textarea>
											</div>
											<div class="blank"></div>
			
											{foreach from=$field_list item=field_item}
											<div class="field {$field_item.field_name}">
													<label for="{$field_item.field_name}">{$field_item.field_show_name}</label>
													{if $field_item.input_type eq 0}
													<input type="text" value="{$field_item.value}" class="f-input" id="settings-{$field_item.field_name}" name="{$field_item.field_name}" size="30">
													{else}
													<select name ="{$field_item.field_name}" id="settings-{$field_item.field_name}">
														{foreach from=$field_item.value_scope item=value_item}
														<option value="{$value_item}" {if $value_item eq $field_item.value}selected="selected"{/if}>{$value_item}</option>
														{/foreach}
													</select>
													{/if}
											</div>
											<div class="blank"></div>
											{/foreach}
											<div class="clear"></div>
											<div class="act">
													<input type="hidden" value="{$user_info.id}" name="id" />
													<input type="submit" class="formbutton" id="settings-submit" name="commit" value="{$LANG.MODIFY}">
											</div>
											
										</td>
										<td valign="top" style="width:180px;">
																			
										</td>
									</tr>
								</table>
								
							
							<div class="blank"></div>	
	</div>
	<div class="inc_foot"></div>
</div>
</form>	
<script type="text/javascript" src="{$TMPL}/js/ajaxupload.js"></script>
<script type="text/javascript">
$(document).ready(function(){

	$("#settings-submit").click(function(){
		
		if($.trim($("#settings-email-address").val()).length == 0)
		{
			$("#settings-email-address").focus();
			$.showErr("{function name="sprintf" format=$LANG.EMPTY_ERROR_TIP value=$LANG.USER_TITLE_EMAIL}");
			
			return false;
		}
		
		if(!$.checkEmail($("#settings-email-address").val()))
		{
			$("#settings-email-address").focus();			
			$.showErr("{function name="sprintf" format=$LANG.FORMAT_ERROR_TIP value=$LANG.USER_TITLE_EMAIL}");
			return false;
		}
		
		if($.trim($("#settings-password").val())!=''&&!$.minLength($("#settings-password").val(),4,false))
		{
			$("#settings-password").focus();
			$.showErr("{function name="sprintf" format=$LANG.FORMAT_ERROR_TIP value=$LANG.USER_TITLE_USER_PWD}");	
			return false;
		}
		
		if($("#settings-password-confirm").val() != $("#settings-password").val())
		{
			$("#settings-password-confirm").focus();
			$.showErr("{$LANG.USER_PWD_CONFIRM_ERROR}");			
			return false;
		}

		if(!$.checkMobilePhone($("#settings-mobile").val()))
		{
			$("#settings-mobile").focus();			
			$.showErr("{function name="sprintf" format=$LANG.FORMAT_ERROR_TIP value=$LANG.USER_TITLE_MOBILE}");	
			return false;
		}		
		
		{if app_conf("MOBILE_MUST") eq 1}
			if($.trim($("#settings-mobile").val()).length == 0)
			{
				$("#settings-mobile").focus();
				$.showErr("{function name="sprintf" format=$LANG.EMPTY_ERROR_TIP value=$LANG.USER_TITLE_MOBILE}");
				
				return false;
			}
		{/if}

		{foreach from=$field_list item=field_item}
			{if $field_item.is_must eq 1}
			if($("#settings-{$field_item.field_name}").val()=='')
			{
				$.showErr("{function name="sprintf" format=$LANG.EMPTY_ERROR_TIP value=$field_item.field_show_name}");	
				$("#settings-{$field_item.field_name}").focus();
				return false;
			}
			{/if}
		{/foreach}

		
	});
});

function upd_file(obj,file_id,uid)
{	
	$("input[name='"+file_id+"']").bind("change",function(){			
		$(obj).hide();
		$(obj).parent().find(".fileuploading").removeClass("hide");
		$(obj).parent().find(".fileuploading").removeClass("show");
		$(obj).parent().find(".fileuploading").addClass("show");
		  $.ajaxFileUpload
		   (
			   {
				    url:APP_ROOT+'/index.php?ctl=avatar&act=upload&uid='+uid,
				    secureuri:false,
				    fileElementId:file_id,
				    dataType: 'json',
				    success: function (data, status)
				    {
				   		$(obj).show();
				   		$(obj).parent().find(".fileuploading").removeClass("hide");
						$(obj).parent().find(".fileuploading").removeClass("show");
						$(obj).parent().find(".fileuploading").addClass("hide");
				   		if(data.status==1)
				   		{
				   			document.getElementById("avatar").src = data.middle_url+"?r="+Math.random();
				   		}
				   		else
				   		{
				   			$.showErr(data.msg);
				   		}
				   		
				    },
				    error: function (data, status, e)
				    {
						$.showErr(data.responseText);;
				    	$(obj).show();
				    	$(obj).parent().find(".fileuploading").removeClass("hide");
						$(obj).parent().find(".fileuploading").removeClass("show");
						$(obj).parent().find(".fileuploading").addClass("hide");
				    }
			   }
		   );
		  $("input[name='"+file_id+"']").unbind("change");
	});	
}

//切换地区
$(document).ready(function(){	
		$("select[name='province_id']").bind("change",function(){
			load_city();
		});
	});
	
	function load_city()
	{
		var id = $("select[name='province_id']").val();
		
		var evalStr="regionConf.r"+id+".c";

		if(id==0)
		{
			var html = "<option value='0'>="+LANG['SELECT_PLEASE']+"=</option>";
		}
		else
		{
			var regionConfs=eval(evalStr);
			evalStr+=".";
			var html = "<option value='0'>="+LANG['SELECT_PLEASE']+"=</option>";
			for(var key in regionConfs)
			{
				html+="<option value='"+eval(evalStr+key+".i")+"'>"+eval(evalStr+key+".n")+"</option>";
			}
		}
		$("select[name='city_id']").html(html);

		
	}
</script>