// infectohoney.js
// zeitform Internet Dienste 2009

/* for iPad * only */
 function BlockMove(event) {
  // Tell Safari not to move the window.
  event.preventDefault() ;
 }

//////////////////////////////////////////////////////////////////////
// cookie functions
//////////////////////////////////////////////////////////////////////

// add cookie elements
function addCookieElement (cookie, value) {

  if ($.cookie(cookie) && $.cookie(cookie).length > 0) {
    var cook = $.cookie(cookie).split("|");
    var newcookie = new Array();
    for (var i=0; i < cook.length; i++) { 
      if (value != cook[i]) newcookie.push(cook[i]);
    }
    newcookie.push(value);
    $.cookie(cookie, newcookie.join("|"));
    //$.cookie(cookie, $.cookie(cookie) + '|' + value);
  } else {
    $.cookie(cookie, value);
  }
}

// remove cookie elements
function removeCookieElement (cookie, value) {

  if ($.cookie(cookie) && $.cookie(cookie).length > 0) {
    var cook = $.cookie(cookie).split("|");
    var newcookie = new Array();
    for (var i=0; i < cook.length; i++) { 
      if (value != cook[i]) newcookie.push(cook[i]);
    }
    $.cookie(cookie, newcookie.join("|"));
  }
}

$(function() {

  // load new mails and faelle
  update_new_mails();
  update_new_faelle();

  // popups
  init_popups();

  // falldoku map
  wundlokalisation();

  // hinweis popups
  //$('img.hinweis').live("click", function(){alert('tip')});


  // reorder products
  //reorder_products();

  // external pages
  $('a[rel=external]').attr("target", "_blank");

  // print button (journal/faq)
  $('.printme')
    .click(function(){
	     var printable = $(this).closest('.printable');
	     //$('div.listcontent', printable).show(); // expand faq answers
	     //$(printable).jqprint({debug: true}); 
	     $(printable).jqprint(); 
	     return false;
	   })
    .show()
    .css('cursor','pointer');

  $('.kapitel .printme').hide();

  // show/hide search icon
  $("input.search")
    .focus(function () {
         $(this).css('background','#fff');
     })
    .blur(function () {
         if ($(this).val().length == 0) {
	    $(this).css('background','#FFFFFF url(/images/icon-suche.png) no-repeat scroll 4px 0');
	 }
     });

  // show/hide faqliste
  $('div.kapitel')
    .hover(function(){
	     $("div.button", this).not('.printme').show();
	     //$("div.printme", this).hide();
	   },function(){
	     $("div.button", this).not('.printme').hide();
	     //$("div.printme", this).show();
	   })
    .click(function(){
             var cnt = $(this).next('div.kapitelcontent');
             if ($(cnt).is(':visible')) {
	       $(cnt).hide('fast'); 
	       $(this).removeClass('show');
	       $("div.printme", this).hide();
	     } else {
	       $('div.kapitelcontent:visible').hide('fast');
	       $('div.kapitel').removeClass('show');
	       //$('div.listheader').removeClass('show');
	       $('div.listheader img').attr('src', '/images/dart-close.png');
	       $('div.listcontent').hide();
	       $("div.kapitel div.printme").hide();
	       $(cnt).show('fast');
	       $(this).addClass('show');
	       $("div.printme", this).show();
	     }
	   })
    .css('cursor','pointer');

  // expand faq/journal by get-param
  if (window.location.search.match(/j=(\d+)/)) {
    var j = RegExp.$1;
    $('#listcontent_' + j).closest('div.kapitelcontent').show('fast');
    $('#listcontent_' + j).closest('div.kapitelcontent').prev('div.kapitel').addClass('show');
    $('#listcontent_' + j).show('fast');
    //$('#listheader_' + j).addClass('show');
    $('#listheader_' + j + ' img').attr('src', '/images/dart-open.png');
    $('#listcontent_' + j).closest('div.meta-group').show('fast');
  }

  // show/hide wundkonsil and faqs
  $('div.listheader').filter('.toggle').click(function(){
      var cnt = $(this).next('div.listcontent');
       $('div.listcontent').filter(':visible').hide('fast');
       //$('div.listheader').removeClass('show');
       $('div.listheader img').attr('src', '/images/dart-close.png');
      if (! $(cnt).is(':visible')) {
	$(cnt).show('fast');
	//$(this).addClass('show');
	$(this).children('img').attr('src', '/images/dart-open.png');
      }
    })
    .css('cursor','pointer');

  // show/hide wundkonsil and faqs
  $('div.listheader').not('.toggle').click(function(){
      var cnt = $(this).next('div.listcontent');
      if ($(cnt).is(':visible'))
	{
	  $(cnt).hide('fast');
	  //$(this).removeClass('show');
	  $(this).children('img').attr('src', '/images/dart-close.png');
	}
      else
	{
	  $(cnt).show('fast');
	  //$(this).addClass('show');
	  $(this).children('img').attr('src', '/images/dart-open.png');
	}
    })
    .css('cursor','pointer');

  // subgroups in journal
  $('div.meta-title').click(function(){
    $(this).next('div.meta-group').toggle('fast');
  })
  .css('cursor','pointer');


  // check orientation of iphone
  window.onorientationchange=setOrientation;
  setOrientation();

});


