var xmlHttp = createXmlHttpRequestObject();

function createXmlHttpRequestObject()
{
	var xmlHttp;
	
	if (window.ActiveXObject)
	{
		try
		{
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch (e)
		{
			xmlHttp  = false;
		}
	}
	else
	{
		try
		{
			xmlHttp = new XMLHttpRequest();
		}
		catch (e)
		{
			xmlHttp  = false;
		}
	}
	
	if (!xmlHttp)
		alert("Ошибка создания переменной AJAX")
	else
		return xmlHttp;
}

function update_database(text)
{
	var sendtext;
	var xmlHttp = createXmlHttpRequestObject();
	if ((xmlHttp.readyState == 4)||(xmlHttp.readyState == 0))
	{
//		name = encodeURICComponent(document.get)
		sendtext = "updatedata.php?text="+text;
		xmlHttp.open("GET",sendtext,true);
//		xmlHttp.onreadystatechange = handleServerResponse;
		xmlHttp.send(null);
	}
	else 
	setTimeout("update_database(text)",1000);
}

function askscript(src)
{
	var sendtext,src2;
	
	if ((xmlHttp.readyState == 4)||(xmlHttp.readyState == 0))
	{
		src2=src;
		src2 = src2.replace('?','yyy');
		src3 = src2.replace('&','xxx');
		while (src2 != src3)
		{
			src2 = src3;
			src3 = src2.replace('&','xxx');
		}

		sendtext = "google.php?src="+src2;
		
		xmlHttp.open("GET",sendtext,false);
	//	xmlHttp.onreadystatechange = handleServerResponse;
		xmlHttp.send(null);
	}
	//else 
	//{setTimeout("getdata_from_mysql(element,value)",2000);}
}

function askscript2(src)
{
	var sendtext,src2;
	
	if ((xmlHttp.readyState == 4)||(xmlHttp.readyState == 0))
	{
		src2=src;
		src2 = src2.replace('?','yyy');
		src3 = src2.replace('&','xxx');
		while (src2 != src3)
		{
			src2 = src3;
			src3 = src2.replace('&','xxx');
		}

		sendtext = "google2.php?src="+src2;
		
		xmlHttp.open("GET",sendtext,false);
	//	xmlHttp.onreadystatechange = handleServerResponse;
		xmlHttp.send(null);
	}
	//else 
	//{setTimeout("getdata_from_mysql(element,value)",2000);}
}

function getdata_from_mysql(element,value)
{
	var sendtext;
	
	if ((xmlHttp.readyState == 4)||(xmlHttp.readyState == 0))
	{
		//senttext = document.getElementById('Yearsel').value;
//		name = encodeURICComponent(document.get)
		sendtext = "return_gigdate.php?year="+value;
		xmlHttp.open("GET",sendtext,true);
		xmlHttp.onreadystatechange = handleServerResponse;
		xmlHttp.send(null);
	}
	//else 
	//{setTimeout("getdata_from_mysql(element,value)",2000);}
}

function handleServerResponse()
{
//	var month,day;
	if (xmlHttp.readyState == 4)
	{
		if (xmlHttp.status == 200)
		{
			xmlResponse = xmlHttp.responseXML;
			xmlDocumentElement = xmlResponse.documentElement;
		    month = xmlDocumentElement.firstChild.data;
			helloMessage = xmlDocumentElement.firstChild.data;

			//day = xmlDocument.firstChild.data;
		//	document.getElementById("monthsel").innerHTML = month;
			temp = "<option>"+month+"</option>";
			document.getElementById("monthmessage").innerHTML = temp;
			document.getElementById("divmessage").innerHTML = month;
			
			
		}
	}
}
