﻿// JavaScript File provides functions to build modal dialog window 
// working in both IE and Mozilla
/* 
  Notes: 
    1. edge & help attributes do not work. 
    2. "height" & "width" must be entered before "center" 
    3. if you should choose to set "center=yes" do not put in "left" and "top" 
    4. Minimize button not hidden, but when clicked the window will not disappear 
    5. Aside from the aforementioned, all features should react the same *fingers crossed* 
*/ 

//dFeatures = 'dialogHeight: 500px; dialogWidth: 700px; dialogTop: 100px; dialogLeft: 4px; edge: Raised; center: Yes; help: No; resizable: No; status: No;';//default features 
dFeatures = 'center: Yes; help: No; resizable: No; status: No;';//default features 

modalWin = ""; 
function xShowModalDialog( sURL, vArguments, sFeatures ) 
    { 
    sURL=sURL + "&rand="+Math.random();
    if (sURL==null||sURL=='') 
    { 
        alert ("Invalid URL input."); 
        return false; 
    } 
    if (vArguments==null||vArguments=='') 
    { 
        vArguments=''; 
    } 
    if (sFeatures==null||sFeatures=='') 
    { 
        sFeatures=dFeatures; 
    } 
    if (window.navigator.appVersion.indexOf("MSIE")!=-1) 
    { 
        window.showModalDialog ( sURL, vArguments, sFeatures );         
        return false; 
    } 
    
    sFeatures = sFeatures.replace(/ /gi,''); 
    aFeatures = sFeatures.split(";"); 
    sWinFeat = "directories=0,menubar=0,titlebar=0,toolbar=0,"; 
    
    for ( x in aFeatures ) 
    { 
        aTmp = aFeatures[x].split(":"); 
        sKey = aTmp[0].toLowerCase(); 
        sVal = aTmp[1]; 
        switch (sKey) 
        { 
            case "dialogheight": 
                sWinFeat += "height="+sVal+","; 
                pHeight = sVal; 
                break; 
            case "dialogwidth": 
                sWinFeat += "width="+sVal+","; 
                pWidth = sVal; 
                break; 
            case "dialogtop": 
                sWinFeat += "screenY="+sVal+","; 
                break; 
            case "dialogleft": 
                sWinFeat += "screenX="+sVal+","; 
                break; 
            case "resizable": 
                sWinFeat += "resizable="+sVal+","; 
                break; 
            case "status": 
                sWinFeat += "status="+sVal+","; 
                break; 
            case "center": 
                if ( sVal.toLowerCase() == "yes" ) 
                { 
                    sWinFeat += "screenY="+((screen.availHeight-pHeight)/2)+","; 
                    sWinFeat += "screenX="+((screen.availWidth-pWidth)/2)+","; 
                } 
                break; 
        } 
    } 
    modalWin=window.open(String(sURL),"",sWinFeat); 
    if (vArguments!=null&&vArguments!='') 
    { 
        modalWin.dialogArguments=vArguments;         
    } 
} 

function checkFocus() 
{ 
    if (window.navigator.appVersion.indexOf("MSIE")==-1) 
    { 
        if (modalWin!=null && !modalWin.closed) 
        { 
            self.blur(); 
            modalWin.focus(); 
        } 
    } 
} 
