var XMLHTTPREQUEST_MS_PROGIDS = new Array(
  "Msxml2.XMLHTTP.7.0",
  "Msxml2.XMLHTTP.6.0",
  "Msxml2.XMLHTTP.5.0",
  "Msxml2.XMLHTTP.4.0",
  "MSXML2.XMLHTTP.3.0",
  "MSXML2.XMLHTTP",
  "Microsoft.XMLHTTP"
);

var XMLHTTPREQUEST_READY_STATE_UNINITIALIZED = 0;
var XMLHTTPREQUEST_READY_STATE_LOADING       = 1;
var XMLHTTPREQUEST_READY_STATE_LOADED        = 2;
var XMLHTTPREQUEST_READY_STATE_INTERACTIVE   = 3;
var XMLHTTPREQUEST_READY_STATE_COMPLETED     = 4;

function getXMLHttpRequest(){
  var httpRequest = null;
  if (window.XMLHttpRequest != null)
    httpRequest = new window.XMLHttpRequest();
  else if (window.ActiveXObject != null){
    var success = false;
    for (var i = 0; i < XMLHTTPREQUEST_MS_PROGIDS.length && !success; i++){
      try{
        httpRequest = new ActiveXObject(XMLHTTPREQUEST_MS_PROGIDS[i]);
        success = true;
      }
      catch (ex)
      {}
    }
  }

  if (httpRequest == null)
    alert("Error in HttpRequest():\n\nCannot create an XMLHttpRequest object.");
  return httpRequest;
}

var myXmlHttpRequest = getXMLHttpRequest();

function checker(event, writein){
  var send_data = document.getElementById(event).value;
  var url = "/ajax_loader?" +event+"="+send_data;
  myXmlHttpRequest.open("GET", url, false);
  myXmlHttpRequest.send(null);
/*
  myXmlHttpRequest.open("POST", url, true);
  myXmlHttpRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  myXmlHttpRequest.send(document.getElementById(event).value);
*/
  try{
    var data = myXmlHttpRequest.responseText;
    document.getElementById(writein).innerHTML=myXmlHttpRequest.responseText
  }
  catch (ex)
  {}
}


function toggle(id){
	e = document.getElementById(id);
	e1 = document.getElementById('link_'+id);
	var display = e.style.display ? '' : 'none';
	e.style.display = display;
}

function getElementPosition(elemID) {
	var offsetTrail = document.getElementById(elemID);
	var offsetLeft = 0;
	var offsetTop = 0;
	while (offsetTrail) {
		offsetLeft += offsetTrail.offsetLeft;
		offsetTop += offsetTrail.offsetTop;
		offsetTrail = offsetTrail.offsetParent;
	}
	if (navigator.userAgent.indexOf("Mac") != -1 && typeof document.body.leftMargin != "undefined" && navigator.appName=="Microsoft Internet Explorer" ) {
		offsetLeft += parseInt(document.body.leftMargin);
		offsetTop += parseInt(document.body.topMargin);
	}
	return {left:offsetLeft, top:offsetTop};
}
