text: (function (define) {
          'use strict';
  
          (function (root, factory)
          {
                  if (typeof define === 'function' && define.amd)
                  {
                          define(ResizerPanelLayout,factory);
                  }
                  else if (typeof exports === 'object')
                  {
                          module.exports = factory();
                  }
                  else
                  {
                          root.jetXhr = factory();
                  }
          }
          (window, function ()
          {
                  return (function ()
                  {
                          function isDOMElement(obj) {
                                  try {
                                          return obj instanceof HTMLElement;
                                  } catch (e) {
                                          // Some browsers don't support using the HTMLElement so some extra
                                          // checks are needed.
                                          return typeof obj === 'object' && obj.nodeType === 1 && typeof obj.style === 'object' && typeof obj.ownerDocument === 'object';
                                  }
                          }
  
                          var events = [
                                  'select',
                                  'JetXhtResponse',
                                  'PostSuccess',
                                  'PostFail'
                          ];
  
                          //var jetXhr={};
                          var jetXhr = function()
                          {
                                  // var responseString='bpp';
                                  //var jsonString='';
  
                                  //var JsonStructure='';
                                  //var JsonMergedStructure='';
  
                                  //var destination='';
                                  //var formMethod='';
                                  //var serverResponseMessage = '';
  
                                  function jetXhr(imputForm,destination,formMethod,JsonStructure,debug)
                                  {
                                          /*NOTE
                                          when 'this' keyword is applied to the constructor variable
                                          the VAR becomes availavble when we instantate the object,
                                          */
  
                                          //Ajax responseEvent
                                          this.handlers = {};
  
                                          //server Response Message
                                          this.serverResponseMessage = '';
  
                                          this.imputForm = imputForm;
                                          this.destination = destination;
                                          this.formMethod = formMethod;
                                          this.jsonPostString = '';
                                          this.responseString ='';
                                          this.jsonStructure =JsonStructure;
                                          this.JsonMergedStructure = '';
                                          this.debug =debug;
  
                                          //this.JsonMergedStructure = '';
  
  this.mode ='';
  
  //check if the response has been returned
  this.XHR_readyState =0;
                                          // var promise = new Promise(function(resolve, reject) {
                                          //   // do a thing, possibly async, then…
                                          //
                                          //   if (/* everything turned out fine */) {
                                          //     resolve("Stuff worked!");
                                          //   }
                                          //   else {
                                          //     reject(Error("It broke"));
                                          //   }
                                          // });
                                          // promise.then('function to run resolve');
                                          // promise.catch('function to run on reject ');
  
                                          /*NOTE
                                          when capturing the event there is a problem that the
                                          form value before the event contains no value
                                          onsubmit  only then the form object has values
  
                                          Instead of using a promise we using Async Await which is a later technology
                                          to catch errors a try catch block
                                          */
                                          //console.log('===================jsonStructure');
                                          //console.log(JsonStructure);
  
                                          //overide The default functionality where no input form exists
                                          if (this.imputForm=='overide'){
  
  this.mode ='TopSecret';
                                                  //console.log("overide super Secrets");
                                                  //create a magic form
                                                  let newForm = this.createHiddenForm();
                                                  //Attach the event hamdelar
                                                  this.submitEvent('fictisions',destination,formMethod,this,debug);
                                                  //Trigger the event
                                                  //T
  
                                                  this.imputForm = newForm;
                                                  this.renderCustomEvents(this);
  
                                                  var event = new Event('submit');
                                                  newForm.dispatchEvent(event);
                                                  this.deleteHiddenForm();
                                                  this.mode ='';
  
  
                                          }else{
  
                                                  this.submitEvent(imputForm,destination,formMethod,this,debug);
                                                  //Next is the post Response Event handelar when the job is done
                                                  this.renderCustomEvents(this);
                                          }
                                          //this.renderCustomEvents(this);
  
                                  }
  
  
  
                                  jetXhr.prototype.createHiddenForm = function ()
                                  {
                                          var newform = document.createElement('form');
                                          newform.setAttribute('id','fictisions');
                                          document.body.appendChild(newform);
                                          var newbutton = document.createElement('button');
                                          newbutton.setAttribute('class','button-component');
                                          newform.appendChild(newbutton);
                                          return newform;
  
                                  }
                                  jetXhr.prototype.deleteHiddenForm = function ()
                                  {
                                          var newform = document.getElementById('fictisions');
                                          newform.remove();
                                          return ;
  
                                  }
  
  
  
  
                                  //Prototype to return the XHR response
                                  jetXhr.prototype.setServerResponse = function (MyResponse)
                                  {
  
                                          this.serverResponseMessage = MyResponse;
                                  }
  
                                  // Allow the response to be called as part of the new instance
                                  jetXhr.prototype.serverResponse = function ()
                                  {
                                          //this.serverResponseMessage = serverResponseMessage;
  // if (this.XHR_readyState ==4) {
  return this.serverResponseMessage;
  // }else{
  //         console.log("its Waiting ",2344);
  // }
  
                                          //return this.serverResponseMessage;
                                  }
  
                                  //object var literal Test
                                  jetXhr.responseString = "foo";
  
  
  
  
                                  /**
                                  * A forEach that will work with a NodeList and generic Arrays
                                  * @param {array|NodeList} arr The array to iterate over
                                  * @param {function} callback Function that executes for each element. First parameter is element, second is index
                                  * @param {object} The context to execute callback with
                                  */
                                  // jetXhr.prototype.forEach=function(arr, callback, scope) {
                                  //         var i;
                                  //         //  len = arr.length;
                                  //         //console.log(callback);
                                  //         //for (i = 0; i < len; i += 1) {
                                  //         callback.call(scope, arr, i);
                                  //         //}
                                  // }
                                  //
                                  //
                                  /**
                                  * A forEach that will work with a NodeList and generic Arrays
                                  * @param {array|NodeList} arr The array to iterate over
                                  * @param {function} callback Function that executes for each element. First parameter is element, second is index
                                  * @param {object} The context to execute callback with
                                  */
                                  jetXhr.prototype.forEach = function(arr, callback, scope) {
                                          var i, len = arr.length;
                                          for (i = 0; i < len; i += 1) {
  
                                                  callback.call(scope, arr[i], i);
  
                                          }
                                  };
  
  
                                  //Blank event objects like Onclick
                                  jetXhr.success = function (){    }
                                  jetXhr.failed = function (){  }
  
                                  jetXhr.prototype.renderCustomEvents = function(self)
                                  {
  
                                          //  var container = isDOMElement(this.node) ? this.node : document.getElementById(this.node);
                                          //
                                          var container = document.getElementById(this.imputForm);
                                          //console.log(this);
  
                                          var postSuccessEvent = function (e) {
  
                                                  var parent =self ; //(e.target || e.currentTarget);
                                                  //console.log(e);
                                                  this.emit(parent, 'PostSuccess', {
                                                          target: e,
                                                          parento :container
                                                  });
  
                                          }.bind(this);
                                          var postFailEvent = function (e) {
  
                                                  var parent =self ; //(e.target || e.currentTarget);
  
                                                  this.emit(parent, 'PostFail', {
                                                          target: e,
                                                          parento :container
                                                  });
  
                                          }.bind(this);
  
                                          //console.log(container.querySelectorAll('.button-component'));
  if(this.mode !== 'TopSecret'){
  
                                          this.forEach(container.querySelectorAll('.button-component[type="submit"]'), function (node) {
                                                  //node.onclick = click;
                                                  //ok so we worked out running a function also triggers the event
  
                                                  jetXhr.success = postSuccessEvent;
                                                  jetXhr.failed = postFailEvent;
  
  
                                          });
                                  }else{
                                  jetXhr.success = postSuccessEvent;
                                  }
  
  
                                  }
  
  
  
                                  //Process Data
                                  jetXhr.prototype.submitEvent = function(imputForm,destination,formMethod,self)
                                  {
  
                                          var testform = document.getElementById(imputForm);
  
                                          //
                                          testform.onsubmit =async function(e){
                                                  //console.log(e);
                                                  e.preventDefault();
                                                  //console.log('Captured Submit');
                                                  try {
                                                          const response = await this.processFormData(testform);
                                                          const editedJson = await this.mergeStucturedData(response,this.jsonStructure,this);
                                                          const postIt = await this.xhrConnect(editedJson,destination,formMethod,this);
  
                                                  } catch(err) {
                                                          // catches errors both in fetch and response.json
                                                          console.log(err);
                                                  }
  
  
  
                                          }.bind(this);
  
  
  
                                  }
  
                                  //extract Data from the HTML Form
                                  jetXhr.prototype.processFormData = function(response)
                                  {
                                          var element = {};
                                          var data = new FormData(response);
  
                                          // Display the key/value pairs
                                          for(var pair of data.entries()) {
                                                  //console.log(pair[0]+ ', '+ pair[1]);
                                                  element[ pair[0].toString() ] = pair[1];
                                          }
  
                                          return element ;
  
  
                                  }
  
                                  //Merge Form Data and JSON Structure
                                  jetXhr.prototype.mergeStucturedData = function(response,JsonStructure,self)
                                  {
                                          //console.log('extractData');
                                          //console.log('------------------dope2');
                                          //console.log(response);
                                          //console.log('===================jsonStructure');
                                          //console.log(JsonStructure);
  
                                          //ok this is not data extraction but loop to allocate the form data to a json string
                                          //still needs a good name
                                          //
                                          //becaese th jsonStringkeeps changing in the loop we need a placeholder string and a condition to the values
                                          //
  
                                          if(this.JsonMergedStructure === '')
                                          {
                                                  this.JsonMergedStructure =this.jsonStructure;
  
                                                  //
                                                  // console.log('===================jsonStructure');
                                                  // console.log(JsonStructure);
                                                  // console.log('===================this.jsonStructure');
                                                  // console.log(this.jsonStructure);
                                          }
  
                                          for(let x in response){
  
                                                  //console.log(x+':'+response[x]);
                                                  //console.log('%c'+JsonStructure,'color:#002');
                                                  this.mergeFormDataWithJson(x,response[x],this.JsonMergedStructure,self);
                                          }
                                          //console.log(JsonMergedStructure);
                                          return this.JsonMergedStructure;
                                  }
  
                                  //function to match form data with the json string
                                  jetXhr.prototype.mergeFormDataWithJson =function (key,value,jsonstringing,self)
                                  {
                                          //console.log(self.debug);
  
                                          var wasSuccesfull = 'False';
                                          var testKey = '';
                                          for (let x in jsonstringing) {
                                                  //document.getElementById("demo").innerHTML +=x +':'+ jsonstringing[x] + "<br>";
  
                                                  if(x == key){
  
                                                          //this means its in the parent structure
                                                          jsonstringing[x] = value ;
                                                          wasSuccesfull = 'true';
                                                          if(self.debug ==true){
                                                                  //        console.log('%c JetXHR Merge found the value in the Parent of :' +x +':'+ jsonstringing[x],' color: #0654b5');
                                                          }
                                                          break;
                                                  }else if(jsonstringing[x] && typeof jsonstringing[x] === 'object')
                                                  {
                                                          //console.log(jsonstringing[x]);
                                                          //console.log(x);
  
                                                          for(let y in jsonstringing[x])
                                                          {
                                                                  //console.log(jsonstringing[x][y]);
  
                                                                  if(y == key)
                                                                  {
                                                                          if(self.debug ==true){
                                                                                  //   console.log(' %c JetXHR Merge found the value in the sibling of :' +x +':'+ jsonstringing[x],' color: #0654b5');
                                                                          }
                                                                          jsonstringing[x][y]=value;
                                                                          wasSuccesfull = 'true';
                                                                          break;
                                                                  }
                                                          }
                                                  }
  
                                          }
                                          if(wasSuccesfull=='False')
                                          {
                                                  testKey=key;
                                                  if(self.debug ==true){
                                                          console.warn('JetXHR Merge Warn :KeysMap Does not find a Key for => '+ testKey);
                                                  }
                                          }
                                          //console.log('--------------------------------');
                                          //console.log(jsonstringing);
  
                                          return jsonstringing;
  
                                  }
  
  
  
  
                                  //send the request
                                  jetXhr.prototype.xhrConnect = function(jsonString,destination,formMethod,self)
                                  {
                                          //console.log('xhrConnect');
                                          //console.log(jsonString,destination,formMethod);
  
  
                                          var XHR = new XMLHttpRequest();
                                          //var url = 'http://127.0.0.1/00_Seeff/rest_api/api/post/create.php';
                                          var url = destination;
                                          XHR.onload = function () {
  
                                                  // Process our return data
                                                  if (XHR.status >= 200 && XHR.status < 300) {
                                                          // This will run when the request is successful
                                                          //console.log('success!', XHR);
                                                          //console.log('==============');
  
                                                          this.responseString = XHR.response;
  
                                                          // set the server response to on the prototype as an instance var
                                                          if (XHR.readyState == 4){
  this.XHR_readyState = 4;
                                                                  //console.log('Status ready ...............!@#$$@!#' ,44444);
                                                          self.setServerResponse(this.responseString);
                                                  }
                                                          jetXhr.success();
                                                          //console.log(responseString);
                                                  } else {
                                                          // This will run when it's not
                                                          //console.log('The request failed!');
  
                                                          self.setServerResponse(responseString);
                                                          jetXhr.failed();
                                                  }
  
                                                  // This will run either way
                                                  // All three of these are optional, depending on what you're trying to do
                                                  //console.log('This always runs...');
                                          };
                                          //XHR.open('GET', 'https://jsonplaceholder.typicode.com/posts');
  
                                          // Set up our request
                                          //XHR.open('POST', 'https://example.com/cors.php');
                                          // XHR.open('POST', url, true);
                                          XHR.open(formMethod, url, true);
                                          // Add the required HTTP header for form data POST requests
                                          XHR.setRequestHeader('Content-Type', 'application/json; charset=utf-8');
                                          XHR.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
                                          //optional header needs to be allowed in .htaccess
                                          XHR.setRequestHeader('authorization','tn3ji4');
  
  
                                          // Finally, send our data.
                                          try {
                                                  XHR.send(JSON.stringify(jsonString));
                                                  //        console.log(XHR);
                                          }catch(XHR){
                                                  self.setServerResponse('Cant Connect to server'+e);
                                                  jetXhr.failed();
                                          }
  
  
                                  }
  
  
  
                                  //handeling the response event with a custom emitter
                                  jetXhr.prototype.emit=function (instance, name) {
                                          var args = [].slice.call(arguments, 2);
                                          var Textnodes;
                                          if (events.indexOf(name) > -1) {
                                                  // console.log('============handle=====================');
                                                  // console.log(instance);
                                                  //
                                                  // console.log(name);
                                                  // console.log(events);
                                                  // console.log('============handle=====================');
  
                                                  if (instance.handlers[name] && instance.handlers[name] instanceof Array) {
                                                          this.forEach(instance.handlers[name], function (handle) {
                                                                  window.setTimeout(function () {
                                                                          // console.log('============handle=====================');
                                                                          // console.log(handle);
                                                                          // console.log('============Callback=====================');
                                                                          // console.log(handle.callback);
                                                                          // console.log('============context=====================');
                                                                          // console.log(handle.context);
                                                                          handle.callback.apply(handle.context, args);
  
                                                                          //console.log(name);
  
                                                                          if (name == 'select'){
  
                                                                                  //console.log("Cocksucker is now working ");
  
                                                                          }
  
  
                                                                  }, 0);
                                                          });
                                                  }
                                          } else {
                                                  throw new Error(name + ' event cannot be found on jetTreeView.');
                                          }
                                  }
                                  // Prototype to attack custom events
                                  jetXhr.prototype.on = function (name, callback, scope) {
                                          if (events.indexOf(name) > -1) {
  
                                                  //console.log(this);
                                                  if (!this.handlers[name]) {
                                                          this.handlers[name] = [];
                                                  }
                                                  this.handlers[name].push({
                                                          callback: callback,
                                                          context: scope
                                                  });
                                          } else {
                                                  throw new Error(name + ' is not supported by jetTreeView.');
                                          }
                                  };
  
  
  
                                  return jetXhr;
                          }();
  
  
  
  
                          return jetXhr;
  
  
  
  
                  }());
          }));
  }(window.define));
  