


var Cookie = {
    set: function(name, value, daysToExpire) {
        var expire = '';
        if (daysToExpire !== undefined) {
            var d = new Date();
            d.setTime(d.getTime() + (86400000 * parseFloat(daysToExpire)));
            expire = '; expires=' + d.toGMTString();
        }
        return (document.cookie = escape(name) + '=' + escape(value || '') + expire + ';path=/;');
    },
    get: function(name) {
        var cookie = document.cookie.match(new RegExp('(^|;)\\s*' + escape(name) + '=([^;\\s]*)'));
        return (cookie ? unescape(cookie[2]) : null);
    },
    erase: function(name) {
        var cookie = Cookie.get(name) || true;
        Cookie.set(name, '', -1);
        return cookie;
    },
    accept: function() {
        if (typeof navigator.cookieEnabled == 'boolean') {
            return navigator.cookieEnabled;
        }
        Cookie.set('_test', '1');
        return (Cookie.erase('_test') === "1");
    }
};

var Custom = {};
Custom.Info = Class.create();
Custom.Info.prototype = {
    
    initialize: function(options) {
        
        this.option = {
            layerpos: {'left':100,'top':100},
            layertext: 'information',
            layerId: 'infoLayer',
            cookieName: 'patientenfragenNet',
            cookieExpire: 7
        }
        Object.extend(this.option, options || {});
        
        this.createInfo();
    },
    
    createInfo: function() {
        
        if(Cookie.get(this.option.cookieName) == null) {
            this.showInfo();
            Cookie.set(this.option.cookieName, 'true', this.option.cookieExpire);
        }
    },
    
    showInfo: function() {
        this.eraseInfo();
        
        var layer     = new Element('div', {'id':this.option.layerId,'class':this.option.layerId});
        var layerHead = new Element('div', {'class':this.option.layerId+'Head'});
        var layerBody = new Element('div', {'class':this.option.layerId+'Body'});
        var layerFoot = new Element('div', {'class':this.option.layerId+'Foot'});
        
        layer.insert(layerHead);
        layer.insert(layerBody);
        layer.insert(layerFoot);
        
        layer.style.position = 'absolute';
        layer.style.top      = this.option.layerpos.top + 'px';
        layer.style.left     = this.option.layerpos.left + 'px';
        
        layerBody.insert(this.option.layertext);
        $(document.body).insert(layer);
    },
    
    eraseInfo: function() {
        if($(this.option.layerId)){
            $(this.option.layerId).remove();
        }
    }
    
};

var TabbedContent = Class.create({
   initialize: function(element){
       this.height = 0;
       this.tabs = $H();
       this.element = $(element);
       this._buildTabnavigation();
       this.tabs.keys().each(function(key){

           $(this.tabs.get(key)).hide();
       }.bind(this));

       this._setActiveTab(this.tabs.keys()[0]);

       this.element.removeClassName('jsTabbedContent');
       this.element.addClassName('tabbedContent');
       this._setEqualHeight();
   },
   
   _setEqualHeight: function(){
       this.tabs.keys().each(function(key){
           this.height = Math.max(this.height, $(this.tabs.get(key)).getHeight());
       }.bind(this));
       this.tabs.keys().each(function(key){
           $(this.tabs.get(key)).setStyle({
               'height': this.height + 'px'
           });
       }.bind(this));
   },
   _buildTabnavigation: function(){
       var tabNavigation = new Element('ul', {'class':'navigationTabs'});
        tabNavigation.addClassName("navigationTabs");
       this.element.select('div.tab').each(function(tabContent){
           tabContent.identify();
           var tab = new Element('li').insert('<a href="javascript:;"><span>' + tabContent.title + '</span></a>');
           tab.identify();
           tabContent.title = '';
           this.tabs.set(tab.id, $(tabContent.id));
           tab.observe('click', this.clickHandler.bindAsEventListener(this));
           tabNavigation.insert(tab);
       }.bind(this));
       this.element.insert({'top' : tabNavigation});
   },
   _setActiveTab: function(tabKey){
       try {
           $(this.active).removeClassName('active');
           $(this.tabs.get(this.active)).hide();
       } catch(e){
           this.tabs.keys().each(function(key){
               $(key).removeClassName('active');
               $(this.tabs.get(key)).hide();
           }.bind(this));
       }
       this.active = tabKey;
       $(this.active).addClassName('active');
       $(this.tabs.get(this.active)).show();
   },
   clickHandler: function(e){
       if (element = e.element().up('li')) {
           this._setActiveTab(element.id);
       }
   }
});

var LabelInputText = Class.create({
    initialize: function(input){
        this.element = $(input);
        this.value = input.value;
        this.element.observe('focus', this.focusHandler.bindAsEventListener(this));
        this.element.observe('blur', this.blurHandler.bindAsEventListener(this));
    },
    focusHandler: function(e){
        if(this.value == this.element.value){
            this.element.value = '';
        }
    },
    blurHandler: function(){
        if('' == this.element.value){
            this.element.value = this.value;
        }
    }
});
