<?php 
// Set flag that this is a parent file
	defined('_FEXEC') or die();
?>
<html style="font: 9 pt 'MS Shell Dlg', Helvetica, sans-serif; width: 470px; height: 497px; "> <!-- ALL features enabled -->
<!-- <html style="font: 9 pt 'MS Shell Dlg', Helvetica, sans-serif; width: 470px; height: 454px; "> <!-- CREATE disabled -->
<!-- <html style="font: 9 pt 'MS Shell Dlg', Helvetica, sans-serif; width: 470px; height: 410px; "> <!-- UPLOAD disabled -->
<!-- <html style="font: 9 pt 'MS Shell Dlg', Helvetica, sans-serif; width: 470px; height: 368px; "> <!-- CREATE & UPLOAD disabled -->

<head>
<title>Insert Image</title>
<style type="text/css">
BODY { background: threedface; color: windowtext; font: 9pt 'MS Shell Dlg', Helvetica, sans-serif; }

<!-- frame styles -->
IFRAME.lister { font: 9pt 'MS Shell Dlg', Helvetica, sans-serif; width: 18em; height:13em; }
IFRAME.viewer { font: 9pt 'MS Shell Dlg', Helvetica, sans-serif; width: 18em; height:13em; }

<!-- input styles -->
INPUT.folder { font: 9pt 'MS Shell Dlg', Helvetica, sans-serif; width: 30em; }
INPUT.image { font: 9pt 'MS Shell Dlg', Helvetica, sans-serif; width: 30em; }
INPUT.name { font: 9pt 'MS Shell Dlg', Helvetica, sans-serif; width: 30em; }
INPUT.number { font: 9pt 'MS Shell Dlg', Helvetica, sans-serif; width: 4em; }
INPUT.txtAltText { font: 9pt 'MS Shell Dlg', Helvetica, sans-serif; width: 31em; }
INPUT.txtBorder { font: 9pt 'MS Shell Dlg', Helvetica, sans-serif; width: 3.5em; }
INPUT.txtHorizontal { font: 9pt 'MS Shell Dlg', Helvetica, sans-serif; width: 3.5em; }
INPUT.txtFileName { font: 9pt 'MS Shell Dlg', Helvetica, sans-serif; width: 31em; }
INPUT.txtVertical { font: 9pt 'MS Shell Dlg', Helvetica, sans-serif; width: 3.5em; }

<!-- button styles -->
INPUT.btnCancel { font: 9pt 'MS Shell Dlg', Helvetica, sans-serif; width: 6em; }
INPUT.btnOK { font: 9pt 'MS Shell Dlg', Helvetica, sans-serif; width: 6em; }
INPUT.create { font: 9pt 'MS Shell Dlg', Helvetica, sans-serif; width: 4.5em; }
INPUT.upload { font: 9pt 'MS Shell Dlg', Helvetica, sans-serif; width: 4.5em; }

<!-- drop-down styles -->
SELECT.selAlignment { font: 9pt 'MS Shell Dlg', Helvetica, sans-serif; width: 6em; }

<!-- table styles -->
TABLE.dialog { font: 9pt 'MS Shell Dlg', Helvetica, sans-serif; width: 36em; }

<!-- cell styles -->
TD.aspect { font: 9pt 'MS Shell Dlg', Helvetica, sans-serif; width: 15em; }
TD.create { font: 9pt 'MS Shell Dlg', Helvetica, sans-serif; width: 37em; }
TD.fldLayout { font: 9pt 'MS Shell Dlg', Helvetica, sans-serif; width: 13em; }
TD.fldSpacing { font: 9pt 'MS Shell Dlg', Helvetica, sans-serif; width: 10em; }
TD.image { font: 9pt 'MS Shell Dlg', Helvetica, sans-serif; width: 40em; }
TD.label { font: 9pt 'MS Shell Dlg', Helvetica, sans-serif; width: 5em; }
TD.manager { font: 9pt 'MS Shell Dlg', Helvetica, sans-serif; width: 37em; }
TD.resize { font: 9pt 'MS Shell Dlg', Helvetica, sans-serif; width: 30em; }
TD.upload { font: 9pt 'MS Shell Dlg', Helvetica, sans-serif; width: 37em; }
</style>

