/* 
  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* 
    6. Still in the works, so don't expect miracles. Any problems/queries/complaints please don't hesitate. 
  Email: 
    [email]x_goose_x@hotmail.com[/email] 
*/ 

modalWin = ""; 
function xShowModalDialog( sURL, vArguments, sFeatures ) 
    { 
    var modalWin;
    //var dFeatures = 'dialogHeight: 450px; dialogWidth: 650px; dialogTop: 646px; dialogLeft: 4px; edge: Raised; center: Yes; help: Yes; resizable: Yes; status: Yes;';//default features 
    var dFeatures = '';
    
    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) 
    { 
        modalWin = window.showModalDialog ( sURL, vArguments, sFeatures ); 
        return modalWin; 
    } 
    sFeatures = sFeatures.replace(/ /gi,''); 
    aFeatures = sFeatures.split(";"); 
    sWinFeat = "directories=0,menubar=0,titlebar=0,toolbar=0,modal=1,"; 
    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 "scroll": 
                sWinFeat += "scrollbars="+sVal+","; 
                break; 
            case "center": 
                if ( sVal.toLowerCase() == "yes" ) 
                { 
                    sWinFeat += "screenY="+((screen.availHeight-pHeight)/2)+"px,"; 
                    sWinFeat += "screenX="+((screen.availWidth-pWidth)/2)+"px,"; 
                } 
                break; 
        } 
    } 
    modalWin=window.open(String(sURL), "", sWinFeat); 
    if (vArguments!=null&&vArguments!='') 
    { 
        modalWin.dialogArguments=vArguments; 
    } 
    return modalWin;
} 

function checkFocus() 
    { 
    if (window.navigator.appVersion.indexOf("MSIE")==-1) 
        { 
        if (modalWin!=null && !modalWin.closed) 
        { 
            self.blur(); 
            modalWin.focus(); 
        } 
    } 
} 

function openContainer(sContainerElement, sParams, sConfirmText) {
	var HTML, sPageName, sScriptName, sWidth, sHeight, sTitle, sURL, oParam, sMsg
	
	sWidth	= getContainerAttr(sContainerElement +'_width');
	sHeight	= getContainerAttr(sContainerElement +'_height');
	sTitle	= getContainerAttr(sContainerElement +'_title');
	sURL	= getContainerAttr(sContainerElement +'_url');
	sURL    = sURL + ((sURL.indexOf('?') != -1) ? '&' : '?');
	if (sParams.indexOf('?') == 0 || sParams.indexOf('&') == 0) {
	    sParams = sParams.substring(1, sParams.length);
	}
	sURL    = sURL + sParams;
    
	oParam = new Object();
	oParam.window 		 = window;
	oParam.element       = sContainerElement;
	oParam.container	 = sContainerElement +'_container';	
		
	if (sConfirmText=='' || sConfirmText==undefined || (sConfirmText!='' && confirm(sConfirmText))) {	
		if (sURL !='') {
			HTML = '<head><title>' + sTitle + '</title></head><body marginheight="0" marginwidth="0" topmargin="0" leftmargin="0"><div align="center">'
			HTML = HTML + '<iframe width="100%" height="100%" id="permfr" src="' + sURL + '" border="0" marginwidth="0" marginheight="0" scrolling="yes"></iframe></body></html>';
			if (window.showModelessDialog) {
			    var dlg = window.showModelessDialog('htmleditor/empty.htm', oParam, 'dialogheight='+ sHeight +'px;dialogwidth='+ sWidth +'px;status=yes;toolbar=no;menubar=no;location=no;resizable=no;scroll=no');
                dlg.document.open();
			    dlg.document.write(HTML);
			    dlg.document.close();
			    window.imageDlg = dlg;
            } else {
                var dlg = xShowModalDialog('htmleditor/empty.htm', oParam, 'dialogheight='+ sHeight +';dialogwidth='+ sWidth +';edge=raised;center=yes;help=0;resizable=0;status=0;scroll=0;') 
			    dlg.document.open();
			    dlg.document.write(HTML);
			    dlg.document.close();
			    window.imageDlg = dlg;
            }
		}
	}
}

function updateContainer(sSourceElement, bClose) {	
    var oWindow = parent.window;
    var oParam  = oWindow.dialogArguments;		
	var srcElement = window.document.getElementById(sSourceElement);
	var dstElement = oParam.window.document.getElementById(oParam.element);
	
	var srcContent = window.document.getElementById(sSourceElement +'_container');
	var dstContent = oParam.window.document.getElementById(oParam.container);

	if (srcContent != null && dstContent != null) {
		dstContent.innerHTML = srcContent.innerHTML;
    }

	if (srcElement != null && dstElement != null) {
		dstElement.value = srcElement.innerHTML;
	}	
    if (bClose) {
        oWindow.close();
    }
}

function getContainerAttr(sAttr){
	var oElement = window.document.getElementById(sAttr);
	if (typeof(oElement) == 'object') {
		return(oElement.value);
	}
}

