var Currfocus;
var existattainfo = new Array ();
var olddelattas = new Array ();
var attaidx = 0;
var Isie;
function Finitmsie () {
if (Navigator.userAgent.indexOf ("MSIE")!=-1) {
Isie = true;
}else{
Isie = false;
}
}
Finitmsie ();
function Ftrim (str) {
str = str.replace (/(^\s*)/, "");
str = str.replace (/(\s*$)/, "");
return str;
}
This JS file is used for compose.htm to send multiple attachments at the same time JS function, support IE and NNX series.
All functions are applicable to IE and NNX series, direct call can be
function to determine the browser type based on the statement, and then add elements based on different Bowser properties
The main function is to dynamically create various form elements and delete form elements
Written by xpr
Function List
// ------------------------------------------------------------------------------------------------------------- ------
Isiebrowser () return value: True (IE) False (NNX)
exist (Fileid) to determine if Fileid already exists
Addinputfile (Spanid,fileid) adds an input file with index number to the element named Spanid
ADDBR (Spanid,brid) adds a newline character with an ID of Brid in the element named Spanid
Adddel (Spanid,index) adds a "delete" to index in the element named Spanid, and he can delete the corresponding input file and BR
Addhidden (Spanid,hiddenid,value) adds an ID of Hiddenid to the element named Spanid, and the value of input Type=hidden
// ------------------------------------------------------------------------------------------------------------- ------
var Isie;
var attaidx = 0;
Search, global variables
//-----------------------------------------------------------------------------------------------------------
function Isiebrowser () {
if (Navigator.userAgent.indexOf ("MSIE")!=-1) {
return true;
} else {
return false;
}
}
Add the Attachment function (), add to Idfilespan, base for Attaidx.
function Add () {
AddFile ("Idfilespan", ATTAIDX);
attaidx++;
return false;
}
----------------------------------------fileexist ()----------------------------------------------------------
Edited by Alun
function exist (Fileid) {
var file = document.getElementById (Fileid);
var result = false;
if (file!=null) {
if (file.value!= null && file.value!= "") {
result = Existfile (file);
}//if
}
if (result)
{
Alert ("This attachment you have already added, the newly added attachment will have been deleted");
Document.sendmail. " +fileid+ ". value=" "";
var attach_num = fileid.substring (10,12);
Delfile ("Idfilespan", attach_num);
--attaidx;
document.getElementById ("Idattachoper" + attaidx). Click ();
}
}//end of function
Added by Alun
function GetFileName (attaname) {
var s = attaname.lastindexof (' \ \ ');
Return Attaname.substr (s+1, attaname.length-s-1);
}
Added by Alun
function Existfile (file)
{
var form = Document.myform;
for (var i= 0; i < form.elements.length i + +) {
if (Form.elements.type = = "File" && form.elements.name!= file.name) {
if (File.value = = Form.elements.value) {
alert (form.elements.value=null);
return true;
}
}
}//for
for (var i=0; i<existattainfo. LENGTH; {
var thename = Existattainfo;
if (thename!= null && thename!= "" && thename = = GetFileName (file.name)) {
return true;
}
}
return false;
}
----------------------------------------AddFile (Spanid,index)----------------------------------------------
function AddFile (spanid,index)
{
var strindex = "" + Index;
var Fileid = "Attachfile" + strindex;
var Brid = "Idattachbr" + strindex;
Addinputfile (Spanid,fileid);
Adddel (Spanid,index);
ADDBR (Spanid,brid);
document.getElementById ("Attachfile" + strindex). Click ();
Return
}
-------------------------------------------Sub Fuction addinputfile-----------------------------------------
function Addinputfile (Spanid,fileid)
{
var span = document.getElementById (Spanid);
if (span!=null) {
if (! Isie) {
var fileobj = document.createelement ("input");
if (fileobj!= null) {
fileobj.type= "File";
Fileobj.name = Fileid;
Fileobj.id = Fileid;
Fileobj.size= "50";
var clickevent = "exist ('" + Fileid + "')";
Fileobj.setattribute ("onclick", clickevent,0);
Span.appendchild (Fileobj);
}//if Fileobj
}// ! Isie
if (Isie) {
var Filetag = "var Filetag =" var fileobj = document.createelement (Filetag);
Span.appendchild (Fileobj);
}//isie if
}//if span
}
function ADDBR (Spanid,brid)
{
var span = document.getElementById (Spanid);
if (span!=null) {
var brobj = document.createelement ("BR");
if (Brobj!=null) {
Brobj.name = Brid;
Brobj.id = Brid;
Span.appendchild (Brobj);
}//i2f
}//if
Return
}
function Adddel (spanid,index)
{
var strindex = "" + Index;
var delid = "Idattachoper" + strindex;
var span = document.getElementById (Spanid);
if (span!= null) {
var otextnode = document.createelement ("SPAN");
OTextNode.style.width = "5px";
Span.appendchild (Otextnode);
if (Isie) {
var tag = "";
var delobj = document.createelement (tag);
if (delobj!= null) {
Span.appendchild (Delobj);
}//if
}//is IE
if (! Isie) {
var delobj = document.createelement ("input");
if (delobj!= null) {
Delobj.name = Delid;
Delobj.id = Delid;
Delobj.type = "button";
var clickevent = "Return Delfile ('" + Spanid + "", "+strindex+"); ";
Delobj.setattribute ("onclick", clickevent);
Span.appendchild (Delobj);
}//if
}// ! Isie if
if (delobj!= null) delobj.value = "Delete";
}//main if
Return
}
//-------------------------------------------------------------------------------------------------------------
---------------------------------------------Delete input File-----------------------------------------------
function Delfile (spanid,index)
{
var strindex = "" + Index;
var Fileid = "Attachfile" + strindex;
var Brid = "Idattachbr" + strindex;
var delid = "Idattachoper" + strindex;
First,get the Element
var span = document.getElementById (Spanid);
Alert ("del span:" + span);
if (span = null) return false;
var fileobj = document.getElementById (Fileid);
if (fileobj = null) return false;
var brobj = document.getElementById (Brid);
if (Brobj ==null) return false;
var delobj = document.getElementById (delid);
Alert ("Del delid:" + delobj);
if (delobj = null) return false;
Second,create the Replace element
var temp= document.createelement ("SPAN");
Third,replace it
Span.replacechild (Temp,fileobj);
Span.replacechild (Temp,brobj);
Added by Harry, Repair Remove attached bug 2005/04/04
Span.removechild (delobj.previoussibling);
var attach = document.getElementById ("Attach");
if (Span.getelementsbytagname ("INPUT"). Length = = 1) attach.childnodes[0].nodevalue= ' Add attachment ';
End
Span.replacechild (Temp,delobj);
return false;
}