/*
 * jQuery design
 */
$(document).ready(function()
 {
   processAfterViewLoad();
 }
);

function processAfterViewLoad()
{
  paintRoundedBorders();
  registerBoxFading();
}

function paintRoundedBorders()
{
  //deactivated 8th of February 2009 - doesn't work somehow
  $("div.boxHeader").corner("tr 20px").corner("notch tl 10px");
  $("div.box").corner("tr bottom 5px");

  $("div.viewImage").corner("tr bottom 5px");
}

function registerBoxFading()
{
  $('div.boxHeader').click(function()
    {
      var textComp = $(this).parent().find('.boxText');
      var addComp = $(this).parent().find('.boxAddContent');
      var hidden = $(textComp).is(":hidden")

      //another nice effect: slideToggle("slow")

      if(!hidden)
      {
        if(addComp != null)
          $(addComp).toggle();
        $(textComp).children().fadeOut("slow");
        $(textComp).slideToggle("slow");
      }
      else
      {
        if(addComp != null)
          $(addComp).toggle();
        $(textComp).children().fadeIn("slow");
        $(textComp).slideToggle("slow");
      }
    }
  );
}

/*
 * MAIL Functionality
 */
function submitMailContent(formId, formContainerId)
{
  if(isValid(formId))
    xajax_getContent("sendMail", xajax.getFormValues('contactForm'), formContainerId);
  return false;
}

function isValid(formId)
{
  var msg = "";
  var fobject = $("form." + formId);
  var mail = fobject.find("input.fmail").val();
  var name = fobject.find("input.fname").val();
  var subject = fobject.find("input.fsubject").val();
  var content = fobject.find("textarea.fmsg").val();

  if(mail.indexOf("@") < 1 ||
     mail.indexOf(".") < 1 ||
     mail.length < 6)
  {
    msg += "Überprüfen Sie die E-Mailadresse!";
  }

  if(name.length == 0)
  {
    msg += "- Leeres Feld: xyz Name xyz\n";
  }

  if(subject == "")
  {
    msg += "- Leeres Feld: xyz Betreff xyz:\n";
  }

  if(content == "")
  {
    msg += "- Leeres Feld: xyz Nachricht xyz:\n";
  }

  if(msg == "")
    return true;

  alert(msg);
  return false;
}

