- //
- // Browser detect
- //
- var agt = navigator.userAgent.toLowerCase();
- var is_ie = (agt.indexOf("msie") != -1);
- var is_ie5 = (agt.indexOf("msie 5") != -1);
- var is_opera = (agt.indexOf("opera") != -1);
- var is_mac = (agt.indexOf("mac") != -1);
- var is_gecko = (agt.indexOf("gecko") != -1);
- var is_safari = (agt.indexOf("safari") != -1);
- function CreateXmlHttpReq(handler) {
- var xmlhttp = null;
- if (is_ie) {
- // Guaranteed to be ie5 or ie6
- var control = (is_ie5) ? "Microsoft.XMLHTTP" : "Msxml2.XMLHTTP";
- try {
- xmlhttp = new ActiveXObject(control);
- xmlhttp.onreadystatechange = handler;
- } catch (ex) {
- // TODO: better help message
- alert("You need to enable active scripting and activeX controls");
- }
- } else {
- // Mozilla
- xmlhttp = new XMLHttpRequest();
- xmlhttp.onload = handler;
- xmlhttp.onerror = handler;
- }
- return xmlhttp;
- }
- function XmlHttpPOST(xmlhttp, url, data) {
- try {
- xmlhttp.open("POST", url, true);
- xmlhttp.send(data);
- } catch (ex) {
- // do nothing
- }
- }
- // XMLHttp send GEt request
- function XmlHttpGET(xmlhttp, url) {
- try {
- xmlhttp.open("GET", url, true);
- xmlhttp.send(null);
- } catch (ex) {
- // do nothing
- }
- }
- /**
- * parses the given xmlhttp response header for the given
- * key's value
- *
- * The header will look like this:
- * NextIndex: 4
- * PrevFirstName: John
- * PrevLastName: Smith
- * PrevDesired: John
- * Content-Type: text/html; charset=ISO-8859-1
- * Date: Mon, 03 Nov 2003 21:19:53 GMT
- * ...
- *
- */
- function parseResponseHeader(key, header) {
- var lines = header.split("\n");
- var re = new RegExp("^" + key + ":\\s");
- for (var i in lines) {
- if (re.exec(lines[i])) {
- var returnValue = trim(RegExp.rightContext);
- return returnValue;
- }
- }
- return "";
- }
- /**
- * Trim Function (trims leading and trailing whitespace)
- * This function is used by parseResponseHeader, needed because the
- * split function in IE doesn't strip the trailing "\n"
- */
- function trim(value) {
- var temp = value;
- var obj = /^(\s*)([\W\w]*)(\b\s*$)/;
- if (obj.test(temp)) {
- temp = temp.replace(obj, '$2');
- }
- return temp;
- }
|