
<script type="text/javascript">
countryRegions = <?php echo $this->helper('directory')->getRegionJson() ?>;
regionCities = <?php echo $this->helper('directory')->getCityJson() ?>;
</script>

<div class="page-title">
	<h1><?php if($data->getAddressId()): ?><?php echo $this->__('Edit Address Entry') ?><?php else: ?><?php echo $this->__('New Address Entry') ?><?php endif ?></h1>
</div>
<?php echo $this->getMessagesBlock()->getGroupedHtml() ?>
<form action="<?php echo $action ?>" method="post" id="form-validate">
	<div class="fieldset">
	<input type="hidden" name="address_id" value="<?php echo $data->getAddressId() ?>" />
	<input type="hidden" name="customer_id" id="address_id" value="<?php echo $data->getCustomerId() ?>" />
		<h2 class="legend"><?php echo $this->__('Personal Information') ?></h2>
		<ul class="form-list">
			<li class="fields">
				<?php echo $this->getLayout()->createBlock('customer/widget_name')->setObject($data)->toHtml() ?>
			</li>
			<li>
				<label for="company"><?php echo $this->__('Company') ?></label>
				<div class="input-box">
					<input type="text" name="company" id="company" title="<?php echo $this->__('Company') ?>" value="<?php echo $this->htmlEscape($data->getCompany()) ?>" class="input-text" />
				</div>
			</li>
		</ul>
	</div>
	<div class="fieldset">
		<h2 class="legend"><?php echo $this->__('Address') ?></h2>
		<ul class="form-list">
			<li class="wide">
				<label for="street_1" class="required"><em>*</em><?php echo $this->__('Street Address') ?></label>
				<div class="input-box">
					<input type="text" name="street[]" value="<?php echo $this->htmlEscape($data->getStreet(1)) ?>" title="<?php echo $this->__('Street Address') ?>" id="street_1" class="input-text required-entry" />
				</div>
			</li>
		<?php for ($_i=2, $_n=$this->helper('customer/address')->getStreetLines(); $_i<=$_n; $_i++): ?>
			<li class="wide">
				<div class="input-box">
					<input type="text" name="street[]" value="<?php echo $this->htmlEscape($data->getStreet($_i)) ?>" title="<?php echo $this->__('Street Address '.$_i) ?>" id="street_<?php echo $_i?>" class="input-text" />
				</div>
			</li>
		<?php endfor ?>
			<li class="fields">
				<div class="field">
					<label for="region_id" class="required"><em>*</em><?php echo $this->__('State/Province') ?></label>
					<div class="input-box">
						<select id="region_id" name="region_id" title="<?php echo $this->__('State/Province') ?>" class="validate-select" style="display:none;">
							<option value=""><?php echo $this->__('Please select region, state or province') ?></option>
						</select>
						<script type="text/javascript">
						//<![CDATA[
							$('region_id').setAttribute('defaultValue',  "<?php echo $this->getAddress()->getRegionId() ?>");
						//]]>
						</script>
						<input type="text" id="region" name="region" value="<?php echo $this->htmlEscape($this->getAddress()->getRegion()) ?>"  title="<?php echo $this->__('State/Province') ?>" class="input-text required-entry" style="display:none;" />
					</div>
				</div>
				<div class="field">
					<label for="city_id" class="required"><em>*</em><?php echo $this->__('City') ?></label>
					<div class="input-box">
						<select id="city_id" name="city_id" title="<?php echo $this->__('City') ?>" class="validate-select" style="display:none;">
							<option value=""><?php echo $this->__('Please select city') ?></option>
						</select>
						<script type="text/javascript">
						//<![CDATA[
							$('city_id').setAttribute('defaultValue',  "<?php echo $this->getAddress()->getCityId() ?>");
						//]]>
						</script>
						<input type="text" id="city" name="city" value="<?php echo $this->htmlEscape($this->getAddress()->getCity()) ?>"  title="<?php echo $this->__('City') ?>" class="input-text" style="display:none;" />
					</div>
				</div>
			</li>
			<li class="fields">
				<div class="field">
					<label for="zip" class="required"><em>*</em><?php echo $this->__('Zip/Postal Code') ?></label>
					<div class="input-box">
						<input type="hidden" name="country_id" id="country_id" value="CN" />
						<input type="text" name="postcode" value="<?php echo $this->htmlEscape($data->getPostcode()) ?>" title="<?php echo $this->__('Zip/Postal Code') ?>" id="zip" class="input-text validate-zip-international required-entry" />
					</div>
				</div>
			</li>
			<li class="fields">
				<div class="field">
					<label for="telephone" class="required"><em>*</em><?php echo $this->__('Telephone') ?></label>
					<div class="input-box">
						<input type="text" name="telephone" value="<?php echo $this->htmlEscape($data->getTelephone()) ?>" title="<?php echo $this->__('Telephone') ?>" class="input-text" id="telephone" />
					</div>
				</div>
				<div class="field">
					<label for="mobile"><?php echo $this->__('Mobile') ?></label>
					<div class="input-box">
						<input type="text" name="mobile" value="<?php echo $this->htmlEscape($data->getMobile()) ?>" title="<?php echo $this->__('Mobile') ?>" class="input-text" id="mobile" />
					</div>
				</div>
			</li>
		<?php foreach ($primaryTypes as $code=>$type): ?>
			<li<?php if (!$address->isPrimary($type['address_type_id'])) echo ' class="control"' ?>>
			<?php if ($address->isPrimary($type['address_type_id'])): ?>
				<strong><?php echo $this->__("This is My Default %s Address", ucfirst($type['name'])) ?></strong>
			<?php else: ?>
				<input type="checkbox" id="primary_<?php echo $code ?>" name="primary_types[]" value="<?php echo $type['address_type_id'] ?>" class="checkbox" /><label for="primary_<?php echo $code ?>"><?php echo $this->__("Use as My Default %s Address", ucfirst($type['name'])) ?></label>
			<?php endif ?>
			</li>
		<?php endforeach ?>
		</ul>
	</div>
	<div class="buttons-set">
		<p class="required"><?php echo $this->__('* Required Fields') ?></p>
		<p class="back-link"><a href="<?php echo $this->getUrl('customer/address/') ?>"><small>&laquo; </small><?php echo $this->__('Back') ?></a></p>
		<button type="submit" class="button" title="<?php echo $this->__('Save Address') ?>"><span><span><?php echo $this->__('Save Address') ?></span></span></button>
	</div>
</form>
<script type="text/javascript">
//<![CDATA[
	var dataForm = new VarienForm('form-validate', true);
	//dataForm.setElementsRelation('country', 'state', '<?php echo $this->getUrl('directory/json/childRegion') ?>');
	var regionUpdater = new RegionUpdater('country_id', 'region', 'region_id', countryRegions);
	regionUpdater.update();

	var cityUpdater = new RegionUpdater('region_id', 'city', 'city_id', regionCities);
//]]>
</script>
