var divBorder;
var YOOBase = {
    matchDivHeight: function(selector, minWidth) {
        var maxHeight = 0;
        var matchDivs = [];
        var selectors = selector.split(" ");
        var elements = selectors.shift();
        var script = '';
        selectors.each(function(el, i) {
            script += '.getElement("' + el + '")'
        });
        $ES(elements).each(function(element, i) {
            eval('matchDivs.push(element' + script + ');')
        });
        matchDivs.each(function(div, i) {
            if (!$chk(div)) return;

            var divHeight, divPadding;
            if (div.offsetHeight) {
                divHeight = div.offsetHeight;
                divPadding = 0;
                divPadding += div.getStyle('padding-top').toInt();
                divPadding += div.getStyle('padding-bottom').toInt();
                divHeight -= divPadding;
                divBorder = 0;
                divBorder += div.getStyle('border-top-width').toInt();
                divBorder += div.getStyle('border-bottom-width').toInt();
                divHeight -= divBorder
            } else if (div.style.pixelHeight) {
                divHeight = div.style.pixelHeight
            }
            maxHeight = Math.max(maxHeight, divHeight)
        });
        if (minWidth != undefined) {
            maxHeight = Math.max(maxHeight, minWidth)
        }
        matchDivs.each(function(div, i) {
            if (!$chk(div)) return;
            if (window.ie6) {
                div.setStyle('height', maxHeight + 'px')
            } else {
                div.setStyle('min-height', maxHeight + 'px')
            }
        })
    }
};
var YOOMorph = new Class({
    initialize: function(element, enter, leave, enterFx, leaveFx, elementFx) {
        this.setOptions({
            duration: 500,
            transition: Fx.Transitions.expoOut,
            wait: false,
            ignoreClass: ''
        },
        enterFx);
        var options = this.options;
        $$(element).each(function(el, i) {
            var elfx = el;
            if (elementFx && el.getElement(elementFx)) {
                elfx = el.getElement(elementFx)
            };
            var fx = new Fx.Styles(elfx, options);
            if (! ($chk(options.ignoreClass) && el.hasClass(options.ignoreClass))) {
                el.addEvent('mouseenter',
                function(e) {
                    fx.setOptions(options, enterFx).start(enter)
                });
                el.addEvent('mouseleave',
                function(e) {
                    fx.setOptions(options, leaveFx).start(leave)
                })
            }
        })
    }
});
YOOMorph.implement(new Options);

var YOOBackgroundFx = new Class({
    initialize: function(options) {
        this.setOptions({
            transition: Fx.Transitions.linear,
            duration: 9000,
            wait: false,
            colors: ['#FFFFFF', '#999999']
        },
        options);
        var body = new Element(document.body);
        var fx = body.effects(this.options);
        var index = 0;
        var colors = this.options.colors;
        var timer = animate.periodical(this.options.duration * 2);
        animate();
        function animate() {
            fx.start({
                'background-color': colors[index]
            });
            if (index + 1 >= colors.length) {
                index = 0
            } else {
                index++
            }
        }
    }
});

YOOBackgroundFx.implement(new Options);

var YOOAccordionMenu = new Class({
    initialize: function(togglers, elements, options) {
        this.setOptions({
            accordion: 'default'
        },
        options);
        this.togs = togglers;
        this.elms = elements;
        switch (this.options.accordion) {
        case 'slide':
            this.createSlide();
            break;
        default:
            this.createDefault()
        }
    },
    createDefault: function() {
        var options = {};
        if (!$defined(this.options.display) && !$defined(this.options.show)) {
            options = {
                show: -1
            }
        }
        $ES(this.togs).each(function(tog, i) {
            if (tog.hasClass('active')) options = {
                show: i
            }
        }.bind(this));
        var accordionMenu = new Fx.Accordion(this.togs, this.elms, $extend(this.options, options))
    },
    createSlide: function() {
        $ES(this.togs).each(function(tog, i) {
            var span = tog.getElement('span');
            var ul = tog.getElement(this.elms);
            var fx = new Fx.Slide(ul, {
                transition: Fx.Transitions.linear,
                duration: 250
            });
            if (! (tog.hasClass('active') || this.options.display == 'all' || this.options.display == i)) {
                fx.hide()
            }
            span.addEvent('click',
            function() {
                fx.toggle()
            })
        }.bind(this))
    }
});

YOOAccordionMenu.implement(new Options);

