var xmlHttp = createXmlHttpRequestObject ();
var nn=new String();
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 ("not XMLHttpRequest");
	else
		return xmlHttp;
}

function process_podp (id)
{
	email=document.getElementById("email").value;
	fio=document.getElementById("fio").value;
	kod1=document.getElementById("kod_val").value;
	kod2=document.getElementById("kod").value;
	go=document.getElementById("go");
	if(kod1==kod2) {
		go.disabled=true;

	if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
	{
		xmlHttp.open ("GET","addpodp.php?mail="+email+"&fio="+fio+"&page="+id+"&nr="+Math.random(), true);
 		xmlHttp.onreadystatechange = handleServerResponse_podp;
 		xmlHttp.send (null);
	}
	else
	{
	  alert("");
	}
	} else {
		alert("Неверный код!");
		document.getElementById("podpis").submit();		
	}
}

function process (now_ch,count_ch,opros)
{
	form=document.getElementById("opros");
	for (i = 0; i < form.length; i++){
		form[i].disabled=true;
	}

	if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
	{
		xmlHttp.open ("GET","addopros.php?variant="+now_ch+"&opr="+opros+"&nr="+Math.random(), true);
 		xmlHttp.onreadystatechange = handleServerResponse;
 		xmlHttp.send (null);
	}
	else
	{
	  alert("");
	}
}

function handleServerResponse ()
{
        if(xmlHttp.readyState == 4)
	{
		if (xmlHttp.status == 200)
		{
			xmlResponse = xmlHttp.responseXML;
			xmlDocumentElement = xmlResponse.documentElement;
			var html="";
			var cn=xmlResponse.getElementsByTagName('res')[0];
			html="";
			for(var i=0;i<cn.childNodes.length;i++)
				   html+=cn.childNodes[i].data;
			if(html.length!=0)
				alert('Ваш голос добавлен!');
			else
				alert('Действие не удалось!');
			form=document.getElementById("opros");
			form.submit();
/*			for (i = 1; i < form.length; i++){
				form[i].disabled=false;
				form[i].checked=false;
				form[i].disabled=true;
			}*/

		}
		else
		{
			alert (xmlHttp.statusText+':'+xmlHttp.status);
		}
	}
}
function handleServerResponse_podp ()
{
        if(xmlHttp.readyState == 4)
	{
		if (xmlHttp.status == 200)
		{
			xmlResponse = xmlHttp.responseXML;
			xmlDocumentElement = xmlResponse.documentElement;
			var html="";
			var cn=xmlResponse.getElementsByTagName('res')[0];
			html="";
			for(var i=0;i<cn.childNodes.length;i++)
				   html+=cn.childNodes[i].data;
			if(html==1)
				alert('Ваш запрос успешно обработан!');
			else
				alert('Действие не удалось!');
			go=document.getElementById("go");
			go.disabled=false;
			document.getElementById("podpis").submit();		
		}
		else
		{
			alert (xmlHttp.statusText+':'+xmlHttp.status);
		}
	}
}
