function newXMLHttpRequest() {

  var xmlreq = false;

  if (window.XMLHttpRequest) {

    // Create XMLHttpRequest object in non-Microsoft browsers
    xmlreq = new XMLHttpRequest();

  } else if (window.ActiveXObject) {

    // Create XMLHttpRequest via MS ActiveX
    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 with ActiveX
      }
    }
  }

  return xmlreq;
}


/*
 * doAjax
 * itemCode - product code of the item to add.
 *isXmlOrTxt :true or false ,booleam value
 *objId is the ojb which the innnerHTML is to be replaced
 */
function doAjax(backCallHandlerFunction,isXmlOrTxt,StrPOSTOrGET,StrhandlePage,StrPageParam,objId) {

  // Obtain an XMLHttpRequest instance
  var req = newXMLHttpRequest();

  // Set the handler function to receive callback notifications
  var handlerFunction = getReadyStateHandler(req, backCallHandlerFunction,isXmlOrTxt,objId);
  req.onreadystatechange = handlerFunction;
  
  // Open an HTTP POST or Get connection to handler the action.
  req.open(StrPOSTOrGET, StrhandlePage, true);

  // Specify that the body of the request contains form data
  req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

  // Send form encoded data .
  if (StrPageParam!=null || StrPageParam=='')
  {
	  StrPageParam='';
  }
  req.send(StrPageParam);
}


/*
 * xmlHttprequestObj xmlhttp对像
 *backCallHandlerFunction 为处理函数名
 */
function getReadyStateHandler(xmlHttprequestObj, backCallHandlerFunction,isXmlOrTxt,objId) {

  // Return an anonymous function that listens to the 
  // XMLHttpRequest instance
  return function () {

    // If the request's status is "complete"
    if (xmlHttprequestObj.readyState == 4) {
      
      // Check that a successful server response was received
      if (xmlHttprequestObj.status == 200) {

        // Pass the XML payload of the response to the 
        // handler function
		if(isXmlOrTxt){
			backCallHandlerFunction(xmlHttprequestObj.responseXML,objId);
		}
		else{
			
			backCallHandlerFunction(xmlHttprequestObj.responseText,objId);
		}

      } else {

        // An HTTP problem has occurred
        alert("HTTP error: "+xmlHttprequestObj.status);
      }
    }
  }
}




/**
*
*页面回调处理函数backCallHandlerFunction
*/
function replaceInnerHTML(responseText,objId) {	 
   document.getElementById(objId).innerHTML=responseText;      
}

function updateByAjax2(url,params,objId){
	// 组织调参数
	doAjax(replaceInnerHTML,false,"GET",url,params,objId);
}
function updateByAjax(url,objId){
	// 组织调参数
	updateByAjax2(url,'',objId);
}
function doAjaxWithBackCall(backCallFunction,isSync,url,objId){
	
	doAjax(backCallFunction,isSync,"GET",url,'',objId);
	
}
function kong(responseText,objId){
	//alert(a);
	//alert(responseText);
	
}
function logVisit(){
var url="/ameng/linkLog/link_visit_log.asp?refer="+escape(document.referrer)+"&linkUrl="+escape(document.location.href)
	var isSync=true;
	var objId="";
	if(typeof window.posted==='undefined'){
		window.posted=true;
		doAjax(kong,isSync,"GET",url,'','');
	}
}
logVisit();