var YOOFancyMenu = new Class({
    initialize: function(menu, options) {
        this.setOptions({
            transition: Fx.Transitions.sineInOut,
            duration: 500,
            wait: false,
            onClick: Class.empty,
            opacity: 1,
            mode: 'move',
            slideOffset: 30,
            colorSelector: ['red', 'pink', 'blue', 'green', 'orange', 'yellow', 'lilac', 'turquoise', 'light_blue', 'dark_blue', 'pink'],
            itemSelector: 'li.level1',
            activeSelector: 'li.active'
        },
        options);
        this.menu = $(menu),
        this.current = this.menu.getElement(this.options.activeSelector);
        this.li = [];
        this.div = [];
        this.menu.getElements(this.options.itemSelector).each(function(item, i) {
            this.createBackground(item, i);
            item.addEvent('click',
            function(event) {
                this.clickItem(event, item)
            }.bind(this));
            item.addEvent('mouseenter',
            function() {
                this.mouseenterItem(item, i)
            }.bind(this));
            if (this.options.mode == 'move') {
                item.addEvent('mouseleave',
                function() {
                    this.mouseleaveItem(this.current, i)
                }.bind(this))
            } else {
                item.addEvent('mouseleave',
                function() {
                    this.mouseleaveItem(item, i)
                }.bind(this))
            }
        }.bind(this));
        if (this.options.mode == 'move') {
            if (this.current) {
                this.setCurrent(this.current)
            } else {
                var first = this.menu.getElement('li');
                first.addClass('active');
                first.addClass('current');
                this.setCurrent(first)
            }
        }
    },
    createBackground: function(item, i) {
        if (this.options.mode == 'move' && i != 0) return;
        var css = 'fancy ' + 'bg' + (i + 1);
        this.options.colorSelector.each(function(col, i) {
            if (item.hasClass(col)) {
                css += ' bg-' + col
            }
        });
        this.div[i] = new Element('div', {
            'class': 'fancy-1'
        }).adopt(new Element('div', {
            'class': 'fancy-2'
        }).adopt(new Element('div', {
            'class': 'fancy-3'
        })));
        this.div[i].fx = this.div[i].effects(this.options);
        this.li[i] = new Element('li', {
            'class': css
        }).adopt(this.div[i]).injectInside(this.menu);
        this.li[i].fx = this.li[i].effects(this.options)
    },
    setCurrent: function(item) {
        this.li[0].setStyles({
            'left': item.offsetLeft,
            'width': item.offsetWidth,
            'visibility': 'visible',
            'opacity': this.options.opacity
        });
        this.current = item
    },
    clickItem: function(event, item) {
        if (!this.current) this.setCurrent(item);
        this.current = item;
        this.options.onClick(new Event(event), item)
    },
    mouseenterItem: function(item, i) {
        switch (this.options.mode) {
        case 'fade':
            this.fadeFx(item, i, true);
            break;
        case 'slide':
            this.slideFx(item, i, true);
            break;
        default:
            this.moveFx(item, 0)
        }
    },
    mouseleaveItem: function(item, i) {
        switch (this.options.mode) {
        case 'fade':
            this.fadeFx(item, i, false);
            break;
        case 'slide':
            this.slideFx(item, i, false);
            break;
        default:
            this.moveFx(item, 0)
        }
    },
    moveFx: function(item, i) {
        if (!this.current) return;
        this.li[i].fx.custom({
            'left': [this.li[i].offsetLeft, item.offsetLeft],
            'width': [this.li[i].offsetWidth, item.offsetWidth]
        })
    },
    fadeFx: function(item, i, show) {
        if (show) {
            this.li[i].fx.setOptions(this.options);
            this.li[i].fx.set({
                'left': item.offsetLeft,
                'width': item.offsetWidth
            });
            this.li[i].fx.custom({
                'opacity': [0, 1]
            })
        } else {
            var dur = this.options.duration * 2;
            this.li[i].fx.setOptions({
                duration: dur
            });
            this.li[i].fx.custom({
                'opacity': [1, 0]
            })
        }
    },
    slideFx: function(item, i, show) {
        var offset = this.options.slideOffset;
        if (show) {
            this.li[i].fx.set({
                'opacity': 1,
                'left': item.offsetLeft,
                'width': item.offsetWidth
            });
            this.div[i].fx.set({
                'margin-top': offset
            });
            this.div[i].fx.custom({
                'margin-top': [offset, 0]
            })
        } else {
            this.div[i].fx.set({
                'margin-top': 0
            });
            this.div[i].fx.custom({
                'margin-top': [0, offset]
            })
        }
    }
});

YOOFancyMenu.implement(new Options);

var YOODropdownMenu = new Class({
    initialize: function(element, options) {
        this.setOptions({
            mode: 'default',
            duration: 600,
            transition: Fx.Transitions.linear,
            wait: false
        },
        options);
        var reset = {
            'width': 0,
            'height': 0,
            'opacity': 0
        };
        switch (this.options.mode) {
        case 'width':
            reset = {
                'width': 0,
                'opacity': 0
            };
            break;
        case 'height':
            reset = {
                'height': 0,
                'opacity': 0
            };
            break
        }
        $$(element).each(function(li) {
            var ul = li.getElement('ul');
            if (ul) {
                var fx = new Fx.Styles(ul, this.options);
                var styles = ul.getStyles('width', 'height', 'opacity');
                ul.setStyles(reset);
                li.addEvents({
                    mouseenter: function() {

                        var parent = li.getParent();
                        if (parent.getStyle('overflow') == 'hidden') parent.setStyle('overflow', 'visible');
                        fx.element.setStyle('overflow', 'hidden');
                        fx.start(styles)
                    },
                    mouseleave: function() {
                        fx.stop();
                        ul.setStyles(reset)
                    }
                })
            }
        }.bind(this))
    }

});

YOODropdownMenu.implement(new Options);

