function show(menu_item)
{
  document.getElementById("podmenu" + menu_item).style.visibility = "visible";
  document.getElementById("a-menu"+menu_item).className = "selected";
}

function hide(menu_item)
{
  document.getElementById("podmenu" + menu_item).style.visibility = "hidden";
  document.getElementById("a-menu"+menu_item).className="";
}

function ZmenCenu(strid,velikost) {
  pozice = velikost.indexOf("~");
  id = velikost.substr(0,pozice);
  nadpis = velikost.substr(pozice+1,velikost.length-pozice) + " Kč";
  retezec = "cena" + strid; 
  document.getElementById(retezec).value = nadpis;
}

function hlavnimenu(menu_item,akce) {
 /* if (akce) {
    soubor = menu_item.substr(0,menu_item.length-4) + "2.jpg";
    id = menu_item.substr(42,menu_item.length-4-42);
    document.getElementById(id).src = soubor;
  }
  else {
    soubor = menu_item.substr(0,menu_item.length-5) + ".jpg";
    id = menu_item.substr(42,menu_item.length-5-42);
    document.getElementById(id).src = soubor;

  } */
}

function ZmenIngredienci() {
  ingredience_pom2 = document.getElementById('ingredience_pom').value + ";";  
  ingredience2 = document.getElementById('ingredience').value;
  if (ingredience2.indexOf(ingredience_pom2) >= 0) {
    ingredience2 = ingredience2.replace(ingredience_pom2,"");
    ingredience_pom2 = "";
    document.getElementById('ingredience').value = ingredience2; 
  } 
  else
    document.getElementById('ingredience').value += ingredience_pom2;
}

function ZmenCenu_index() {
  pizzax = document.getElementById("pizzax").value;
  velikost = document.getElementById("velikost").value;
  ks = document.getElementById("ks").value;
  pole = pizzax.split("~");
  cena = pole[velikost] * ks;
  document.getElementById("cena").value = cena + ",- Kč";
}

function ZjistiJednotkovouCenu_index() {
  pizzax = document.getElementById("pizzax").value;
  velikost = document.getElementById("velikost").value;
  pole = pizzax.split("~");
  return pole[velikost];
}


function UpravAdresu(index, jmeno, ulice, mesto, psc, poznamka, jmeno2, ulice2, mesto2, psc2, poznamka2) {
	if (index==1) {
		document.getElementById("o-jmeno").value = jmeno2;
		document.getElementById("o-ulice").value = ulice2;
		document.getElementById("o-mesto").value = mesto2;
		document.getElementById("o-psc").value = psc2;
		document.getElementById("o-poznamka").value = poznamka2;
	} else {
		document.getElementById("o-jmeno").value = jmeno;
		document.getElementById("o-ulice").value = ulice;
		document.getElementById("o-mesto").value = mesto;
		document.getElementById("o-psc").value = psc;
		document.getElementById("o-poznamka").value = poznamka;
	}
}

// pripojit FB Connect
function auth_using_fb() {
	  //get the users data from FB
	  var viewer  = FB.Facebook.apiClient.fql_query(
	  
	      'SELECT name, pic_square_with_logo,profile_url FROM user WHERE uid='+FB.Facebook.apiClient.get_session().uid,
	      
	      function(results) {
	        update_userbox( results[0].name,
	                        results[0].pic_square_with_logo,
	                        results[0].profile_url,
	                        'FB.Connect.logoutAndRedirect("./index.php");return false;')
	      }
	  );
	}

function update_userbox(name, image, url, logout) {
	var uid=FB.Facebook.apiClient.get_session().uid;
    if (uid && !document.getElementById("uzivatelCheck").value) {
//	alert(document.getElementById("uzivatelCheck").value);
		getdata("../scripts/fb_propoj.php?uid="+uid, "prihlasenyBox");
	} else {
	//populate the data in #userbox and <b style="color:black;background-color:#ffff66">show</b> it
	//document.getElementById('fbConnectUserbox').style.display = "block";
	//document.getElementById('fbConnectDiv').style.display = "none";
	
	document.getElementById('fbConnectUserbox').innerHTML = "<a href='"+url+"'>" + "<img alt='"+name+"' src='"+image+"' />"  + name + "</a> " + "<input type='hidden' value='"+uid+"' name='fb_id'/>";
}
	  //hide name input and service
	  //login buttons
	//  $('#userinfo').hide();


	  //populate the values of the inputs
	  //using data from service
	/*  $('#name').val(name);
	  $('#url').val(url);
	  $('#image').val(image);
*/
}

var ajaxdestination="";

function getdata(what,where) { // get data from source (what)
	 try {
	   xmlhttp = window.XMLHttpRequest?new XMLHttpRequest():
	  		new ActiveXObject("Microsoft.XMLHTTP");
	 }
	 catch (e) { /* do nothing */ }
	 document.getElementById(where).innerHTML ="<center><img src='../img/loading.gif'></center>";
	// we are defining the destination DIV id, must be stored in global variable (ajaxdestination)
	 ajaxdestination=where;
	 xmlhttp.onreadystatechange = triggered; // when request finished, call the function to put result to destination DIV
	 xmlhttp.open("GET", what);
	 xmlhttp.send(null);
	  return false;
	}

	function triggered() { // put data returned by requested URL to selected DIV
	  if (xmlhttp.readyState == 4) if (xmlhttp.status == 200) 
	    document.getElementById(ajaxdestination).innerHTML =xmlhttp.responseText;
	}


	function ajax(what) { // get data from source (what)
		 try {
		   xmlhttp = window.XMLHttpRequest?new XMLHttpRequest():
		  		new ActiveXObject("Microsoft.XMLHTTP");
		 }
		 catch (e) { /* do nothing */ }
		// document.getElementById(where).innerHTML ="<center><br /><img src='loading.gif'></center>";
		// we are defining the destination DIV id, must be stored in global variable (ajaxdestination)
		// ajaxdestination=where;
		// xmlhttp.onreadystatechange = triggered; // when request finished, call the function to put result to destination DIV
		 xmlhttp.open("GET", what);
		 xmlhttp.send(null);
		  return false;
		}
