function getXmlHttp() {
  var xmlhttp;
  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 sendingContent(hash, type) {
	var xmlHttp;
	xmlHttp = getXmlHttp();

	xmlHttp.onreadystatechange = function()  {
	    if (xmlHttp.readyState == "4") {

			var json = eval( "(" + xmlHttp.responseText + ")" );

			document.getElementById("getInfoContent").style.display = "block";
		}
		else {
			// выводим элемент загрузки
			document.getElementById("spanShowInformation").innerHTML += '<b style="font-weight:normal; color:orange;">Подождите, идёт отправление контента на модерацию</b><br />';
		}
	}

		xmlHttp.open('GET', '/ajax/contentWork.php?type=5&row='+type+'&hash='+hash+'&rand='+Math.random(), true);
		xmlHttp.send(null);

}

function getMainChastota(hash, type) {
	var xmlHttp;
	xmlHttp = getXmlHttp();

	xmlHttp.onreadystatechange = function()  {
	    if (xmlHttp.readyState == "4") {

			var json = eval( "(" + xmlHttp.responseText + ")" );

			var sAlert = json.alert;

			document.getElementById("spanShowInformation").innerHTML += sAlert;

			sendingContent(hash, type);
		}
		else {
			// выводим элемент загрузки
			document.getElementById("spanShowInformation").innerHTML += '<b style="font-weight:normal; color:orange;">Подождите, идёт выделение частоты ключевых слов исходника</b><br />';
		}
	}

		xmlHttp.open('GET', '/ajax/contentWork.php?type=4&row='+type+'&hash='+hash+'&rand='+Math.random(), true);
		xmlHttp.send(null);
}


function getContentChastota(hash, type) {
	var xmlHttp;
	xmlHttp = getXmlHttp();

	xmlHttp.onreadystatechange = function()  {
	    if (xmlHttp.readyState == "4") {

			var json = eval( "(" + xmlHttp.responseText + ")" );

			var sAlert = json.alert;

			document.getElementById("spanShowInformation").innerHTML += sAlert;

			getMainChastota(hash, type);
		}
		else {
			// выводим элемент загрузки
			document.getElementById("spanShowInformation").innerHTML += '<b style="font-weight:normal; color:orange;">Подождите, идёт выделение частоты ключевых слов контента</b><br />';
		}
	}

		xmlHttp.open('GET', '/ajax/contentWork.php?type=3&row='+type+'&hash='+hash+'&rand='+Math.random(), true);
		xmlHttp.send(null);
}


function getUnikText(hash, type) {
	var xmlHttp;
	xmlHttp = getXmlHttp();

	xmlHttp.onreadystatechange = function()  {
	    if (xmlHttp.readyState == "4") {

			var json = eval( "(" + xmlHttp.responseText + ")" );

			var sAlert = json.alert;

			document.getElementById("spanShowInformation").innerHTML += sAlert;

			getContentChastota(hash, type);
		}
		else {
			// выводим элемент загрузки
			document.getElementById("spanShowInformation").innerHTML += '<b style="font-weight:normal; color:orange;">Определение уникальности текста займёт от 30 до 120 секунд, идите попейте пока кофе ;)</b><br />';
		}
	}

		xmlHttp.open('GET', '/ajax/contentWork.php?type=2&row='+type+'&hash='+hash+'&rand='+Math.random(), true);
		xmlHttp.send(null);
}


function getUrlContent(hash, type) {
	var xmlHttp;
	xmlHttp = getXmlHttp();

	xmlHttp.onreadystatechange = function()  {
	    if (xmlHttp.readyState == "4") {

			var json = eval( "(" + xmlHttp.responseText + ")" );

			var sAlert = json.alert;

			document.getElementById("spanShowInformation").innerHTML += sAlert;

			getUnikText(hash, type);
		}
		else {
			// выводим элемент загрузки
			document.getElementById("spanShowInformation").innerHTML += '<b style="font-weight:normal; color:orange;">Подождите, идёт сбор информации о контенте</b><br />';
		}
	}

		xmlHttp.open('GET', '/ajax/contentWork.php?type=1&row='+type+'&hash='+hash+'&rand='+Math.random(), true);
		xmlHttp.send(null);

}



function checkUnikSpec(hash) {
	var xmlHttp;
	xmlHttp = getXmlHttp();

	xmlHttp.onreadystatechange = function()  {
	    if (xmlHttp.readyState == "4") {

			var json = eval( "(" + xmlHttp.responseText + ")" );

			var sAlert = json.alert;

			document.getElementById("spanShowInformation").innerHTML += sAlert;
			document.getElementById("getInfoContent").style.display	=	"";

			getUnikText(hash, type);
		}
		else {
			// выводим элемент загрузки
			document.getElementById("spanShowInformation").innerHTML += '<b style="font-weight:normal; color:orange;">Подождите, идёт проверка уникальности. Операция может занять пару минут!</b><br />';
		}
	}

		xmlHttp.open('GET', '/ajax/checkUnikSpec.php?hash='+hash+'&rand='+Math.random(), true);
		xmlHttp.send(null);

}


function onLineUsers(id, locate) {
	var xmlHttp;
	xmlHttp = getXmlHttp();

	xmlHttp.onreadystatechange = function()  {
		if (xmlHttp.readyState == "4") {
		}
	}

	xmlHttp.open('GET', '/ajax/onLineUsers.php?id='+id+'&locate='+locate+'&rand='+Math.random(), true);
	xmlHttp.send(null);
}



function showOnLineUsers() {
	var xmlHttp;
	xmlHttp = getXmlHttp();

	xmlHttp.onreadystatechange = function()  {
	    if (xmlHttp.readyState == "4") {
			var json = eval( "(" + xmlHttp.responseText + ")" );
			
			var sReturnData = json.returnData;
			
			document.getElementById("spanOfOnLineUsers").innerHTML = sReturnData;
		}
		else {
			document.getElementById("spanOfOnLineUsers").innerHTML	=	'<img src="/games/9/karts/preloader.gif" border="0" /><br /><br />';
		}
	}

	xmlHttp.open('GET', '/ajax/spanOfOnLineUsers.php?rand='+Math.random(), true);
	xmlHttp.send(null);
}

function getUrlToInput(url) {
	document.getElementById("idMainSource").value	=	url;
}

function getListOfPortalLinks(id) {
	var xmlHttp;
	xmlHttp = getXmlHttp();

	xmlHttp.onreadystatechange = function()  {
	    if (xmlHttp.readyState == "4") {
			var json = eval( "(" + xmlHttp.responseText + ")" );
			
			var sReturnData = json.returnData;
			if (sReturnData != "") {
				document.getElementById("spanOfListOfPortalLinks").innerHTML = "<br /><br />"+sReturnData;
			}
			else {
				document.getElementById("spanOfListOfPortalLinks").innerHTML = "<br /><br /><b style='color:red;'>информация не найдена</b>";
			}
		}
		else {
			document.getElementById("spanOfListOfPortalLinks").innerHTML	=	'<img src="/games/9/karts/preloader.gif" border="0" /><br /><br />';
		}
	}

	xmlHttp.open('GET', '/ajax/getPortalLinks.php?id='+id+'rand='+Math.random(), true);
	xmlHttp.send(null);
}