var searchLive = new Class({
    initialize: function(container, options) {
        this.setOptions({
            fieldText: 'search...',
            formSelector: 'form',
            fieldSelector: 'input.searchfield',
            closeSelector: 'button.search-close',
            resultsSelector: 'div.resultbox',
            msgResults: 'Search results',
            msgCategories: 'Search categories',
            msgNoResults: 'No results found',
            msgMoreResults: 'More results',
            url: 'index.php?option=com_search&tmpl=raw&type=json&ordering=&searchphrase=all'
        },
        options);
        this.form = $(container).getElement(this.options.formSelector);
        this.field = $(container).getElement(this.options.fieldSelector);
        this.close = $(container).getElement(this.options.closeSelector);
        this.resultbox = $(container).getElement(this.options.resultsSelector);
        this.sections = new Array();
        this.focussed = false;
        this.selection = false;
        this.observer = new Observer(this.field, this.processSearch.bind(this), {
            delay: 400
        });
        this.field.setProperty('autocomplete', 'off');
        this.field.addEvents({
            focus: this.toggleFocus.bind(this, [true]),
            blur: this.toggleFocus.bind(this, [false])
        });
        this.close.setStyle('display', 'none');
        this.close.addEvents({
            mousedown: this.clearSearch.bindWithEvent(this)
        })
    },
    requestSearch: function() {
        this.close.setStyle('display', 'inline');
        this.close.removeClass('search-close');
        this.close.addClass('search-loader')
    },
    clearSearch: function() {
        this.close.setStyle('display', 'none');
        this.field.value = this.options.fieldText;
        this.clearResults()
    },
    processSearch: function() {
        if (this.field.value) {
            var url = this.options.url;
            var ajaxRequest = new Ajax(url, {
                method: 'post',
                data: 'searchword=' + this.field.value,
                onRequest: this.requestSearch.bind(this),
                onComplete: this.processResults.bind(this)
            }).request()
        }
    },
    processResults: function(data) {
        this.clearResults();
        this.resultbox.setStyle('display', 'block');
        this.close.addClass('search-close');
        this.close.removeClass('search-loader');
        if (data) {
            data = Json.evaluate(data);
            var results = new Element('div', {
                'class': 'resultbox-bg'
            });
            if (data.categories.length > 0) {
                var section = this.createSection('search-categories', this.options.msgCategories);
                data.categories.each(function(res) {
                    this.createResult(res.title, res.text, res.url, res.image).injectInside(section)
                }.bind(this))
            }
            var section = this.createSection('search-results', this.options.msgResults);
            if (data.results.length > 0) {
                data.results.each(function(res) {
                    this.createResult(res.title, res.text, res.url).injectInside(section)
                }.bind(this))
            } else {
                this.createResult(this.options.msgNoResults, data.error, '#').injectInside(section)
            }
            this.sections.each(function(section, i) {
                section.injectInside(results)
            });
            results.injectInside(this.resultbox);
            this.createResultbox(data.results.length > 0).injectInside(this.resultbox)
        }
    },
    clearResults: function() {
        this.sections = new Array();
        this.select = false;
        this.resultbox.empty();
        this.resultbox.setStyle('display', 'none')
    },
    selectResult: function(state) {
        this.selection = state
    },
    createSection: function(css, name) {
        var div = new Element('div', {
            'class': css
        });
        var h3 = new Element('h3', {
            'class': 'search-header'
        }).setHTML(name).injectInside(div);
        var ul = new Element('ul', {
            'class': 'results'
        }).injectAfter(h3);
        this.sections.include(div);
        return ul
    },
    createResult: function(title, text, url, image) {
        var li = new Element('li');
        var a = new Element('a').setProperty('href', url).injectInside(li);
        if (image) var img = new Element('img').setProperty('src', image).injectInside(a);
        var h3 = new Element('h3').setHTML(title).injectInside(a);
        a.appendText(text);
        a.addEvents({
            mouseenter: this.selectResult.bind(this, [true]),
            mouseleave: this.selectResult.bind(this, [false])
        });
        return li
    },
    createResultbox: function(searchMore) {
        var bl = new Element('div', {
            'class': 'resultbox-bl'
        });
        var br = new Element('div', {
            'class': 'resultbox-br'
        }).injectInside(bl);
        var b = new Element('div', {
            'class': 'resultbox-b'
        }).injectInside(br);
        if (searchMore) {
            var a = new Element('a', {
                'class': 'search-more'
            }).injectInside(b);
            var span = new Element('span', {
                'class': 'search-more'
            }).injectInside(a);
            a.appendText(this.options.msgMoreResults);
            a.addEvents({
                mouseenter: this.selectResult.bind(this, [true]),
                mouseleave: this.selectResult.bind(this, [false]),
                mousedown: function() {
                    this.form.submit()
                }.bind(this)
            })
        }
        return bl
    },
    toggleFocus: function(state) {
        this.focussed = state;
        if (!state && !this.selection) this.clearResults()
    }
});

searchLive.implement(new Options);
var Observer = new Class({
    options: {
        periodical: false,
        delay: 1000
    },
    initialize: function(el, onFired, options) {
        this.setOptions(options);
        this.addEvent('onFired', onFired);
        this.element = $(el);
        this.listener = this.fired.bind(this);
        this.value = this.element.getValue();
        if (this.options.periodical) this.timer = this.listener.periodical(this.options.periodical);
        else this.element.addEvent('keyup', this.listener)
    },
    fired: function() {
        var value = this.element.getValue();
        if (this.value == value) return;
        this.clear();
        this.value = value;
        this.timeout = this.fireEvent.delay(this.options.delay, this, ['onFired', [value]])
    },
    clear: function() {
        $clear(this.timeout);
        return this
    }
});
Observer.implement(new Options);
Observer.implement(new Events);

/* Copyright (C) 2007 - 2009 YOOtheme GmbH */