<!-- script copied from original "insert_image.html" -->
<script defer>
function _CloseOnEsc(e) {
    var eve;
    if (window.event)
		eve=window.event.keyCode;
	else eve=e.which;
	if(eve.keyCode == 27) {
        window.close();
        return;
    }
}

function _getTextRange(elm) {
    var r = elm.parentTextEdit.createTextRange();

    r.moveToElementText(elm);
    return r;
}

//window.onerror = HandleError

function HandleError(message, url, line) {
    var str = "An error has occurred in this dialog." + "\n\n"
               + "Error: " + line + "\n" + message;

    alert(str);
    window.close();
    return true;
}

function Init() {
    var elmSelectedImage;
    var htmlSelectionControl = "Control";   
    //alert(window.dialogArguments  + " " + document.all.lister.dialogArguments);    
    //var globalDoc = window.dialogArguments;
    //var grngMaster = globalDoc.selection.createRange();
    var dpi = 96;
    if(document.all.dpicheck) {
        dpi = document.all.dpicheck.width;
    }    
	document.all.lister.src='includes/imageviewer/lister.php?DPI=' + dpi;	
	document.all.viewer.src='includes/imageviewer/viewer.php?DPI=' + dpi;
    //document.all.lister.contentWindow.navigate('includes/imageviewer/lister.php?DPI=' + dpi);
    //document.all.viewer.contentWindow.navigate('includes/imageviewer/viewer.php?DPI=' + dpi);
    document.all.actions.DPI.value = dpi;
    if(dpi != 96) {
        var xfactor = ((dpi < 96) ? (dpi / 95) : (dpi / 97.5));
        var yfactor = ((dpi < 96) ? (dpi / 95) : (dpi / 99.5));
        var width = dialogWidth.substr(0, dialogWidth.search(/\D/));
        var height = dialogHeight.substr(0, dialogHeight.search(/\D/));

        window.dialogWidth = Math.floor((width * xfactor)) + 'px';
        window.dialogHeight = Math.floor((height * yfactor)) + 'px';
    }

    // event handlers
    document.body.onkeypress = _CloseOnEsc;
    //btnOK.onclick = new Function("OKClick()");

    txtFileName.fImageLoaded = false;
    txtFileName.intImageWidth = 0;
    txtFileName.intImageHeight = 0;

    /*if(globalDoc.selection.type == htmlSelectionControl) {
        if(grngMaster.length == 1) {
            elmSelectedImage = grngMaster.item(0);
            if(elmSelectedImage.tagName == "IMG") {
                txtFileName.fImageLoaded = true;
                if(elmSelectedImage.src) {
                    txtFileName.value          = elmSelectedImage.src.replace(/^[^*]*(\*\*\*)/, "$1");  // fix placeholder src values that editor converted to abs paths
                    txtFileName.intImageHeight = elmSelectedImage.height;
                    txtFileName.intImageWidth  = elmSelectedImage.width;
                    txtVertical.value          = elmSelectedImage.vspace;
                    txtHorizontal.value        = elmSelectedImage.hspace;
                    txtBorder.value            = elmSelectedImage.border;
                    txtAltText.value           = elmSelectedImage.alt;
                    selAlignment.value         = elmSelectedImage.align;
                }
            }
        }
    }*/

    //txtFileName.value = txtFileName.value || "http://";
    txtFileName.focus();
}

function _isValidNumber(txtBox) {
    var val = parseInt(txtBox);

    if(isNaN(val) || val < 0 || val > 999) {
        return false;
    }
    return true;
}

function OKClick() {	
	if (window.opener){
		window.opener.setFileName(txtFileName.value);
	}
    window.close();
}
</script>

</head>

