var xmlHttp = createXmlHttpRequestObject(); 

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("Error creating the XMLHttpRequest object.");
  else 
    return xmlHttp;
}

function change_product(prName,prNum)
	{
	document.getElementById("act_pic").src = "img/"+prName+"_"+prNum+".jpg";
	document.getElementById("act_table").src = "img/tab_"+prName+".gif";
	var new_name = "natur"
	switch (prName)
		{
		case "natur":
			new_name = "natur";
			break;
		case "malina":
			new_name = "mailna";
			break;
		case "jahoda":
			new_name = "jahoda";
			break;
		case "lesne_plody":
			new_name = "lesné plody";
			break;
		case "visna":
			new_name = "višňa";
			break;
		}
	document.getElementById("product_title").innerHTML = '<span class="text_light">Actimel</span> '+new_name+' <span class="text_light">'+prNum+'x100g</span>';
	}

var popup_style='1';
function winner_action2(winnerDay,winnerMonth,winnerStyle)
{	
	popup_style = winnerStyle;
	/*
	document.getElementById("winner_popup").style.top = (tempY-count_position)+"px";
      document.getElementById("winner_popup").style.left = tempX+"px";
      document.getElementById("winner_popup").style.width = "auto";
      document.getElementById("winner_popup").style.heigth = "auto";
     */
	//alert("FUNGUJE");
	
	popup_style=winnerStyle;
  if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
  	{
    xmlHttp.open("GET", "templates/get_winners.php?winner_day="+winnerDay+"&winner_month="+winnerMonth+"&winner_style="+winnerStyle, true);
    xmlHttp.onreadystatechange = handleWinnResponse2;
    xmlHttp.send(null);
  	}
  else{
    // if the connection is busy, try again after one second  
    setTimeout('winner_action2(winnerDay,winnerMonth,winnerStyle)', 1000);
    }
   
}

function handleWinnResponse2()
{
  if (xmlHttp.readyState == 4) 
  {
    if (xmlHttp.status == 200) 
    {      
      myResult = xmlHttp.responseText;
      /*
      if(popup_style == '1')
      	{
      	count_position = '58';
      	}
      if(popup_style == '5')
      	{
      	count_position = '175';
      	}
      document.getElementById("winner_popup").innerHTML = myResult;
      document.getElementById("winner_popup").style.top = (tempY-count_position)+"px";
      document.getElementById("winner_popup").style.left = tempX+"px";
      document.getElementById("winner_popup").style.visibility = "visible";
      document.getElementById("winner_popup").style.width = "auto";
      document.getElementById("winner_popup").style.heigth = "auto";
      //document.getElementById("winner_popup").style.top = (tempY-155)+"px";
      */
      //document.getElementById("winner_popup").innerHTML = myResult;
      //document.getElementById("winner_popup").style.visibility = "visible";
      //document.getElementById("winner_popup").innerHTML = "FUNGUJE!!!!!!";
      show_win_popup(myResult);
    } 
    else 
    {
      alert("There was a problem accessing the server: " + xmlHttp.statusText);
    }
  }
}
function show_win_popup(myResult)
	{
	if(popup_style == '1')
      	{
      	count_position = '140';
      	}
      if(popup_style == '4')
      	{
      	count_position = '190';
      	}
	document.getElementById("winner_popup").style.top = (tempY-count_position)+"px";
    document.getElementById("winner_popup").style.left = tempX+"px";
    document.getElementById("winner_popup").style.width = "auto";
    document.getElementById("winner_popup").style.heigth = "auto";
	document.getElementById("winner_popup").innerHTML = myResult;
    document.getElementById("winner_popup").style.visibility = "visible";
	}

function hide_winner_popup()
	{
	document.getElementById("winner_popup").style.top = "0px";
	document.getElementById("winner_popup").style.left = "0px";
	document.getElementById("winner_popup").style.visibility = "hidden";
	document.getElementById("winner_popup").style.width = "0px";
	document.getElementById("winner_popup").style.heigth = "0px";
	}