var Tools = {

    start: function() {

        /* Match height of div tags */
        Tools.setDivHeight();

        /* Accordion menu */
        /*new YOOAccordionMenu('div#middle ul.menu li.toggler', 'ul.accordion', {
            accordion: 'slide'
        });*/

        /* Fancy menu */
        /*new YOOFancyMenu($E('ul', 'menu'), { mode: 'fade', transition: Fx.Transitions.linear, duration: 500 });*/

        /* Dropdown menu */
       /* new YOODropdownMenu('div#menu li.parent', {
            mode: 'height',
            transition: Fx.Transitions.Expo.easeOut
        });*/

        /* Morph: color settings */
       /* var page = $('page');

       /* var enterColor = '#000000';*/

      /*  if (page.hasClass('green')) enterColor = '#97AF82';
        if (page.hasClass('pink')) enterColor = '#B995B1';
        if (page.hasClass('orange')) enterColor = '#D1934E';
        if (page.hasClass('blue')) enterColor = '#639FB7';
        if (page.hasClass('yellow')) enterColor = '#AEAC57';
        if (page.hasClass('lilac')) enterColor = '#87829D';
        if (page.hasClass('turquoise')) enterColor = '#789696';
        if (page.hasClass('black')) enterColor = '#3C372D';*/

        /* Morph: main menu - level1 (background) */
      /*  var menuEnter = {
            'color': enterColor
        };
        //var menuLeave = { 'background-color': '#E6E6D2' };
        var menuLeave = {
            'color': '#000000'
        };
        //var menuLeave = { 'background': 'transparent' };		
        new YOOMorph('div#menu li.level1 span', '#000000', '#000000', {
            transition: Fx.Transitions.linear,
            duration: 100,
            ignoreClass: 'active'
        },
        {
            transition: Fx.Transitions.sineIn,
            duration: 300
        },
        '.level1');*/

        /* Morph: main menu - level2 and deeper (background) */
       /* var menuEnter = {
            'margin-left': 0,
            'margin-right': 0,
            'text-indent': 20
        };
        var menuLeave = {
            'margin-left': 5,
            'margin-right': 5,
            'text-indent': 15
        };*/

       /* var selector = 'div#menu li.level2 a, div#menu li.level2 span.separator';

        /* fix for Opera because Mootools 1.1 is not compatible with latest Opera version */

       /* if (window.opera) {
            selector = 'div#menu li.item1 li.level2 a, div#menu li.item1 li.level2 span.separator, div#menu li.item2 li.level2 a, div#menu li.item2 li.level2 span.separator, div#menu li.item3 li.level2 a, div#menu li.item3 li.level2 span.separator, div#menu li.item4 li.level2 a, div#menu li.item4 li.level2 span.separator, div#menu li.item5 li.level2 a, div#menu li.item5 li.level2 span.separator, div#menu li.item6 li.level2 a, div#menu li.item6 li.level2 span.separator, div#menu li.item7 li.level2 a, div#menu li.item7 li.level2 span.separator';
        }

        new YOOMorph(selector, menuEnter, menuLeave, {
            transition: Fx.Transitions.expoOut,
            duration: 0
        },
        {
            transition: Fx.Transitions.sineIn,
            duration: 200
        });
*/
        /* Morph: main menu - level1 (color) */
        /*var menuEnter = {
            'color': '#000000'
        };
        var menuLeave = {
            'color': '#323232'
        };

        new YOOMorph('div#menu li.level1', menuEnter, menuLeave, {
            transition: Fx.Transitions.linear,
            duration: 0,
            ignoreClass: 'active'
        },
        {
            transition: Fx.Transitions.sineIn,
            duration: 200
        },
        '.level1');*/

        /* Morph: main menu - level1 subline (color) */
       /* var menuEnter = {
            'color': '#ffffff'
        };
        var menuLeave = {
            'color': '#646464'
        };*/

        /*new YOOMorph('div#menu li.level1', menuEnter, menuLeave, {
            transition: Fx.Transitions.linear,
            duration: 0,
            ignoreClass: 'active'
        },
        {
            transition: Fx.Transitions.sineIn,
            duration: 200
        },
        'span.sub');*/

        /* Morph: sub menu (left/right) */
        var submenuEnter = {
            'margin-left': 0,
            'margin-right': 0,
            'padding-left': 5
        };
        var submenuLeave = {
            'margin-left': 5,
            'margin-right': 5,
            'padding-left': 0
        };

        new YOOMorph('div#middle ul.menu a, div#middle ul.menu span.separator', submenuEnter, submenuLeave, {
            transition: Fx.Transitions.expoOut,
            duration: 0
        },
        {
            transition: Fx.Transitions.sineIn,
            duration: 200
        });

        /* Morph: module (hover) */
        var moduleEnter = {
            'background-color': '#F5F5E6'
        };
        var moduleLeave = {
            'background-color': '#ffffff'
        };

        new YOOMorph('div.mod-hover div.box-2', moduleEnter, moduleLeave, {
            transition: Fx.Transitions.expoOut,
            duration: 100
        },
        {
            transition: Fx.Transitions.sineIn,
            duration: 300
        });

        /* Smoothscroll */
        new SmoothScroll({
            duration: 500,
            transition: Fx.Transitions.Expo.easeOut
        });
    },

    /* Include script */
    include: function(library) {
        $ES('script').each(function(s, i) {
            var src = s.getProperty('src');
            var path = '';
            if (src && src.match(/yoo_tools\.js(\?.*)?$/)) path = src.replace(/yoo_tools\.js(\?.*)?$/, '');
            if (src && src.match(/template\.js\.php(\?.*)?$/)) path = src.replace(/template\.js\.php(\?.*)?$/, '');
            if (path != '') document.write('<script language="javascript" src="' + path + library + '" type="text/javascript"></script>');
        });
    },

    /* Match height of div tags */
    setDivHeight: function() {
        YOOBase.matchDivHeight('div.topbox div.deepest', 40);
        YOOBase.matchDivHeight('div.bottombox div.deepest', 40);
        YOOBase.matchDivHeight('div.maintopbox div.deepest', 40);
        YOOBase.matchDivHeight('div.mainbottombox div.deepest', 40);
        YOOBase.matchDivHeight('div.contenttopbox div.deepest', 40);
        YOOBase.matchDivHeight('div.contentbottombox div.deepest', 40);
    }

};