<body onLoad="Init()">
<img id="dpicheck" style="position: absolute; left: 1; top: 1; width: 1in; height: 1; visibility: hidden;" src="dpi.gif">
<table class="dialog" border="0" cellpadding="0" cellspacing="5">
  <tr>
    <td>
      <table name="manager" border="0" cellpadding="0" cellspacing="0">
        <tr>
          <td class="manager" colspan="3" align="center" valign="middle">
            <fieldset>
              <legend align="left">Image Manager</legend>
              <table name="wrapper" border="0" cellpadding="2" cellspacing="0">
                <tr>
                  <td valign="top">
                    <iframe valign="top" class="lister" width="250" name="lister" marginwidth="0" marginheight="0"></iframe>
                  </td>
                  <td valign="top">
                    <iframe valign="top" class="viewer" width="250" name="viewer" marginwidth="0" marginheight="0"></iframe>
                  </td>
                </tr>
                <tr>
                  <td colspan="3">
                    <form name="actions" method="POST" action="includes/imageviewer/lister.php" enctype="multipart/form-data" target="lister">
                      <table border="0" cellpadding="0" cellspacing="0" width="100%">
						<!-- BEGIN 'UPLOAD' HTML (delete the '>' at the end of this comment to disable the 'UPLOAD' feature) -->
                        <tr>
                          <td class="upload" colspan="2">
                            <fieldset>
                              <legend align="left">Upload New Image</legend>
                              <table border="0" cellpadding="1" cellspacing="0">
                                <tr>						
                                  <td class="label" align="left" valign="middle">
										<input class="upload" type="submit" value="Upload" onClick="this.form.action.value='upload'">&nbsp;
                                  </td>
                                  <td colspan="2">
                                    <input class="image" type="file" name="image">
                                  </td>
                                </tr>
                                <tr>
                                  <td class="label" align="left" valign="middle">
                                    Name as:
                                  </td>
                                  <td colspan="2">
                                    <input class="name" type="input" name="name">
                                  </td>
                                </tr>
                                <tr>
								<Td colspan="2">
								<table border="0" cellpadding="1" cellspacing="0" width="100%">
								  <tr>
									  <td class="label" align="left" valign="middle">Resize to:</td>
									  <td class="resize" align="left" valign="middle" width="50">
										&nbsp;&nbsp;<input class="number" type="input" name="width">
										&nbsp;&#215;&nbsp;
										<input class="number" type="input" name="height">
										<i>
										  &nbsp;(width &#215; height)&nbsp;
										</i>
									  </td>
									  <td  align="left" valign="middle" width="150">
										<input type="checkbox" name="aspect" checked>
										<font size='2'>Preserve aspect ratio</font>
									  </td>
								   </tr>
								  </table>
								</Td>	  
                                </tr>
                              </table>
                            </fieldset>
                          </td>
                        </tr>
<!-- END 'UPLOAD' HTML -->
<!-- BEGIN 'CREATE' HTML (delete the '>' at the end of this comment to disable the 'CREATE' feature) -->
                        <tr>
                          <td class="create" colspan="2">
                            <fieldset>
                              <legend align="left">Create New Folder</legend>
                              <table border="0" cellpadding="1" cellspacing="0">
                                <tr>
                                  <td class="label" align="left" valign="top">
                                    <input class="create" type="submit" value="Create" onClick="this.form.action.value='create'">&nbsp;
                                  </td>
                                  <td>
                                    <input class="folder" type="input" name="folder">
                                  </td>
                                </tr>
                              </table>
                            </fieldset>
                          </td>
                        </tr>
<!-- END 'UPLOAD' HTML -->
                      </table>
                      <input type="hidden" name="DPI" value="">
                      <input type="hidden" name="action" value="">
                      <input type="hidden" name="path" value="">
                    </form>
                  </td>
                </tr>
              </table>
            </fieldset>
          </td>
        </tr>
        <tr>
          <td class="image" colspan="3" valign="middle">
            <fieldset>
              <legend align="left">Selected Image</legend>
              <table border="0" cellpadding="1" cellspacing="0">
                <tr>
                  <td class="label" valign="middle">Image URL:</td>
                  <td valign="middle">
                    <input class="txtFileName" type="text" id="txtFileName" name="txtFileName" onFocus="select()">
                  </td>
                </tr>
              </table>
            </fieldset>
          </td>
        </tr>
        <tr>
          <td valign="bottom">
            <table align="right" border="0" cellpadding="2" cellspacing="0">
              <tr>
              	<td valign="top">
              		<input class="btnCancel" type="reset" value="Cancel&nbsp;" name="btnCancel" onClick="window.close();">
              	</td>
                <td valign="top">
                  <input class="btnOK" type="button" value="OK" name="btnOK" onClick="javascript:OKClick()">
                </td>
              </tr>              
            </table
          ></td>
        </tr>
      </table>
    </td>
  </tr>
</table>
</body>
</html>
