function opin() {
	divTarget = document.getElementById('div_opinion');
	btnSend = document.getElementById('input_send');
	arAnswers = document.getElementById('form_opinion').input_answer;
	text_mask = document.getElementById('input_text_mask').value.split(':');
	polling_id = document.getElementById('input_polling_id').value;
	input_text = document.getElementById('input_text');
	btnSend.onclick = setOpin;
	xmlHTTP = init_ajax();
}

function setOpin() {
	var messEmpSel = 'Ñäåëàéòå ñâîé âûáîð';
	var	messEmpText = 'Ââåäèòå òåêñò â ïîëå ââîäà';
	select = false;
	for(var i = 0;i < arAnswers.length;i++) 
		if(arAnswers[i].checked === true) {
			select = arAnswers[i].value;
			select_id = i;
			break;
		} 
	text = '';
	if(!select) alert(messEmpSel);
	else 
		if(text_mask[select_id] == '1')
			if(input_text.value=='') alert(messEmpText);
			else {
				text = '&text='+escape(input_text.value);
				opin_ajax_request();
			}
		else {
			opin_ajax_request();
		}
}

function init_ajax() {
	var ajax;
	if(window.XMLHttpRequest) ajax = new XMLHttpRequest();
	else {
		try {
			ajax = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(e1) {
			try {
				xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(e2) {
				xmlHttp = null;
			}
		}
	}
	if(ajax) return ajax;
	else alert("Ajax is not enabled");
}

function opin_ajax_request() {
	var baseUrl = '/ajax/opin_ajax.php';
	var url = baseUrl+'?polling_id='+escape(polling_id)+'&answer_id='+escape(select)+text; 
	xmlHTTP.open('GET',url,true);
	xmlHTTP.onreadystatechange = opin_ajax_response;
	xmlHTTP.send(null);
} 

function opin_ajax_response() {
	if(xmlHTTP.readyState == 4 && xmlHTTP.status == 200)
		divTarget.innerHTML = xmlHTTP.responseText;
}