/* Load IE6 fix */
if (window.ie6) {
    Tools.include('addons/ie6fix.js');
    Tools.include('addons/ie6png.js');
    Tools.include('ie6fix.js');
}

/* faq */
window.addEvent('domready', function() {

if(showShadow && $('body_shadow')) {
if($('right_outside')){		
	if($('middle').clientHeight > $('right_outside').clientHeight) 
	$('body_shadow').setStyle('display','block');
}else{
	$('body_shadow').setStyle('display','block');
}
}

Tools.start();
							
if($('faq_accordion'))	{								 
	var accordion = new Accordion($$('.toggler'),$$('.element'), {
		start:-1,
		opacity: 0,
		onActive: function(toggler) { toggler.setStyle('background', '#D9E2EE'); toggler.setStyle('color', '#0347B9'); toggler.setStyle('padding', '3px'); },
		onBackground: function(toggler) { toggler.setStyle('background', '#fff'); toggler.setStyle('color', '#464646'); toggler.setStyle('padding', '5px 3px'); }
	});
}

//plan chooser
if($('size-container')){

		//size S
		$('sizeS').addEvent('click',function(){	
			if($('sizeS').className != 'size-s-on'){ 
			  changeSizesOff(); 
			  this.className = 'size-s-on'; 
			  $('plan_selected').value = 's';}
		});		
		
		$('sizeS').addEvent('mouseover',function(){ if($('sizeS').className != 'size-s-on') this.className = 'size-s-over';	});
		$('sizeS').addEvent('mouseout',function(){ if(($('plan_selected').value != 's') && ($('sizeS').className != 'size-s-on'))this.className = 'size-s-off';});	
		
		//size M
		$('sizeM').addEvent('click',function(){	
			if($('sizeM').className != 'size-m-on'){ 
			  changeSizesOff(); 
			  this.className = 'size-m-on'; 
			  $('plan_selected').value = 'm';}
		});		
		
		$('sizeM').addEvent('mouseover',function(){ if($('sizeM').className != 'size-m-on') this.className = 'size-m-over';	});
		$('sizeM').addEvent('mouseout',function(){ if(($('plan_selected').value != 'm') && ($('sizeM').className != 'size-m-on'))this.className = 'size-m-off';});			
		
		//size L
		$('sizeL').addEvent('click',function(){	
			if($('sizeL').className != 'size-l-on'){ 
			  changeSizesOff(); 
			  this.className = 'size-l-on'; 
			  $('plan_selected').value = 'l';}
		});		
		
		$('sizeL').addEvent('mouseover',function(){ if($('sizeL').className != 'size-l-on') this.className = 'size-l-over';	});
		$('sizeL').addEvent('mouseout',function(){ if(($('plan_selected').value != 'l') && ($('sizeL').className != 'size-l-on'))this.className = 'size-l-off';});			
		
		//size XL
		$('sizeXL').addEvent('click',function(){	
			if($('sizeXL').className != 'size-xl-on'){ 
			  changeSizesOff(); 
			  this.className = 'size-xl-on'; 
			  $('plan_selected').value = 'xl';}
		});		
		
		$('sizeXL').addEvent('mouseover',function(){ if($('sizeXL').className != 'size-xl-on') this.className = 'size-xl-over';	});
		$('sizeXL').addEvent('mouseout',function(){ if(($('plan_selected').value != 'xl') && ($('sizeXL').className != 'size-xl-on'))this.className = 'size-xl-off';});				
	


}//end plan chooser



});

function changeSizesOff(){
	$('sizeS').className = 'size-s-off';		
	$('sizeM').className = 'size-m-off';	
	$('sizeL').className = 'size-l-off';	
	$('sizeXL').className = 'size-xl-off';		
}


var quoteErrorMessage = new Array('','Business Name','Name','Email','Phone','Bussiness URL','Service','Project Type','Project start date');

