function createXMLHttpRequest() {
  var xmlReq = false;
  // branch for native XMLHttpRequest object
  if(window.XMLHttpRequest) {
    try {
      xmlReq = new XMLHttpRequest();
    } catch(e) {
      xmlReq = false;
    }
  // branch for IE/Windows ActiveX version
  } else if(window.ActiveXObject) {
    try {
      xmlReq = new ActiveXObject("Msxml2.XMLHTTP");
    } catch(e) {
      try {
        xmlReq = new ActiveXObject("Microsoft.XMLHTTP");
      } catch(e) {
        xmlReq = false;
      }
    }
  }
  return xmlReq;
}

var userAgent = { };
userAgent.isAJAX = (createXMLHttpRequest()?true:false);
userAgent.isMozilla = (navigator.userAgent.match(/\bGecko\b/));
userAgent.isOpera = (navigator.userAgent.match(/\bOpera\b/));
userAgent.isInternetExplorer = (navigator.userAgent.match(/\bMSIE\b/) && !userAgent.isOpera);

function callServer(method, url, data, dataType, func, arg) {
  if (!method) method='GET';
  var xmlReq = createXMLHttpRequest();
  if(xmlReq) {
    xmlReq.onreadystatechange = function() {
        // only if xmlReq shows "loaded"
        if (xmlReq.readyState == 4) {
          func(arg, xmlReq.responseText, xmlReq.responseXML, xmlReq.status, xmlReq.statusText);
        }
      };
    xmlReq.open(method, url, true);
    if (data) {
      if (!dataType) dataType='application/xml';
      if (typeof(data)!="string" && dataType.indexOf("charset=")<0 && userAgent.isMozilla) dataType=dataType+';charset=utf-8'; // in Mozilla XML always serialized as UTF-8
      xmlReq.setRequestHeader('Content-Type', dataType);
    }
    xmlReq.send(data);
    return false;
  }
  return true;
}


function showHTML(element, responseText, responseXML, statusCode, statusText) {
  if (typeof(element)=="string") element=document.getElementById(element);
  if (statusCode==200 || statusCode==201) {
    element.innerHTML=responseText;
  }
  else {
    alert("Загрузить информацию не удалось:\n"+statusText);
  }
}






function ChangeHTML(id,elm) {
	document.getElementById(id).innerHTML = elm.innerHTML;
	document.getElementById(id).onclick = function onclick(event) {GetWordSyns(this)};
	document.getElementById(id).style.borderBottom = '1px #0C0 dashed;';
	return false;
}

function GetContent(id,url) {
	callServer(null, url, null, null, showHTML, id);
}

function gcl(url,id){
	gid(id).innerHTML = '<img src="/images/icons/loading.gif">';
	callServer(null, url, null, null, showHTML, id);
}

function remember(id){
callServer(null, '/remember/?id='+id, null, null, showHTML, 'rmbr'+id);
}

function remind(id,email,phone){
gcl('/rem/?product_id='+id+'&email='+email+'&phone='+phone, 'prodremind');
}
function remindRoll(id){
  gid('prodremind').innerHTML='';
  Elem = gid('srem');
  Elem.style.display = 'block';
  Elem.style.top=document.body.scrollTop-getClientHeight()/2;
  Elem.style.left=document.body.scrollLeft+getClientWidth()/2-300;
  gid('remprod_id').value=id;
}
function remindRoll2(id){
  gid('prodremind').innerHTML='';
  Elem = gid('srem');
  Elem.style.display = 'block';
  Elem.style.top=document.body.scrollTop+getClientHeight()/2-200;
  Elem.style.left=document.body.scrollLeft+getClientWidth()/2-300;
  gid('remprod_id').value=id;
}

function getClientWidth()
{
  return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientWidth:document.body.clientWidth;
}

function getClientHeight()
{
  return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientHeight:document.body.clientHeight;
}


