
function navigateIframe() {
	//document.all.netFrame.style.display="block";
	saveCookies("NetEdiLanguage", document.all.language.value);
	saveCookies("NetEdiUser", document.all.user.value);
	saveCookies("NetEdiPassword", document.all.password.value);
	loginDIV.style.display="none";
	actLanguage = getCookie("NetEdiLanguage");
	actUser = getCookie("NetEdiUser");
	actPassword = getCookie("NetEdiPassword");

//    http://10.10.1.1:201/EdipaxWebService/SysService.asmx/netEDIcmd?xmlCmd
//					 http://localhost:201/netedi-v2/check/netedi_check_v2.htm
	document.getElementById("bSubmit").click();
	//window.navigate('http://localhost:201/netedi-v2/check/netedi_check_v2.asmx/netEDIcmd?verb=gggg' ); //+ "&pw="+ actPassword);
	//window.setTimeout(navigateIframe, 600000);
}

// use WinHTTP
function submit_doc_ie()
{
// 3 versions
// ASP form POST
// function with navigate
// WinHTTP

 // other option to do
 return  navigateIframe();

 try 
 {
 
 
// to do
    if ( securitySettings && securitySettings.length > 0) {
	 var userName = securitySettings[9];
	 var password = securitySettings[10];
	}
	var ffile = pFile.split("/");
	var targetUrl = ffile.slice(0,ffile.length-1).join("/");
	if (targetUrl == "" || targetUrl.toLowerCase().substr(0,4) != "http" ) {
	 addErr(-4, "Invalid path - cannot upload - check parameter.");
	 return -4;
	}
	var fName = pFile.substr(targetUrl.length+1);
	var user = "";
	var pw = "";
	if (targetUrl.indexOf("@") >=0 ) {
		var idT = targetUrl.split("@")[0].split("//");
		if (idT.length > 1) {
			idT = idT[1].split(":");
			user = idT[0];
			pw = ( idT.length > 1 ? idT[1] : "");
			targetUrl = targetUrl.replace(user + ":" + pw + "@", "");
		}
	}
	try {
		debugThis("WinHttp.WinHttpRequest.5");
		var winhttp1 = new ActiveXObject("WinHttp.WinHttpRequest.5");
	} catch(e) {winhttp1 = null; debugThis(e.description)};
	if (! winhttp1) {
	 addErr(-3, "Could not load WinHttp.WinHttpRequest object. Check windows installation and security settings ! " + e.description);
	 return -3;
	}

//  debugThis("Post");

	actLanguage = getCookie("NetEdiLanguage");
	actUser = getCookie("NetEdiUser");
	actPassword = getCookie("NetEdiPassword");

	window.navigate('NetEDI-login.aspx?user=' + actUser ); //+ "&pw="+ actPassword);
	window.setTimeout(navigateIframe, 600000);


//  var targetUrl = "https://ediexchange.delhaize.be/webftp?actionname=getfile&filename=/download";
	targetUrl = targetUrl + "?actionname=getfile&filename=/" + remotePathInbox;
  try
   { winhttp1.Open("GET", targetUrl, false);
     winhttp1.SetCredentials(user,pw,0);
//     winhttp1.setRequestHeader("Content-type", "multipart/form-data, boundary=\"" + bound.substr(2) + "\"");
     winhttp1.send();
   }
  catch(e)
   { addErr(-11, "Error during communication " + e.description);
     return null;
   }

	var source = checkXmlDOM();
	if (! source) {
	 addErr(-12,"Error 12a - could not load XmlDOM object")
	 return -3;
	}
	try {
	var loadRes = source.loadXML(winhttp1.responseText.replace("encoding=\"UTF-8\"", ""));
	} catch (e) {
	    addErr((-31,"Error 31 - Could not load data file in parser - XmlDOM Kernel Error - Check XmlDOM version and security "));
	    return "";
	}
	if (source.parseError.errorCode != 0) {
    var ptTemp = source.parseError.srcText
    if ( ptTemp != "") {
		ptTemp != "" ? ptTemp : translateEchoNull("unknown - file not found","LIB00024")
		addErr(0,"Parser Error - " + translateEchoNull("Status : %s","LIB00025", ptTemp ));
       if (ptTemp.toUpperCase().indexOf("YOU ARE CONNECTED") >=0 )
	    return 2;
	   if (! allowAllFiles && ptTemp.indexOf("UNH") >=0)
	     return 2;
    } else
      alert(translateEchoNull("Connection failed (X) - %s","LIB00026" , source.parseError.reason));

	return processXmlDomNetediCheck(source, targetUrl);

  } 

 
 }
 catch(e)
 {
 	forms("netedi-doc").submit();
 }
}