function setOrientation () {
  //alert(window.orientation ? 'landscape' : 'portrait');
  if (window.orientation == undefined) return;
  $('div.marker img').each(function(){
    if (window.orientation) {
      $(this).attr('style', $(this).attr('l:style'));
    } else {
      $(this).attr('style', $(this).attr('p:style')); 
    }
    //alert($(this).attr('style'));
  });
}

function update_new_mails() {

  if ($('#new_mails').size() > 0) {
  $.ajax({
         type: "POST",
         url: "/cgi-bin/ajax/mail_count.pl",
         success: function(msg){
	   //alert(msg);
	   if (msg>0) {
	     $('#new_mails div a').text('Sie haben ' + msg + ' neue Nachricht' + (msg>1 ? 'en' : ''));
	     $('#new_mails').show();
	   } else {
	     $('#new_mails').hide();
	   }
         }
    });
  }
}
function update_new_faelle() {

  if ($('#open_faelle').size() > 0) {
  $.ajax({
         type: "POST",
         url: "/cgi-bin/ajax/fall_count.pl", 
         success: function(msg){
	   var res = msg.split(/,/);
	   if (res[0]>0) {
	     $('#open_faelle div a').text('Sie haben ' + res[0] + (res[0]>1 ? ' offene Fälle' : ' offenen Fall'));
	     $('#open_faelle').show();
	   } else {
	     $('#open_faelle').hide();
	   }
	   if (res[1]>0) {
	     $('#closed_faelle div a').text('Sie haben ' + res[1] + (res[1]>1 ? ' abgeschlossene Fälle' : ' abgeschlossenen Fall'));
	     $('#closed_faelle').show();
	   } else {
	     $('#closed_faelle').hide();
	   }
         }
    });
  }
}
function reorder_products() {

  // reorder product pages
  var reorder = new Object();
  reorder['l'] = new Array();
  reorder['r'] = new Array();
  $('.reorder').each(function(){
    var rel = $(this).attr('rel');
    if (rel && rel.match(/^([rl])(\d+)$/)) {
      //var lr = RegExp.$1;
      //var e = RegExp.$2;
      reorder[RegExp.$1][RegExp.$2] = $(this).html();
    }
    $(this).remove();
  });

  $('#leftcol').html(reorder['l'].join(""));
  $('#rightcol').html(reorder['r'].join(""));

}

