﻿// 2010-05-27  Walt Edwards added CloseRadWindow().

function document_onclick() {
    if (window.event.srcElement.tagName == "SPAN") {
        if (window.event.srcElement.parentElement.tagName == "A") {   // It's an ANCHOR tag
            /* 2009-07-06  Walt Edwards commented out because it should no longer be required as the quirks in IE these fixed appear to be gone in IE8.
                 
            var Target = window.event.srcElement.parentElement.target;
            var URL = window.event.srcElement.parentElement.href;
            var i = URL.toLowerCase().indexOf("/app/") + 5;

            if ((URL.length > 0) && (Target.length > 0)) {
            alert(URL);
            if ((URL.substring(i, URL.length).indexOf("://") != -1) && (i > 4)) {   // There is a secondary protocol and domain within the URL, so strip default from beginning
            URL = URL.substring(i, URL.length);
            window.open(URL, Target);
            }
            else if (URL.substring(URL.length - 1, URL.length) != '/') {   // We don't open window if the end of URL is / because it's actually an empty link
            window.open(URL, Target);
            }
            }
            window.event.returnValue = false;   // Intercept before anchor behavior can fire
            */
        }
    }
    else if (window.event.srcElement.tagName == "A") {   // It's an ANCHOR tag 
        var URL = window.event.srcElement.href;
        if (URL.indexOf('StreamResource.axd') != -1) {
            // We've found a resource link, so intercept it and open window with properties we want...
            // 2009-09-08  Walt Edwards updated to use relative path to ShowFile.aspx since it should only be in FILE application.
            URL = URL.replace('StreamResource.axd', '../file/ShowFile.aspx');
            window.open(URL, '_blank');
            window.event.returnValue = false;
        }
    }
}

document.onclick = document_onclick;

function CloseRadWindow() {
    var oWnd = GetRadWindow();
    oWnd.close();
}

function GetRadWindow() {
    var oWindow = null;
    if (window.radWindow) oWindow = window.radWindow;
    else if (window.frameElement.radWindow) oWindow = window.frameElement.radWindow;
    return oWindow;
}

// Syntax:  If Not IsPostBack() Then txtMessage.Attributes.Add("OnKeyPress", "javascript:return PressButtonOnEnter('" & btnSend.ClientID & "',event)")
function PressButtonOnEnter(ButtonID, e) {
    var key;
    if (window.event)
        key = window.event.keyCode; //IE
    else
        key = e.which; // FireFox

    if (key == 13) {
        document.getElementById(ButtonID).click();
        if (window.event)
            event.keyCode = 0; // IE
        else
            e.cancelBubble = true; // FireFox
        return false;
    }
}

// Cancel keystroke or click
function CancelEvent(e) {
    if (window.event) {
        event.cancelBubble = true;  // IE
        event.returnValue = false;
    }
    else {
        e.cancelBubble = true;
        e.returnValue = false;
        e.preventDefault();
    }
        // e.cancelBubble = true;  // FireFox
        // event.returnValue = false;
        // event.stopPropagation();
    return false;
}

// Called by HOMEPaGE data driven pages that want to show details in a dialog.
// Ex. <a href="c:" onclick="javascript: ShowHtmlDialog(313, 'height=350, width=500');">click me</a>
function ShowHtmlDialog(idHTML, Params) {
    window.open("HTML_Dialog.aspx?DSN=SYSTM&idHTML=" + idHTML, '_blank', 'menubar=0,statusbar=0,toolbar=0,' + Params);
    return 0;
}