function GetXmlHttpObject() {
  var xmlHttp=null;
  try {
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
  }
  catch (e) {
    // Internet Explorer
    try {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch (e) {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
  return xmlHttp;
}

function stateChanged(idElement) {
  if (xmlHttp.readyState==4 && xmlHttp.status == 200) {
    document.getElementById(idElement).innerHTML=xmlHttp.responseText;
  }
}

function stateChangedClassName(idElement, ca, cn, a, n) {
  if (xmlHttp.readyState==4 && xmlHttp.status == 200) {
    if (parseInt(xmlHttp.responseText)) {
      document.getElementById(idElement).className = ca;
      document.getElementById(idElement).innerHTML = a;
    } else {
      document.getElementById(idElement).className = cn;
      document.getElementById(idElement).innerHTML = n;
    }
  }
}
 
function stateChangedTexts(idElement, a, n) {
  if (xmlHttp.readyState==4 && xmlHttp.status == 200) {
    document.getElementById(idElement).innerHTML=(parseInt(xmlHttp.responseText))?a:n;
  }
}

function stateChangedButtons(idElement, a, n) {
  if (xmlHttp.readyState==4 && xmlHttp.status == 200) {
    document.getElementById(idElement).value=(parseInt(xmlHttp.responseText))?n:a;
  }
}

function stateChangedImages(idElement, a, n) {
  if (xmlHttp.readyState==4 && xmlHttp.status == 200) {
    document.getElementById(idElement).src=(parseInt(xmlHttp.responseText))?n:a;
  }
}

function stateChangedAlert() {
  if (xmlHttp.readyState==4 && xmlHttp.status == 200) {
    window.alert(xmlHttp.responseText);
  }
}

function stateChangedSendForm(a, n) {
  if (xmlHttp.readyState==4 && xmlHttp.status == 200) {
    window.alert((parseInt(xmlHttp.responseText))?a:n);
  }
}

function stateChangedFunction(func) {
  if (xmlHttp.readyState==4 && xmlHttp.status == 200) {
    eval(func+"('"+xmlHttp.responseText+"');");
  }
}

function do_Ajax(url, target) {
  xmlHttp=GetXmlHttpObject();
  if (xmlHttp==null) {
    alert ("Your browser does not support AJAX!");
    return;
  } 
  
  xmlHttp.open("GET", url, true);
  xmlHttp.onreadystatechange=new Function("", "stateChanged('" + target+ "');");
  xmlHttp.send(null);
}

function do_Ajax_ClassName(url, target, ca, cn, a, n) {
  xmlHttp=GetXmlHttpObject();
  if (xmlHttp==null) {
    alert ("Your browser does not support AJAX!");
    return;
  } 
  
  xmlHttp.open("GET", url, true);
  xmlHttp.onreadystatechange=new Function("", "stateChangedClassName('" + target+ "', '" + ca + "', '" + cn + "', '" + a + "', '" + n + "');");
  xmlHttp.send(null);
}

function do_Ajax_Function(url, func) {
  xmlHttp=GetXmlHttpObject();
  if (xmlHttp==null) {
    alert ("Your browser does not support AJAX!");
    return;
  } 
  
  xmlHttp.open("GET", url, true);
  xmlHttp.onreadystatechange=new Function("", "stateChangedFunction('" + func + "');");
  xmlHttp.send(null);
}

function do_Ajax_Images(url, target, a, n) {
  xmlHttp=GetXmlHttpObject();
  if (xmlHttp==null) {
    alert ("Your browser does not support AJAX!");
    return;
  } 
  
  xmlHttp.open("GET", url, true);
  xmlHttp.onreadystatechange=new Function("", "stateChangedImages('" + target+ "', '" + a + "', '" + n + "');");
  xmlHttp.send(null);
}

function do_Ajax_Buttons(url, target, a, n) {
  xmlHttp=GetXmlHttpObject();
  if (xmlHttp==null) {
    alert ("Your browser does not support AJAX!");
    return;
  } 
  
  xmlHttp.open("GET", url, true);
  xmlHttp.onreadystatechange=new Function("", "stateChangedButtons('" + target+ "', '" + a + "', '" + n + "');");
  xmlHttp.send(null);
}

function do_Ajax_Texts(url, target, a, n) {
  xmlHttp=GetXmlHttpObject();
  if (xmlHttp==null) {
    alert ("Your browser does not support AJAX!");
    return;
  } 
  
  xmlHttp.open("GET", url, true);
  xmlHttp.onreadystatechange=new Function("", "stateChangedTexts('" + target+ "', '" + a + "', '" + n + "');");
  xmlHttp.send(null);
}

function do_Ajax_Alert(url) {
  xmlHttp=GetXmlHttpObject();
  if (xmlHttp==null) {
    alert ("Your browser does not support AJAX!");
    return;
  } 
  
  xmlHttp.open("GET", url, true);
  xmlHttp.onreadystatechange=stateChangedAlert;
  xmlHttp.send(null);
}

function stateAvailChanged() {
  if (xmlHttp.readyState==4 && xmlHttp.status == 200) {
    retVal = xmlHttp.responseText;
    for (i=0; i<retVal.length; i++) {
      clss = retVal.substr(i,1);
      idElement = document.getElementById('ib_' + i);
      if (idElement != null) {
        idElement.className = 'bx' + clss;
      }
    }    
  }
}

function check_avails() {
  xmlHttp=GetXmlHttpObject();
  if (xmlHttp==null) {
    alert ("Your browser does not support AJAX!");
    return;
  }
  url = '/frontoff/och.php?type=basket';
  xmlHttp.open("GET", url, true);
  xmlHttp.onreadystatechange=new Function("", "stateAvailChanged();");
  xmlHttp.send(null);
}


function getElementValue(formElement)
{
	if(formElement.length != null) var type = formElement[0].type;
	if((typeof(type) == 'undefined') || (type == 0)) var type = formElement.type;

	switch(type)
	{
		case 'undefined': return;

		case 'radio':
			for(var x=0; x < formElement.length; x++) 
				if(formElement[x].checked == true)
			return formElement[x].value;

		case 'select-multiple':
			var myArray = new Array();
			for(var x=0; x < formElement.length; x++) 
				if(formElement[x].selected == true)
					myArray[myArray.length] = formElement[x].value;
			return myArray;

		case 'checkbox': return formElement.checked;
	
		default: return formElement.value;
	}
}


	function do_Ajax_sendForm(formElement, a, n){
  var query = "";
	for(var i=0; i< formElement.length; i++)
        if (formElement.elements[i].name)
          query+=formElement.elements[i].name+"="+getElementValue(formElement.elements[i])+"&";

	  xmlHttp=GetXmlHttpObject();
  if (xmlHttp==null) {
    alert ("Your browser does not support AJAX!");
    return;
  } 
  
  xmlHttp.open("GET", formElement.action+"?"+query, true);
  xmlHttp.onreadystatechange=new Function("", "stateChangedSendForm('" + a + "', '" + n + "');");
  xmlHttp.send(null);
	}
