var Page_ModalDialogVer = "1.7";


function ModalDialogOnLoad() {
    
    if ( !ModalDialogBrowserCapable() ) return;
    if (typeof(Page_ModalDialogs) == "undefined") return;


    var i, modalDialogButton;
    for (i = 0; i < Page_ModalDialogs.length; i++) {
        modalDialogButton = Page_ModalDialogs[i];
        if (typeof(modalDialogButton) == "string") {
            modalDialogButton = document.getElementById( modalDialogButton );
        }
        
        if ( typeof(modalDialogButton.url ) == "undefined" ) {
            if ( typeof( modalDialogButton.attributes ) != "undefined" ) {
                modalDialogButton.url = modalDialogButton.attributes["url"].value;
            } else {
                modalDialogButton.url = "DialogTemplate.aspx";
            }
        }

        if ( typeof(modalDialogButton.urlArgument ) == "undefined" ) {
            if ( typeof( modalDialogButton.attributes ) != "undefined" ) {
                modalDialogButton.urlArgument = modalDialogButton.attributes["urlArgument"].value;
            } else {
                modalDialogButton.urlArgument = "";
            }
        }

        if ( typeof(modalDialogButton.urlFeature ) == "undefined" ) {
            if ( typeof( modalDialogButton.attributes ) != "undefined" ) {
                modalDialogButton.urlFeature = modalDialogButton.attributes["urlFeature"].value;
            } else {
                modalDialogButton.urlFeature = "";
            }
        }

        ModalDialogHookupControl(modalDialogButton);
        
    }
}

function ModalDialogBrowserCapable() {
    if ( typeof( document.getElementById ) == "undefined" ) {
        if( typeof( document.all ) != "undefined" ) {
            document.getElementById = function( elementId ) { return document.all[elementId]; };
            return true;
        }
        return false;
    }
    return true;
}



function ModalDialogHookupControl( modalDialogButton ) {
    var ev = modalDialogButton.onclick;
    
    if (typeof(ev) == "function" ) {            
        ev = ev.toString();
        ev = ev.substring(ev.indexOf("{") + 1, ev.lastIndexOf("}"));
    }
    else {
        ev = "";
    }
    var func = new Function("if ( !ModalDialogOnClick( this )) { return false; }" + ev);

    modalDialogButton.onclick = func;
}

function ModalDialogOnClick( modalDialogButton ) {
    return showModalDialog( modalDialogButton.url, modalDialogButton.urlArgument, modalDialogButton.urlFeature );
}

function ModalDialogOnCreate( ) {
    document.title = "Modal Dialog";

    var path = decodeURI(document.URL);
    var pos = path.indexOf("?");
    if (pos > -1) {
        var args = path.substring(pos+1).split("&");
        if (typeof( args ) != "undefined") {
	    for (var i=0; i<args.length; i++) {
               pos = args[i].indexOf("title=");
               if (pos > -1) {
                   document.title = args[i].substring(pos+6);
                   break;
               }
            }
        } 
    }
    
    var urls = window.window.dialogArguments;
    document.writeln("<frameset rows='0,*'>");
    document.writeln("<frame name='header' src='' scrolling='no' noresize>");
    document.writeln("<frame name='main' src='" + urls + "'>");
    document.writeln("</frameset>");
}

function ModalDialogOnClose( confirmation ) {
    window.returnValue = confirmation;
    window.close();
}

