function handleEditobjChoice() {
  var i = $("#edit_choice input#edit_choice_objid").val();
  var v = $("#edit_choice input.edit_choice_radio:checked").val();
  if(v==undefined || v=='') {
    alert('Bitte wähle eine der genannten Optionen.');
    return false;
  }
  if(v==1) {
    location.href = '/DE/Community/edit.php?obj='+i;
  } else if(v==2) {
    $.nyroModalManual({url:'/DE/ajax/community_inhaber_auth.php?obj='+i+'#owner_auth_main'});
  }
}

function handleAuthRequest() {
  var f = Array('auth_vorname','auth_nachname','auth_email','auth_telefon');
  for(var i=0; i<f.length; i++) {
    var v = $("input#"+f[i]).val();
    v = v.replace(/^\s+/,'').replace(/\s+$/,'');
    if(v=='') {
      alert('Bitte fülle alle gekennzeichneten Felder aus.');
      return false;
    }
  }
  if(!$("input#auth_bedingungen").is(":checked")) {
    alert('Bitte akzeptiere die Nutzungsbedingungen.');
    return false;
  }
  var objid = $("#auth_form #auth_objid").val();
  if(objid!=undefined && objid!='') {
    $("#auth_form #auth_submitbtn").attr("disabled","disabled").addClass("is_disabled");
    $.post("/DE/ajax/community_inhaber_auth_senden.php",$("#auth_form").serialize(),function(data){
      if(data==true) {
        alert('Du wurdest vorläufig als Inhaber eingetragen, vielen Dank.');
        location.href = '/DE/Community/edit.php?obj='+objid;
      } else {
        alert('Es ist ein Fehler aufgetreten. Bitte versuche es später erneut.');
      }
    },"json");
  }
  return false;
}

function changeProfilHeadTab(e) {
  var u = $("input#profile_uid").val();
  $("table.community_headtab a").removeClass("current");
  $("table.community_headtab a.headtab_"+e).addClass("current");
  $("div[id^='profil_maintab_']").hide();
  if($("div#profil_maintab_"+e).length) {
    $("div#profil_maintab_"+e).show();
  } else {
    $("#profil_waitcontainer").show();
    $.post("/DE/ajax/community_profile.php",{tab:e,userid:u},function(data){
      $("div#profil_maintab_main").after('<div id="profil_maintab_'+e+'"></div>');
      $("div#profil_maintab_"+e).html(data);
      $("#profil_waitcontainer").hide();
    },"html");
  }
  return false;
}

function changeProfilCommentPage(o) {
  var u = $("input#profile_uid").val();
  $("div#profil_maintab_comments").empty();
  $("#profil_waitcontainer").show();
  $.post("/DE/ajax/community_profile.php",{tab:'comments',userid:u,offset:o},function(data){
    $("div#profil_maintab_comments").html(data);
    $("#profil_waitcontainer").hide();
  },"html");
  return false;
}

function changeProfilTab(link,e) {
  $("div[id^='profil_tab_']").hide();
  $("div#profil_tab_"+e).show();
  $("#profiltab_main a").removeClass("current");
  $(link).addClass("current");
  return false;
}

function changeSettingTab(link,e) {
  $("div[id^='setting_tab_']").hide();
  $("div#setting_tab_"+e).show();
  $("#settingtab_main a").removeClass("current");
  $(link).addClass("current");
  return false;
}

function initFlickrpicRow() {
  $(".profile_flickpic").each(function(){
    $(this).find("a img:first").load(function(){
      var h = $(this).height();
      if(h<100) { $(this).parents(".profile_flickpic").css("padding-top",Math.round((100-h)/2)); }
    });
  });
}

function initTagInput() {
  $(document).ready(function() {
    taginput_startvalue = $("input#comment_tags").val();
    $("input#comment_tags").focus(function() {
      if($(this).val()==taginput_startvalue) { $(this).val('').addClass("current"); }
    }).blur(function(){
      if($(this).val()=='') { $(this).val(taginput_startvalue).removeClass("current"); }
    });
  });
}

function insertTag(e) {
  if($("input#comment_tags").val()==taginput_startvalue) { $("input#comment_tags").val('').addClass("current"); }
  var newval = $("input#comment_tags").val();
  if(newval.substr(newval.length-2,2)==', ') { newval=newval.substr(0,newval.length-2); }
  if(newval.substr(newval.length-1,1)==',') { newval=newval.substr(0,newval.length-1); }
  if(newval!='') { newval+=', '; }
  newval += e;
  $("input#comment_tags").val(newval);
  return false;
}

