﻿// JavaScript Document
function getxmlhttp (){
	var xmlhttp = false;
	try {
	xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		try {
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (E) {
			xmlhttp = false;
		}
	}
	
		if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
			xmlhttp = new XMLHttpRequest();
		}
		return xmlhttp;
}
	
function processajax (serverPage, obj, getOrPost, str){
	xmlhttp = getxmlhttp();
	if (getOrPost == "GET"){
		xmlhttp.open("GET", serverPage);
		xmlhttp.onreadystatechange = function() {
			if(xmlhttp.readyState < 4) { 
			obj.innerHTML = "<img style='padding: 40px; background-color: #999999; border: solid 1px #ffffff;' src='img/ajax-load.gif' border='0'>";
			}
			if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			obj.innerHTML = xmlhttp.responseText; 
			}
		}
	xmlhttp.send(null);
	} else {
		xmlhttp.open("POST", serverPage, true);
		xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
		xmlhttp.onreadystatechange = function() {
			if(xmlhttp.readyState < 4) { 
			obj.innerHTML = "<img style='padding: 80px; background-color: #999999; border: solid 1px #cccccc;' src='img/ajax-load.gif' border='0'>";
			}
			if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			obj.innerHTML = xmlhttp.responseText; 
			}
		}
	xmlhttp.send(str);
	}
}

var showBlock = true;

function showHideBlock(objID, serverPage, e) {
	// objID id объекта в который будет открываться блок АЯКС
	// serverPage путь страницы на сервере в который хранится контент АЯКС для передачи на сайт
	// buttonID #id кнопки или ссылки которая будет менять своё имя/название/содержание при нажатии
		var obj = document.getElementById(objID);
		processajax(serverPage, obj, "GET", "");
}