function checkQuote(){
var qFrom = document.ChronoContact_requestquote;

//bussiness
if(qFrom.business_name.value == '' || qFrom.business_name.value == null){
	qFrom.business_name.focus();
	qFrom.business_name.style.border = '1px solid red';
	checkQuoteAlert(quoteErrorMessage[1]);	
	return false;
}else{qFrom.business_name.style.border = '1px solid #d7d7d7';}

//name
if(qFrom.your_name.value == '' || qFrom.your_name.value == null){
	qFrom.your_name.focus();
	qFrom.your_name.style.border = '1px solid red';
	checkQuoteAlert(quoteErrorMessage[2]);	
	return false;
}else{qFrom.your_name.style.border = '1px solid #d7d7d7';}

// restore
qFrom.your_mail.style.border = '1px solid #d7d7d7';
qFrom.your_phone.style.border = '1px solid #d7d7d7';

if(qFrom.contact_preference[0].checked){
	
  if(qFrom.your_mail.value == '' || qFrom.your_mail.value == null || !isValidEmail(qFrom.your_mail.value)){
	  qFrom.your_mail.focus();
	  qFrom.your_mail.style.border = '1px solid red';
	  checkQuoteAlert(quoteErrorMessage[3]);	
	  return false;
  }else{qFrom.your_mail.style.border = '1px solid #d7d7d7'}

}else{

if(qFrom.your_phone.value == '' || qFrom.your_phone.value == null){
	  qFrom.your_phone.focus();
	  qFrom.your_phone.style.border = '1px solid red';
	  checkQuoteAlert(quoteErrorMessage[4]);	
	  return false;
  }else{qFrom.your_phone.style.border = '1px solid #d7d7d7';}	

}

//url
if(!isValidHttp(qFrom.your_url.value)){
	qFrom.your_url.focus();
	qFrom.your_url.style.border = '1px solid red';
	checkQuoteAlert(quoteErrorMessage[5]);	
	return false;
}else{qFrom.your_url.style.border = '1px solid #d7d7d7';}

//project service_required
if(qFrom.service_required.value == ''){
	  qFrom.service_required.focus();
	  qFrom.service_required.style.border = '1px solid red';
	  checkQuoteAlert(quoteErrorMessage[6]);	
	  return false;
  }else{qFrom.service_required.style.border = '1px solid #d7d7d7';}	
  
//project service_required
if(qFrom.project_type.value == ''){
	  qFrom.project_type.focus();
	  qFrom.project_type.style.border = '1px solid red';
	  checkQuoteAlert(quoteErrorMessage[7]);	
	  return false;
  }else{qFrom.project_type.style.border = '1px solid #d7d7d7';}	  
  
//project service_required
if(qFrom.project_start_date.value == ''){
	  qFrom.project_start_date.focus();
	  qFrom.project_start_date.style.border = '1px solid red';
	  checkQuoteAlert(quoteErrorMessage[7]);	
	  return false;
  }else{qFrom.project_start_date.style.border = '1px solid #d7d7d7';}	    




return true;
}

function isValidEmail(str) {
   return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
 }
function isValidHttp(str) {
	if(str.indexOf(".") > 2) return true; else return false;

}
function isNumberKey(evt){
   var charCode = (evt.which) ? evt.which : event.keyCode
   if (charCode > 31 && (charCode < 48 || charCode > 57))
	  return false;

   return true;
}



function checkQuoteAlert(message){
	/*$('popup_quote_inner').innerHTML = message;	
	showBox('popup_quote');
	setTimeout('closeQuoteAlert()',1800);*/
}
function closeQuoteAlert(){
	showBox('popup_quote');
}

var showBox = null;
var boxes = [];
showBox = function (box) {
	box = $(box);
	if (!box) return;
	boxes.include(box);
	if (box.getStyle('display') == 'none') {
		box.setStyles({
			display: 'block',
			opacity: 0
		});
	}
	if (box.status == 'show') {
		//hide
		box.status = 'hide';
		var fx = new Fx.Style (box,'opacity');
		fx.stop();
		fx.start (box.getStyle('opacity'), 0);
	} else {
		boxes.each(function(box1){
			if (box1!=box && box1.status=='show') {
				box1.status = 'hide';
				var fx = new Fx.Style (box1,'opacity');
				fx.stop();
				fx.start (box1.getStyle('opacity'), 0);
			}
		},this);
		box.status = 'show';
		var fx = new Fx.Style (box,'opacity',{onComplete:function(){}});
		fx.stop();
		fx.start (box.getStyle('opacity'), 1);
	}
}



function call_me(){
	document.getElementById('inputOne').style.display = 'none';
	document.getElementById('inputResult').style.display = 'block';	
	document.callonme.submit();
}
/* <![CDATA[ */
var errorMSG = 'Error processing';

var please_wait = 'Please wait';
var errorMSG = 'Error processing';
var succesMSG = 'Succes sending';
var missing_email = 'Please enter your email';
var missing_name = 'Please enter your name';
var missing_message = 'Please enter your message';
var missing_cv = 'Please enter your portfolio';


//general enguery
function submitFormGeneral(){
  if($('name').value == '' || $('name').value == null){
	  //showMissing(1,missing_name,true);
	  $('name').focus();
	  $('name').setStyle("border","1px solid red");
  return;
  }else{ $('name').setStyle("border","1px solid #C8C8C8"); }
  
  if(!checkMail($('email').value)){
	//showMissing(1,missing_email,true);
	$('email').focus();
	$('email').setStyle("border","1px solid red");
	return;
  }else{ $('email').setStyle("border","1px solid #C8C8C8"); }
  
  if($('message').value == '' || $('message').value == null){
	  //showMissing(1,missing_message,true);
	  $('message').focus();
	  $('message').setStyle("border","1px solid red");	  
  return;
  }else{ $('message').setStyle("border","1px solid #C8C8C8"); } 

$('contact_tab_1c_result').setStyle('display','block')
$('contact_tab_1_result').innerHTML = please_wait;

setTimeout("sendPost2Process()",1500);




}

function sendPost2Process(){
	
		
	
	var url = '/en/component/form/?tmpl=component';
	var params = '';
	params = "name="+$('name').value+"&";
	params += "company="+$('company').value+"&";
	params += "email="+$('email').value+"&";
	params += "phone="+$('phone').value+"&";
	params += "date="+$('date').value+"&";	
	params += "budget="+$('budget').value+"&";	
	params += "url="+$('url').value+"&";
	params += "message="+$('message').value+"&";
	params += "emailTO=info@attshop.dk&";
	params += "id=x4a72faa1e4d82&";
	params += "hash=ab012e323a101d2de2a852a3fceb4040&";
	params += "type=quote";	

	var x = new Ajax(url,{postBody:params, onComplete: returnMSG}).request();
}