function load_faelle(expert) {

  $.ajax({
         type: "POST",
	 url: (expert ? "/cgi-bin/ajax/faelle_expert.pl" : "/cgi-bin/ajax/faelle.pl"),
         success: function(msg){
	   
   	   $('#wunde').html(msg);
  
  	   // popups
	   $("a[rel^='fall_popup']").prettyPopin({
	      modal : true, /* true/false */
	      width : false, /* false/integer */
	      height: false, /* false/integer */
	      opacity: 0.7, /* value from 0 to 1 */
	      animationSpeed: 'fast', /* slow/medium/fast/integer */
	      followScroll: true, /* true/false */
	      loader_path: '/images/prettyPopin/loader.gif', /* path to your loading image */
	      start_callback: function() { /* required zeitform version */
		 hinweis_popups();
		 create_upload(); // for document upload
	      },
	      callback: function(){ 
		 load_faelle(expert);
		 update_new_faelle();
		 $('#tooltip').hide(); // hide tooltips on close
	      }
	   });

	   // click faelle
	   $('tr.liste', $('#wunde')).each(function(){

 	      var id;
	      if( $(this).attr('id').match(/fall_(\d+)/)) { id = RegExp.$1; }

	      $(this).click(function(e){ 

                // find click target
		var target = $(e.target).attr("rel");

		// is current fall active?
                var active = $(this).hasClass('active') ? 1 : 0;
		

		// click on inactive row
		if (! active) {

                  // hide all details
                  $('tr.inhalt', $('#wunde')).hide();

	   	  // remove active flag
		  $('tr.active', $('#wunde')).removeClass('active');

		}


		if (active) {

		  if (target)
		    {
		      $('div.listcontent[rel=' + (target||'anamnese') + ']', $('#inhalt_' + id)).toggle();
		      if ($('div.listcontent[rel=' + (target||'anamnese') + ']', $('#inhalt_' + id)).is(':visible')) {
			$('div.listheader[rel=' + (target||'anamnese') + '] img', $('#inhalt_' + id))
			  .attr('src', '/images/dart-open.png');
		      } else {
			$('div.listheader[rel=' + (target||'anamnese') + '] img', $('#inhalt_' + id))
			  .attr('src', '/images/dart-close.png');
		      }

		      toggle_konsil(target, id, expert);
		    }

		  if (!target) {
		    $('#inhalt_' + id).hide();
		    $(this).removeClass('active');
		    $.cookie((expert?'expert_':'')+'fall_id', null);
		    $.cookie((expert?'expert_':'')+'konsil', null);
		  }

		} else {

		  // set cookie
                  if ($.cookie((expert?'expert_':'')+'fall_id') && $.cookie((expert?'expert_':'')+'fall_id') != id)
		    {
		      //console.log('clear');
		      $.cookie((expert?'expert_':'')+'konsil', null);
		    }

		  $.cookie((expert?'expert_':'')+'fall_id', id);

		  //$('div.listcontent', $('#wunde')).hide();
		  //$('div.listheader', $('#wunde')).removeClass('show');

		  // add active flag to current
		  $(this).addClass('active');

		  if ( $('#inhalt_' + id).size() > 0) {

		    // load old content
		    $('#inhalt_' + id).show();

		    if (target) {
		      //$('div.listcontent[rel=' + target + ']', $('#inhalt_' + id)).show()
		      //.prev('div.listheader').addClass('show');//
		      $('div.listcontent[rel=' + target + ']', $('#inhalt_' + id)).show()
			.prev('div.listheader').contents('img').attr('src', '/images/dart-open.png');

		      toggle_konsil(target, id, expert);
		    }

		  } else {

		    // fetch new content
		    $.ajax({
		      type: "POST",
		      url: expert ? "/cgi-bin/ajax/fall_details_expert.pl" : "/cgi-bin/ajax/fall_details.pl",
                      data: "id=" + id,
                      success: function(msg){
		      
		        $('#fall_' + id).after(msg);
			$('#inhalt_' + id).show();


			// popups
			$("a[rel^='fall_popup_" + id + "']").prettyPopin({
			  modal : true, /* true/false */
			      width : false, /* false/integer */
			      height: false, /* false/integer */
			      opacity: 0.7, /* value from 0 to 1 */
			      animationSpeed: 'fast', /* slow/medium/fast/integer */
			      followScroll: true, /* true/false */
			      loader_path: '/images/prettyPopin/loader.gif', /* path to your loading image */
			      start_callback: function() { /* required zeitform version */
			        hinweis_popups();
				create_upload(); // for upload
			      },
			      callback: function(){ 
			        load_faelle(expert);
			        update_new_faelle();
			      }
			  });

			// previews
			$("a[rel^='preview']").prettyPopin({
			  modal : true, /* true/false */
                          width : false, /* false/integer */
	                  height: 600, /* false/integer */
	                  opacity: 0.7, /* value from 0 to 1 */
	                  animationSpeed: 'fast', /* slow/medium/fast/integer */
	                  followScroll: true, /* true/false */
	                  loader_path: '/images/prettyPopin/loader.gif', /* path to your loading image */
	                  start_callback: function() { /* required zeitform version */
			      $('.prettyPopin').height('700px');
                          },
                          callback: function(){ 
			  }
			});

			// either click target or load cookie or use default (row-click)
			var url = window.location.href;
			if (target) {
			  $('div.listcontent[rel=' + target + ']', $('#inhalt_' + id)).show();
			  $('div.listheader[rel=' + target + '] img', $('#inhalt_' + id))
			    .attr('src', '/images/dart-open.png');
			} else if ($.cookie((expert?'expert_':'')+'konsil')) { // && $.cookie('konsil').length > 0) {
			  var cook = $.cookie((expert?'expert_':'')+'konsil').split("|");
			  for (var i=0; i < cook.length; i++) {
			    $('div.listcontent[rel=' + cook[i] + ']', $('#inhalt_' + id)).show();
			    $('div.listheader[rel=' + cook[i] + '] img', $('#inhalt_' + id))
			      .attr('src', '/images/dart-open.png');
			  }
			} else if (url && url.match(/\b#fall_(\d+)\b/)) {
			  // open anamnese and expertenkonsil on url request
			  $('div.listcontent[rel=anamnese]', $('#inhalt_' + id)).show();
			  $('div.listheader[rel=anamnese] img', $('#inhalt_' + id))
			    .attr('src', '/images/dart-open.png');
			  $('div.listcontent[rel=expertenkonsil]', $('#inhalt_' + id)).show();
			  $('div.listheader[rel=expertenkonsil] img', $('#inhalt_' + id))
			    .attr('src', '/images/dart-open.png');
			  $.cookie((expert?'expert_':'')+"konsil", "expertenkonsil");
			} else {
			  $('div.listcontent[rel=anamnese]', $('#inhalt_' + id)).show();
			  $('div.listheader[rel=anamnese] img', $('#inhalt_' + id))
			    .attr('src', '/images/dart-open.png');
			}
			
			// write cookie
			toggle_konsil(target, id, expert);

			setOrientation();

			$('div.listheader', $('#inhalt_' + id)).click(function(){
                           if ($(this).next('div.listcontent').is(':visible')) {
			     $('img', $(this)).attr('src', '/images/dart-close.png');
			   } else {
			     $('img', $(this)).attr('src', '/images/dart-open.png');
			   }
			   $(this).next('div.listcontent').toggle();

			   toggle_konsil($(this).next('div.listcontent').attr('rel'), id, expert);
		        })
			  .css("cursor", "pointer");

		      }

		    });
		  }

		}

		  $('div.marker').hide(); // does this work; on safari we had problems with random bullets
		  $('#marker_' + id).show();
		  //console.log('click ' + id);
		  //console.log($('div.marker'));

		  // now add .inactive to all <tr> for print (but only if we have one .active)
		  $('tbody tr', $('#wunde')).removeClass('inactive');
		  if ($('tbody tr.active', $('#wunde')).size() > 0) {
		    $('tbody tr', $('#wunde')).not('.active').addClass('inactive');
		  } 

	      })
		.css("cursor", "pointer");

	   });

	   // if cookie load this one
	   var id = $.cookie((expert?'expert_':'')+'fall_id');

	   // if url has #fall_xx load this one
	   var url = window.location.href;
	   if (url && url.match(/\b#fall_(\d+)\b/)) {
	     id = RegExp.$1;
	     //console.log('hit');
	     // open anamnese and expertenkonsil
	     //$.cookie((expert?'expert_':'')+"konsil", "expertenkonsil|anamnese");
	   }

	   //var k = ;
	   if (id) { 
	     $('#fall_' + id).click(); 
	   }

         }

    });

}

function toggle_konsil(target, id, expert) {
  if (!target) target = 'anamnese';

  if ($('div.listcontent[rel=' + target + ']', $('#inhalt_' + id)).is(':hidden')) {
    removeCookieElement((expert?'expert_':'')+"konsil", target);
    //console.log('remove ' + target);
  } else {
    addCookieElement((expert?'expert_':'')+"konsil", target);
    //console.log('add ' + target);
  }
}

function load_inbox() {

  $.ajax({
         type: "POST",
         url: "/cgi-bin/ajax/inbox.pl",
         success: function(msg){
	   
	$('#postfachcontainer').html(msg);

	// popups
	$("a[rel^='mail_popup']").prettyPopin({
	      modal : true, /* true/false */
	      width : false, /* false/integer */
	      height: false, /* false/integer */
	      opacity: 0.7, /* value from 0 to 1 */
	      animationSpeed: 'fast', /* slow/medium/fast/integer */
	      followScroll: true, /* true/false */
	      loader_path: '/images/prettyPopin/loader.gif', /* path to your loading image */
              start_callback: function() { /* required zeitform version */
                create_upload()
              },
	      callback: function(){ 
	          $('tr.isopen').each(function(){

			if ($(this).attr('id').match(/mail_(\d+)/)) {
			    var id = RegExp.$1;
			    var self = this;

			    $.ajax({
			      type: "POST",
			      url: "/cgi-bin/ajax/mail.pl",
			      data: { id : id },
			      success: function(msg){
				  //alert(msg);
				  //$('#mail_' + id).after(msg);
				  $(self).nextAll('tr.mailtext_' + id).remove();
				  $(self).after(msg);
				  //init_popups();
				  $(self).removeClass('urgent'); // read mail
				  $(self).addClass('isopen');
				  $("div.reply_button", self).show();
				  $('th.first img', $(self)).attr('src', '/images/dart-open.png');
				  
				  update_new_mails();
			      }
			    });
 
			}
		   })
	      }
	      //callback: function(){ load_inbox(); } /* callback called when closing the popin */
	  });

	// show/hide mails
	$('tr.mail')
	  .hover(function(){
		   $("div.button", this).show();
		 },function(){
		   $("div.button", this).hide();
		 })
	  .click(function(){
		   
		   if ($(this).attr('id').match(/mail_(\d+)/)) {
		     var id = RegExp.$1;
		     var self = this;
		     //alert(id);
		     
		     if ($(self).hasClass('isopen')) {
		       
		       $(self).nextAll('tr.mailtext_' + id).remove();
		       $('th.first img', $(self)).attr('src', '/images/dart-close.png');
		       $(self).removeClass('isopen');
		       $("div.reply_button", self).hide();
		       
		     } else {
		       
		       $.ajax({
			 type: "POST",
			 url: "/cgi-bin/ajax/mail.pl",
			 data: { id : id },
			 success: function(msg){
			     //alert(msg);
			     //$('#mail_' + id).after(msg);
			     $(self).after(msg);
			     //init_popups();
			     $(self).removeClass('urgent'); // read mail
			     $(self).addClass('isopen');
			     $("div.reply_button", self).show();
			     $('th.first img', $(self)).attr('src', '/images/dart-open.png');
			     
			     update_new_mails();
			   }
			 });
		       
		     }
		   }
		   
		 })
	  .css('cursor','pointer');

      }
    });

}


function create_upload() {

          // for falldoku uploads only
          $('div.rm_attachment img').click(function(){
              $(this).parents('div.rm_attachment').remove();
          });

          $('#upload_button').each(function(){

                 var admin = $(this).attr('rel') == "admin"; // upload in admin interface

	         new AjaxUpload(this, {
		   action: admin ? '/cgi-bin/ajax/admin/upload.pl' : '/cgi-bin/ajax/upload.pl',
		   name: 'upload',
                   onSubmit: function(file, ext){
		     this.disable();
		     $('#upload_status').text('Die Datei ' + file + ' wird hinzugefügt ...');
		   },
		   onComplete: function(file, response){
 		     if (response.match(/^success:/)) {
                       var statusmsg = response.substr(8);
	               $('#upload_status').text('Die Datei ' + file + ' wurde erfolgreich hinzugefügt.');
                       admin ? $('#attachlist').html(statusmsg) : $('#attachlist').append(statusmsg);
	               this.enable();
	               $('div.rm_attachment img').click(function(){
                          $(this).parents('div.rm_attachment').remove();
			  $('#upload_status').text('');
                       });
                     } else { // error
                       $('#upload_status').text('Fehler: Die Datei ' + file + ' konnte nicht hinzugefügt werden.');
                       this.enable();
                     }
		     $('.prettyPopin').height('700px'); // looks like this fixes height problems in IE7 
	           }		
	         });

          });

}


function init_popups(s) {

  $("a[rel^='popup']").prettyPopin({
        modal : true, /* true/false */
	width : false, /* false/integer */
	height: false, /* false/integer */
	opacity: 0.7, /* value from 0 to 1 */
	animationSpeed: 'fast', /* slow/medium/fast/integer */
	followScroll: true, /* true/false */
	loader_path: '/images/prettyPopin/loader.gif', /* path to your loading image */
        start_callback: function() { /* required zeitform version */
          $('div.rm_attachment img').click(function(){
             $(this).parent('div.rm_attachment').remove();
          });
          create_upload();
          
	  if ($('textarea.tinymce').size() > 0) init_tinymce();
        },
	callback: function(){ /* callback called when closing the popin */
	  if (window.location.pathname.match(/konto/)) {
	    location.reload()
	  }
	  
        } 
  });

  //$("a[rel^='popup']").attr('rel','');
}

function wundlokalisation() {

  $("#mapbody").unbind('click').click(function(e){

   var offset = $('#map').offset();
   var relativeX = e.pageX - parseInt(offset.left+0.5);
   var relativeY = e.pageY - parseInt(offset.top+0.5); 

   //$('.pos-x').html(relativeX);
   //$('.pos-y').html(relativeY);

   $('#marker img').css({'margin-left':(relativeX+5),'margin-top':(relativeY-5)}).show();

   //alert(relativeX + " " + relativeY);

   $.ajax({ 
     url: '/cgi-bin/ajax/polygon.pl',
     data: "x=" + relativeX + ";y="+relativeY,
     success: function(msg){
	 //alert(msg);
	 $('#wundlokalisation').html(msg).parent('p').removeClass('alert');
	 $('#posx').val(relativeX);
	 $('#posy').val(relativeY);
     }
   });

});

}

function hinweis_popups () {

  if ($('img[rel=hinweis]').size() > 0) {
    $('img[rel=hinweis]').tooltip({
      showURL: false,
      delay: 0
    });
  }
}

function init_tinymce () {

  $('textarea.tinymce').tinymce({
        // Location of TinyMCE script
        script_url : '/js/tinymce/jscripts/tiny_mce/tiny_mce.js',
	auto_reset_designmode : true,

	// General options
	theme : "advanced",
	//plugins : "safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",
	// 	mode : "exact",
	// 	elements : "content",
	
	//         document_base_url : "<tmpl_var base_url>",
	convert_urls : false,
	relative_urls : false,

	theme_advanced_buttons1 : "bold,italic,underline,sub,sup,|,formatselect,|,bullist,numlist,|,undo,|,link,image,charmap,code",
	theme_advanced_buttons2 : "",
	theme_advanced_buttons3 : "",
	theme_advanced_toolbar_location : "top",
	theme_advanced_toolbar_align : "left",
	theme_advanced_statusbar_location : "bottom",
	extended_valid_elements : "a[class|name|href|rel|title],img[class|src|alt|title|width|height],hr[class],span[class|style]"

   });
}

// konsil functions
function heilungsstatus (e) {
  if (e) {
    if (e.value == 1) { 
      $('#heilungsstatus_alert').show(); 
      $('select').attr("disabled", true);
      $('#heilungsstatus_id').attr("disabled", false);
      $('#abschlusskonsil').attr("checked", true).attr("disabled", true);
    } else { 
      $('#heilungsstatus_alert').hide(); 
      $('select').attr("disabled", false);
      $('#abschlusskonsil').attr("checked", false).attr("disabled", false);
    }

    erregerstatus($('#erregerstatus_id'));

    $('.prettyPopin').height('700px'); // looks like this fixes height problems in IE7 

  }
}

function wundnekrose (e) {
  if (e) {
    if (e.value == 3) { $('#wundnekrose_alert').show(); } 
    else { $('#wundnekrose_alert').hide(); }
  }
}

function schaedigung (e) {
  if (e) {
    if (e.value == 3) { $('#schaedigung_alert1').show(); $('#schaedigung_alert2').hide(); }
    else if (e.value > 3) { $('#schaedigung_alert2').show(); $('#schaedigung_alert1').hide(); }
    else { $('#schaedigung_alert2,#schaedigung_alert1').hide(); }
  }
}

function erregerstatus (e) {
  //alert(e.value);
  if (e) {
    if (e.value > 1) { $('#erreger_id').attr("disabled", false); }
    else { $('#erreger_id').attr("disabled", true); }
  }
}