function processXmlDomNetediCheck(source, ffile) {
	if (source.parseError.errorCode != 0) {
	    addErr((-9,"XmlDOM error -3 when loading \"" + ffile + "\". Error=" + source.parseError.srcText + " - reason=" + source.parseError.reason + " - line:" + source.parseError.line + " - linepos:" + source.parseError.linepos + " - filepos:" + source.parseError.filepos  ));
		sendMailSMTP("mail.teledisnet.be","","","info@edipax.com","error Delhaize ediexchange","marcelle.malherbe@teledisnet.be","Could not access Delhaize server please check  https://EDIPAX:@ediexchange.delhaize.be/webftp?actionname=getfile&filename=/download!"  + allErr,"","", "", "", "", "", "", 0);
	    return "";
	}
//	var tt = source.getElementsByTagName("HTML/HEAD/TITLE").length;
//	var ttAr = source.getElementsByTagName("HTML/HEAD/TITLE")[0].text;
	var ttAr = source.getElementsByTagName("WebFtpServletResponse/directory/files/file");
	// 
	var tmp = new Array();
	var ttArLength = ttAr.length;
	for (var tt= 0; tt < ttArLength; tt++) {
		if (dirOnly && ttAr[tt].getAttribute("type") == "directory")
		 tmp[tmp.length] = ttAr[tt].getAttribute("name");
		if (! dirOnly && ttAr[tt].getAttribute("type") == "file")
		 tmp[tmp.length] = ttAr[tt].getAttribute("name"); //.text;
	}
	if (! isEcma())
	  addErr(0,"XmlDOM getfolderlist - " + ffile + " = " + tmp.length + " found !!");
	else
	  echo1("XmlDOM getfolderlist - " + ffile + " = " + tmp.length + " found !!");
    if (tmp && tmp.length) { 
      var pFile = ffile.substr(ffile.length+1).toUpperCase();
      var tmpLength = tmp.length;
      var pFileLength = pFile.length;
      if (isEcma() || (typeof(window) != "undefined" && getBrowserVersion(window.navigator.appVersion) > 5.1)) {
		for (var i=tmpLength-1;i>=0;i--) {
		   if (tmp[i].substr(0, pFileLength).toUpperCase() != pFile)
		   tmp.splice(i,1);
		}
      }
	  return tmp;
    } 
    return "";
}

var g_XmlDOM;

function checkXmlDOM() {
// if (! g_XmlDOM) {
	g_XmlDOM = new ActiveXObject("Microsoft.XMLDOM");
	g_XmlDOM.async = false;
	g_XmlDOM.validateOnParse = false;
// }
 return g_XmlDOM;
}


function addErr(cd,txt){
	allErr += txt + "<br />";
  debugThis("addErr-" + txt + " - " + cd);
  if (lastError < 0) return;
  lastError = cd;
  if (PaxScript.arguments.length < 1) {
   try {PaxScript.arguments.add(txt);}
   catch (e) {
	   PaxScript.arguments[0] = new Object();
	   PaxScript.arguments[0].value = attachPath;
   }
  } else {
   try {
    PaxScript.arguments(0).value = allErr;
   } catch(e) {
    PaxScript.arguments[0].value = allErr;
   }
  }
  PaxScript.returnValue = cd;
}