function returnMSG(request){
	if(request.between('[RESULT]','[/RESULT]') == '1'){
		$('contact_tab_1_result').setStyle('background','url("/images/contact/succes.png") no-repeat');
		$('contact_tab_1_result').innerHTML = succesMSG;		
		}else{
		$('contact_tab_1_result').setStyle('background','url("/images/contact/error.png") no-repeat');
		$('contact_tab_1_result').innerHTML = errorMSG;		
	}
}

function checkMail(str){
  var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
  if (filter.test(str))
	  testresults=true
	  else
		  testresults=false
  return testresults;
}



function str_replace(search, replace, subject) {
    var s = subject;
    var ra = r instanceof Array, sa = s instanceof Array;
    var f = [].concat(search);
    var r = [].concat(replace);
    var i = (s = [].concat(s)).length;
    var j = 0;
    
    while (j = 0, i--) {
        if (s[i]) {
            while (s[i] = (s[i]+'').split(f[j]).join(ra ? r[j] || "" : r[0]), ++j in f){};
        }
    }
 
    return sa ? s : s[0];
}

/**
 * Usage  var you = 'hello you guys'.between('hello ',' guys');
 * you = 'you';
 */
String.prototype.between = function(prefix, suffix) {
  s = this;
  var i = s.indexOf(prefix);
  if (i >= 0) {
    s = s.substring(i + prefix.length);
  }
  else {
    return '';
  }
  if (suffix) {
    i = s.indexOf(suffix);
    if (i >= 0) {
      s = s.substring(0, i);
    }
    else {
      return '';
    }
  }
  return s;
}

window.addEvent('domready', function(){

	$$('input.DatePicker').each( function(el){
		new DatePicker(el);
	});

});

