/*
 * Returns an new XMLHttpRequest object, or false if the browser
 * doesn't support it
 */
function newXMLHttpRequest() {

  var xmlreq = false;

  // Create XMLHttpRequest object in non-Microsoft browsers
  if (window.XMLHttpRequest) {
    xmlreq = new XMLHttpRequest();

  } else if (window.ActiveXObject) {

    try {
      // Try to create XMLHttpRequest in later versions
      // of Internet Explorer

      xmlreq = new ActiveXObject("Msxml2.XMLHTTP");
      
    } catch (e1) {

      // Failed to create required ActiveXObject
      
      try {
        // Try version supported by older versions
        // of Internet Explorer
      
        xmlreq = new ActiveXObject("Microsoft.XMLHTTP");

      } catch (e2) {

        // Unable to create an XMLHttpRequest by any means
        xmlreq = false;
      }
    }
  }

return xmlreq;
}
/*
function getReadyStateHandler(req) {
   // Return an anonymous function that listens to the XMLHttpRequest instance
   return function () {
		//alert("in here1");
     // If the request's status is "complete"
     if (req.readyState == 4) {
       
       // Check that we received a successful response from the server
       if (req.status == 200) {
       	 //re-create session("SL")already	
       		
       } else {			
         // An HTTP problem has occurred
         alert("HTTP error "+req.status+": "+req.statusText);
         //hideLoadingMessage(SpanID);
       }
     }
   }
}
*/
function getReadyStateHandler(SpanID, req, responseXmlHandler) {
   // Return an anonymous function that listens to the XMLHttpRequest instance
   return function () {
		//alert("in here1");
     // If the request's status is "complete"
     if (req.readyState == 4) {
       
       // Check that we received a successful response from the server
       if (req.status == 200) {
       //alert("in here2");
         // Pass the XML payload of the response to the handler function.         
         responseXmlHandler(req.responseText); //response HTML
         //responseXmlHandler(req.responseXML);    //response XML
         hideLoadingMessage(SpanID);
		 //window.showMessage(SpanID,"Success")
    	 //window.setTimeout("window.hideLoadingMessage('"+SpanID+"')",1000);	
       } else {
			
         // An HTTP problem has occurred
         alert("HTTP error "+req.status+": "+req.statusText);
         hideLoadingMessage(SpanID);
       }
     }
   }
}

function getReadyXMLStateHandler(SpanID, msgId, flag, tagId, req, responseXmlHandler) {
   // Return an anonymous function that listens to the XMLHttpRequest instance
   return function () {
		//alert("in here1");
     // If the request's status is "complete"
     if (req.readyState == 4) {
       
       // Check that we received a successful response from the server
       if (req.status == 200) {
       //alert("in here2");
         // Pass the XML payload of the response to the handler function.         
         //responseXmlHandler(req.responseText); //response HTML
         responseXmlHandler(msgId, flag, tagId, req.responseXML);    //response XML
         hideLoadingMessage(SpanID);
		 //window.showMessage(SpanID,"Success")
    	 //window.setTimeout("window.hideLoadingMessage('"+SpanID+"')",1000);	
       } else {
			
         // An HTTP problem has occurred
         alert("HTTP error "+req.status+": "+req.statusText);
         hideLoadingMessage(SpanID);
       }
     }
   }
}

function getReadyUploadStateHandler(SpanID, tagId, req, responseXmlHandler) {
   // Return an anonymous function that listens to the XMLHttpRequest instance
   return function () {
		//alert("in here1");
     // If the request's status is "complete"
     if (req.readyState == 4) {
       
       // Check that we received a successful response from the server
       if (req.status == 200) {
       //alert("in here2");
         // Pass the XML payload of the response to the handler function.         
         responseXmlHandler(tagId,req.responseText); //response HTML
         //responseXmlHandler(tagId, req.responseXML);    //response XML
         if(!SpanID && SpanID!=""){
	         hideLoadingMessage(SpanID);
			 //window.showMessage(SpanID,"Success")		
	    	 //window.setTimeout("window.hideLoadingMessage('"+SpanID+"')",1000);
    	 }	
       } else {
			
         // An HTTP problem has occurred
         alert("HTTP error "+req.status+": "+req.statusText);
         if(!SpanID && SpanID!=""){
         	hideLoadingMessage(SpanID);
         }
       }
     }
   }
}

function getReadySwitchStateHandler(SpanID, tagId, url, req, responseXmlHandler) {
   // Return an anonymous function that listens to the XMLHttpRequest instance
   return function () {
		//alert("in here1");
     // If the request's status is "complete"
     if (req.readyState == 4) {
       
       // Check that we received a successful response from the server
       if (req.status == 200) {
       //alert("in here2");
         // Pass the XML payload of the response to the handler function.         
         //responseXmlHandler(tagId,url,req.responseText); //response HTML
         responseXmlHandler(tagId,url,req.responseXML);    //response XML
         hideLoadingMessage(SpanID);
		 //window.showMessage(SpanID,"Success")
    	 //window.setTimeout("window.hideLoadingMessage('"+SpanID+"')",1000);	
       } else {
			
         // An HTTP problem has occurred
         alert("HTTP error "+req.status+": "+req.statusText);
         hideLoadingMessage(SpanID);
       }
     }
   }
}

function getReadyPicStateHandler(SpanID, field, tagId, req, responseXmlHandler) {
   // Return an anonymous function that listens to the XMLHttpRequest instance
   return function () {
		//alert("in here1");
     // If the request's status is "complete"
     if (req.readyState == 4) {
       
       // Check that we received a successful response from the server
       if (req.status == 200) {
       //alert("in here2");
         // Pass the XML payload of the response to the handler function.         
         responseXmlHandler(tagId,field,req.responseText); //response HTML
         //responseXmlHandler(tagId, req.responseXML);    //response XML
         hideLoadingMessage(SpanID);
		 //window.showMessage(SpanID,"Success")
    	 //window.setTimeout("window.hideLoadingMessage('"+SpanID+"')",1000);	
       } else {
			
         // An HTTP problem has occurred
         alert("HTTP error "+req.status+": "+req.statusText);
         hideLoadingMessage(SpanID);
       }
     }
   }
}
