
var isMSIE;
var found = false;

var StandardRules = {
    'body' : function(){
        if( window.ActiveXObject ) isMSIE = true;
        //breakFrames();
    }/*,


    
    '#msg' : function(element){
        Element.cleanWhitespace(element);
    },


    '#container a.negative' : function(element){
        element.onclick = function(){
            var question = confirm("are you sure you want to delete " + this.rel.replace (/_/gi,' ') +"?");
            if( !question )
                return false;
        }
    },


    'a.icon_hide' : function(element){
        Element.block(element);

        var item        = $(element.rel);
        item.SysBlock   = new fx.SysBlock(item, element, "icon_show", "icon_hide");
        if( item.offsetHeight<=0 ){
            Element.addClassName(element, "icon_show");
            element.title = "show";
        }else{
            Element.addClassName(element, "icon_hide");
            element.title = "hide";
        }

        if( item.offsetHeight > 0) item.style.height = "1%";
        element.onclick = function(){ item.SysBlock.toggle(); }
    },


    '#searchform' : function(element){
        element.onsubmit = function(){
            if( $F('livesearch')!="" && $F('livesearch')!=null && $F('livesearch').length>1 )
                this.submit;
            else
                return false;
        }
    },


    '#livesearch' : function(element){
        element.setAttribute("autocomplete","off");
        var liveSearch = new LiveSearch('livecontainer', sysdir+"index.php/livesearch", 'ajax=true&key=');

        element.onkeyup = function(){
            liveSearch.setTimer(this.value);
        }
        element.onblur = function(){
            setTimeout(liveSearch.hide.bind(liveSearch), 200)
        }
    },


    'a.cancel' : function(element){
        element.onclick = function(){
            if( this.rel ){
                return confirm("are you sure you want to " + this.rel + "?");
            }
        }
    },

    'input.artsave' : function(element){
        element.onmouseup = function(){
            Element.getParentForm(this).submit();
        }
    },

    'input.artcancel' : function(element){
        element.onmouseup = function(){
            this.relForm            = Element.getParentForm(this);
            var inputcancel         = this.relForm.appendChild(document.createElement("p"));
            inputcancel.innerHTML   = "<input type='hidden' name='cancel' value='cancel'/>";

            var question = confirm("are you sure you want to cancel ?");

            if( question )
                this.relForm.submit();
            else
                Element.remove(inputcancel);
        }
    },


    '#filter' : function(form){
        form.onsubmit = function(){
            return false;
        }
    }
    */
};

SiteAttitude.append(StandardRules);




var FormRules = {
    '#frm_suche' : function(element){
        element.onsubmit = function(){
            var elm_sucheinfo       = $('suchehinweis');
            var obj_suchbegriff     = $('suchbegriff');
            var obj_artikelnr       = $('artikelnr');
            var form_action_site    = $F('sitesuche_url');
            var form_action_shop    = $F('shopsuche_url');

            // man beachte > suchbegiff gewinnt vor artikelnr
            if( obj_suchbegriff.value!='' ){
                this.action = form_action_site;
                this.target = '';

                obj_artikelnr.value = ''; // loesche artikelnr-value

                if( obj_suchbegriff.value.length<3 ){
                    elm_sucheinfo.style.display = '';
                    if( obj_suchbegriff.hasClassName('display_fehler')==false ) obj_suchbegriff.addClassName('display_fehler');
                    obj_suchbegriff.focus();
                    return false;
                }else{
                    elm_sucheinfo.style.display = 'none';
                    return true;
                }
            }else if( obj_artikelnr.value!='' ){
                this.action = form_action_shop;
                this.target = '_blank';

                if( obj_artikelnr.value.length<3 ){
                    elm_sucheinfo.style.display = '';
                    if( obj_artikelnr.hasClassName('display_fehler')==false ) obj_artikelnr.addClassName('display_fehler');
                    obj_artikelnr.focus();
                    return false;
                }else{
                    elm_sucheinfo.style.display = 'none';
                    return true;
                }
            }else{
                elm_sucheinfo.style.display = '';
                obj_suchbegriff.focus();
                return false;
            }
        }
    },

    '#suchbegriff' : function(element){
        var cn              = 'display_fehler';
        var elm_sucheinfo   = $('suchehinweis');
        var obj_artikelnr   = $('artikelnr');

         // loesche value in artikelnr
        element.onfocus = function(){ obj_artikelnr.value = ''; }
        element.onkeyup = function(){
            if( this.value.length<3 && this.hasClassName(cn)==false ){ // zeichenanzahl < 3 dann setze fehlerklasse
                this.addClassName(cn);
                if( elm_sucheinfo.style.display == '' ) elm_sucheinfo.style.display = 'none';
            }

            if( this.value.length>2 && this.hasClassName(cn) ){ // zeichenanzahl > 2 dann entferne fehlerklasse und hinweis
                this.removeClassName(cn);
                elm_sucheinfo.style.display = 'none';
            }
        }
    },

    '#artikelnr' : function(element){
        var cn              = 'display_fehler';
        var elm_sucheinfo   = $('suchehinweis');
        var obj_suchbegriff = $('suchbegriff');

        // loesche value in suchbegriff
        element.onfocus = function(){ obj_suchbegriff.value = ''; }
        element.onkeyup = function(){
            if( this.value.length<3 && this.hasClassName(cn)==false ){ // zeichenanzahl < 3 dann setze fehlerklasse
                this.addClassName(cn);
                if( elm_sucheinfo.style.display == '' ) elm_sucheinfo.style.display = 'none';
            }

            if( this.value.length>2 && this.hasClassName(cn) ){ // zeichenanzahl > 2 dann entferne fehlerklasse und hinweis
                this.removeClassName(cn);
                elm_sucheinfo.style.display = 'none';
            }
        }
    },

    'a.link_suche_blaettern' : function(element){
        var seBlFld = $('suche_seite');
        element.onmouseover = function(){
            seBlFld.value = this.rel;
            this.href="javascript:$('frm_suche_blaettern').submit();";
        }
        element.onfocus     = function(){
            seBlFld.value = this.rel;
            this.href="javascript:$('frm_suche_blaettern').submit();";
        }
    }

};

SiteAttitude.append(FormRules);


var ButtonRules = {
    '.toogle_imagesrc' : function(element){
        var old_source = element.src;
        var new_source = old_source.replace("_off.","_ov.");

        element.onmouseover = function(){ this.src = new_source; }
        element.onmouseout  = function(){ this.src = old_source; }

        element.onfocus     = function(){ this.src = new_source; }
        element.onblur      = function(){ this.src = old_source; }
    }


};

SiteAttitude.append(ButtonRules);
