/*
 * Spezial-Funktionen
 */

function SwapDisplay(htmlIDName,bJumpToBlock)
{
	tagState = $("#"+htmlIDName).css("display");
	if(tagState == "block")
	{
		$("#"+htmlIDName).css("display","none");
	}
	else
	{
	  $("#"+htmlIDName).css("display","block");
      if(bJumpToBlock != null)
	  {
	      if(bJumpToBlock)
	          document.location.href ="#" + htmlIDName;
	  }
	}
}



/*
 * AJAX-Funktionen
 */

function build_page_container_selector(modName,pageName)
{
  return '.'+modName+'_'+pageName+'_container';
}

function activate_ajax_page_turning(modName,pageName,REQUEST_URI)
{
  var targetSelector = build_page_container_selector(modName, pageName);
  $(targetSelector+' .pageTurningMenu a').click(function(){
    var QUERY_STRING = $(this).attr('href');
    get_module(REQUEST_URI,targetSelector,QUERY_STRING,'GET');
    return false;
  });
}

function form_action_ajax(moduleName,pageName)
{
  post_form_to_module( '/'+moduleName+'/'+pageName , '.'+moduleName+'_'+pageName+'_container' , '.'+moduleName+'_'+pageName+'_container form' );
}


/*
 * Funktionen für /Gastgeber/anzeige
 */

function load_Gastgeber_edit()
{
  get_module('/Gastgeber/edit','.Gastgeber_edit_container');
  window.location.href = '#Gastgeber_anzeige_edit_Anchor';
  $('#Gastgeber_edit_dataForm').submit(function()
  {
    post_form_to_module('/Gastgeber/edit','.Gastgeber_edit_container','#Gastgeber_edit_dataForm');
    get_module('/Gastgeber/anzeige_booking','.Gastgeber_anzeige_booking_container');
    window.location.href = '#Gastgeber_anzeige_Anchor';
    return false;
  });
}

function load_Gastgeber_leistungen()
{
  get_module('/Gastgeber/leistungen','.Gastgeber_leistungen_container');
  window.location.href = '#Gastgeber_anzeige_edit_Anchor';
  $('#Gastgeber_leistungen_dataForm').submit(function()
  {
    post_form_to_module('/Gastgeber/leistungen','.Gastgeber_leistungen_container','#Gastgeber_leistungen_dataForm');
    get_module('/Gastgeber/anzeige_booking','.Gastgeber_anzeige_booking_container');
    window.location.href = '#Gastgeber_anzeige_Anchor';
    return false;
  });
}


/*
 * Funktionen für /Gastgeber/leistungen
 */

function init_Gastgeber_leistungen()
{
  FancyForm.add($$('#Gastgeber_leistungen_dataForm input'));
}


/*
 * Funktionen für /User/kurzprofil
 */

function init_kurzprofil_ajaxForm_callback()
{
  init_kurzprofil('');
}
var init_kurzprofil_moduleName = '';
function init_kurzprofil(moduleName)
{
  if(moduleName)
    init_kurzprofil_moduleName = moduleName;
  else
    moduleName = init_kurzprofil_moduleName;

  Counter(150);

  $('#KurzprofilData').submit(function(){
    $(this).ajaxSubmit({
      target: '.'+moduleName+'_kurzprofilformular_container',
      success: init_kurzprofil_ajaxForm_callback
    });
    return false;
  });
}

function kurzprofil_delete_image(imageType,message)
{
  if(imageType)
  {
    if(!message)
      message = 'Möchten Sie das gewählte Element entgültig löschen?';
    if(confirm(message))
    {
      document.KurzprofilData.del.value = imageType;
      $('#KurzprofilData').submit();
    }
  }
}



/*
 * Funktionen für /Gastgeber/kurzprofil
 */

function check_wordlength()
{
  var Satz = document.KurzprofilData.uspText.value;
  var Woerter = Satz.split(" ");
  var maxWordLength = 25;
  for (var i = 0; i < Woerter.length; i++)
  {
    if(Woerter[i].length > maxWordLength)
    {
      alert("{zu_langes_wort} "+Woerter[i]);
      Woerter[i] = Woerter[i].substr(0,maxWordLength);
      document.KurzprofilData.uspText.value = Woerter.join(" ");
    }
  }
}

function Counter(userlength)
{
  var wert,maxlen;
  var fromLength = 0;
  maxlen = userlength - (fromLength + 1);
  wert = maxlen - document.KurzprofilData.uspText.value.length;
  if(wert < 0)
  {
    if(old.length > maxlen)
      document.KurzprofilData.uspText.value = document.KurzprofilData.uspText.value.substr(0,maxlen);
    else
      document.KurzprofilData.uspText.value = old;
  }
  document.KurzprofilData.msgtxt.value  = "Es stehen Dir noch " + (maxlen - document.KurzprofilData.uspText.value.length) + " Zeichen zur Verfügung.";
  old = document.KurzprofilData.uspText.value;
  check_wordlength();
}

