
function HTTPRequest(eMail) {
  this.pageHTTPRequests = new Object;
  this.mailTo = eMail;
}

function isEmpty(str) { return str == null || str.search(/\S/) < 0; }
function evalScript(code) {
   function getAttribute(i, limit) {
      while (i<limit && (code[i] == ' ' || code[i] == '\n' || code[i] == '\r'
             || code[i] == '\f' || code[i] == '\t')) ++i;
      if (i<limit) {
         var delimiter = code[i];
         var j;
         if (delimiter=="'" || delimiter=='"') {
            j = ++i;
            while (j<limit && delimiter != code[j]) ++j;
         } else {
            j = i+1;
            while (j<limit && code[j] != ' ' && code[j] != '\n'
               && code[j] != '\ r' && code[j] != '\f' && code[j] != '\t') ++j;
         }
         return j<=limit ? code.substring(i,j) : '';
      }
      return '';
   }
   var start=code.indexOf("<script");
   if (start >= 0) {
      var end=code.indexOf(">",start+=7);
      if (end >= 0) {
         var scriptEnd=code.indexOf("</script>",end);
         while (scriptEnd >= 0 && end >= 0 && start >= 0) {
            var attr=code.indexOf("src=",start);
            if (attr >= 0 && attr < start) {
               var script = document.createElement('script');
               script.id = "script"+ new Date().getTime();
               script.src = getAttribute(attr+4, end);
               attr=code.indexOf("language=",start);
               script.language = attr >= 0 && attr < start
                     ? getAttribute(attr+9 , end) : 'javascript';
               attr=code.indexOf("type=",start);
               script.type = attr >= 0 && attr < start
                     ? getAttribute(attr+5, end) : 'text/javascript';
               document.getElementsByTagName("head")[0].appendChild(script);
            }
            eval(code.substring(end+1,scriptEnd));
            start=code.indexOf("<script", scriptEnd+9);
            if (start >= 0) {
               end=code.indexOf(">",start+7);
               if (end >= 0) scriptEnd=code.indexOf("</script>",end);
            }
         }
      }
   }
}

// format 'args' as a request string.  e.g. "x=1&y=2".
// use function getFormValues below to get values from a form.
function makeRequest(url, args, asynchronously, updateFunction, nocache) {
   var req = getHTTPRequestObject(url, args, asynchronously,
                      updateFunction, nocache);
   return asynchronously ? null : req.responseText;
}

function pageHTTPRequest(reqId, updateFunction) {
   this.updateFunction = updateFunction;
   this.reqId = reqId;
   this.isAborted = false;
   this.abort = function() {
      this.isAborted = true;
      this.updateFunction("Currently this content is unavailable..."
         + "  Please refresh later.<br>Contact "+g_request.mailTo
         + " if this problem persists.", false);
     // if(g_request.pageHTTPRequests[this.reqId]!=null)
     // g_request.pageHTTPRequests[this.reqId] = null;
   }
}

function getFormValues(form)  {
   var str = "";
   for (var i=form.elements.length; --i>=0;) {
       var elem = form.elements[i];
       switch (elem.type) {
           case "hidden":
           case "text":
           case "textarea":
           case "password":
                str += elem.name + "=" + escape(elem.value) + "&";
                break;
           case "radio":
           case "checkbox":
                if (elem.checked)
                  str += elem.name + "=" + escape(elem.value) + "&";
                break;
           case "select-one":
                str += elem.name + "=" +
                       elem.options[elem.selectedIndex].value + "&";
                break;
           case "select-multiple": {
                var options = elem.options;
                for (var j=options.length; --j>=0;) {
                   var option = options[j];
                   if (option.selected)
                      str += elem.name + "=" + option.value + "&";
                }
                break;
            }
       }
   }
   return str.substr(0,str.length-1);
}

// format 'args' as a request string.  e.g. "x=1&y=2".
// use function getFormValues below to get values from a form.
//rallsun updated one more argument ptimeDelay in MR20.7 for portlet timeout.
function getHTTPRequestObject(url, args, asynchronously,
                             updateFunction, nocache, ptimeDelay) {
    //START:MR20.7_98
          var timeDelay  =0;                   
                   
           if(ptimeDelay==null||ptimeDelay=='undefined'||ptimeDelay==0){
            timeDelay =60000; //for 60 sec req other than portlet
            // allow 60 seconds for req other than portlets/blocks
           
           }
           else{
           timeDelay =parseInt(ptimeDelay); 
           //timedelay obtained from dcc or default value for portlet DCCKey:BHI_PORTLET_TIMEOUT_MILLISECONDS
           }
                             
      //END:MR20.7_98                     
  var req = false;
// For Safari, Firefox, and other non-MS browsers
  if (window.XMLHttpRequest) {
    try {
      req = new XMLHttpRequest();
    } catch (e) {
      req = false;
    }
  } else if (window.ActiveXObject) {
// For Internet Explorer on Windows
    try {
      req = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        req = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e) {
        req = false;
      }
    }
  }
  if (req) {
   if (typeof asynchronously == 'undefined') asynchronously = false;
   if (typeof updateFunction == 'function') {
      var reqId = ""+ new Date().getTime();
      var pageReqest = g_request.pageHTTPRequests[reqId] =
            new pageHTTPRequest(reqId, updateFunction);
            //START:MR20.7_98 : UPDATED TIMEDELAY ARGUMENT MAKING IT DYNAMIC FOR PORTLETS WHIHC IS 
            //CONFIGURABLE IN DCC
            //alert(g_request.pageHTTPRequests[reqId]+ "req: "+reqId+"\n"+url);
      var abortId = setTimeout("g_request.pageHTTPRequests['"
                     +reqId+"'].abort()", timeDelay); // allow 60 seconds for req other than portlets/blocks
                     //END:MR20.7_98
      req.onreadystatechange = function() {
         if (!pageReqest.isAborted && req.readyState==4) {
            clearTimeout(abortId);
            if (req.status==200)
               updateFunction(req.responseText, true);
            else
               updateFunction("A browser "+req.status
                  +" problem was encountered retrieving this content..."
                  +"  Please refresh later.<br>Contact "
                  +g_request.mailTo+" if this problem persists.", false);
         // if(g_request.pageHTTPRequests[reqId]!=null)
           // g_request.pageHTTPRequests[reqId] = null; 
         }
      };
   }
   if (typeof args == 'undefined' || args == null) {
       req.open('GET', url, asynchronously);
       if (nocache)
          req.setRequestHeader("If-Modified-Since",
                               "Sat, 1 Jan 2000 00:00:00 GMT");
       req.send(null);
   } else {
       req.open('POST', url, asynchronously);
       req.setRequestHeader("Content-Type",
         "application/x-www-form-urlencoded; charset=UTF-8"); 
       req.send(args);
   }
  } else if (typeof updateFunction == 'function') {
      updateFunction("Your browser does not support XMLHTTPRequest objects."
               + "  This page requires Internet Explorer 5 or better"
               + " for Windows, or Firefox for any operating system. Other "
               + "compatible browsers may also exist.", false);
  }
  return req;
}

var g_request = new HTTPRequest("<a href='mailto:ebiz_support@bakerhughes.com'>your BakerHughesDirect administrator</a>");




