function getID(elem) {
	return document.getElementById(elem);
}
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 vote() {
    var req = getXmlHttp();  
	var statusElem = getID('voteBlock');
	var radio = $('input[name="otvet"]:checked').val();
	req.open('GET', '/ajax.php?otvetNum='+radio+'&voteID='+getID('voteID').value, true);
    req.onreadystatechange = function() {  
        if (req.readyState == 4 && req.status == 200) { 
            statusElem.innerHTML = req.responseText;
			$('.vote_line').show('slow');
        }
    }
    req.send(null);
    statusElem.innerHTML = "<img src='/zm_cms/images/loading.gif' alt='' />";
}
function sendQuestion() {
    var req = getXmlHttp();
	var onemail = ($("input:checked[name=onemail]").val() == 1)?1:0;
	var param = 'qName='+$("#qName").val()+'&qEmail='+$("#qEmail").val()+'&qQuestion='+$("#qQuestion").val()+'&onemail='+onemail;
	req.open('POST', '/ajax.php', true);
	req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	req.setRequestHeader("Content-length", param.length);
	req.setRequestHeader("Connection", "close");
    req.onreadystatechange = function() {  
        if (req.readyState == 4 && req.status == 200) { 
            $("#voprosModal").html(req.responseText);
			$( ".sendQuestionBtn" ).button({icons: {primary: "ui-icon-disk"},text: true	})
			$( ".closeBtn" ).button({icons:{primary: "ui-icon-closethick"},text: true})
        }
    }
    req.send(param);
    $("#voprosModal").html("<img src='/zm_cms/images/loading.gif' alt='' />");
}
function loadCalendar(y,d) {
	var req = getXmlHttp();
	req.open('GET', '/ajax.php?calendarYear='+y, true);
    req.onreadystatechange = function() {
        if (req.readyState == 4 && req.status == 200) {
			if(d == 'in') $('#calendarUp').html("<img src='/images/catalog_up.gif' width='14' height='14' alt='Выйти' title='Выйти' onclick=\"loadCalendar('','out')\" style='cursor:pointer;' />");
			else $('#calendarUp').html("");
			$('#vScroll').html(req.responseText);
		}
    }
    req.send(null);
    $('#vScroll').html("<li><center><img src='/zm_cms/images/loading.gif' alt='' style='padding:10px' /></center></li>");
}
function showFilters() {
    var req = getXmlHttp();  
	req.open('GET', '/ajax.php?showFilters=yes', true);
    req.onreadystatechange = function() {  
        if (req.readyState == 4 && req.status == 200) { 
            $('#catalogFormHead').html(req.responseText);
			$('.vote_line').show('slow');
        }
    }
    req.send(null);
    $('#catalogFormHead').html("<img src='/zm_cms/images/loading.gif' alt='' style='margin:25px' />");
}
function catalogSearch() {
    var req = getXmlHttp();
	var param = 'goSearch=1&cTitle='+$("select[name=cTitle]").val()+'&cOEM='+$("select[name=cOEM]").val()+'&cMark='+$("select[name=cMark]").val()+'&cModel='+$("select[name=cModel]").val()+'&cEngine='+$("select[name=cEngine]").val()+'&cYear='+$("select[name=cYear]").val()+'&cArticle='+$("input[name=cArticle]").val();
	req.open('POST', '/ajax.php', true);
	req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	req.setRequestHeader("Content-length", param.length);
	req.setRequestHeader("Connection", "close");
    req.onreadystatechange = function() {  
        if (req.readyState == 4 && req.status == 200) { 
            $("#catalogContent").html(req.responseText);
        }
    }
    req.send(param);
    $("#catalogContent").html("<img src='/zm_cms/images/loading.gif' alt='' style='margin:15px' />");
}
function changeTovar() {
	var tovar = $("select[name=rTitle]").val();
	$("#rightMark").load("/ajax.php?rightTovar="+encodeURIComponent(tovar));
}
function changeMark() {
	var mark = $("#rightMark").find(':selected').text(); 
	$("#rightModel").load("/ajax.php?rightMark="+encodeURIComponent(mark));
}
