﻿var isfirefox = false;
var ua = navigator.userAgent.toLowerCase();
if (ua.match(/firefox\/([\d.]+)/))
{ isfirefox = true; }
if (isfirefox) {
    FixPrototypeForGecko();
}
function FixPrototypeForGecko() {
    HTMLElement.prototype.__defineGetter__("runtimeStyle", element_prototype_get_runtimeStyle);
    window.constructor.prototype.__defineGetter__("event", window_prototype_get_event);
    Event.prototype.__defineGetter__("srcElement", event_prototype_get_srcElement);
    Event.prototype.__defineGetter__("keyCode", window_prototype_get_keyCode);

    HTMLElement.prototype.__defineSetter__("outerHTML", function(sHTML) {
        var r = this.ownerDocument.createRange();
        r.setStartBefore(this);
        var df = r.createContextualFragment(sHTML);
        this.parentNode.replaceChild(df, this);
        return sHTML;
    });

    HTMLElement.prototype.__defineGetter__("outerHTML", function() {
        var attr;
        var attrs = this.attributes;
        var str = "<" + this.tagName.toLowerCase();
        for (var i = 0; i < attrs.length; i++) {
            attr = attrs[i];
            if (attr.specified)
                str += " " + attr.name + '="' + attr.value + '"';
        }
        if (!this.canHaveChildren)
            return str + ">";
        return str + ">" + this.innerHTML + "</" + this.tagName.toLowerCase() + ">";
    });

    HTMLElement.prototype.__defineGetter__("canHaveChildren", function() {
        switch (this.tagName.toLowerCase()) {
            case "area":
            case "base":
            case "basefont":
            case "col":
            case "frame":
            case "hr":
            case "img":
            case "br":
            case "input":
            case "isindex":
            case "link":
            case "meta":
            case "param":
                return false;
        }
        return true;

    });

    HTMLElement.prototype.click = function() {
        var evt = document.createEvent("MouseEvents");
        evt.initEvent("click", true, true);
        this.dispatchEvent(evt);
    };
}
function element_prototype_get_runtimeStyle() {
    //return style instead...
    return this.style;
}
function window_prototype_get_event() {
    return SearchEvent();
}
function event_prototype_get_srcElement() {
    return this.target;
}
function window_prototype_get_keyCode() {
    return this.which;
}
function SearchEvent() {
    //IE
    if (document.all)
        return window.event;

    func = SearchEvent.caller;
    while (func != null) {
        var arg0 = func.arguments[0];
        if (arg0) {
            if (arg0.constructor == KeyboardEvent)
                return arg0;
        }
        func = func.caller;
    }
    return null;
}

function StopPropagation() {
    if (window.event.stopPropagation)
        window.event.stopPropagation();
    else
        window.event.cancelBubble = true;
    return false;
}
function CancelDefaultAction() {
    if (window.event.preventDefault)
        window.event.preventDefault();
    else
        window.event.returnValue = false;
    return false;
}