function detailvoteSet(o,q,p) {
  $(".community_detail_vote #vote_star_container_"+q+" a.vote_star").hide();
  $(".community_detail_vote #vote_star_container_"+q+" .vote_star_wait").show();
  var param = new Object({
    objID: o,
    question: q,
    points: p
  });
  $.post("/DE/ajax/community_setvoting.php",param,function(data,status){
    if(data!=undefined && data.successful) {
      $.each(data.newvote,function(i,v) {
        var g = v.avg.split('.');
        g[1] = g[1].substr(0,1);
        $(".community_detail_vote #vote_grade_"+i).html(g.join(','));
        $(".community_detail_vote #vote_count_"+i).html(v.count);
        $(".community_detail_vote #vote_star_container_"+i+" a.vote_star").removeClass("full").removeClass("half");
        for(var z=1; z<=4; z++) {
          if((v.avg*1)>=(z-0.25)) {
            $(".community_detail_vote #vote_star_container_"+i+" a.vote_star:nth-child("+z+")").addClass("full");
          } else if((v.avg*1)>(z-0.75) && (v.avg*1)<(z-0.25)) {
            $(".community_detail_vote #vote_star_container_"+i+" a.vote_star:nth-child("+z+")").addClass("half");
          }
        }
      });
    }
    $(".community_detail_vote #vote_star_container_"+q+" a.vote_star").show();
    $(".community_detail_vote #vote_star_container_"+q+" .vote_star_wait").hide();
  },"json");
  return false;
}

function setCommentStars(e) {
  $("#comment_stars_container a").css("background-position","0 0");
  $("#comment_stars_container a:lt("+e+")").css("background-position","0 -38px");
  $("input#comment_stars").val(e);
  return false;
}

function commentCheckForm() {
  var v = $(".write_comment textarea#comment_text").val();
  v = v.replace(/^\s+/,'').replace(/\s+$/,'');
  if(v=='') {
    alert('Schreibe vor dem Speichern erst einmal Deinen Kommentar.');
    return false;
  }
  var s = $("#comment_stars").val();
  if(s=='' || isNaN(s)) {
    alert('Gebe für Deine Bewertung bitte die Anzahl der Sterne an.');
    return false;
  }
  var t = $("input#comment_tags").val();
  if(t==taginput_startvalue) { $("input#comment_tags").val(''); }
  return true;
}

function commentCheckReplyForm(e) {
  var v = $("#reply_container_"+e+" .reply_form textarea#comment_reply_text_"+e).val();
  v = v.replace(/^\s+/,'').replace(/\s+$/,'');
  if(v=='') {
    alert('Schreibe vor dem Speichern erst einmal Deinen Kommentar.');
    return false;
  }
  return true;
}

function favEvent(o) {
  var param = new Object({
    job: 'favEvent',
    obj: o
  });
  $("a.location_moegen").addClass("loading");
  $.post("/DE/ajax/community_compliment.php",param,function(data,status){
    if(data!=undefined && data.successful) {
      $("a.location_moegen").html("Ich gehe hin ("+data.newcount+")").addClass("already").removeClass("loading").unbind('click').removeAttr('onclick').click(function(){ return alreadyMyFav(); });
      alert('Diese Veranstaltung wurde zu Deinen persönlichen Events hinzugefügt.');
    }
  },"json");
  return false;
}

function favInfoDB(o) {
  var param = new Object({
    job: 'favInfoDB',
    obj: o
  });
  $("a.location_moegen").addClass("loading");
  $.post("/DE/ajax/community_compliment.php",param,function(data,status){
    if(data!=undefined && data.successful) {
      $("a.location_moegen").html("Ich mag die Location ("+data.newcount+")").addClass("already").removeClass("loading").unbind('click').removeAttr('onclick').click(function(){ return alreadyMyFav(); });
      alert('Diese Location wurde zu Deinen Lieblingen hinzugefügt.');
    }
  },"json");
  return false;
}

function alreadyMyFav() {
  alert('Du hast diese Location bereits zu Deinen Lieblingen hinzugefügt.');
  return false;
}

function favComment(o) {
  var param = new Object({
    job: 'favComment',
    obj: o
  });
  $("a#comment_lob_"+o).addClass("loading");
  $.post("/DE/ajax/community_compliment.php",param,function(data,status){
    if(data!=undefined && data.successful) {
      $("a#comment_lob_"+o+" span").html("("+data.newcount+")");
      $("a#comment_lob_"+o).addClass("already").removeClass("loading").unbind('click').removeAttr('onclick').click(function(){ return favCommentAlready(); })
    }
  },"json");
  return false;
}

function favCommentAlready() {
  alert('Du hast diesen Beitrag bereits als gut geschrieben gekennzeichnet.');
  return false;
}

function favCommentOwn() {
  alert('Du kannst deinen eigenen Beitrag nicht als gut geschrieben markieren.');
  return false;
}

function flickrEventpic() {
  $(document).ready(function() {
    var t = $("input#unique_flickrtag").val();
    $.post("/DE/ajax/community_flickr_events.php",{tag:t},function(data){
      data = trimStr(data);
      if(data!=undefined && data!='') {
        $("#flickrtag_pic_container").html(data).slideDown(250,function(){
          lightboxStart("#flickrtag_pic_container a.flickr_pic");
        });
      }
      $("#flickrtag_wait").slideUp(250);
    },"html");
  });
}

