
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>File Browser</title>
<SCRIPT LANGUAGE="JavaScript">
var Nav4 = ((navigator.appName == "Netscape") && (parseInt(navigator.appVersion) >= 4))

function getFormData(form)
 {	
    str=document.getElementById("filepath").value;   
    str = "../texteditor/"+str;
	//alert(str);
    return str.substr(0,str.length);
	//return str.substr(3,str.length-3);
 }

// Send gathered data to the dialog window object's returnedValue property
function transferData() {
	if (opener && !opener.closed) {
		opener.dialogWin.returnedValue = getFormData(document.prefs);
	}
}

// Close the dialog
function closeme() {
	window.close()
}

// Handle click of OK button
function handleOK() {
	if (opener && !opener.closed) {
		transferData()
		opener.dialogWin.returnFunc()
	} else {
		alert("You have closed the main window.\n\nNo action will be taken on the choices in this dialog box.")
	}
	closeme()
	return false
}

// Handle click of Cancel button
function handleCancel() {
	closeme()
	return false
}

function validate()
{        
		RgExp= new RegExp("[^\\s]+");
		if(!RgExp.test(document.uploadform.uploadfile.value))
		{
			alert("Select File to Upload.");
			document.uploadform.uploadfile.focus();
			
		}
		else if(document.uploadform.folders.value==0)
		{
			alert("Select destination Folder.");
			document.uploadform.folders.focus();
			
		}
		else
		{	
		    document.uploadform.opt.value = "0"  ;
			document.uploadform.submit();
		}
		
}
function newFolder(name,opt)
{	err=false;
	if(document.uploadform.folders.value!=0)
	{	newname=prompt("Enter Name for Folder",name);
			RgExp= new RegExp("[^\\s]+");
			if (newname!=null)
			{	if(!RgExp.test(newname))
				{
					alert("Enter Folder name.");
					err=true;
				}
				else
				{
					for(i=2;i<document.uploadform.folders.options.length;i++)
					{	
						if((document.uploadform.folders.options[i].text).toLowerCase()!=name.toLowerCase())
						{	if((document.uploadform.folders.options[i].text).toLowerCase()==newname.toLowerCase())
							{	
								alert("Specified Folder Already Exists, Specify Another.");
								//document.regform.catname.focus();
								err=true;
								break;
							}
						}
					}
				}
			}
			else
			{
			 err=true;
			}
		}
		else
		{
			alert("Select Destination Folder.");
			document.uploadform.folders.focus();
			err=true;
		}
			if (!err)
			{	document.uploadform.opt.value=opt;
			 // alert(document.uploadform.opt.value);
				document.uploadform.newname.value=newname;
				document.uploadform.submit();
			}
}
</SCRIPT>
<link href="entities/pageform.css" rel="stylesheet" type="text/css">
</head>

<body >
<table width="100%" height="450" border="0" cellpadding="3" cellspacing="1" class="font">
  <tr valign="top">
    <td height="27" colspan="2" class="heading1">::.. File Browser </td>
  </tr>
  <tr>
    <td width="50%" height="411" rowspan="4" valign="top"><iframe name="listframe" src="FolderList.php" width="100%" height="100%" frameborder="1"></iframe></td>
    <td width="50%" height="135" valign="top" >
	<form action="upload.php"  method="post" enctype="multipart/form-data" name="uploadform" target="listframe">
	<table width="100%"  border="0" cellspacing="1" cellpadding="3">
      <tr>
        <td width="34%" align="left" class="font">Upload New File: </td>
        <td width="66%">
		<input type="file" name="uploadfile">
		<input type="hidden" name="opt" value="0">
		<input type="hidden" name="curpath" value="">
		<input type="hidden" name="existname" value="">
		<input type="hidden" name="newname" value="">
		</td>
      </tr>
      <tr>
        <td class="font">Destination Folder: </td>
        <td><select name="folders">		
        </select></td>
      </tr> 
      <tr align="left">
        <td>&nbsp;</td>
        <td> <input name="Submit3" type="button" class="button" value="Create New Folder" onClick="newFolder('',3);" > </td>
      </tr> 
      <tr align="left">
        <td colspan="2"><span class="note">Note:</span> <span class="font">Uploaded file will overwrite  same file in destination folder. If Exists.</span></td>
      </tr>
      <tr>
        <td>&nbsp;           </td>
        <td height="25"><input name="Submit2" type="button" class="button" value="Upload" onClick="validate();">
&nbsp;&nbsp;
<input name="Submit3" type="reset" class="button" value="Cancel"></td>
      </tr>
    </table>
	</form>	</td>
  </tr>
  <tr>
    <td height="25" valign="top" id="fileinfo">&nbsp;</td>
  </tr>
  <tr>
    <td height="212" valign="top"><iframe height="100%" width="100%" id="imgdisp" name="imgdisp" frameborder="0" style="border: 1px solid #000000; "></iframe></td>
  </tr>
  <tr>
    <td valign="bottom">
	<input type="hidden" name="filepath" id="filepath">
	<input name="Submit" type="button" class="button" onClick="handleOK();" value="Insert">
	<input name="Submit" type="button" class="button" onClick="handleCancel();" value="Cancel">	</td>
  </tr>
</table>
</body>
</html>
