var ctemplates = new Array();
ctemplates['txtInput'] = new Template('<div class="input-box"><label>#{label}</label><span class="grey-border"><input type="text" name="#{name}" class="input-text #{classes}" value="#{value}"/></span></div>');
Event.observe(window, 'load', function() {
    $$('.hint').each(function(k){
        k.style.display='none';
        k.addClassName('hint-override');
    });
    if($('wizard_form')){
        window.valid = new Validation('wizard_form', {onSubmit:false});
    }
    $$('select.styled').each(function(key){
        new Autocompleter.SelectBox(key);
    })
    if($$('ul.tabs-header li')[0])
        $$('ul.tabs-header li')[0].addClassName('first');

    if($$('ul.tabs-header li').last())
        $$('ul.tabs-header li').last().addClassName('last');

    __ie=false;
    if(!Prototype.Browser.IE){
        [$$('select'), $$('textarea'), $$('input')].each(function(elm){
            elm.each(function(el){
                if(el.parentNode.hasClassName('grey-border')){
                    el.tch_el=el.parentNode;
                }else{
                    el.tch_el=el;
                }
                el.observe('focus', function(e){
                    e.target.tch_el.addClassName('activeInputElement');
                });
                el.observe('blur', function(e){
                    e.target.tch_el.removeClassName('activeInputElement');
                });
            })
        });
        __ie=false;
    }else{
        __ie=true;
    }
    $$('.be-table').each(function(mkk){
       decorateTable(mkk);
    });
/*
    $$('*').each(function(elm){
       elm.observe('click', function(e){
           console.log(e.target);
       })
    });
*/
    var zIndexNumber = 0;

    $$('input[type=radio]').each(function(k){
         k.style.border="";
         k.style.background="";
         k.style.padding="";   
    });
    
    function inputFunctRegExp(regexpstring, event) {
        var re = new RegExp(regexpstring, "g");
        var inputdom = $(event.target);
        inputdom.value = inputdom.value.replace(re, "");
    }
    $$('.allow-only-digits').each(function(elem){
        elem.observe('keyup', inputFunctRegExp.bind(this, "[^0-9]"));
        elem.observe('change', inputFunctRegExp.bind(this, "[^0-9]"));
    });
    $$('.allow-only-digits-and-comma').each(function(elem){
        elem.observe('keyup', inputFunctRegExp.bind(this, "[^0-9_\._\¾]"));
        elem.observe('change', inputFunctRegExp.bind(this, "[^0-9_\._\¾]"));
    });


    if(($$('.column-2').first())&&($$('.column-1').first())){
        if($$('.column-1').first().offsetHeight > $$('.column-2').first().offsetHeight){
            var newHeight=$$('.column-1').first().offsetHeight+50;
            $$('.column-2-set').first().style.height =  newHeight + 'px';
        }
    }
    window.removeHeightW = function(){
       window.heightW = $$('.column-2-set').first().style.height;
       $$('.column-2-set').first().style.height = '';
    }
    window.addHeightW = function(){
        $$('.column-2-set').first().style.height = window.heightW;
    }

    $$('.hlist li').each(function(objLi){
        if(((objLi.innerHTML=='')||(objLi.innerHTML==' '))&&(objLi.nodeName=="LI")){
            objLi.remove();
        }
        if(objLi.innerHTML.substring(0, 3)==', ,'){
            objLi.remove();
        }
    });
    if(__ie){
        $$('.mail-grid tr td').each(function(td){
            Element.forceRerendering(td);
            (function(){
                td.style.height="auto";
                td.style.height="";
            }).defer();
        })
    }else{
        Element.forceRerendering ($$('body').first());
    }
})

var coolFader = Class.create();
if(!Prototype.Browser.IE){
    coolFader.prototype = {
        initialize:function(trigger, objectX, durationIn, durationOut, fadeWait){
            this.tmrFade=0;
            if (!durationIn){
                durationIn = 0.5;
            }
            if (!durationOut){
                durationOut = 0.5;
            }
            if (!fadeWait){
                fadeWait = 500;
            }
            this.durIn = durationIn;
            this.durOut/* ;) */ = durationOut;

            this.fadeWait = fadeWait;
            if (trigger&&objectX){
                this.mObj = objectX;
                Event.observe(trigger, 'click', this.toggleObj.bind(this));
            }
        },
        toggleObj:function(){
            if(this.mObj.style.display!='none'){
                this.fadeObject();
            }else{
                this.startAppear();
            }
        },
        fadeObject:function(){
            Effect.Fade(this.mObj, {duration:this.durOut});
        },

        startAppear:function(){
            Effect.Appear(this.mObj, {duration:this.durIn});
        }
    }
}else{
    coolFader.prototype = {
        initialize:function(trigger, objectX, durationIn, durationOut, fadeWait){
            if (trigger&&objectX){
                this.mObj = objectX;
                Event.observe(trigger, 'click', this.toggleObj.bind(this));
            }
        },
        toggleObj:function(){
            if(this.mObj.style.display!='none'){
                this.hide();
            }else{
                this.show();
            }
        }
    }
}
