// ajax request
var req;

function loadXMLDoc(url) {

//FF
if (window.XMLHttpRequest) {
	req = new XMLHttpRequest();
	req.onreadystatechange = processReqChange;
    req.open("GET", url, true);
    req.send(null);
}
//IE
else if (window.ActiveXObject) {
    req = new ActiveXObject("Microsoft.XMLHTTP");
	req.onreadystatechange = processReqChange;
    if (req) {
        req.open("GET", url, true);
        req.send();
    }
}
}

// handle onreadystatechange event of req object
function processReqChange(){
	if (typeof req != "undefined") {//can become undefined in FF
		// only if req shows "complete"
		if (req.readyState == 4) {
			// only if "OK"
			if (req.status == 200) {
				eval(req.responseText);

			} else {
				alert("There was a problem retrieving the XML data:\n" + req.statusText);
//				document.getElementById("searchResults").innerHTML = 'There was a problem retrieving the XML data' + req.statusText;
			}
		}
	}
}



//via http://www.ajaxfreaks.com/tutorials/6/1.php

function createRequestObject() {

       var req;

       if(window.XMLHttpRequest){
          // Firefox, Safari, Opera...
          req = new XMLHttpRequest();
       } else if(window.ActiveXObject) {
          // Internet Explorer 5+
          req = new ActiveXObject("Microsoft.XMLHTTP");
       } else {
          // There is an error creating the object,
          // just as an old browser is being used.
          alert('Problem creating the XMLHttpRequest object');
       }

       return req;

    }

    // Make the XMLHttpRequest object
    var http = createRequestObject();

    function sendRequest(q,ph,b,s) {

       // Open PHP script for requests
//       http.open('get', 'suggest.php?q='+q);
//       http.onreadystatechange = handleResponse;
//       http.send(null);
    if (http) {
        http.open("GET", '/ziumsystem/livesearch.asp?q='+q+'&pagehandler='+ph+'&brochureid='+b+'&sessionid='+s, true);
		http.onreadystatechange = handleResponse;
        http.send();
    }
    }

    function handleResponse() {
    	if (typeof http != "undefined") {//can become undefined in FF
		// only if req shows "complete"
		if (http.readyState == 4) {
			// only if "OK"
			if (http.status == 200) {
				document.getElementById("searchResults").innerHTML = http.responseText;
			} else {
				document.getElementById("searchResults").innerHTML = 'There was a problem retrieving the XML data' + http.statusText;
//				alert("There was a problem retrieving the XML data:\n" + http.statusText);
			}
		}
	}

}

//via http://www.captain.at/howto-ajax-form-post-request.php
   var http_request = false;
   function makePOSTRequest(url, parameters) {
      http_request = false;
      if (window.XMLHttpRequest) { // Mozilla, Safari,...
         http_request = new XMLHttpRequest();
         if (http_request.overrideMimeType) {
         	// set type accordingly to anticipated content type
            //http_request.overrideMimeType('text/xml');
            http_request.overrideMimeType('text/html');
         }
      } else if (window.ActiveXObject) { // IE
         try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {
               http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }
      if (!http_request) {
         alert('Cannot create XMLHTTP instance');
         return false;
      }

      http_request.onreadystatechange = alertContents;
      http_request.open('POST', url, true);
      http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      http_request.setRequestHeader("Content-length", parameters.length);
      http_request.setRequestHeader("Connection", "close");
      http_request.send(parameters);
   }

   function alertContents() {
      if (http_request.readyState == 4) {
         if (http_request.status == 200) {
//            alert(http_request.responseText);
            result = http_request.responseText;
//            document.getElementById('fn-sms-response').innerHTML = result;
         } else {
            alert('There was a problem with the request.');
         }
      }
   }

   function get(obj) {
      var poststr = "mytextarea1=" + encodeURI( document.getElementById("mytextarea1").value ) +
                    "&mytextarea2=" + encodeURI( document.getElementById("mytextarea2").value );
      makePOSTRequest('/ziumsystem/sendsms.asp', poststr);
   }

