generic = {     
    init: function() {  
        this.env.debug = this.env.query("debug"); 
        if (this.env.debug && this.env.isIE) console.drawWin(); 
    },
    env: { 
        isIE : !!(typeof(ActiveXObject) == 'function'),
        isIE6 : !!(!!(typeof(ActiveXObject) == 'function') && (/MSIE\s6\.0/.test(navigator.appVersion))),
        isFF : Prototype.Browser.Gecko,
        isFF2 : !!(typeof(navigator.product) != 'undefined' && navigator.product == 'Gecko' && !((document.childNodes) && (!navigator.taintEnabled)) && navigator.userAgent.toLowerCase().split(' firefox/')[1].split('.')[0] == '2'),
        isFF3 : !!(typeof(navigator.product) != 'undefined' && navigator.product == 'Gecko' && !((document.childNodes) && (!navigator.taintEnabled)) && navigator.userAgent.toLowerCase().split(' firefox/')[1].split('.')[0] == '3'),
        isMac    : !!(/macppc|macintel/.test(navigator.platform.toLowerCase())),
        isSafari : !!(/Safari/.test(navigator.userAgent)),
        
        domain : window.location.protocol + "//" + window.location.hostname,
        
        query: function(key) {
            if (typeof generic.env.parsedQuery == "undefined") {
                generic.env.parsedQuery = window.location.href.toQueryParams();
            }
            var result = generic.env.parsedQuery[key] || null;
            return result; 
        },
        
        debug: false
        
    }, 
    helpers: { 
        div: new Element("div") //used by Widget class, Prototype way is needed for IE
    },
    events: {
        target: document,
        fire: function(args) {
            //console.log("generic.events.fire: "+args.event + " / " + args.msg);  
            if (!args) return;
            var e = args.event; 
            var msg = (typeof args.msg == "undefined") ? null : args.msg; 
            generic.events.target.fire(e, {msg:msg});
        },
        observe: function(evt, func) {
            if (!evt || !func) return; 
            generic.events.target.observe(evt, function(e){   
                func(e.memo.msg);
            });
        }   
    },
    forms: {
        select: {
            addOption:  function(args) {
                if (!args || !args.menuNode) return;
                var val = args.value;
                var label = args.label || val;
                var options = args.menuNode.options;
                options[options.length] = new Option(label, val);
            },
            setValue: function(args) {
                var idx = 0;
                for (var i=0, len=args.menuNode.options.length; i<len; i++) {
                    if (args.value == args.menuNode.options[i].value) {
                        idx = i;
                        break;
                    }
                }
                args.menuNode.selectedIndex = idx;
            }
        }
    }
}; 

    
// debug    
if (typeof console === "undefined") {
    if (generic && generic.env.debug) {
        console = {
            tracen : 0,
            win : {},
            drawWin: function() {  
                outp = document.createElement("DIV");
                outp.id = "console-window";
                outp.style.cssText = "position:absolute;top:10px;right:10px;width:400px;height:200px;padding:5px;overflow-x:hidden;overflow-y:scroll;background-color:#ffffff;color:#000000;font-size:12px;border:1px solid red;z-index:9999";
                document.body.appendChild(outp);  
                this.win = $(outp.id);
            },
            log: function(s) {
                if ((typeof this.win != "undefined") && (typeof this.win.innerHTML != "undefined")) {
                    this.tracen++;
                    s = (typeof(s) == "undefined") ? "undefined" : s.toString().replace(/\</gi, "&lt;").replace(/\>/gi, "&gt;");
                    this.win.innerHTML = this.win.innerHTML + "<b>" + this.tracen + "</b>. " + s + "<br/>";
                }
            }    
        }   
    } else {
        console = {
            tracen : 0,
            win : {},
            drawWin: function() {  
                return;
            },
            log: function(s) {
                return;
            }    
        }
    }
};

