function getURL(url){
//alert(url);
  document.location.href=url;
}
function toggleTextInInput(e,label){
  obj = $('#'+e);
  obj.val(label);
  //alert(" tolge");
  obj.bind("click", function(e){
    e.val('clci');  
  });
}
function checkACUser(){
  o = $('#userAC').val(); 
  $.ajax({
  type: "POST",   
  url: "ajax.userInfo.php",
  data: "login="+o,
  success: function(msg){
      msgs = msg.split(";");
      var status = msgs[0];
      var ico = msgs[1];
      switch(status) {
          default: 
            if(ico=='1') $('#userACIco').attr('src', "ico/"+status+".gif"); else $('#userACIco').attr('src', "img/noico.gif");
            $('#userACExists').val(status);
            break;
          case 'not exists':  
            $('#userACIco').attr('src', "img/noico.gif");
            $('#userACExists').val('0');
            break;
      }

  }//eof ajax succes
  });
 //alert(e);
}


function rate(hash,link){
   //alert(hash);
  //$('#rateDialog_'+hash).html('test');
  $('#rateDialog_'+hash).dialog({width:500,height:290,modal:true});
  $('#rateDialog_'+hash).dialog('open');
  $.ajax({
    type: "POST",   
    url: link,
    //data: "note="+note,
    success: function(msg){
      $('#rateDialog_'+hash).html(msg);
    }//eof ajax succes
  });
    
}
//not used!
/*
function rating(owner, theme, sender, opinion, hash, note){
  cnter = $('#counter_'+hash);
  origVal = cnter.html(); 
  cnter.html("<img src='img/loading.gif' alt='načítám..'/>");
  $.ajax({
    type: "POST",   
    url: "ajax.rate.php",
    data: "owner="+owner+"&theme="+theme+"&sender="+sender+"&opinion="+opinion+"&hash="+hash+"&note="+note,
    success: function(msg){
      msgs = msg.split(";");
      var status = msgs[0];
      var num = msgs[1];
      switch(status) {
          case 'passed': 
            cnter.html(num);
            if(num<0) { cnter.removeClass('positive'); cnter.addClass('negative'); } 
            if(num<-10) num=-10;
            if(num>10) num=10;
            switch(opinion){
              case 'down': $('#thumbs_'+hash).html("<img src='img/thumb_down.png' alt='Ohodnotili jste negativně'/>");  break;
              case 'up': $('#thumbs_'+hash).html("<img src='img/thumb_up.png' alt='Ohodnotili jste pozitivně'/>");  break;
            }
            $('#rateTitle_'+hash).attr("title", "Ohodnoceno");
            break;
          default:
            alert(status);
            cnter.html(origVal);
            break;
      }
    }//eof ajax succes
  });
  //alert(hash);
}
*/
function eraseQuery(link){
  e = window.confirm('Opravdu si přejete vymazat záznam?');
  if(e) getURL(link);
}
function newPhotoSubmit(){
  $('#photoForm').submit();
  $('#photoUpload').css("display","none");  
  $('#photoLoading').slideDown("fast");  
}

$('#chatBox').ready(function(){
  //setTimeout(chatLoad(),
  chatLoad();
  
});

function chatLoad(){
  cnt=$('#chatCnt').val();
  cnt++;
  $('#chatCnt').val(cnt);
  $.ajax({
    type: "POST",   
    url: "ajax.chat.php",
    data: "foo=foo",
    success: function(msg){
      $('#chatBox').html(msg);
    }//eof ajax succes
  });
  if(cnt<8) setTimeout("chatLoad()",15000);
  //setTimeout(chatLoad(),500000);
}
function chatSend(){
  $('#chatForm').preventDefault;
  chi=$('#chatI');
  $.ajax({
    type: "POST",   
    url: "ajax.chatSend.php",
    data: "text="+chi.val(),
    success: function(msg){
      if(msg) { alert(msg);} else {chi.val(''); $('#chatCnt').val('1'); chatLoad(); }      
    }//eof ajax succes
  });
}

function porotaHlasDialog(cnt){
  koloId=$('#koloId').val();
  not=";";
  for(i=1;i<=10;i++){
    not+=$('#choiceUcast_'+i).val()+";";
  }
  $('#choiceDialog').dialog({
    width:600,
    height:390,
    modal:true,
    buttons: { "Zavřít": function() { $(this).dialog("close"); } }
  });
  $('#choiceDialog').dialog('open');
  $('#choiceDialog').html("<div class='center padded'><img src='/img/loading.gif' alt='...'/></div>");
  $.ajax({
    type: "POST",   
    url: "ajax.porotaHlas.php",
    data: "misto="+cnt+"&koloId="+koloId+"&not="+not,
    success: function(msg){
      $('#choiceDialog').html(msg);
    }//eof ajax succes
  });
}
function porotaHlasZrus(cnt){
  $('#choice_'+cnt).html("<a href='javascript:void(0)' onclick='porotaHlasDialog("+cnt+")'>vybrat</a>");
  $('#choiceUcast_'+cnt).val("0");
  $('#choicePassed_'+cnt).val("0");
}
function porotaHlasVyber(cnt,ucastId,photoId,photoOrigin){
  //$('#choice_'+cnt).html("<a href='javascript:void(0)' onclick=\"porotaHlasZrus("+cnt+")\"><img src='gallery/ico/"+photoOrigin+"/"+photoId+".gif' alt='vyber' title='Výběr na "+cnt+". místo, klikněte pro zrušení'/></a>");
  $('#choice_'+cnt).html("<img src='gallery/ico/"+photoOrigin+"/"+photoId+".gif' alt='vyber' title='Výběr na "+cnt+". místo'/>");
  $('#choiceUcast_'+cnt).val(ucastId);
  $('#choicePassed_'+cnt).val("1");
  $('#choiceDialog').dialog('close');
}

$(document).ready(function() {

  $('#choiceForm').submit(function(){
    approved=true;
    for(i=1;i<=10;i++){
      if($('#choicePassed_'+i).val()=="0") approved=false;
    }
    if(approved) {
      return true;
      //$('#choiceForm').submit(); 
    }else{
      alert("Je třeba doplnit všechny bodované pozice.");
      return false;
    }
  });

});