var DatePicker = new Class({

	/* set and create the date picker text box */
	initialize: function(dp){

		// Options defaults
		this.dayChars = 1; // number of characters in day names abbreviation
		this.dayNames = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
		this.daysInMonth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
		this.format = 'mm/dd/yyyy';
		this.monthNames = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
		this.startDay = 7; // 1 = week starts on Monday, 7 = week starts on Sunday
		this.yearOrder = 'asc';
		this.yearRange = 10;
		this.yearStart = (new Date().getFullYear());


		// Finds the entered date, or uses the current date
		if(dp.value != '') {
			dp.then = new Date(dp.value);
			dp.today = new Date();
		} else {
			dp.then = dp.today = new Date();
		}
		// Set beginning time and today, remember the original
		dp.oldYear = dp.year = dp.then.getFullYear();
		dp.oldMonth = dp.month = dp.then.getMonth();
		dp.oldDay = dp.then.getDate();
		dp.nowYear = dp.today.getFullYear();
		dp.nowMonth = dp.today.getMonth();
		dp.nowDay = dp.today.getDate();

		// Pull the rest of the options from the alt attr
		if(dp.alt) {
			options = Json.evaluate(dp.alt);
		} else {
			options = [];
		}
		dp.options = {
			monthNames: (options.monthNames && options.monthNames.length == 12 ? options.monthNames : this.monthNames) || this.monthNames, 
			daysInMonth: (options.daysInMonth && options.daysInMonth.length == 12 ? options.daysInMonth : this.daysInMonth) || this.daysInMonth, 
			dayNames: (options.dayNames && options.dayNames.length == 7 ? options.dayNames : this.dayNames) || this.dayNames,
			startDay : options.startDay || this.startDay,
			dayChars : options.dayChars || this.dayChars, 
			format: options.format || this.format,
			yearStart: options.yearStart || this.yearStart,
			yearRange: options.yearRange || this.yearRange,
			yearOrder: options.yearOrder || this.yearOrder
		};
		dp.setProperties({'id':dp.getProperty('name'), 'readonly':true});
		dp.container = false;
		dp.calendar = false;
		dp.interval = null;
		dp.active = false;
		dp.onclick = dp.onfocus = this.create.pass(dp, this);
	},

	/* create the calendar */
	create: function(dp){
		if (dp.calendar) return false;

		// Hide select boxes while calendar is up
		if(window.ie6){
			$$('select').addClass('dp_hide');
		}
		
		/* create the outer container */
		dp.container = new Element('div', {'class':'dp_container'}).injectBefore(dp);
		
		/* create timers */
		dp.container.onmouseover = dp.onmouseover = function(){
			$clear(dp.interval);
		};
		dp.container.onmouseout = dp.onmouseout = function(){
			dp.interval = setInterval(function(){
				if (!dp.active) this.remove(dp);
			}.bind(this), 500);
		}.bind(this);
		
		/* create the calendar */
		dp.calendar = new Element('div', {'class':'dp_cal'}).injectInside(dp.container);
		
		/* create the date object */
		var date = new Date();
		
		/* create the date object */
		if (dp.month && dp.year) {
			date.setFullYear(dp.year, dp.month, 1);
		} else {
			dp.month = date.getMonth();
			dp.year = date.getFullYear();
			date.setDate(1);
		}
		dp.year % 4 == 0 ? dp.options.daysInMonth[1] = 29 : dp.options.daysInMonth[1] = 28;
		
		/* set the day to first of the month */
		var firstDay = (1-(7+date.getDay()-dp.options.startDay)%7);
		
		
		
		/* create the month select box */
		monthSel = new Element('select', {'id':dp.id + '_monthSelect'});
		for (var m = 0; m < dp.options.monthNames.length; m++){
			monthSel.options[m] = new Option(dp.options.monthNames[m], m);
			if (dp.month == m) monthSel.options[m].selected = true;
		}
		
		/* create the year select box */
		yearSel = new Element('select', {'id':dp.id + '_yearSelect'});
		i = 0;
		dp.options.yearStart ? dp.options.yearStart : dp.options.yearStart = date.getFullYear();
		if (dp.options.yearOrder == 'desc'){
			for (var y = dp.options.yearStart; y > (dp.options.yearStart - dp.options.yearRange - 1); y--){
				yearSel.options[i] = new Option(y, y);
				if (dp.year == y) yearSel.options[i].selected = true;
				i++;
			}
		} else {
			for (var y = dp.options.yearStart; y < (dp.options.yearStart + dp.options.yearRange + 1); y++){
				yearSel.options[i] = new Option(y, y);
				if (dp.year == y) yearSel.options[i].selected = true;
				i++;
			}
		}
		
		/* start creating calendar */
		calTable = new Element('table');
		calTableThead = new Element('thead');
		calSelRow = new Element('tr');
		calSelCell = new Element('th', {'colspan':'7'});
		monthSel.injectInside(calSelCell);
		yearSel.injectInside(calSelCell);
		calSelCell.injectInside(calSelRow);
		calSelRow.injectInside(calTableThead);
		calTableTbody = new Element('tbody');
		
		/* create day names */
		calDayNameRow = new Element('tr');
		for (var i = 0; i < dp.options.dayNames.length; i++) {
			calDayNameCell = new Element('th');
			calDayNameCell.appendText(dp.options.dayNames[(dp.options.startDay+i)%7].substr(0, dp.options.dayChars)); 
			calDayNameCell.injectInside(calDayNameRow);
		}
		calDayNameRow.injectInside(calTableTbody);
		
		/* create the day cells */
		while (firstDay <= dp.options.daysInMonth[dp.month]){
			calDayRow = new Element('tr');
			for (i = 0; i < 7; i++){
				if ((firstDay <= dp.options.daysInMonth[dp.month]) && (firstDay > 0)){
					calDayCell = new Element('td', {'class':dp.id + '_calDay', 'axis':dp.year + '|' + (parseInt(dp.month) + 1) + '|' + firstDay}).appendText(firstDay).injectInside(calDayRow);
				} else {
					calDayCell = new Element('td', {'class':'dp_empty'}).appendText(' ').injectInside(calDayRow);
				}
				// Show the previous day
				if ( (firstDay == dp.oldDay) && (dp.month == dp.oldMonth ) && (dp.year == dp.oldYear) ) {
					calDayCell.addClass('dp_selected');
				}
				// Show today
				if ( (firstDay == dp.nowDay) && (dp.month == dp.nowMonth ) && (dp.year == dp.nowYear) ) {
					calDayCell.addClass('dp_today');
				}
				firstDay++;
			}
			calDayRow.injectInside(calTableTbody);
		}
		
		/* table into the calendar div */
		calTableThead.injectInside(calTable);
		calTableTbody.injectInside(calTable);
		calTable.injectInside(dp.calendar);
		
		/* set the onmouseover events for all calendar days */
		$$('td.' + dp.id + '_calDay').each(function(el){
			el.onmouseover = function(){
				el.addClass('dp_roll');
			}.bind(this);
		}.bind(this));
		
		/* set the onmouseout events for all calendar days */
		$$('td.' + dp.id + '_calDay').each(function(el){
			el.onmouseout = function(){
				el.removeClass('dp_roll');
			}.bind(this);
		}.bind(this));
		
		/* set the onclick events for all calendar days */
		$$('td.' + dp.id + '_calDay').each(function(el){
			el.onclick = function(){
				ds = el.axis.split('|');
				dp.value = this.formatValue(dp, ds[0], ds[1], ds[2]);
				this.remove(dp);
			}.bind(this);
		}.bind(this));
		
		/* set the onchange event for the month & year select boxes */
		monthSel.onfocus = function(){ dp.active = true; };
		monthSel.onchange = function(){
			dp.month = monthSel.value;
			dp.year = yearSel.value;
			this.remove(dp);
			this.create(dp);
		}.bind(this);
		
		yearSel.onfocus = function(){ dp.active = true; };
		yearSel.onchange = function(){
			dp.month = monthSel.value;
			dp.year = yearSel.value;
			this.remove(dp);
			this.create(dp);
		}.bind(this);
	},
	
	/* Format the returning date value according to the selected formation */
	formatValue: function(dp, year, month, day){
		/* setup the date string variable */
		var dateStr = '';
		
		/* check the length of day */
		if (day < 10) day = '0' + day;
		if (month < 10) month = '0' + month;
		
		/* check the format & replace parts // thanks O'Rey */
		dateStr = dp.options.format.replace( /dd/i, day ).replace( /mm/i, month ).replace( /yyyy/i, year );
		dp.month = dp.oldMonth = '' + (month - 1) + '';
		dp.year = dp.oldYear = year;
		dp.oldDay = day;
		
		/* return the date string value */
		return dateStr;
	},
	
	/* Remove the calendar from the page */
	remove: function(dp){
		$clear(dp.interval);
		dp.active = false;
		if (window.opera) dp.container.empty();
		else if (dp.container) dp.container.remove();
		dp.calendar = false;
		dp.container = false;
		$$('select.dp_hide').removeClass('dp_hide');
	}
});


