<?php
/**
 * Avalanche for Magento 1.8+
 * Designed by Fast Division (http://fastdivision.com)
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the EULA
 * that is bundled with this package in the file license.txt.
 * It is also available through the world-wide-web at this URL:
 * http://fastdivision.com/legal/license.txt
 *
 * @author     Fast Division
 * @version    1.5.0
 * @copyright  Copyright 2013 Fast Division
 * @license    http://fastdivision.com/legal/license.txt
 */
?>
<?php $prefix = $this->getFieldNamePrefix();?>
<fieldset>
    <ul class="form-list form-list-narrow">
    <li id="<?php echo $prefix ?>-address-form" class="address-form">
        <fieldset>
            <input type="hidden" name="<?php echo $prefix ?>[address_id]" value="<?php echo $this->getAddress()->getId() ?>" id="<?php echo $prefix ?>:address_id" />
            <ul>
                <li class="fields"><?php echo $this->getLayout()->createBlock('customer/widget_name')->setObject($this->getAddress()->getFirstname() ? $this->getAddress() : $this->getQuote()->getCustomer())->setForceUseCustomerRequiredAttributes(!$this->isCustomerLoggedIn())->setFieldIdFormat($prefix . ':%s')->setFieldNameFormat($prefix . '[%s]')->toHtml() ?></li>
                <li class="fields">
                    <div class="field">
                        <label for="<?php echo $prefix ?>:company"><?php echo $this->__('Company') ?></label>
                        <div class="input-box">
                            <input type="text" id="<?php echo $prefix ?>:company" name="<?php echo $prefix ?>[company]" value="<?php echo $this->escapeHtml($this->getAddress()->getCompany()) ?>" title="<?php echo $this->__('Company') ?>" class="input-text <?php echo $this->helper('customer/address')->getAttributeValidationClass('company') ?>" />
                        </div>
                    </div>
        <?php if(!$this->isCustomerLoggedIn() && !$this->getHideEmailAddress()): ?>
                    <div class="field">
                        <label for="<?php echo $prefix ?>:email" class="required"><?php echo $this->__('Email Address') ?><em>*</em></label>
                        <div class="input-box">
                            <input type="text" name="<?php echo $prefix ?>[email]" id="<?php echo $prefix ?>:email" value="<?php echo $this->escapeHtml($this->getAddress()->getEmail()) ?>" title="<?php echo $this->__('Email Address') ?>" class="input-text validate-email required-entry" />
                        </div>
                    </div>
        <?php endif; ?>
                </li>
        <?php $_streetValidationClass = $this->helper('customer/address')->getAttributeValidationClass('street'); ?>
                <li class="wide">
                    <div class="field">
                        <label for="<?php echo $prefix ?>:street1" class="required"><?php echo $this->__('Address') ?><em>*</em></label>
                        <div class="input-box">
                            <input type="text" title="<?php echo $this->__('Street Address') ?>" name="<?php echo $prefix ?>[street][]" id="<?php echo $prefix ?>:street1" value="<?php echo $this->escapeHtml($this->getAddress()->getStreet(1)) ?>" class="input-text <?php echo $_streetValidationClass ?>" />
                        </div>
                    </div>
                    <?php $_streetValidationClass = trim(str_replace('required-entry', '', $_streetValidationClass)); ?>
                    <?php for ($_i = 2, $_n = $this->helper('customer/address')->getStreetLines(); $_i <= $_n; $_i++): ?>
                    <div class="field">
                        <label>&nbsp;</label>
                        <input type="text" title="<?php echo $this->__('Street Address %s', $_i) ?>" name="<?php echo $prefix ?>[street][]" id="<?php echo $prefix ?>:street<?php echo $_i?>" value="<?php echo $this->escapeHtml($this->getAddress()->getStreet($_i)) ?>" class="input-text <?php echo $_streetValidationClass ?>" />
                    </div>
                    <?php endfor; ?>
                </li>
                <?php if ($this->helper('customer/address')->isVatAttributeVisible()) : ?>
                <li class="wide">
                    <label for="<?php echo $prefix ?>:vat_id"><?php echo $this->__('VAT Number') ?></label>
                    <div class="input-box">
                        <input type="text" id="<?php echo $prefix ?>:vat_id" name="<?php echo $prefix ?>[vat_id]" value="<?php echo $this->escapeHtml($this->getAddress()->getVatId()) ?>" title="<?php echo $this->__('VAT Number') ?>" class="input-text <?php echo $this->helper('customer/address')->getAttributeValidationClass('vat_id') ?>" />
                    </div>
                </li>
                <?php endif; ?>
                <li class="fields">
                    <div class="field">
                        <label for="<?php echo $prefix ?>:city" class="required"><?php echo $this->__('City') ?><em>*</em></label>
                        <div class="input-box">
                            <input type="text" title="<?php echo $this->__('City') ?>" name="<?php echo $prefix ?>[city]" value="<?php echo $this->escapeHtml($this->getAddress()->getCity()) ?>" class="input-text <?php echo $this->helper('customer/address')->getAttributeValidationClass('city') ?>" id="<?php echo $prefix ?>:city" />
                        </div>
                    </div>
                    <div class="field">
                        <label for="<?php echo $prefix ?>:region_id" class="required"><?php echo $this->__('State/Province') ?><em>*</em></label>
                        <div class="input-box">
                            <select id="<?php echo $prefix ?>:region_id" name="<?php echo $prefix ?>[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[
                                $('<?php echo $prefix ?>:region_id').setAttribute('defaultValue',  "<?php echo $this->getAddress()->getRegionId() ?>");
                            //]]>
                            </script>
                            <input type="text" id="<?php echo $prefix ?>:region" name="<?php echo $prefix ?>[region]" value="<?php echo $this->escapeHtml($this->getAddress()->getRegion()) ?>"  title="<?php echo $this->__('State/Province') ?>" class="input-text <?php echo $this->helper('customer/address')->getAttributeValidationClass('region') ?>" style="display:none;" />
                        </div>
                    </div>
                </li>
                <li class="fields">
                    <div class="field">
                        <label for="<?php echo $prefix ?>:postcode" class="required"><?php echo $this->__('Zip/Postal Code') ?><em>*</em></label>
                        <div class="input-box">
                            <input type="text" title="<?php echo $this->__('Zip/Postal Code') ?>" name="<?php echo $prefix ?>[postcode]" id="<?php echo $prefix ?>:postcode" value="<?php echo $this->escapeHtml($this->getAddress()->getPostcode()) ?>" class="input-text validate-zip-international <?php echo $this->helper('customer/address')->getAttributeValidationClass('postcode') ?>" />
                        </div>
                    </div>
                    <div class="field">
                        <label for="<?php echo $prefix ?>:country_id" class="required"><?php echo $this->__('Country') ?><em>*</em></label>
                        <div class="input-box">
                            <?php echo $this->getCountryHtmlSelect($prefix) ?>
                        </div>
                    </div>
                </li>
                <li class="fields">
                    <div class="field">
                        <label for="<?php echo $prefix ?>:telephone" class="required"><?php echo $this->__('Telephone') ?><em>*</em></label>
                        <div class="input-box">
                            <input type="text" name="<?php echo $prefix ?>[telephone]" value="<?php echo $this->escapeHtml($this->getAddress()->getTelephone()) ?>" title="<?php echo $this->__('Telephone') ?>" class="input-text <?php echo $this->helper('customer/address')->getAttributeValidationClass('telephone') ?>" id="<?php echo $prefix ?>:telephone" />
                        </div>
                    </div>
                    <div class="field">
                        <label for="<?php echo $prefix ?>:fax"><?php echo $this->__('Fax') ?></label>
                        <div class="input-box">
                            <input type="text" name="<?php echo $prefix ?>[fax]" value="<?php echo $this->escapeHtml($this->getAddress()->getFax()) ?>" title="<?php echo $this->__('Fax') ?>" class="input-text <?php echo $this->helper('customer/address')->getAttributeValidationClass('fax') ?>" id="<?php echo $prefix ?>:fax" />
                        </div>
                    </div>
                </li>
                <?php echo $this->getChildHtml('form.additional.info'); ?>
                <?php if ($this->getShowAsShippingCheckbox()): ?>
                    <li class="control">
                        <input type="checkbox" name="<?php echo $prefix ?>[as_shipping]" class="checkbox" value="1" title="<?php echo $this->__('Same as shipping') ?>" id="<?php echo $prefix ?>:as_shipping" <?php if ($this->getAddress()->getSameAsBilling()):?>checked="checked"<?php endif;?>/>
                        <label for="<?php echo $prefix ?>:as_shipping"><?php echo $this->__('Same as shipping') ?></label>
                    </li>
                <?php endif; ?>
            </ul>
        </fieldset>
     </li>
    </ul>
</fieldset>
<script type="text/javascript">
//<![CDATA[
    var <?php echo $prefix ?>RegionUpdater = new RegionUpdater('<?php echo $prefix ?>:country_id', '<?php echo $prefix ?>:region', '<?php echo $prefix ?>:region_id', <?php echo $this->helper('directory')->getRegionJson() ?>, undefined, '<?php echo $prefix ?>:postcode');
    <?php echo $prefix ?>RegionUpdater.update();
//]]>
</script>
