var msg0 = 'уже голосовали';
var msg1 = 'спасибо'
var msg10 = 'всего голосов: '

var xmlhttp
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
  try {
  xmlhttp=new ActiveXObject("Msxml2.XMLHTTP")
 } catch (e) {
  try {
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
  } catch (E) {
   xmlhttp=false
  }
 }
@else
 xmlhttp=false
@end @*/
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
 try {
  xmlhttp = new XMLHttpRequest();
 } catch (e) {
  xmlhttp=false
 }
}
function myXMLHttpRequest() {
  var xmlhttplocal;
  try {
    xmlhttplocal= new ActiveXObject("Msxml2.XMLHTTP")
 } catch (e) {
  try {
    xmlhttplocal= new ActiveXObject("Microsoft.XMLHTTP")
  } catch (E) {
    xmlhttplocal=false;
  }
 }

if (!xmlhttplocal && typeof XMLHttpRequest!='undefined') {
 try {
  var xmlhttplocal = new XMLHttpRequest();
 } catch (e) {
  var xmlhttplocal=false;
  alert('couldn\'t create xmlhttp object');
 }
}
return(xmlhttplocal);
}


function sendVoteRes(votingid) {
	
	var element = document.getElementById('votingdiv');
	
	var answer=document.votingform.voterb;
	
	answerselected=-1;

	for(i=0;i<answer.length;i++){
		if (answer[i].checked)
		{
			answerselected=answer[i].value;
		}
	}
	//new Effect.Fade(element);
    element.innerHTML = '<div id="votingdiv" name="votingdiv" style="padding-top:60px">Идет обработка ...</div>';
	
    sid=Math.round(Math.random()*100);

	xmlhttp.open('get', '/controlsystem/vote.php?voting='+votingid+'&votingtype=1'+"&answer="+answerselected+"&sid="+sid);
    xmlhttp.onreadystatechange = handleResponse;
    xmlhttp.send(null);
	
}

function sendVoteResMult(votingid) {
	
	var element = document.getElementById('votingdiv');
	
	var answer=document.votingform.voterb;
	var votingtype=document.votingform.votingtype.value;
//	votingtype=2;
	
	answstr='';

	for(i=0;i<document.votingform.elements.length;i++){
		var elmnt=document.votingform.elements[i];
		elmntname=elmnt.name;
		if (elmntname.substr(0,7)=='votechk')
		{
			if (document.votingform.elements[i].checked)
			{
				answstr=answstr+'&'+elmntname+'=1'
			}
		}
	}
//	alert(votingtype);
	if (answstr=='')
	{
		return false;
	}

	//new Effect.Fade(element);
    element.innerHTML = '<div id="votingdiv" name="votingdiv" style="padding-top:60px">Идет обработка ...</div>';
	
    sid=Math.round(Math.random()*100);

	xmlhttp.open('get', '/controlsystem/vote.php?voting='+votingid+'&votingtype='+votingtype+answstr+"&sid="+sid);
    xmlhttp.onreadystatechange = handleResponse;
    xmlhttp.send(null);
	
}

function handleResponse() {

//	var response = xmlhttp.responseText;
//	alert(response);

	if(xmlhttp.readyState == 4)
	{
		if (xmlhttp.status == 200)
		{
       	
			var response = xmlhttp.responseText;
//			alert(response);

			text=response;
			document.all['votingdiv'].innerHTML=text;
			document.getElementById('votingdiv').innerHTML=text;
		}			
    }
}

function showText() {
	st="";
	st="<table width=100% border=0 cellpadding=0 cellspacing=0>";
	st+="<tr><td colspan=3><b>Спартак - Интер. Едем?</b></td></tr><tr><td colspan=3 height=10></td></tr><tr><td width=80%>Определюсь ближе к матчу";
	st+="<td width=10% align=right valign=bottom>5<td width=10% align=right valign=bottom>(<i>7%</i>)";
	st+="<tr class='votebar'><td colspan=3 class='votebar'><img src='/controlsystem/icons/opin_im.gif' width='17.75%' height='6px' border=1 vspace=0></td></tr>";
	st+="<tr><td width=80%>Всенепременно";
	st+="<td width=10% align=right valign=bottom>13<td width=10% align=right valign=bottom>(<i>18.3%</i>)";
	st+="<tr class='votebar'><td colspan=3 class='votebar'><img src='/controlsystem/icons/opin_im.gif' width='46.4035714286%' height='6px' border=1 vspace=0></td></tr>";
	st+="<tr><td width=80%>Не имею возможности";
	st+="<td width=10% align=right valign=bottom>25<td width=10% align=right valign=bottom>(<i>35.2%</i>)";
	st+="<tr class='votebar'><td colspan=3 class='votebar'><img src='/controlsystem/icons/opin_im.gif' width='89.2571428571%' height='6px' border=1 vspace=0></td></tr>";
	st+="<tr><td width=80%>Возможность имею, но буду смотреть по ТВ";
	st+="<td width=10% align=right valign=bottom>28<td width=10% align=right valign=bottom>(<i>39.4%</i>)";
	st+="<tr class='votebar'><td colspan=3 class='votebar'><img src='/controlsystem/icons/opin_im.gif' width='99.9071428571%' height='6px' border=1 vspace=0></td></tr>";
	st+="<tr align=bottom height=20 colspan=3 valign=bottom><td>Проголосовало: 71</td></tr></table>";
	return st;
}

function changeText(div2show, text) {
    // Detect Browser

	text = text.replace("[msg0]", msg0);
	text = text.replace("[msg1]", msg1);
	text = text.replace("[msg4]", msg4);
	text = text.replace("[msg5]", msg5);
	text = text.replace("[msg6]", msg6);
	text = text.replace("[msg7]", msg7);
	text = text.replace("[msg10]", msg10);

    var IE = (document.all) ? 1 : 0;
    var DOM = 0; 
    if (parseInt(navigator.appVersion) >=5) {DOM=1};
    // Grab the content from the requested "div" and show it in the "container"

    if (DOM) {
        var viewer = document.getElementById(div2show)
        viewer.innerHTML=text
    }
    else if(IE) {
        document.all[div2show].innerHTML=text
    }
}
