﻿function rollOn(element) {
    if (element != null) {
        var old = element.src;
        var newsrc = "";
        newsrc = old.replace("-off", "-on");
        element.src = newsrc;
    }
}

function rollOff(element) {
    if (element != null) {
        var old = element.src;
        var newsrc = "";
        newsrc = old.replace("-on", "-off");
        element.src = newsrc;
    }
}
$(document).ready(function () {

  $('.selectors img').hover(function () {
    var src = $(this).attr('src');
    var subsrc = src.split('-off');
    $(this).attr('src', subsrc[0] + '-on' + subsrc[1]);
    $(this).css('cursor', 'pointer');
  },
    function () {
      var src = $(this).attr('src');
      var subsrc = src.split('-on');
      $(this).attr('src', subsrc[0] + '-off' + subsrc[1]);
    });

  function storeCookie(cookieType, cookieValue) {
    $.cookie(cookieType, cookieValue);
  }


  $('.selectors .step-1 img').click(function () {
    var userProvider = $(this).attr('alt');
    if (userProvider == 'CommercialIndustrial') {
      window.location.replace("/CommercialIndustrial");
    }
    else {
      $('.selectors .step-1').fadeOut(1000);
      $('.selectors .step-2').delay(1005).fadeIn(1000);
      $('.steps .step-1').fadeOut(1000);
      $('.steps .step-2').delay(1005).fadeIn(1000);
      $('.steps .step-2 .arrow .buttons .step1').css('cursor', 'pointer');
      $.cookie('UserType', $(this).attr('alt'), { expires: 1 });
    }
    //storeCookie('UserType', $(this).attr('alt'));
  });

  $('.selectors .step-2 img').click(function () {
    $('.selectors .step-2').fadeOut(1000);
    $('.selectors .step-3').empty();
    var stateAbb = $(this).attr('title');
    var userType = $.cookie('UserType');

    $.getJSON('/home/GetProvidersByState/' + stateAbb, function (data) {
      $.each(data, function (i) {
        $('.selectors .step-3').append('<div class="company"><a href="/GoToRates/' + userType + '/' + data[i].Code + '">' + data[i].Name + '</a></div>');
      });
    });
    $('.selectors .step-3').delay(1005).fadeIn(1000);
    $('.selectors .step-3 .company img').css('cursor', 'pointer');
    $('.steps .step-2').fadeOut(1000);
    $('.steps .step-3').delay(1005).fadeIn(1000);
    $('.steps .step-3 .arrow .buttons .step1').css('cursor', 'pointer');
    $('.steps .step-3 .arrow .buttons .step2').css('cursor', 'pointer');
    $.cookie('UserState', $(this).attr('alt'), { expires: 1 });
    //storeCookie('UserState', $(this).attr('alt'));
  });
  $('.selectors .step-3 .company img').click(function () {
    //$('.selectors .step-3').fadeOut(1000);
    $.cookie('UserProvider', $(this).attr('alt'), { expires: 1 });
    //storeCookie('UserProvider', $(this).attr('alt'));
  });
  $('.steps .step-2 .arrow .buttons .step1').click(function () {
    $('.selectors .step-2').fadeOut(1000);
    $('.selectors .step-1').delay(1005).fadeIn(1000);
    $('.steps .step-2').fadeOut(1000);
    $('.steps .step-1').delay(1005).fadeIn(1000);
  });

  $('.steps .step-3 .arrow .buttons .step1').click(function () {
    $('.selectors .step-3').fadeOut(1000);
    $('.selectors .step-2').delay(1005).fadeIn(1000);
    $('.steps .step-3').fadeOut(1000);
    $('.steps .step-2').delay(1005).fadeIn(1000);
  });

  $('.steps .step-3 .arrow .buttons .step2').click(function () {
    $('.selectors .step-3').fadeOut(1000);
    $('.selectors .step-2').delay(1005).fadeIn(1000);
    $('.steps .step-3').fadeOut(1000);
    $('.steps .step-2').delay(1005).fadeIn(1000);
  });

  $('#more-info').click(function () {
    $('.popup-modal').fadeIn('slow');
  });
  $('a.close').click(function () {
    $('.popup-modal').fadeOut('slow');
  });
});

function setIdentification(indexText, valueText) {
    var url = "/Home/SetIdentification/";
    $.post(url), { index: indexText, value: valueText };
}

function getDisplayState(state) {
    switch (state) {
        case "OH":
            return "Ohio"
        case "MI":
            return "Michigan"
        case "NY":
            return "New York"
        case "KY":
            return "Kentucky"
        case "PA":
            return "Pennsylvania"
        case "IL":
            return "Illinois"
        case "IN":
          return "Indiana"
        case "MD":
          return "Maryland"
        case "VA":
          return "Virginia"
    }
}

function getDisplayProvider(provider) {
    switch (provider) {
        case "COH":
            return "Columbia Gas Of Ohio"
        case "DEO":
            return "Dominion East Ohio"
        case "VEC":
            return "Vectren"
        case "CGE":
            return "Duke Energy"
        case "ECO":
            return "The Energy Cooperative"
        case "WOG":
            return "West Ohio Gas"
        case "CON":
            return "Consumers"
        case "MC":
            return "MichCon"
        case "CHD":
            return "Central Hudson"
        case "NGD":
            return "National Grid"
        case "NFN":
            return "National Fuel"
        case "CKY":
            return "Columbia Gas of Kentucky"
        case "CPA":
            return "Columbus Gas of Pennsylvania"
        case "NFP":
            return "National Fuel PA"
        case "NCR":
            return "Nicor Gas"
        case "NIP":
          return "NIPSCO"
        case "BGE":
          return "Baltimore Gas and Electric"
        case "CGV":
          return "Columbia Gas of Virginia"
        case "CED":
            return "ComEd";
        case "DQE":
            return "Duquesne";
        case "PECO":
            return "PECO";
        case "AEP":
            return "American Electric Power";
    }
}

