function fadeImages(startcol){
   
   if(startcol==1){
       jQuery("#fi1").fadeIn(2000);
       jQuery("#fi3").fadeOut(2000);
                 
   }else if(startcol==2){
       jQuery("#fi2").fadeIn(2000);
       jQuery("#fi1").fadeOut(2000);
       
   }else if(startcol==3){
       jQuery("#fi3").fadeIn(2000);
       jQuery("#fi2").fadeOut(2000);
                     
   }
   startcol = startcol+1;
   if(startcol == 4){
    startcol=1;
   }
   setTimeout("fadeImages("+startcol+")",6000);
}

function searchkeyup(){      
    if ( ! e ) {
      e = window.event;
    }    
    if (e.which) {
        Tastencode = e.which;
     } else if (e.keyCode) {
        Tastencode = e.keyCode;
     } 
    
    switch( Tastencode) {                              
      case 13:
         document.location.href='/search/node/'+jQuery('#search_block_form').val();        
      break; 
        
    }
}

function setSummaryStars (rounded) {   
   var borders = {
       1 : [10,20],
       2 : [30,40],
       3 : [50,60],
       4 : [70,80],
       5 : [90,100]
   }
   for(var i = 1; i < 6; i++){
      var star = $('#summary_star_'+i);
      star.removeClass();
      if(rounded >= borders[i][0] && rounded < borders[i][1]){
          star.addClass('on half');
      }else if(rounded >= borders[i][0] && rounded >= borders[i][1]){
          star.addClass('on');
      }else{
          star.addClass('off');
      }
   }

}

function calcVoteWeights() {
   average = 0;
/*
Gewichtsverlust	23%
Hungergefühl	16%  x
Verständnis & Komplexität	12%  x
Durchhaltevermögen	16% x
Einschränkungen	10% x
Auswärtsessen	5%  x
Wohlbefinden	18%
*/

var voteWeights = [23,16,16,12,10,5,18];
for (var i = 0; i < 7; i++) {
 var val = $('#edit-field-criteria'+(i+1)+'-0-rating-1').val();
 val = val == '-' ? 0 : parseInt(val, 10);
 average = average + (val * voteWeights[i]); 
}

   average = average / 100;
   $('#edit-field-voting-result-0-value').val(average);
   var rounded = Math.round(average/10)*10;
   $('#edit-field-vote-0-rating-1').val(rounded);
   setSummaryStars(rounded);
}

