/***
* Copyright (C) 2005-2009 by Juergen Heinemann www.hjcms.de
* THIS SOFTWARE IS PROVIDED BY DEVELOPER Heinemann All rights reserved.
***/

function toAnker( lnk )
{
   if ( document.getElementById(lnk) )
      window.location.href = '#'+lnk;
}

function swapDisplay ( i )
{
   if (document.getElementById(i).style.display == 'none') {
      document.getElementById(i).style.display = '';
   } else {
      document.getElementById(i).style.display = 'none';
   }
}

function checkTextInput( na, info )
{
   var s = document.getElementById( na );
   if ( s.value.length < 2 ) {
      alert( "Fehlende Eingabe bei " + info + "!" );
      s.style.background = '#FFFFC0';
      s.focus();
      return false;
   }
   s.style.background = '#E6E8FA';
   return true;
}

function checkEMail( na )
{
   var m = document.getElementById( na );
   if ( m.value.length < 2 ) {
      alert( "Keine E-Mail angegeben!" );
      m.style.background = '#FFFFC0';
      m.focus();
      return false;
   }

   var r = new RegExp(/([\w\d\-\._]{3,})(@)([\w\d\-\._]{3,})(\.)(\w){2,5}/i);
   if ( r.test( m.value ) == false ) {
      alert( "Das scheint keine Reguläre E-Mail Adresse zu sein!" );
      m.style.background = '#FFFFC0';
      m.focus();
      return false;
   }

   var p = new RegExp(/.+(@dgmcoaching\.de)$/i);
   if ( p.test( m.value ) == true ) {
      alert( "Sie können keine E-Mail des Seitenbetreibers als Antwort Adresse verwenden!" );
      m.style.background = '#FFFFC0';
      m.focus();
      return false;
   }
   m.style.background = '#E6E8FA';
   return true;
}

function checkCaptcha( na )
{
   var c = document.getElementById( na );
   if ( c.value.length < 4 ) {
      alert( "Keine Captcha Eingabe vorhanden!" );
      c.style.background = '#FFFFC0';
      c.focus();
      return false;
   }
   c.style.background = '#E6E8FA';
   return true;
}

function checkMailFormContent( f )
{
   if ( ! checkTextInput( 'mailSubject', 'Betreffzeile' ) )
      return false;

   if ( ! checkEMail( 'mailRe' ) )
      return false;

   if ( ! checkCaptcha( 'mailCa' ) )
      return false;

   return true;
}

function checkAdminFormContent( f )
{
   if ( document.getElementById( 'remove' ).checked == true )
      return true;

   var fields= new Object();
   fields["name"] = "Vorname";
   fields["nachname"] = "Nachname";
   fields["ort"] = "Wohnort";

   for (var inp in fields)
   {
      if ( ! checkTextInput( inp, fields[inp] ) )
         return false;
   }

   if ( document.getElementById( 'force' ).checked == true )
      return true;

   var extra= new Object();
   extra["plz"] = "Postleitzahl";
   extra["strasse"] = "Strasse";
   extra["tel_vorwahl"] = "Vorwahl";
   extra["tel_nummer"] = "Telefon";
   extra["tel_fax"] = "Fax";

   for (var exts in extra)
   {
      if ( ! checkTextInput( exts, extra[exts] ) )
         return false;
   }

   if ( ! checkEMail( 'email' ) )
      return false;

   return true;
}

function checkQuestion( obj, txt )
{
   if ( obj.checked )
   {
      if ( ! confirm( txt  ) )
         obj.checked = false;
   }
}

function checkBewerberFormContent(obj)
{
   var fields= new Object();
   fields["b_vorname"] = "Vorname";
   fields["b_nachname"] = "Nachname";
   fields["b_strasse"] = "Strasse";
   fields["b_plz_ort"] = "Postleitzahl und Wohnort";
   fields["b_telefon"] = "Telefon";

   for (var inp in fields)
   {
      if ( ! checkTextInput( inp, fields[inp] ) )
         return false;
   }

   if ( ! checkEMail( 'b_email' ) )
      return false;

   return true;
}

function updateBackground( span, str )
{
   var bimg = new Image();
   bimg.onload = function()
   {
      span.removeAttributeNode( span.getAttributeNode('style') );
      var st = document.createAttribute('style');
      st.nodeValue="background: #3A3A3A url('"+str+"') no-repeat center bottom;width=100px;height:93px;";
      span.setAttributeNode( st );
   }
   bimg.src = str;
}

function documentPrint()
{
   var imp = document.getElementById( "printableContent" );
   var popup = window.open( "print.html", "QOCA Druckansicht", "width=650,height=550,left=50,top=50,menubar=yes,toolbar=no,status=no,dependent=yes,resizable=yes,scrollbars=yes");
   var preload = function()
   {
      var body = popup.document.getElementById( "print_content" );
      body.innerHTML=imp.innerHTML;
   }
   popup.onload = preload;
}

