var ikKontakt = window.ikKontakt || {};

var szFocusColor= '#fffff0';
var szBlurColor=  '#ffffff';
var nFocusDuration= 1;
var nBlurDuration=  .2;

ikKontakt.initialize = function() {
   $( 'kontakt_submit' ).setAttribute( 'type', 'button' );
  
  /*Aus Gründen, die ich noch nicht ganz erklären kann schmiert Firefox
    nach zweimaligem Durchlauf an dieser Stelle ab. */
  /*
   Event.observe( 'namefield', 'focus', ikKontakt.focusEffect, false );
   Event.observe( 'emailfield', 'focus', ikKontakt.focusEffect, false );
   Event.observe( 'messagefield', 'focus', ikKontakt.focusEffect, false );   

   Event.observe( 'namefield', 'blur', ikKontakt.blurEffect, false );
   Event.observe( 'emailfield', 'blur', ikKontakt.blurEffect, false );
   Event.observe( 'messagefield', 'blur', ikKontakt.blurEffect, false );   
  */
   Event.observe( 'kontakt_submit', 'click', ikKontakt.submitMessage, false );   
}

// initialize ikBalken
Event.observe( window, 'load', ikKontakt.initialize, false );

ikKontakt.focusEffect = function(e) {
	new Effect.Highlight( Event.element(e), {duration: nFocusDuration, startcolor: szBlurColor, endcolor: szFocusColor, restorecolor: szFocusColor } );
}

ikKontakt.blurEffect = function(e) {
	new Effect.Highlight( Event.element(e), {duration: nBlurDuration, startcolor: szFocusColor, endcolor: szBlurColor, restorecolor: szBlurColor } );
}


ikKontakt.submitMessage = function(){
  var myAjax = new Ajax.Request( 'scripts/sendMessage.php', {method: 'post', postBody: Form.serialize( 'kontakt_form' ), onComplete: ikKontakt.messageSend} );
}

ikKontakt.messageSend = function(response){
  Form.reset( 'kontakt_form' );
  switch( response.responseText ){
  	case "0":
  	  new Effect.Fade( 'text_kontakt' );
	  window.setTimeout( 'ikNav.show( "text_kontakt_send" )',1000 );
	  ikNav.messageSend = true;
  	  break;
  	default:
  	  alert( "Leider ist bei der Übertragung ein Fehler aufgetreten. Bitte versuchen Sie es später noch einmal." );
  	  break;
  }
}
