$(document).ready(function() {

//check username
$("#new #username").blur(function()
{
 //remove all the class add the messagebox classes and start fading
 $("#msgbox").removeClass().addClass('messagebox').text('Kontroluji...').fadeIn("slow");
 //check the username exists or not from ajax
 $.post("/ajax/CheckUserName.php",{ username:$(this).val() } ,function(data)
 {
  if(data=='no') //if username not avaiable
  {
   $("#msgbox").fadeTo(200,0.1,function() //start fading the messagebox
   {
    //add message and change the class of the box and start fading
    $(this).html('Toto již existuje!').addClass('messageboxerror').fadeTo(900,1);
	$("#username2").val("0");
   });
  }
  else
  {
   $("#msgbox").fadeTo(200,0.1,function()  //start fading the messagebox
   {
    //add message and change the class of the box and start fading
    $(this).html('Ok! Pokračujte.').addClass('messageboxok').fadeTo(900,1);
	$("#username2").val("1");
   });
  }
 });
});


$("#objednavka").click(function(){
	$.post("/ajax/CheckPostovne.php",'',function(data){
		if(data=='no'){
			alert('Vyberte poštovné!');
		}else{
			window.location='http://'+location.hostname+'/kosik/?typ=nahled';
		}
});
}
	);


$('#upravit').click(function(){
	$.post('/ajax/EditUserData.php','',function(data){
		if(data!=''){
			$('#upravit').hide();
			$('#area').html(data);
			$('#odeslat').show();
		}
});
}
	);

$('#odeslat').click(function(){
	$.post(
		'/ajax/EditUserData.php',
		{
			jmeno: $("#jmeno").val(),
			prijmeni: $("#prijmeni").val(),
			email: $("#email").val(),
			telefon: $("#telefon").val(),
			firma: $("#firma").val(),
			fax: $("#fax").val(),
			ulice: $("#ulice").val(),
			ico: $("#ico").val(),
			obec: $("#obec").val(),
			dic: $("#dic").val(),
			psc: $("#psc").val()			
		},
		function(data){
			if(data!=''){
				$('#odeslat').hide();
				$('#upravit').show();
				$('#area').html(data);
			}
		}
	);
}
	);
/*
$("#objednavka2").click(function(){
	$.post("/ajax/CheckPostovne.php",'',function(data){
		if(data=='no'){
			alert('Vyberte poštovné!');
		}
});
}
	);
*/
    $("#menu1").change(function () {
          var str = "";
          $("select option:selected").each(function () {
                str += $(this).val() + " ";
              });
		  $.post(
				  "/ajax/SetPostovne.php", 
				  {postovne: $(this).val()}, 
				  function(data)
				  {
					  $("#cenapost").val(data.postovne);
					  $("#celkemview").val(data.celkem);
				  },
				  "json"
				  );
        });

	$("#cekat").change(function(){
		$.post("/ajax/SetKomplet.php", {
		  	cekat: $(this).val()
		  });
	});
	
function trHover(co, sudaBarva, lichaBarva, hoverBarva){
  $("#"+co+" tr:even:not(:first)").css("background-color", sudaBarva);
  $("#"+co+" tr:odd").css("background-color", lichaBarva);
  $("#"+co+" tr:even:not(:first)").hover(
     function () {
       $(this).css("background-color", hoverBarva);
     },
     function () {
       $(this).css("background-color", sudaBarva);
     }
   );
  $("#"+co+" tr:odd").hover(
     function () {
       $(this).css("background-color", hoverBarva);
     },
     function () {
       $(this).css("background-color", lichaBarva);
     }
   );
}

trHover('zbozi', '#FDF4F4', '#FFFFFF', '#E1EAFE');

//konecek	
	});