﻿if(user_agent_is_supported()){
	
var help_enabled = false;

function replace_products_units(elements_array, products_type){	
  var array_index;
  if(products_type == 'Strom'){
     array_needle_index  = 1;
     array_replace_index = 0;
  }
  else if(products_type == 'Gas'){
     array_needle_index  = 0;
     array_replace_index = 1;
  }
  else{
     array_needle_index  = 2;
     array_replace_index = 0;
  }

  for(var i = 0; i < elements_array.length-2; i++){
     if(elements_array[i].id != ''){
        var content = $("#"+elements_array[i].id).html();
        for(var j=0; j < language_array.length; j++){
          content = replace_in_string(content,language_array[j][array_needle_index],language_array[j][array_replace_index]);
        }
        $('#'+elements_array[i].id).html(content);
      }
    }
}

function replace_products_units_in_elements(products_type){
  var elements_array;
  elements_array = $("h4");
  replace_products_units(elements_array, products_type);
  elements_array = $("#col3_legend");
  replace_products_units(elements_array, products_type);
  elements_array = $("#inputText_step0-2");
  replace_products_units(elements_array, products_type);
  elements_array = $(".error");
  replace_products_units(elements_array, products_type);
  elements_array = $(".help");
  replace_products_units(elements_array, products_type);

  if(products_type == 'Strom'){
     $('#help_step0-2_additional_info').html(language_array[5][0]);
     $('#help_step0-2_additional_info_2').show();
  }
  else if(products_type == 'Gas'){
     $('#help_step0-2_additional_info').html(language_array[5][1]);
     $('#help_step0-2_additional_info_2').hide();
  }
  else{
     $('#help_step0-2_additional_info').html(language_array[5][2]);
  }

  enable_set_comsumption_default_values();
  if(!help_enabled){
  	enable_help();
  	help_enabled = true;
  }
}

$(document).ready(function(){
    $("#verbrauchsartS").click(function () {
        replace_products_units_in_elements('Strom');
    });

    $("#verbrauchsartG").click(function () {
        replace_products_units_in_elements('Gas');
    });

    // without this, help only works after changing product type
    if(verbrauchsart == '' || verbrauchsart == 'undefined' || verbrauchsart == 'both')replace_products_units_in_elements('both');
    else if(verbrauchsart == 'Strom')replace_products_units_in_elements('Strom');
    else if(verbrauchsart == 'Gas')replace_products_units_in_elements('Gas');

    if(!error_codes_array.in_error_section('e0-2')){
      $("#help_step0-2").hide();
      $("#help-link_step0-2 > img").attr('alt', general_language_array[1]);
      $("#help-link_step0-2").attr('title', general_language_array[1]);
    }
    else{
      $("#help-link_step0-2 > img").attr('alt', general_language_array[0]);
      $("#help-link_step0-2").attr('title', general_language_array[0]);
    }

    $("#help-link_step0-2").css('display', 'inline');
    enable_set_comsumption_default_values();

});

}