/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Open Software License (OSL 3.0)
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/osl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magentocommerce.com so we can send you a copy immediately.
 *
 * @category  Symmetrics
 * @package   Symmetrics_Lv
 * @author    symmetrics gmbh <info@symmetrics.de>
 * @author    Sebastian Tobias <st@symmetrics.de>
 * @copyright 2011 symmetrics gmbh
 * @license   http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 * @link      http://www.symmetrics.de/
 */

if (!window.Symmetrics) {
    window.Symmetrics = {};
}
if (!Symmetrics.lv) {
    Symmetrics.lv = {};
}

/**
 * Depending on how the customer go on in checkout step, the Terms of Use will appear or disappear.
 * If customer go to checkout as guest, Terms of Use will not be hidden and required-entry will be removed.
 * If customer go to checkout and register first time, Terms of Use will be shown and required-entry will be set.
 *
 * @category  Symmetrics
 * @package   Symmetrics_Lv
 * @author    symmetrics gmbh <info@symmetrics.de>
 * @author    Sebastian Tobias <st@symmetrics.de>
 * @copyright 2011 symmetrics gmbh
 * @license   http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 * @link      http://www.symmetrics.de/
 */

function bindInputWrap(prefix) {

    if (prefix === undefined) {
        prefix = '';
    }
    prefix += ' .form-list ';

    $$(prefix + 'input.input-text').each(function(item) {
        var inputWrapper = new Element('div', {'class': 'input-wrapper form-fields'});
        Element.wrap(item, inputWrapper);
    });

    $$(prefix + 'select').each(function(item) {
        var selectWrapper = new Element('div', {'class': 'select-wrapper form-fields'});
        Element.wrap(item, selectWrapper);
    });

    $$(prefix + 'textarea').each(function(item) {
        var textareaWrapper = new Element('div', {'class': 'textarea-wrapper form-fields'});
        Element.wrap(item, textareaWrapper);
    });

};
document.observe("dom:loaded", function() {
    bindInputWrap();
});

// Equal heights for boxes with same id or class.
function equalHeight(element) {
    var H = 0;
    jQuery(element).each(function(item) {
        var height = jQuery(element).eq(item).height();
        if (height > H) {
            H = height;
        }
    });
    jQuery(element).height(H);
};


VarienForm.prototype.initialize = function(formId, firstFieldFocus){
    firstFieldFocus = false;
    this.form       = $(formId);
    if (!this.form) {
        return;
    }
    this.cache      = $A();
    this.currLoader = false;
    this.currDataIndex = false;
    this.validator  = new Validation(this.form);
    this.elementFocus   = this.elementOnFocus.bindAsEventListener(this);
    this.elementBlur    = this.elementOnBlur.bindAsEventListener(this);
    this.childLoader    = this.onChangeChildLoad.bindAsEventListener(this);
    this.highlightClass = 'highlight';
    this.extraChildParams = '';
    this.firstFieldFocus= firstFieldFocus || false;
    this.bindElements();
    if(this.firstFieldFocus){
        try{
            Form.Element.focus(Form.findFirstElement(this.form))
        }
        catch(e){}
    }
};

