function SetAjaxLoader(id_element) {
	if ($("#ajax_loader")) {
		$("#ajax_loader").remove();
	}
	var ajax_loadercontainer = document.createElement('div');
	ajax_loadercontainer.id = 'ajax_loader';
	ajax_loadercontainer.style.position = 'absolute';
	ajax_loadercontainer.style.zIndex = '9';
	ajax_loadercontainer.style.fontSize = '10pt';
	ajax_loadercontainer.style.fontFamily = 'Verdana';	
	ajax_loadercontainer.innerHTML="<center><img src='img/loader.gif'><br>подождите...</center>";
	document.body.appendChild(ajax_loadercontainer);
	$("#ajax_loader").css('top',$("#"+id_element).offset().top + ($("#"+id_element).height())/2 - ($("#ajax_loader").height())/2 +'px');
	$("#ajax_loader").css('left',$("#"+id_element).offset().left + ($("#"+id_element).width())/2  - ($("#ajax_loader").width())/2 +'px');
}


function MyMenu (lst) {
	lst.childNodes[1].style.display="block";
	lst.childNodes[1].style.top = lst.offsetHeight;
	lst.style.background = '#C6000A';
	if($.browser.opera){    
		lst.childNodes[1].style.top = lst.offsetHeight -5 + 'px';
	}
}

function HideMyMenu (lst) {
	lst.childNodes[1].style.display="none";
	lst.style.background = '#404040';
}

function RateMarks(all_marks, rating, lst) {
	all_marks = parseInt(all_marks);
	rating = parseInt(rating);
	var marks = new Array();
	marks.push(all_marks);
	marks.push((all_marks + rating)/2);
	marks.push(all_marks - marks[marks.length-1]);
	
	container = document.createElement('span');
		with(container){
				className = 'RateBox';
				style.left = $(lst).offset().left-0+'px';
				if($.browser.msie){    
                            			style.top = $(lst).offset().top + $(lst).height() + 1 + 'px';
                      			}
				else {
					style.top = $(lst).offset().top + $(lst).height() + 2 + 'px';
                        		}
				//innerHTML = 'Голосов: ' + marks[0] + '<br><font color=green>Плюсов: ' + marks[1] + '</font><br><font color=red>Минусов: ' + marks[2] + '</font>';
				innerHTML = '<div style=float:left;>Проголосовало:</div> &nbsp;' + marks[0] + '<br><font color=green><div style=float:left;>Нравится:</div> &nbsp;' + marks[1] + '</font><br><font color=red><div style=float:left;>Не нравится:</div> &nbsp;' + marks[2] + '</font>';
		}
	$(lst).after(container);
	$(lst).next().slideDown('normal');
}


function HideRate(lst){
	$(lst).next().slideUp('normal', function(){ $(this).remove(); });
}

var http_request = false;
function makeRequest(url,func) {
	http_request = false;

	if (window.XMLHttpRequest) { //   ...
		http_request = new XMLHttpRequest();
        if (http_request.overrideMimeType) {
        		http_request.overrideMimeType('text/xml');
				}
        } 
		
	else if (window.ActiveXObject) { //  
    	try {
        http_request = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
        	try {
            	http_request = new ActiveXObject("Microsoft.XMLHTTP");
            	} catch (e) {}
        	}
      	}
		
	if (!http_request) {
    	alert('Unsuccessful query.');
        return false;
        }
		
    http_request.onreadystatechange = function(){ alertContents(func) };
    http_request.open('GET', url, true);
    http_request.send(null);
}

function alertContents(func_name) {
	if (http_request.readyState == 4) {
    	if (http_request.status == 200) {
        	var xmldata = http_request.responseXML;
            //var xmldata = http_request.responseText;
			func_name(xmldata);
          } 
		else{
        	alert('Data does not return.');
			}
		}
}

// --> Голосование за новость статью
function vote(id_vote,type,direct){
	var amountArea = document.getElementById('am_'+type+'_'+id_vote).innerHTML = '<span class=\'grey\'>обновление...</span>';
	var url = 'js/vote.php?id_vote='+id_vote+'&type='+type+'&direct='+direct;
	makeRequest(url,rtrn_vote);
}

function rtrn_vote(xmldoc){
	var RN = xmldoc.getElementsByTagName('values');
	var id_vote = RN[0].childNodes[0].firstChild.nodeValue;
	var type = RN[0].childNodes[1].firstChild.nodeValue;
	var html = RN[0].childNodes[2].firstChild.nodeValue;	
	
	document.getElementById('am_'+type+'_'+id_vote).innerHTML = html;
}
// --> end

// --> Опрос
function poll(id_poll,theGroup){
	var answer = 0;
	for (i=0; i<= theGroup.length; i++) {
		if (theGroup[i]) {
			if (theGroup[i].checked) {
				var answer = theGroup[i].value;
				break;
			}
		}
	}
	/* var amountArea = document.getElementById('poll_'+id_poll).innerHTML = '<span class=\'grey\'>обновление...</span>'; */
	var url = 'js/poll.php?id_poll='+id_poll + '&answer=' + answer;
	makeRequest(url,rtrn_poll);
}

function rtrn_poll(xmldoc){
	var RN = xmldoc.getElementsByTagName('values');
	var id_poll = RN[0].childNodes[0].firstChild.nodeValue;
	var html = RN[0].childNodes[1].firstChild.nodeValue;	
	
	document.getElementById('poll_'+id_poll).innerHTML = html;
}
// --> end