<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="fieldFile.aspx.cs" Inherits="view.view.fieldFile" %>

<html>
<head>
<meta http-equiv="Content-Type" content='text/html; charset=utf-8' />
<script language=javascript>document.write("<script type='text/javaScript' src='../common/view"+((parent&&parent._sLang)?parent._sLang:"cn")+".js'><\/script>");</script>
<script type='text/javaScript' src='../common/utility.js'></script>
</head>
  <body oncontextmenu="return false;">
  <script type="text/javaScript" language="javaScript">
      function display(n) {
          if (n) {
              for (var i = 1; i < n; i++) {
                  document.getElementById("file" + i).style.display = "block";
              }
              if(n > 1) {
                  document.getElementById("oPaste").style.display = "inline";
              }
          }
      }
      function upload(obj) {
          document.getElementById("filesToDelete").style.display = "none";
          document.forms[0].style.display = "block";
          var bHasFile = false;
          var sType = document.getElementById("fileType").value.toLowerCase();
          if (sType.length > 0) {
              var ec = document.forms[0].elements;
              for (var i = 0; i < ec.length; i++) {
                  if (ec[i].type == "file") {
                      var s = ec[i].value;
                      if (s.length > 0) {
                          if (sType.indexOf(s.substring(s.lastIndexOf("."), s.length).toLowerCase()) < 0) {
                              document.getElementById('inform').innerHTML = translate["fileOnlyWithType"] + sType;
                              ec[i].focus();
                              return;
                          }
                          bHasFile = true;
                      }
                  }
              }
          }
          else {
              var ec = document.forms[0].elements;
              for (var i = 0; i < ec.length; i++) {
                  if (ec[i].type == "file") {
                      var s = ec[i].value;
                      if (s.length > 0) {
                          bHasFile = true;
                      } 
                  }
              }
          }
          if (bHasFile) {
              obj.disabled = true;
              document.getElementById('inform').innerHTML = translate["uploading"];
              document.forms[0].submit();
          }
      }
      var bGetFilesToDetele = false;
      function remove(obj) {
          var eField = window.parent.document.getElementById("e." + document.getElementById("fieldName").value);
          if (eField) {
              var vFilesToDelete = document.getElementById("filesToDelete");
              if (!bGetFilesToDetele) {
                  var as = eField.getElementsByTagName("A");
                  if (as.length == 0) {
                      vFilesToDelete.innerHTML = translate["noFile"];
                  }
                  else {
                      vFilesToDelete.innerHTML = "";
                      for (var i = 0; i < as.length; i++) {
                          vFilesToDelete.innerHTML += "<div>" + as[i].innerHTML + "<img onclick='removeOne(this);' src='../images/delete.gif' style='vertical-align:middle;cursor:pointer;' alt='" + translate['remove'] + "'></div>";
                      };
                  }
                  bGetFilesToDetele = true;
              }
              document.forms[0].style.display = "none";
              vFilesToDelete.style.display = "block";
          }
          else {
              obj.disabled = true;
          }
      }
      function removeOne(e) {
          if (confirm(translate["areYouSure"])) {
              var pe = e.parentNode;
              var es = pe.parentNode.getElementsByTagName("DIV");
              var i = 0;
              for (; i < es.length; i++) {
                  if (es[i] == pe) break;
              }
              pe.parentNode.removeChild(pe);
              pe = window.parent.document.getElementById("e."+document.getElementById("fieldName").value);
              var s = pe.innerHTML;
              var sSearch = "<A";
              if (s.indexOf(sSearch) < 0) sSearch = "<a";
              var nPos = -1;
              for (j = 0; j <= i; j++) nPos = s.indexOf(sSearch, ++nPos);
              var nPos2 = s.indexOf(sSearch, nPos + 1);
              if (nPos2 > 0) pe.innerHTML = s.replace(s.substring(nPos, nPos2), "");
              else pe.innerHTML = s.replace(s.substr(nPos), "");
          }
      }
      function paste(obj) {
          if(confirm(translate["pasteFromDoc"])) {
              var s = $ajax("invoke.aspx?key=pasteDoc");
              if(s.indexOf("<a") == 0) {
                  var eField = window.parent.document.getElementById("e." + document.getElementById("fieldName").value);
                  if (eField) eField.innerHTML += s;
                  if (window.parent._eLastActiveSource) {
                      parent._eLastActiveSource.style.display = "none";
                      parent._eLastActiveSource = null;
                  }
              }
              else if(s.length > 0) {
                  alert(s);
              }
          }
      }
  </script>
  <form runat="server" method="post" enctype="multipart/form-data" style="margin:0">
  <div><input type="file" size="50" name="file0" /></div>
  <div id="file1" style="display:none"><input type="file" size="50" name="file1" /></div>
  <div id="file2" style="display:none"><input type="file" size="50" name="file2" /></div>
  <div id="file3" style="display:none"><input type="file" size="50" name="file3" /></div>
  <div id="file4" style="display:none"><input type="file" size="50" name="file4" /></div>
  <div id="file5" style="display:none"><input type="file" size="50" name="file5" /></div>
  <div id="file6" style="display:none"><input type="file" size="50" name="file6" /></div>
  <div id="file7" style="display:none"><input type="file" size="50" name="file7" /></div>
  <div id="file8" style="display:none"><input type="file" size="50" name="file8" /></div>
  <div id="file9" style="display:none"><input type="file" size="50" name="file9" /></div>
  </form>
  <div style="margin:5 0 5 0;"><script language=javascript>document.write("<input type='button' value=' " + translate['upload'] + " ' onclick='upload(this);'/> <input type='button' value=' " + translate['remove'] + " ' onclick='remove(this);'/> <input type='button' id=oPaste style='display:none;' value=' " + translate['paste'] + " ' onclick='paste(this);'/>");</script> <span id="inform" runat="server"></span><input type="hidden" id="fileType" runat="server" /></div>
  <div id="filesToDelete" style="font-size:12px;font-family:tahoma,arial,verdana,sans-serif;"></div><input type="hidden" id="fieldName" runat="server" />
  </body>
</html>