﻿var ie = (document.defaultCharset && document.getElementById && !window.home);

if (ie) {
    //document.write("<style id='hideObject'> object{display:none;} </style>");
}

objectSwap = function() {
    /*if (!document.getElementsByTagName) {
        return;
    }
    var stripQueue = [];
    var objects = document.getElementsByTagName('object');
    for (var i = 0; i < objects.length; i++) {
        var o = objects[i];
        var h = o.outerHTML;
        var params = "";
        var hasFlash = true;
        for (var j = 0; j < o.childNodes.length; j++) {
            var p = o.childNodes[j];
            if (p.tagName == "PARAM") {
                if (p.name == "flashVersion") {
                    hasFlash = detectFlash(p.value);
                    if (!hasFlash) {
                        o.id = (o.id == "") ? ("stripFlash" + i) : o.id;
                        stripQueue.push(o.id);
                        break;
                    }
                }
                params += p.outerHTML;
            }
        }
        if (!hasFlash) {
            continue;
        }
        if (!ie) {
            continue;
        }
        if (o.className.toLowerCase().indexOf("noswap") != -1) {
            continue;
        }
        var tag = h.split(">")[0] + ">";
        var newObject = tag + params + o.innerHTML + " </OBJECT>";
        o.outerHTML = newObject;
    }
    if (stripQueue.length) {
        stripFlash(stripQueue)
    }
    if (ie) {
        //document.getElementById("hideObject").disabled = true;
    }*/
}

detectFlash = function(version) {
    if (navigator.plugins && navigator.plugins.length) {
        var plugin = navigator.plugins["Shockwave Flash"];
        if (plugin == undefined) {
            return false;
        }
        var ver = navigator.plugins["Shockwave Flash"].description.split(" ")[2];
        return (Number(ver) >= Number(version))
    } else if (ie && typeof (ActiveXObject) == "function") {
        try {
            var flash = new ActiveXObject("ShockwaveFlash.ShockwaveFlash." + version);
            return true;
        }
        catch (e) {
            return false;
        }
    }
    return true;
}

stripFlash = function(stripQueue) {
    if (!document.createElement) {
        return;
    }
    for (var i = 0; i < stripQueue.length; i++) {
        var o = document.getElementById(stripQueue[i]);
        var newHTML = o.innerHTML;
        newHTML = newHTML.replace(/<!--\s/g, "");
        newHTML = newHTML.replace(/\s-->/g, "");
        newHTML = newHTML.replace(/<embed/gi, "<span");
        var d = document.createElement("div");
        d.innerHTML = newHTML;
        d.className = o.className;
        d.id = o.id;
        o.parentNode.replaceChild(d, o);
    }
}

function addLoadEvent(func) {
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
        window.onload = func;
    } else {
        window.onload = function() {
            if (oldonload) {
                oldonload();
            }
            func();
        }
    }
}

function addResizeEvent(func) {
    var oldresize = window.onresize;
    if (typeof window.onresize != 'function') {
        window.onresize = func;
    } else {
        window.onresize = function() {
            if (oldresize) {
                oldresize();
            }
            func();
        }
    }
}

addLoadEvent(objectSwap);

function OnWatermarkFocus(elementId, defaultText, styleSheet) {
    if (document.getElementById(elementId).value == defaultText) {
        document.getElementById(elementId).className = styleSheet;
        document.getElementById(elementId).value = '';
    }
}

function OnWatermarkBlur(elementId, defaultText, styleSheet) {

    var textValue = document.getElementById(elementId).value;
    if (textValue == defaultText || textValue.length == 0) {
        document.getElementById(elementId).className = styleSheet;
        document.getElementById(elementId).value = defaultText;
    }
}

function OpenPopup(src, width, height) {
    if (document.all) {
        document.body.insertAdjacentHTML('beforeEnd', '<DIV STYLE="position:absolute;left:0px;top:0px;width:100%;height:100%;z-index:100000;background-color:Blue;" ID="dvModal"/>');
        document.body.insertAdjacentHTML('beforeEnd', '<IFRAME WIDTH="' + width + '" HEIGHT="' + height + '" BORDER="0" FRAMEBORDER="0" SRC="' + src + '" style="z-index:100001;" ID=\"frmPopup\" NAME=\"frmPopup\"><\/IFRAME>');
    }
    else if (document.getElementById) {
        var div = document.createElement('DIV');
        div.id = "dvModal";
        div.style.width = "100%";
        div.style.height = "100%";
        div.style.position = "absolute";
        div.style.top = "0";
        div.style.left = "0";
        div.style.zIndex = 100000;
        div.style.backgroundColor = "Blue";
        document.body.appendChild(div);
        var ifr = document.createElement('IFRAME');
        ifr.src = src;
        ifr.id = "frmPopup";
        ifr.name = "frmPopup";
        ifr.border = "0px";
        ifr.frameBorder = "0px";
        ifr.style.zIndex = 100001;
        ifr.width = width;
        ifr.height = height;
        document.body.appendChild(ifr);
    }

    ShowDeadCenterDiv(width, height, "frmPopup");
}

function ClosePopup() {
    document.body.removeChild(document.getElementById("frmPopup"));
    document.body.removeChild(document.getElementById("dvModal"));
}

function ShowDeadCenterDiv(Xwidth, Yheight, divid) {
    // First, determine how much the visitor has scrolled
    var scrolledX, scrolledY;
    if (self.pageYOffset) {
        scrolledX = self.pageXOffset;
        scrolledY = self.pageYOffset;
    } else if (document.documentElement && document.documentElement.scrollTop) {
        scrolledX = document.documentElement.scrollLeft;
        scrolledY = document.documentElement.scrollTop;
    } else if (document.body) {
        scrolledX = document.body.scrollLeft;
        scrolledY = document.body.scrollTop;
    }

    // Next, determine the coordinates of the center of browser's window
    var centerX, centerY;
    if (self.innerHeight) {
        centerX = self.innerWidth;
        centerY = self.innerHeight;
    } else if (document.documentElement && document.documentElement.clientHeight) {
        centerX = document.documentElement.clientWidth;
        centerY = document.documentElement.clientHeight;
    } else if (document.body) {
        centerX = document.body.clientWidth;
        centerY = document.body.clientHeight;
    }

    // Xwidth is the width of the div, Yheight is the height of the 
    // div passed as arguments to the function: 
    var leftOffset = scrolledX + (centerX - Xwidth) / 2;
    var topOffset = scrolledY + (centerY - Yheight) / 2;
    // The initial width and height of the div can be set in the 
    // style sheet with display:none; divid is passed as an argument to // the function 
    var o = document.getElementById(divid);
    var r = o.style;
    r.position = 'absolute';
    r.top = topOffset + 'px';
    r.left = leftOffset + 'px';
    r.display = "block";
}