var billValueCleared = false;
var nextTab = ".pan02";
var slidesPaused = false;
var sliderTimeout = null;
var hasFocus = false;
var isPageDirty = false;
var channelDivId = "";
var channelChkId = "";
function ServiceChanged() {
    isPageDirty = true;
}

function ShowChannelPopUp(subDivId, chkId) {

    if (channelDivId != "") {
        j_q("#" + channelDivId).html(j_q("#divSlide").html());
    }
  
    j_q("#divSlide").css("display", "");
    j_q("#anchClose").css("display", "");
    j_q("#divMainChannelList").css("display", "");
    var cnt = j_q("#" + subDivId + " img").length * 1;
    var height1 = "'" + cnt / 6 + "'";
    var arr = height1.split(".");
    if (arr.length >= 2) {
        var aa = parseInt((cnt / 6), 10)
        if (aa >= 1 ) {
            var a = aa * 1;
            var height = (a * 1 + 1) * (78+10);
        }
        else {
            if (height1.substr(1,1) == "0") {
                arr[0] = "1";
            }
            var a = arr[0] * 1;
            var height = a * 1 * 78;
        }
    }
    else {
        var a = parseInt((cnt / 6), 10) * 1;
        var height = a * 1 * (78+10);
    }
    j_q("#divSlide").html(j_q("#" + subDivId).html());
    j_q("#divSlide").css("height", height+15);
    channelDivId = subDivId;
}
function CloseChannelPopUp() {

    //j_q("#divSlide").replaceWith('<div id="divSlide" style="display:none" class="scrollable"><br /><a id="anchClose" style="cursor:hand;display:none" onclick="CloseChannelPopUp();">Close</a></div>');
    j_q("#" + channelDivId).html(j_q("#divSlide").html());
    channelDivId = "";
    j_q("#divSlide").css("display", "none");
    j_q("#divMainChannelList").css("display", "none");
}
function InactiveText() {
    if (j_q("#HomeAddress").val() == "" || j_q("#HomeAddress").val() == "(required)") {
        j_q("#HomeAddress").css("color", "InactiveCaptionText");
    }
    if (j_q("#AptCondoNo").val() == "" || j_q("#AptCondoNo").val() == "(optional)") {
        j_q("#AptCondoNo").css("color", "InactiveCaptionText");
    }
    if (j_q("#CityStateZip").val() == "" || j_q("#CityStateZip").val() == "(required)") {
        j_q("#CityStateZip").css("color", "InactiveCaptionText");
    }
}
function ValidateRequired() {
    
    if (j_q("#HomeAddress").val() == "(required)") {

        j_q("#HomeAddress").val("");
    }


    if (j_q("#CityStateZip").val() == "(required)") {

        j_q("#CityStateZip").val("");
    }
}

function ValidateRequiredAddressEntry() {

    if (j_q("#valSumContainer").find("ul")[0].innerHTML.indexOf("City, State and/or Zip") == -1
                        && j_q("#valSumContainer").find("ul")[0].innerHTML.indexOf("Street Address") == -1) {
        if (j_q("#HomeAddress").val() == "(required)") {
            j_q("#HomeAddress").val("");
        }

        if (j_q("#CityStateZip").val() == "(required)") {

            j_q("#CityStateZip").val("");
        }
        if (j_q("#HomeAddress").val() == "(required)") {
            j_q("#HomeAddress").val("");
        }

        if (j_q("#CityStateZip").val() == "(required)") {

            j_q("#CityStateZip").val("");
        }
    }
    else if (j_q("#valSumContainer").find("ul")[0].innerHTML.indexOf("City, State and/or Zip") > -1
                        || j_q("#valSumContainer").find("ul")[0].innerHTML.indexOf("Street Address") > -1) {

        if (j_q("#valSumContainer").find("ul")[0].innerHTML.indexOf("City") > -1) {
            if (j_q("#CityStateZip").val() == "(required)") {
                j_q("#CityStateZip").val("");
                j_q("#valSumContainer").find("li:contains('City, State and/or Zip')").remove();
            }
            else if (j_q("#CityStateZip").val() != "") {
                j_q("#valSumContainer").find("li:contains('City, State and/or Zip')").remove();
            }
        }
        else {
            if (j_q("#CityStateZip").val() == "(required)") {

                j_q("#CityStateZip").val("");
            }
            else if (j_q("#CityStateZip").val() == "") {
                j_q("#CityStateZip").val("(required)");
            }
        }
        if (j_q("#valSumContainer").find("ul")[0].innerHTML.indexOf("Street") > -1) {
            if (j_q("#HomeAddress").val() == "(required)") {
                j_q("#HomeAddress").val("");
                j_q("#valSumContainer").find("li:contains('Street Address')").remove();
            }
            else if (j_q("#HomeAddress").val() != "") {
                j_q("#valSumContainer").find("li:contains('Street Address')").remove();
            }
        }
        else {
            if (j_q("#HomeAddress").val() == "(required)") {

                j_q("#HomeAddress").val("");
            }
            else if (j_q("#HomeAddress").val() == "") {
                j_q("#HomeAddress").val("(required)");
            }
        }
    }   
}

function SetRequired() {
    if (j_q("#HomeAddress").val() == "" || j_q("#HomeAddress").val() == "(required)") {

        j_q("#HomeAddress").val("(required)");
        j_q("#HomeAddress").css("color","InactiveCaptionText");
    }
    if (j_q("#AptCondoNo").val() == "" || j_q("#AptCondoNo").val() == "(optional)") {

        j_q("#AptCondoNo").val("(optional)");
        j_q("#AptCondoNo").css("color", "InactiveCaptionText");
    }
    if (j_q("#CityStateZip").val() == "" || j_q("#CityStateZip").val() == "(required)") {

        j_q("#CityStateZip").val("(required)");
        j_q("#CityStateZip").css("color","InactiveCaptionText");
    }
}

function SetRequiredText(val1) {
    if (val1 == "1" && j_q("#HomeAddress").val() == "") {
        j_q("#HomeAddress").val("(required)");
        j_q("#HomeAddress").css("color", "InactiveCaptionText");
    }
    else if (val1 == "2" && j_q("#AptCondoNo").val() == "") {
        j_q("#AptCondoNo").val("(optional)");
        j_q("#AptCondoNo").css("color", "InactiveCaptionText");
    }
    else if (val1 == "3" && j_q("#CityStateZip").val() == "") {
        j_q("#CityStateZip").val("(required)");
        j_q("#CityStateZip").css("color", "InactiveCaptionText");
    }
}

function ClearRequiredText(val1) {
    if (val1 == "1" && j_q("#HomeAddress").val() == "(required)") {
        j_q("#HomeAddress").val("");
        j_q("#HomeAddress").css("color", "Black");
    }
    else if (val1 == "1" && j_q("#HomeAddress").val() != "(required)"
                            && j_q("#HomeAddress").val() != "") {
        j_q("#HomeAddress").css("color", "Black");
    }

    else if (val1 == "2" && j_q("#AptCondoNo").val() == "(optional)") {
        j_q("#AptCondoNo").val("");
        j_q("#AptCondoNo").css("color", "Black");
    }
    else if (val1 == "2" && j_q("#AptCondoNo").val() != "(optional)"
                            && j_q("#AptCondoNo").val() != "") {
        j_q("#AptCondoNo").css("color", "Black");
    }
    else if (val1 == "3" && j_q("#CityStateZip").val() == "(required)") {
        j_q("#CityStateZip").val("");
        j_q("#CityStateZip").css("color", "Black");
    }
    else if (val1 == "3" && j_q("#CityStateZip").val() != "(required)"
                            && j_q("#CityStateZip").val() != "") {
        j_q("#CityStateZip").css("color", "Black");
    }
}
function AlertChanged() {
    isPageDirty = true;
}

j_q(document).ready(function() {
	j_q(".imageLogo").error(function() { j_q(this).attr('src', contentBaseUrl + '/hsa/no-logo.gif'); });
});

//j_q(document).ready(function() {
//	j_q('img').error(function() {
//		j_q(this).attr('src', contentBaseUrl + '/hsa/no-logo.gif');
//	});
//});
function InitializeCreditSlider(sliderID, className, creditValue,creditScore) {
    if (creditScore != j_q("#creditRatings").val()) {
        
        if (j_q("#creditRatings").val() == "NoCredit") {
            creditValue = 70;
        }
        else if (j_q("#creditRatings").val() == "Poor") {
            creditValue = 140;
        }
        else if (j_q("#creditRatings").val() == "OK") {
            creditValue = 210;
        }
        else if (j_q("#creditRatings").val() == "Good") {
            creditValue = 280;
        }
        else if (j_q("#creditRatings").val() == "VeryGood") {
            creditValue = 350;
        }
       
    }
    
    if (creditValue == "") {
      //  creditValue = 70;
    }
    j_q(sliderID).slider({
        value: creditValue,
        min: 0,
        max: 389,
        step: 70,
        slide: function(event, ui) {
            if (ui.value == 70) {
                j_q("#creditRatings").val("NoCredit");
            }
            else if (ui.value == 140) {
                j_q("#creditRatings").val("Poor");
            }
            else if (ui.value == 210) {
                j_q("#creditRatings").val("OK");
            }
            else if (ui.value == 280) {
                j_q("#creditRatings").val("Good");
            }
            else if (ui.value == 350) {
                j_q("#creditRatings").val("VeryGood");
            }
            else if (ui.value > 350) {
                j_q("#creditRatings").val("VeryGood");
                return false;
            }
            if (ui.value < 70) {
                j_q("#creditRatings").val("NoCredit");
                return false;
            }
        }
    });
    j_q(sliderID).removeClass('ui-widget-content').addClass(className);
    j_q(sliderID + " a").removeClass('ui-state-focus').removeClass('ui-corner-all').removeClass('ui-state-hover').removeClass('ui-state-hover').removeClass('ui-state-default');
    j_q(sliderID + " a").addClass('ui-slider-handle-default').addClass('ui-slider-state-hover').addClass('ui-InitializeSlider-state-focus');

}
function ShowHideHelper(id, isShow) {
    j_q("#" + id).css("display", isShow);
}
function HideToolTip() {
    ShowHideHelper('internetSpeedDialContent', 'none');
    ShowHideHelper('internetSpeedLowContent', 'none');
    ShowHideHelper('internetSpeedMedContent', 'none');
    ShowHideHelper('internetSpeedFastContent', 'none');
    ShowHideHelper('internetSpeedTurboContent', 'none');
}
function InitializeSpeedSlider(sliderID, className, creditValue,internetScore) {
    if (internetScore != j_q("#internetSpeedOption").val()) {
        
        if (j_q("#internetSpeedOption").val() == "DialUp") {
            creditValue = 70;
        }
        else if (j_q("#internetSpeedOption").val() == "Low") {
            creditValue = 140;
        }
        else if (j_q("#internetSpeedOption").val() == "Medium") {
            creditValue = 210;
        }
        else if (j_q("#internetSpeedOption").val() == "Fast") {
            creditValue = 280;
        }
        else if (j_q("#internetSpeedOption").val() == "Turbo") {
            creditValue = 350;
        }

    }

    j_q(sliderID).slider({
        value: creditValue,
        min: 0,
        max: 389,
        step: 70,
        slide: function(event, ui) {

            if (ui.value == 70) {
                j_q("#internetSpeedOption").val("DialUp");
                ShowHideHelper('internetSpeedDialContent', '');
                ShowHideHelper('internetSpeedLowContent', 'none');
                ShowHideHelper('internetSpeedMedContent', 'none');
                ShowHideHelper('internetSpeedFastContent', 'none');
                ShowHideHelper('internetSpeedTurboContent', 'none');

            }
            else if (ui.value == 140) {
                j_q("#internetSpeedOption").val("Low");
                ShowHideHelper('internetSpeedDialContent', 'none');
                ShowHideHelper('internetSpeedLowContent', '');
                ShowHideHelper('internetSpeedMedContent', 'none');
                ShowHideHelper('internetSpeedFastContent', 'none');
                ShowHideHelper('internetSpeedTurboContent', 'none');
            }
            else if (ui.value == 210) {
                j_q("#internetSpeedOption").val("Medium");
                ShowHideHelper('internetSpeedDialContent', 'none');
                ShowHideHelper('internetSpeedLowContent', 'none');
                ShowHideHelper('internetSpeedMedContent', '');
                ShowHideHelper('internetSpeedFastContent', 'none');
                ShowHideHelper('internetSpeedTurboContent', 'none');
            }
            else if (ui.value == 280) {
                j_q("#internetSpeedOption").val("Fast");
                ShowHideHelper('internetSpeedDialContent', 'none');
                ShowHideHelper('internetSpeedLowContent', 'none');
                ShowHideHelper('internetSpeedMedContent', 'none');
                ShowHideHelper('internetSpeedFastContent', '');
                ShowHideHelper('internetSpeedTurboContent', 'none');
            }
            else if (ui.value == 350) {
                j_q("#internetSpeedOption").val("Turbo");
                ShowHideHelper('internetSpeedDialContent', 'none');
                ShowHideHelper('internetSpeedLowContent', 'none');
                ShowHideHelper('internetSpeedMedContent', 'none');
                ShowHideHelper('internetSpeedFastContent', 'none');
                ShowHideHelper('internetSpeedTurboContent', '');
            }
            else if (ui.value > 350) {
                j_q("#internetSpeedOption").val("Turbo");
                ShowHideHelper('internetSpeedDialContent', 'none');
                ShowHideHelper('internetSpeedLowContent', 'none');
                ShowHideHelper('internetSpeedMedContent', 'none');
                ShowHideHelper('internetSpeedFastContent', 'none');
                ShowHideHelper('internetSpeedTurboContent', '');
                return false;
            }
            if (ui.value < 70) {
                j_q("#internetSpeedOption").val("DialUp");
                ShowHideHelper('internetSpeedDialContent', '');
                ShowHideHelper('internetSpeedLowContent', 'none');
                ShowHideHelper('internetSpeedMedContent', 'none');
                ShowHideHelper('internetSpeedFastContent', 'none');
                ShowHideHelper('internetSpeedTurboContent', 'none');
                return false;
            }
        }

    });
    
    
    //j_q("#MyServices.CreditRating").val();
    j_q(sliderID).removeClass('ui-widget-content').addClass(className);
    j_q(sliderID+" a").removeClass('ui-state-focus').removeClass('ui-corner-all').removeClass('ui-state-hover').removeClass('ui-state-hover').removeClass('ui-state-default');
    j_q(sliderID + " a").addClass('ui-slider-handle-default').addClass('ui-slider-state-hover').addClass('ui-InitializeSlider-state-focus');

}

function InitializeRecSlider(sliderID, className, initialValue) {
    var leftMargin = -10;
    j_q(".slides").css("position", "relative");
    j_q(".boxslider").css("position", "relative");
    j_q(sliderID).slider({
        value: initialValue,
        min: 0,
        max: 100,
        step: 1,
        slide: function(event, ui) {
            if (ui.value > 43) {
                leftMargin = -500;
                j_q(this).slider("value", 43);
                j_q(".slides").css("left", leftMargin + "px");

                return false;
            }
            else {
                leftMargin = -12 * ui.value;
                if (ui.value == 0) {
                    leftMargin = 0;
                }
                j_q(".slides").css("left", leftMargin + "px");
            }
        }
    });

    if (initialValue > 0) {
        leftMargin = -12 * initialValue;
        j_q(".slides").css("left", leftMargin + "px");
    }
    j_q(sliderID).removeClass('ui-widget-content').addClass(className);
    j_q(sliderID + " a").removeClass('ui-state-focus').removeClass('ui-corner-all').removeClass('ui-state-hover').removeClass('ui-state-hover').removeClass('ui-state-default').removeClass('ui-slider-handle').removeClass('ui-slider-state-hover');
    j_q(sliderID + " a").addClass('ui-rec-slider-handle');

}

function ShowFirstItem(displayCount) {
	if (parseInt(displayCount) > 5) {
		j_q("#recSlider").slider("value", 0);
		j_q(".slides").css("position", "relative");
		j_q(".slides").css("left", "0px");
	}
}

function ShowLastItem(displayCount) {
	if (parseInt(displayCount) > 5) {
		j_q("#recSlider").slider("value", 43);
		j_q(".slides").css("position", "relative");
		j_q(".slides").css("left", "-528px");
	}
}

function ShowNext() {
    j_q("#slideDiv").css("left", "-110px");
    j_q("#leftSlider").css("display", "block");
    j_q("#rightSlider").css("display", "none");
    
    
}

function ShowPrevious() {
    j_q("#slideDiv").css("left", "0px");
    j_q("#leftSlider").css("display", "none");
    j_q("#rightSlider").css("display", "block");
    
}

/*Hes Calculator start*/

function CalculatorDisplayControl(value) {
    if (value < 2) {
        j_q("#dv2").css("display", "none");
        j_q("#dv3").css("display", "none");
    }
    if (value < 3) {
        j_q("#dv3").css("display", "none");
    }

    if (value >= 2) {
        j_q("#dv2").css("display", "block");
    }
    if (value > 2) {
        j_q("#dv3").css("display", "block");
    }
}

function setFuel(elem) {
    j_q("#hdnFuel").val(elem);
}

function setChangeHeatFuel(elem) {
    j_q("#hdnFuel").val(elem);
    showERorGR(elem);
}

function showERorGR(elem) {
    if (elem == '4') {
        j_q("#dvElectric").css("display", "block");
        j_q("#dvGas").css("display", "none");
    } else {
        j_q("#dvElectric").css("display", "none");
        j_q("#dvGas").css("display", "block");
    }
}

function setTD(elem) {
    j_q("#hdnTD").val(elem);
}

function setElemValue(elem, value) {
    j_q(elem).val(value);
    ShowAcOrHp(value);
}

function ShowAcOrHp(value) {
    if (value == '5') {
        j_q("#dvNU").css("display", "block");
        j_q("#dvSeer").css("display", "block");
        j_q("#dvAge").css("display", "block");
        j_q("#dvSize").css("display", "block");

        j_q("#dvSeer1").css("display", "none");
    } else {
        j_q("#dvNU").css("display", "none");
        j_q("#dvSeer").css("display", "none");
        j_q("#dvAge").css("display", "none");
        j_q("#dvSize").css("display", "none");

        j_q("#dvSeer1").css("display", "block");
    }

}

function InitializeCalcSlider(sliderID, min, max, step, className, targetID, initialValue, sa) {
    
    j_q(sliderID).slider({
    value: initialValue,
        min: min,
        max: max,
        step: step,
        slide: function(event, ui) {
            j_q(targetID).val(ui.value);
            if (sa == 1) CalculatorDisplayControl(j_q(targetID).val());
        }
    });
    j_q(sliderID).removeClass('ui-widget-content').addClass(className);
    j_q(sliderID + " a").removeClass('ui-state-focus').removeClass('ui-corner-all').removeClass('ui-state-hover').removeClass('ui-state-hover').removeClass('ui-state-default');
    j_q(sliderID + " a").addClass('ui-slider-handle-default').addClass('ui-slider-state-hover').addClass('ui-slider-state-focus');

    if(sa == 1) CalculatorDisplayControl(initialValue);

    j_q(targetID).keypress(function(e) {
        if (e.which != 8 && e.which != 0 && e.which != 46 && (e.which < 48 || e.which > 57)) {
            return false;
        }
    });

    j_q(targetID).blur(function() {
        if (j_q(targetID).val() > max) {
            j_q(targetID).val(max);
        }
        if (j_q(targetID).val() < min) {
            j_q(targetID).val(min);
        }
        if (parseInt(j_q(sliderID).val()) > max) {
            j_q(sliderID).slider("option", "max", j_q(targetID).val());
            j_q(sliderID).slider("option", "value", j_q(targetID).val());

        }
        else {
            j_q(sliderID).slider("option", "value", parseInt(j_q(targetID).val()));
        }

        if (sa == 1) CalculatorDisplayControl(j_q(targetID).val());
    });

}

/*Hes Calculator end*/

function DetachSliderDiv() {

    j_q("#divTempSlider").detach();
}

function InitializeBillSlider(sliderID, className, maxSliderValue, targetID, initialValue, isBundle) {
    if (j_q("#monthlyBillID").val() != initialValue) {
        initialValue = j_q("#monthlyBillID").val();
    }
    
    var maxValue = j_q(maxSliderValue).val();
//    if (initialValue < 10) {
//        initialValue = 10;
//    }
    j_q(sliderID).slider({
        value: initialValue,
        min: 0,
        max: maxValue,
        step: 1,
        slide: function(event, ui) {
            //            if (ui.value > maxValue - 10) {
            //                return false;
            //            }
            j_q(targetID).val(ui.value);
                j_q("#divTempSlider").detach();
                j_q("#br1").detach();
                j_q("#br2").detach();
                j_q("#monthlySlider A").append('<br id="br1"/><br id="br2"/><div class="slider_bill_lbl"  id="divTempSlider">' + '$' + ui.value + '</div>');
        }

    });
    j_q(sliderID).removeClass('ui-widget-content').addClass(className);
    j_q(sliderID + " a").removeClass('ui-state-focus').removeClass('ui-corner-all').removeClass('ui-state-hover').removeClass('ui-state-hover').removeClass('ui-state-default');
    j_q(sliderID + " a").addClass('ui-slider-handle-default').addClass('ui-slider-state-hover').addClass('ui-slider-state-focus');

    j_q("#monthlyBillID").keypress(function(e) {
        if (e.which != 8 && e.which != 0 && e.which != 46 && (e.which < 48 || e.which > 57)) {
            return false;
        }
    });

    j_q("#monthlyBillID").blur(function() {
        var mthlyBill = j_q("#monthlyBillID").val();
        if (isNaN(mthlyBill) || isNaN(parseFloat(mthlyBill))) {
            mthlyBill = 0;
            j_q("#monthlyBillID").val("0.00");
        }
        if (parseInt(mthlyBill) > parseInt(j_q("#maxPrice").val())) {
            //            j_q("#monthlySlider").slider("option", "max", mthlyBill + 10);
            //            j_q("#monthlySlider").slider("option", "value", mthlyBill + 10);
            j_q("#monthlySlider").slider("option", "max", mthlyBill);
            j_q("#monthlySlider").slider("option", "value", mthlyBill);
        }
        else {
            //j_q("#monthlySlider").slider("option", "value", parseFloat(mthlyBill) + 10);
            j_q("#monthlySlider").slider("option", "value", parseFloat(mthlyBill));

        }
    });

    if (parseInt(j_q("#monthlyBillID").val()) == 0) {
        billValueCleared = true;
    }
    if (j_q("#monthlyBillID").val() > 0 && isBundle) {
        j_q(".monthly-bill-slider").css("background-image", "url(" + contentBaseUrl + "/hsa/slider_monthly-bill-disabled.gif)");
        j_q(".ui-slider-handle-default").css("background-image", "url(" + contentBaseUrl + "/hsa/slider-disabled.gif)");
        j_q(".bill-details").css("display", "none");
        j_q(".bundle-bill-message").css("display", "block");
        j_q('#monthlyBillID').attr("disabled","disabled")
        j_q("#disableSlider").addClass("disable-overlay");
        
    }
    else {
        j_q("#disableSlider").removeClass("disable-overlay");
    }

    

}
function ValidateService(elementName,errorElement) {
    var isChecked = j_q('input[name='+elementName+']:checked').length > 0;
    if (isChecked) {
        j_q("#" + errorElement).css("display", "none");
        return true;
    }
    else {
        j_q("#" + errorElement).css("display", "block");
        return false;
    }

}
function InitializeSlider(sliderID, className, min, max, step, defaultValue, targetID, omniture) {
    j_q(sliderID).slider({
        value: defaultValue,
        min: min,
        max: max,
        step: step,
        slide: function(event, ui) { 
            j_q(targetID).text(ui.value); 
        },
        change: function(event, ui) {
            if (j_q('#currenttab .tabitem > a')) {
                j_q('#currenttab .tabitem > a').addClass("tabSelected");
            }
            FilterResults(this);
        }
    });
    j_q(sliderID).removeClass('ui-widget-content').addClass(className);
    j_q(sliderID + " a").removeClass('ui-state-focus').removeClass('ui-corner-all').removeClass('ui-state-hover').removeClass('ui-state-hover').removeClass('ui-state-default');
    j_q(sliderID + " a").addClass('ui-slider-handle-default').addClass('ui-slider-state-hover').addClass('ui-slider-state-focus');
    if (omniture) {
        j_q(sliderID).attr("omniture", omniture);
    }
}

function InitializeUnlimitedSlider(sliderID, className, min, max, step, defaultValue, targetID, omniture) {
    j_q(sliderID).slider({
        value: defaultValue,
        min: min,
        max: max,
        step: step,
        slide: function(event, ui) {
            if (ui.value == max) {
                j_q(targetID).text('Unlimited');
            }
            else {
                j_q(targetID).text(ui.value);
            }
        },
        change: function(event, ui) {
            if (j_q('#currenttab .tabitem > a')) {
                j_q('#currenttab .tabitem > a').addClass("tabSelected");
            }
            FilterResults(this);
        }
    });
    j_q(sliderID).removeClass('ui-widget-content').addClass(className);
    j_q(sliderID + " a").removeClass('ui-state-focus').removeClass('ui-corner-all').removeClass('ui-state-hover').removeClass('ui-state-hover').removeClass('ui-state-default');
    j_q(sliderID + " a").addClass('ui-slider-handle-default').addClass('ui-slider-state-hover').addClass('ui-slider-state-focus');
    if (omniture) {
        j_q(sliderID).attr("omniture", omniture);
    }
}

function ToggleChannel(elem) {
    //var arr = jQuery.trim(j_q(elem).attr("class")).split(' ')
    if (j_q(elem).attr("class").indexOf("selected")==-1) {
        j_q(elem).addClass('selected');
    }
    else {
        j_q(elem).removeClass('selected');
    }
}

function CallRatingReview(ratingDivID) {
    j_q(ratingDivID).show();
}

function InitializeCalendar(calendarID) {
    j_q(calendarID).datepicker({
        showOn: 'button',
        buttonImage: contentBaseUrl + '/hsa/date-picker.gif',
        buttonImageOnly: true
    });

}

function ApplyRoundedButtonStyle() {
    if (jQuery.browser.msie) {
        j_q('.button').each(function() {
            var me = j_q(this);
            if (me.is(':visible')) {
                var meclass = j_q(this).attr("class");
                me.css("border", "none").wrap('<div class="button-wrap ' + (meclass) + '" style="width:' + (me.innerWidth()) + 'px;">');
                j_q('.button-wrap').cornerz({ radius: 5 });
                j_q('.button-wrap .button').hover(function() {
                    j_q(this).parent().addClass("hover");
                }, function() {
                    j_q(this).parent().removeClass("hover");
                });
            }
        });
    }
}

function ShowFullPlanDescription() {
    j_q('#spnShortDescription').hide();
    j_q('#spnFullDescription').show();
   }

function TabClick(TabClicked, TabNames) {
    $.each(
        TabNames,
        function(intIndex, objValue) {
            if (objValue == TabClicked) {
                j_q('#div' + objValue).show();
                j_q('#a' + objValue).removeClass('tab').addClass('tab active');
            }
            else {
                j_q('#div' + objValue).hide();
                j_q('#a' + objValue).removeClass('tab active').addClass('tab');
            }
        }
        );
    }   
    
function ClearFormErrors(formID) {

    clearForm(formID)
    j_q('#' + formID + ' input.input-validation-error')
                            .removeClass('input-validation-error')
                            .addClass('');


    j_q('#' + formID + ' .input-validation-error')
                            .removeClass('input-validation-error')
                            .addClass('input-validation-valid');

    j_q('#' + formID + ' .field-validation-error')
                            .removeClass('field-validation-error')
                            .addClass('field-validation-valid');

    j_q('#' + formID + ' .validation-summary-errors')
                            .removeClass('validation-summary-errors')
                            .addClass('validation-summary-valid');
}

function clearForm(formID) {
    // declare element type  
    var type = null;
    for (var y = 0; y < document.forms[formID].elements.length; y++) {
        // define element type  
        type = document.forms[formID].elements[y].type
        // alert before erasing form element  
        //alert('form='+x+' element='+y+' type='+type);  
        // switch on element type  
        switch (type) {
            case "text":

            case "textarea":
            case "password":
                //case "hidden":  
                document.forms[formID].elements[y].value = "";
                break;
            case "radio":
            case "checkbox":
                document.forms[formID].elements[y].checked = "";
                break;
            case "select-one":
                document.forms[formID].elements[y].options[0].selected = true;
                break;
            case "select-multiple":
                for (z = 0; z < document.forms[formID].elements[y].options.length; z++) {
                    document.forms[formID].elements[y].options[z].selected = false;
                }
                break;
        }
    }
}

function CheckRegisterCheckBoxes() {
    j_q('#SendEmailAlerts').attr('checked', true);
    j_q('#SendNewsletter').attr('checked', true);
}

function ChangeBundle(elem, showDialog) {
    var currentlySelected = j_q("#ActiveBundle").val();
    var currentElementID;
    j_q("input[name=MyCurrentService.TypeOfBundle]").each(function() {
        if (currentlySelected == this.value) {
            currentElementID = this.id;
        }
    });

    if (!billValueCleared) {
        if (showDialog) {
            j_q("#dialog-confirm").dialog({
                resizable: false,
                height: 160,
                width: 400,
                modal: true,
                buttons: {
                    'Continue': function() {
                        j_q(this).dialog('close');
                        j_q("#ActiveBundle").val(j_q(elem).value);
                        ResetBillUI();
                    },
                    Cancel: function() {
                        j_q(this).dialog('close');
                        j_q(elem).attr("checked", false);
                        j_q("#" + currentElementID).attr("checked", "checked");
                    }
                }
            });
        }
    }
    
}

function ChangeBundleAmount() {
    j_q("#dialog-confirm").dialog({
        resizable: false,
        height: 160,
        width: 400,
        modal: true,
        buttons: {
            'Continue': function() {
                j_q(this).dialog('close');
                ResetBillUI();
            },
            Cancel: function() {
                j_q(this).dialog('close');
            }
        }
    });
}



function ResetBillUI() {
    j_q(".monthly-bill-slider").css("background-image", "url(" + contentBaseUrl + "/hsa/slider_monthly-bill.gif)");
    j_q(".ui-slider-handle-default").css("background-image", "url("+contentBaseUrl+"/hsa/slider.gif)");
    j_q(".bill-details").css("display", "block");
    j_q(".bundle-bill-message").css("display", "none");
    j_q('#monthlyBillID').attr("disabled", false);
    j_q("#fld").css("display", "none");
    j_q("#fldBundle").css("display", "");
    j_q("#fldSlider").css("display", "");
    j_q("#bundleViewID").css("display", "");    
    j_q(".bundle-form").css("display", "block");
    j_q("#disableSlider").removeClass("disable-overlay"); 
    ClearBillInformation();
}

function ToggleContract(elem, serviceType) {
    

    $.ajax({
        url: "/FindSavings/Contract",
        type: "POST",
        cache: false,
        data: { hasContract: elem, ServiceType: serviceType },
        success: function(result) {
        }
    });
    if (elem == "True") {
        j_q("#divContract").css("display", "");        
    }
    else {
        j_q("#contractTimeRemaining").attr("selectedIndex", "0");
        j_q("#datepicker").val("");
        j_q("#terminationFee").val("0.00");
        j_q("#divContract").css("display", "none");
    }   

}

function HideBar(id){
	j_q("div#" + id).hide('slow');
}

function ShowShoppingCart(id) {
	//j_q("div#" + id).slideDown('slow');
    j_q("div#" + id).toggle('slow');
    if (j_q("div#" + id).is(":visible")) {
        LogOmnitureShowShoppingCart();
    }
}
function ShowCart() {
    j_q("#shoppingcart").css("display", "");
    if (j_q("#shoppingcart").is(":visible")) {
        LogOmnitureShowShoppingCart();
    }
}

//String.prototype.trim = function() { return this.replace(/^\s*/, "").replace(/\s*$/, ""); }

function OpenProviderCopyStatement() {
	var url = "http://www.allconnect.com/corporate/copyrights.html";
	window.open(url, 'Providercopystatements', 'toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=yes,copyhistory=no,scrollbars=yes,width=725,height=490,Left=275,Top=150');
}
function InitializeHomePage(delay, rootUrl) {
    tabDelay = delay;
    StartSlideShow(nextTab, rootUrl, tabDelay);
    j_q(document).ready(function() {
        j_q(".hoverpanel a").hover(
                  function() {
                      HandleTab(j_q(this).parent(), rootUrl);
                  },
                  function() {

                  }
                );
        j_q(".home-slides").hover(
           function() {
               window.clearTimeout(sliderTimeout);
               slidesPaused = true;
           },
           function() {
               if (!hasFocus) {
                   StartSlideShow(nextTab, rootUrl, tabDelay);
                   slidesPaused = false;
               } else {
                   slidesPaused = false;
               }
           }
        );

        j_q(".home-slides input").focus(
          function() {
              hasFocus = true;
          }
        );

        j_q(".home-slides input").blur(
          function() {
              hasFocus = false;
              RestartSlideshow(rootUrl, tabDelay);
          }
        );

    });
}

function StartSlideShow(panelID, rootUrl, tabDelay) {
    sliderTimeout = window.setTimeout(function() {
        HandleTab(j_q(panelID), rootUrl);
        RestartSlideshow(rootUrl, tabDelay);
    }, tabDelay);
}

function RestartSlideshow(rootUrl, tabDelay) {
    if (!slidesPaused) {
        StartSlideShow(nextTab, rootUrl, tabDelay);
    }
}

function HandleTab(tab, rootUrl) {
    j_q(".hoverpanel").removeClass("current");
    j_q(tab).addClass("current");
    if (j_q(tab).hasClass("pan01")) {
        nextTab = ".pan02";
        j_q('#mainHoverPanel').removeClass();
        j_q('#mainHoverPanel').addClass("panel01");
        j_q('#panelbackground').attr("src", rootUrl + "/hsa/heading-panel01.gif");
        j_q('.panel-message').html("Optimize your bills with cost-saving recommendations and instant alerts for savings on <b>cable and Internet packages</b> ... based on your home address!");
    }
    else if (j_q(tab).hasClass("pan02")) {
        nextTab = ".pan03";
        j_q('#mainHoverPanel').removeClass();
        j_q('#mainHoverPanel').addClass("panel02");
        j_q('#panelbackground').attr("src", rootUrl + "/hsa/heading-panel02.gif");
        j_q('.panel-message').html("Get tips to lower utility bills from your local <b>electric company</b> and <b>gas company</b>, calculate savings on your <b>water bill</b> and <b>trash removal</b> services.");
    }
    else if (j_q(tab).hasClass("pan03")) {
        nextTab = ".pan04";
        j_q('#mainHoverPanel').removeClass();
        j_q('#mainHoverPanel').addClass("panel03");
        j_q('#panelbackground').attr("src", rootUrl + "/hsa/heading-panel03.gif");
        j_q('.panel-message').html("Find reviews and prices of <b>cable and Internet packages</b>, <b>home phone service</b>, <b>high speed Internet</b>, natural gas prices, electric plans and more!");
    }
    else if (j_q(tab).hasClass("pan04")) {
        nextTab = ".pan05";
        j_q('#mainHoverPanel').removeClass();
        j_q('#mainHoverPanel').addClass("panel04");
        j_q('#panelbackground').attr("src", rootUrl + "/hsa/heading-panel04.gif");
        j_q('.panel-message').html("Compare local costs for <b>cable and Internet packages</b>, <b>high speed Internet</b>, <b>home phone service</b>, gas and electric company bills to see how much you can save!");
    }
    else if (j_q(tab).hasClass("pan05")) {
        nextTab = ".pan01";
        j_q('#mainHoverPanel').removeClass();
        j_q('#mainHoverPanel').addClass("panel05");
        j_q('#panelbackground').attr("src", rootUrl + "/hsa/heading-panel05.gif");
        j_q('.panel-message').html("Receive instant email updates when new <b>cable and Internet package</b> deals, high speed <b>Internet service</b> bundles, or other discounts become available.");
    }
}

function formatCurrency(num) {
    num = num.toString().replace(/\$|\,/g, '');
    if (isNaN(num))
        num = "0";
    sign = (num == (num = Math.abs(num)));
    num = Math.floor(num * 100 + 0.50000000001);
    cents = num % 100;
    num = Math.floor(num / 100).toString();
    if (cents < 10)
        cents = "0" + cents;
    for (var i = 0; i < Math.floor((num.length - (1 + i)) / 3); i++)
        num = num.substring(0, num.length - (4 * i + 3)) + ',' +
num.substring(num.length - (4 * i + 3));
    return (((sign) ? '' : '-') + '$' + num + '.' + cents);
}

function setFilterNonNumericKeys(parentid, id) {
    var item;
    if (parentid == "") {
        item = j_q(id);
    }
    else {
        item = j_q(parentid).find(id);
    }
    item.keypress(function(e) {
        if (e.which != 8 && e.which != 0 && e.which != 46 && (e.which < 48 || e.which > 57)) {
            return false;
        }
    });    
 }
function setFilterNonIntegerKeys(parentid, id) {
    var item;
    if (parentid == "") {
        item = j_q(id);
    }
    else {
        item = j_q(parentid).find(id);
    }
    item.keypress(function(e) {
        if (e.which != 8 && e.which != 0 && (e.which < 48 || e.which > 57)) {
            return false;
        }
    });
}
function setValidFloatRange(targetid, validationid, minRange, maxRange) {
    j_q(targetid).blur(function() {
        return ValidateFloatRange(targetid, validationid, minRange, maxRange);
    });
}
function ValidateFloatRange(targetid, validationid, minRange, maxRange) {
    var val = parseFloat(j_q(targetid).val());
    if (val < minRange || val > maxRange) {
        isFormValid = false;
        j_q(validationid).html("Please enter a valid number between " + minRange + " and " + maxRange);
        j_q(targetid).focus().focus();    //IE7 workaround
        return false;
    }
    else {
        isFormValid = true;
        j_q(validationid).html("");
        return true;
    }
}

function ValidateDate(field, validationid) {
    var allowBlank = true;
    var minYear = 1902;
    var maxYear = (new Date()).getFullYear() + 100;

    var errorMsg = "";

    // regular expression to match required date format
    re = /^(?=\d)(?:(?:(?:(?:(?:0?[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0?[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})|(?:0?2(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))|(?:(?:0?[1-9])|(?:1[0-2]))(\/|-|\.)(?:0?[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{2}))($|\ (?=\d)))?(((0?[1-9]|1[012])(:[0-5]\d){0,2}(\ [AP]M))|([01]\d|2[0-3])(:[0-5]\d){1,2})?$/;

    if (field.value != '') {
        if (regs = field.value.match(re)) {
            //valid date
        } else {
            errorMsg = "Invalid date format: " + field.value;
        }
    } else if (!allowBlank) {
        errorMsg = "Empty date not allowed!";
    }

    if (errorMsg != "") {
        j_q("#" + validationid).html(errorMsg);
        j_q("#" + validationid).removeClass("field-validation-valid");
        j_q("#" + validationid).addClass("field-validation-error");
        field.focus();  //IE7 workaround
        return false;
    }
    else {
        j_q("#" + validationid).html("");
        j_q("#" + validationid).removeClass("field-validation-error");
        j_q("#" + validationid).addClass("field-validation-valid");
        return true;
    }
}

function GetBundleTypeFromValue(bundleTypeValue) {
    var bundleType = "";
    if (bundleTypeValue == 9) {
        bundleType = 'TV-Internet-Phone';
    }
    else if (bundleTypeValue == 10) {
        bundleType = 'TV-Internet';
    }
    else if (bundleTypeValue == 11) {
        bundleType = 'TV-Phone';
    }
    else if (bundleTypeValue == 12) {
        bundleType = 'Internet-Phone';
    }
    else {
        bundleType = 'Unspecified';
    }

    return bundleType;
}

function LogOmnitureSignIn(userName) {
    s.events = "event3";
    s.prop1 = userName.toLowerCase();
    s.eVar1 = userName.toLowerCase();
    s.t();
    s.events = "";
    s.prop1 = "";
    s.eVar1 = "";
}
function LogOmnitureRegister() {
    s.events = "event1";
    s.t();
    s.events = "";
}

function LogOmnitureGetRecClick() {
    s.events = "event7";
    s.prop7 = s.pageName;
    s.eVar7 = s.pageName;
    s.t();
    s.events = "";
    s.prop7 = "";
    s.eVar7 = "";
}

function LogOmnitureNextClick(buttonType) {
    var configOptions = '';
    if (buttonType == 'UserBundleType') {
        //Get the radio button that is checked
        var bundleType = j_q('input[name=UserBundleType]:checked').val();
        configOptions = GetBundleTypeFromValue(bundleType);
    }
    else if (buttonType == 'UserServiceType') {
        //Find all checked items
        var checkedItems = j_q('input[name=UserServiceType]:checked');
        var i = 0;
        for (i = 1; i <= 8; i++) {
            j_q(checkedItems).each(function(index) {
                if (j_q(this).val() == i) {

                    if (configOptions.length > 0) {
                        configOptions += ",";
                    }
                    if (i == 1) {
                        configOptions += 'TV';
                    }
                    else if (i == 2) {
                        configOptions += 'Internet';
                    }
                    else if (i == 3) {
                        configOptions += 'Phone';
                    }
                    else if (i == 4) {
                        configOptions += 'Electric';
                    }
                    else if (i == 5) {
                        configOptions += 'Natural Gas';
                    }
                    else if (i == 6) {
                        configOptions += 'Water';
                    }
                    else if (i == 7) {
                        configOptions += 'Trash Removal';
                    }
                    else if (i == 8) {
                        configOptions += 'Home Security';
                    }
                }
            });
        }
    }
    
    s.events = "event8";
    s.prop5 = configOptions;
    s.eVar5 = configOptions;
    s.t();
    s.events = "";
    s.prop5 = "";
    s.eVar5 = "";
}

function LogOmnitureFacetChange(item) {
    s.events = "event8";
    if (item && j_q(item).attr("omniture") != null ) {
        s.prop12 = j_q(item).attr("omniture");
        s.eVar12 = j_q(item).attr("omniture");
    }
    else {
        s.prop12 = "";
        s.eVar12 = "";
    }
    s.t();
    s.events = "";
    s.prop12 = "";
    s.eVar12 = "";
}

function LogOmnitureUsageData(serviceType) {
    //Current Provider
    serviceType = j_q("#servicetypename").val();
    var noCurrentService = j_q("#noServiceCheckbox").attr('checked');
    var providerName = "Unspecified"
    if (!noCurrentService) {
        var selectedProviderName = j_q("#providerList > option:selected").text();
        var selectedProviderValue = j_q("#providerList > option:selected").val();
        if (selectedProviderName == "Other") {
            var otherName = j_q("#otherTextbox").val();
            if (otherName.length > 0) {
                providerName = "Other: " + otherName;
            }
            else {
                providerName = "Other: Unspecified";
            }
        }
        else if (selectedProviderValue.length > 0) {
            providerName = selectedProviderName;
        }
    }
    else {
        providerName = "No Service";
    }

    //MonthlyBill
    var billAmount = j_q("#monthlyBillID").val();
    //Current Contract
    var contractInfo = j_q("#datepicker").val();
    var noContract = j_q("#hasContract").attr('checked');
    var terminationFee = j_q("#terminationFee").val();
    if (noContract) {
        contractInfo = "No";
    }
    else if (contractInfo.length > 0) {
        var currentTime = Date.parse(j_q('#currenttime').val());
        var contractTime = Date.parse(contractInfo);
        // The number of milliseconds in one day
        var ONE_DAY = 1000 * 60 * 60 * 24

        // Calculate the difference in milliseconds
        var difference_ms = Math.abs(currentTime - contractTime)

        // Convert back to days and return
        contractInfo = Math.round(difference_ms / ONE_DAY)
    }
    else {
        contractInfo = "Unspecified";
    }
    //Bundle Stuff
    var isBundle = false;
    var bundleType = "";
    if (j_q("#noBundle")) {
        isBundle = j_q("#yesBundle").attr('checked');
        if (isBundle) {
            var bundleTypeValue = j_q("#ActiveBundle").val();
            bundleType = GetBundleTypeFromValue(bundleTypeValue);
        }
    }

    var creditScore = j_q("#internetSpeedOption").val();

    var featuresIncludedRadio = j_q("input[name='CurrentServiceHasAllFeatures']:checked");
    var featuresIncluded = "No";
    if (featuresIncludedRadio && j_q(featuresIncludedRadio).val() == 'True') {
        featuresIncluded = "Yes";
    }

    s.events = "event17";
    s.prop13 = providerName;
    s.eVar13 = providerName;
    s.prop14 = billAmount;
    s.eVar14 = billAmount;
    s.prop15 = contractInfo;
    s.eVar15 = contractInfo;
    s.prop16 = bundleType;
    s.eVar16 = bundleType;
    s.prop17 = creditScore;
    s.eVar17 = creditScore;
    s.prop19 = featuresIncluded;
    s.eVar19 = featuresIncluded;

    var featureData = "";
    var featuresIncluded = "";
    //TV Features
    if (serviceType == 'TV') {
        var numTVs = j_q("#NumberOfTVs > option:selected").text();
        featureData += "TVs:" + numTVs;
        var numDVRs = j_q("#NumberOfDVRNeeded > option:selected").text();
        featureData += ",DVRs:" + numDVRs;

        var wantsHD = j_q("#tv_hd").attr('checked');
        if (wantsHD) {
            featureData += ",HD"
        }
        if (j_q('#aFeatures').hasClass('active')) {
            var tvFeatures = j_q("input[name='ServiceOptions']:checked");
            if (tvFeatures) {
                j_q(tvFeatures).each(function(index) {
                    if (j_q(this).attr("omniture") != null) {
                        if (featureData.length > 0) {
                            featureData += ","
                        }
                        featureData += j_q(this).attr("omniture");
                    }
                });
            }
        }
    }
    
    //Internet
    if (serviceType == 'Internet') {
        var internetFeatures = j_q("input[name='ServiceOptions']:checked");
        if (internetFeatures) {
            j_q(internetFeatures).each(function(index) {
                if (j_q(this).attr("omniture") != null) {
                    if (featureData.length > 0) {
                        featureData += ","
                    }
                    featureData += j_q(this).attr("omniture");
                }
            });
        }
    }

    //Phone
    if (serviceType == 'Phone') {
        var longDistance = j_q("input[name='LongDistanceMinutesOption']:checked");
        if (longDistance) {
            if (j_q(longDistance).attr("omniture") != null) {
                if (featureData.length > 0) {
                    featureData += ","
                }
                featureData += j_q(longDistance).attr("omniture");
            }
        }
        var phoneFeatures = j_q("input[name='ServiceOptions']:checked");
        if (phoneFeatures) {
            j_q(phoneFeatures).each(function(index) {
                if (j_q(this).attr("omniture") != null) {
                    if (featureData.length > 0) {
                        featureData += ","
                    }
                    featureData += j_q(this).attr("omniture");
                }
            });
        }
    }

    //Home Security
    if (serviceType == 'Home Security') {
        var security = j_q("input[name='OwnOrRent']:checked");
        if (security) {
            if (j_q(longDistance).attr("omniture") != null) {
                if (featureData.length > 0) {
                    featureData += ","
                }
                featureData += j_q(longDistance).attr("omniture");
            }
        }

        if (j_q('#renterCost').val().length > 0) {
            if (featureData.length > 0) {
                featureData += ","
            }
            featureData += "$" + j_q('#renterCost').val();
        }
        var frequency = j_q("input[name='Frequency']:checked");
        if (security) {
            if (j_q(longDistance).attr("omniture") != null) {
                featureData += " " + j_q(longDistance).attr("omniture");
            }
        }
    }
    
    //Electric
    var effeciencyData = "";
    if (serviceType == 'Electric') {
        var elecFeatures = j_q("input[name='ServiceOptions']:checked");
        if (elecFeatures) {
            j_q(elecFeatures).each(function(index) {
                if (j_q(this).attr("omniture") != null) {
                    if (effeciencyData.length > 0) {
                        effeciencyData += ","
                    }
                    effeciencyData += j_q(this).attr("omniture");
                }
            });
        }
    }
    
    //Gas
    var usageData = "";
    if (serviceType == 'Natural Gas'){
        var elecFeatures = j_q("input[name='ServiceOptions']:checked");
        j_q(elecFeatures).each(function(index) {
            if (j_q(this).attr("omniture") != null) {
                if (usageData.length > 0) {
                    usageData += ","
                }
                usageData += j_q(this).attr("omniture");
            }
        });
    }
    
    //Water
    if (serviceType == 'Water')
    {
        var waterdata = ("input[name='ServiceOptions']:checked");
        if (waterdata) {
            j_q(waterdata).each(function(index) {
                if (j_q(this).attr("omniture") != null) {
                    if (j_q(this).hasClass("efficiencydata")) {
                        if (effeciencyData.length > 0) {
                            effeciencyData += ","
                        }
                        effeciencyData += j_q(this).attr("omniture");
                    }
                    else if (j_q(this).hasClass("usagedata")) {
                    if (usageData.length > 0) {
                        usageData += ","
                    }
                    usageData += j_q(this).attr("omniture");
                    }
                }
            });
        }
    }
    
    if (featureData)
    {
        s.prop18 = featureData;
        s.eVar18 = featureData;
    }
    if (effeciencyData){
        s.prop20 = effeciencyData;
        s.eVar20 = effeciencyData;
    }
    if (usageData) {
        s.prop21 = usageData;
        s.eVar21 = usageData;
    }
    
    s.t();
    s.events = "";
    s.prop13 = "";
    s.eVar13 = "";
    s.prop14 = "";
    s.eVar14 = "";
    s.prop15 = "";
    s.eVar15 = "";
    s.prop16 = "";
    s.eVar16 = "";
    s.prop17 = "";
    s.eVar17 = "";
    s.prop19 = "";
    s.eVar19 = "";
    s.prop18 = "";
    s.eVar18 = "";
    s.prop20 = "";
    s.eVar20 = "";
    s.prop21 = "";
    s.eVar21 = "";
    
}

function LogOmnitureCarouselClick(serviceType) {
    s.events = "event13";
    s.prop9 = serviceType;
    s.eVar9 = serviceType;
    s.t();
    s.events = "";
    s.prop9 = "";
    s.eVar9 = "";
}

function LogOmnitureAmbigousAddress() {
    s.events = "event14";
    s.t();
    s.events = "";
}

function LogOmnitureShowCalculator(calcName) {

    s.events = "event15";
    s.prop10 = calcName;
    s.eVar10 = calcName;
    s.t();
    s.events = "";
    s.prop10 = "";
    s.eVar10 = "";
}

function LogOmnitureCalcFindSavings(calcUrl) {
    var slashPosition = calcUrl.lastIndexOf("/");
    if (slashPosition > 0) {
        var calcName = calcUrl.substring(slashPosition + 1);

        s.events = "event16";
        s.prop10 = calcName;
        s.eVar10 = calcName;
        s.t();
        s.events = "";
        s.prop10 = "";
        s.eVar10 = "";
    }
}

function LogOmnitureShowShoppingCart() {
    s.events = "scOpen,event10:" + j_q("#oid").val();
    s.t();
    s.events = "";
}

function LogOmnitureAddToShoppingCart(eId) {
    s.events = "scAdd,event11:" + j_q("#oid").val();
    s.products = ";" + eId;
    s.t();
    s.events = "";
    s.products = "";
}

function LogOmnitureAddBundleToShoppingCart(eIds) {
    s.events = "scAdd,event11:" + j_q("#oid").val();
    if (eIds) {
        if (eIds.length > 0) {
            s.products = ";" + eIds.replace(/,/g, ",;");
        }
    }
    s.t();
    s.events = "";
    s.products = "";
}

function LogOmnitureRemoveFromShoppingCart(eId) {
    s.events = "scRemove,event20:" + j_q("#oid").val(); ;
    s.products = ";" + eId;
    s.t();
    s.events = "";
    s.products = "";
}

function LogOmnitureCheckoutShoppingCart(sessionID) {
    s.events = "scCheckout,event19:" + j_q("#oid").val();
    s.products = "";
    s.t();
    s.events = "";
    s.products = "";
}

function OptionFeatureTVCostCheck(selectedValue, optFeature) {
	//alert(selectedValue);
	var ddlid;
	var parsedResponse = (typeof optFeature) == 'string' ? eval('(' + optFeature + ')') : optFeature;
	for (var item in parsedResponse) {
		if (selectedValue == parsedResponse[item].ExternalID) {
			j_q("#Cost_" + parsedResponse[item].ExternalID).text("$0.00/mo");
			j_q("#SltdCost_" + parsedResponse[item].ExternalID).text("$0.00/mo");
			j_q("#Selected_" + parsedResponse[item].ExternalID).text(parsedResponse[item].Name);
			j_q("#NonCost_" + parsedResponse[item].ExternalID).text("0");
			ddlid = "select#ddl_" + parsedResponse[item].ExternalID;
			j_q(ddlid).attr("style", "width: 115px; font-size: 11px;");	
			PalnDetailsFeaturePricebyMonth();
			return;
		}
	}
	
	for (var item in parsedResponse) {
		j_q("#Cost_" + parsedResponse[item].ExternalID).text(parsedResponse[item].RecurringPrice == undefined ? "$0.00/mo" : "$" + parseFloat((parsedResponse[item].RecurringPrice * selectedValue)).toFixed(2) + "/mo");
		j_q("#SltdCost_" + parsedResponse[item].ExternalID).text(parsedResponse[item].RecurringPrice == undefined ? "$0.00/mo" : "$" + parseFloat((parsedResponse[item].RecurringPrice * selectedValue)).toFixed(2) + "/mo");
		j_q("#Selected_" + parsedResponse[item].ExternalID).text(parsedResponse[item].Name + " (" + selectedValue + ")");
		j_q("#NonCost_" + parsedResponse[item].ExternalID).text(parsedResponse[item].NonRecurringPrice == undefined ? "0" : parseFloat((parsedResponse[item].NonRecurringPrice)));
		ddlid = "select#ddl_" + parsedResponse[item].ExternalID;
		j_q(ddlid).attr("style", "width: 115px; font-size: 11px;");	
		PalnDetailsFeaturePricebyMonth();
		return;
	}
}


function OptFeatureTVCheck(checkBox, eid, value, desc) {
	j_q('input[value=' + j_q(checkBox).val() + ']').each(function(index) {
		j_q(this)[0].checked = checkBox.checked;
	});
	
	var totalRecurringPrice = parseFloat(j_q('#totalRecuringprice').text());
	if (checkBox.checked) {
		j_q('#ddl_' + eid).attr("disabled", false);
		totalRecurringPrice += value;
	}
	else {
		j_q('#ddl_' + eid).attr("disabled", true);
		j_q("select#ddl_" + eid).val(eid);
		j_q("#Cost_" + eid).text("$0.00/mo");
		j_q("#SltdCost_" + eid).text("$0.00/mo");
		j_q("#Selected_" + eid).text(desc);
		j_q('#ddl_' + eid).attr("style", "width: 115px; font-size: 11px;");
		totalRecurringPrice -= value;
	}
	PalnDetailsFeaturePricebyMonth();
}

function OptionFeatureInternetCostCheck(selectedValue, optFeature) {
	//alert(selectedValue);
	var parsedResponse = (typeof optFeature) == 'string' ? eval('(' + optFeature + ')') : optFeature;
	for (var item in parsedResponse) {
		if (selectedValue == parsedResponse[item].FeatureID) {
			//alert(parsedResponse[item].ExternalID + '-' + parsedResponse[item].RecurringPrice + '-' + parsedResponse[item].NonRecurringPrice);
			j_q("#Cost_" + parsedResponse[item].ExternalID).text(parsedResponse[item].RecurringPrice == undefined ? "$0.00/mo" : "$" + parseFloat(parsedResponse[item].RecurringPrice).toFixed(2) + "/mo");
			j_q("#SltdCost_" + parsedResponse[item].ExternalID).text(parsedResponse[item].RecurringPrice == undefined ? "$0.00/mo" : "$" + parseFloat(parsedResponse[item].RecurringPrice).toFixed(2) + "/mo");
			j_q("#Selected_" + parsedResponse[item].ExternalID).text(parsedResponse[item].ExternalDesc + " (" + parsedResponse[item].Description + ")");
			j_q("#NonCost_" + parsedResponse[item].ExternalID).text(parsedResponse[item].NonRecurringPrice == undefined ? "0" : parseFloat((parsedResponse[item].NonRecurringPrice)));
			ddlid = "select#ddl_" + parsedResponse[item].ExternalID;
			j_q(ddlid).attr("style", "width: 115px; font-size: 11px;");
			PalnDetailsFeaturePricebyMonth();
			return;
		}
	}

	for (var item in parsedResponse) {
		if (selectedValue == parsedResponse[item].ExternalID) {
			j_q("#Cost_" + parsedResponse[item].ExternalID).text("$0.00/mo");
			j_q("#SltdCost_" + parsedResponse[item].ExternalID).text("$0.00/mo");
			j_q("#Selected_" + parsedResponse[item].ExternalID).text(parsedResponse[item].ExternalDesc);
			j_q("#NonCost_" + parsedResponse[item].ExternalID).text("0");
			ddlid = "select#ddl_" + parsedResponse[item].ExternalID;
			j_q(ddlid).attr("style", "width: 115px; font-size: 11px;");
			PalnDetailsFeaturePricebyMonth();
			return;
		}
	}
}

function OptFeatureInternetCheck(checkBox,eid,value, desc) {
	j_q('input[value=' + j_q(checkBox).val() + ']').each(function(index) {
		j_q(this)[0].checked = checkBox.checked;		
	});

	var totalRecurringPrice = parseFloat(j_q('#totalRecuringprice').text());
	if (checkBox.checked) {
		j_q('#ddl_' + eid).attr("disabled", false);
		totalRecurringPrice += value;
	}
	else {
		j_q('#ddl_' + eid).attr("disabled", true);
		j_q("select#ddl_" + eid).val(eid);
		j_q("#Cost_" + eid).text("$0.00/mo");
		j_q("#SltdCost_" + eid).text("$0.00/mo");
		j_q("#Selected_" + eid).text(desc);
		j_q('#ddl_' + eid).attr("style", "width: 115px; font-size: 11px;");
		totalRecurringPrice -= value;
	}
	PalnDetailsFeaturePricebyMonth();
}

function OptFeatureCheck(checkBox, value) {
	j_q('input[value=' + j_q(checkBox).val() + ']').each(function(index) {
		j_q(this)[0].checked = checkBox.checked;
	});
	var totalRecurringPrice = parseFloat(j_q('#totalRecuringprice').text());

	if (checkBox.checked) {
		totalRecurringPrice += value;
	}
	else {
		totalRecurringPrice -= value;
	}
	totalRecurringPrice = Math.round(totalRecurringPrice * 100) / 100
	j_q('#totalRecuringprice').text(totalRecurringPrice.toFixed(2));
	j_q('#totalRecuringpricewithfea').text(totalRecurringPrice.toFixed(2));
}


function PalnDetailsFeaturePricebyMonth() {
	var recPrice = 0;
	var selectedOptPrice = 0;
	var totalprice = 0;
	var totalnonrecprice = 0;
	var baseoneprice = 0;
	var eachbaseoneprice = 0;
	if (j_q("#baseprice1").text().length > 0) {
		recPrice = parseFloat(j_q("#baseprice1").text().replace("/mo", "").replace("$", ""));
	}
	else if (j_q("#baseprice2").text().length > 0 && j_q("#speoffprice2").text().length > 0) {
		//recPrice = parseFloat(j_q("#baseprice2").text().replace("/mo", "").replace("$", ""));
		recPrice = parseFloat(j_q("#speoffprice2").text().replace("/mo", "").replace("$", ""));
	}

	if (j_q("#baseNonOnetime1").text().length > 0) {
		baseoneprice = parseFloat(j_q("#baseNonOnetime1").text().replace("$", ""));
	}
	else if (j_q("#baseNonOnetime2").text().length > 0 && j_q("#prodisNonOnetime2").text().length > 0) {
		//baseoneprice = parseFloat(j_q("#baseNonOnetime2").text().replace("$", ""));
		baseoneprice = parseFloat(j_q("#prodisNonOnetime2").text().replace("$", ""));
	}

	//	if (j_q("#totbaseNonOnetime").text().length > 0) {
	//		baseoneprice = parseFloat(j_q("#totbaseNonOnetime").text().replace("$", ""));
	//	}
		
	//alert(recPrice);
	j_q('input[name|=externalFeatureOptionsTVChk]:checked').each(function(index) {
		//alert(j_q(this).val());
		var ctl = "#Cost_" + j_q(this).val();
		var nonctl = "#NonCost_" + j_q(this).val();
		//alert(j_q(nonctl).text());
		selectedOptPrice = parseFloat(selectedOptPrice) + parseFloat(j_q(ctl).text().replace("/mo", "").replace("$", ""));

		if (!isNaN(parseFloat(j_q(nonctl).text()))) {			
			eachbaseoneprice = parseFloat(eachbaseoneprice) + parseFloat(j_q(nonctl).text());
		}
		//alert(parseFloat(selectedOptPrice).toFixed(2));
	});

	totalprice = parseFloat(totalprice) + parseFloat(recPrice);
	totalprice = parseFloat(totalprice) + parseFloat(selectedOptPrice);
	if (isNaN(eachbaseoneprice)) {
		totalnonrecprice = parseFloat(baseoneprice);
	}
	else {
		totalnonrecprice = parseFloat(eachbaseoneprice) + parseFloat(baseoneprice);
	}
	
	//alert(parseFloat(totalprice).toFixed(2));
	j_q('#totalRecuringprice').text(parseFloat(totalprice).toFixed(2));
	j_q('#totalRecuringpricewithfea').text(parseFloat(totalprice).toFixed(2));
	j_q("#totbaseNonOnetime").text("$" + parseFloat(totalnonrecprice).toFixed(2));
	//j_q("#pricewithyourfeatures").text("$" + totalprice.toFixed(2) + "/mo");
}

function ToggleFilters(tabTitle) {
    switch (tabTitle) {
        case "TV":
            j_q('#tvfilterdiv').show();
            j_q('#internetfilterdiv').hide();
            j_q('#phonefilterdiv').hide();
            break;
        case "Internet":
            j_q('#tvfilterdiv').hide();
            j_q('#internetfilterdiv').show();
            j_q('#phonefilterdiv').hide();
            break;
        case "Phone":
            j_q('#tvfilterdiv').hide();
            j_q('#internetfilterdiv').hide();
            j_q('#phonefilterdiv').show();
            break;
        case "Bundle":
        case "TV + Internet + Phone":
            j_q('#tvfilterdiv').show();
            j_q('#internetfilterdiv').show();
            j_q('#phonefilterdiv').show();
            break;
        case "TV + Phone":
            j_q('#tvfilterdiv').show();
            j_q('#internetfilterdiv').hide();
            j_q('#phonefilterdiv').show();
            break;
        case "TV + Internet":
            j_q('#tvfilterdiv').show();
            j_q('#internetfilterdiv').show();
            j_q('#phonefilterdiv').hide();
            break;
        case "Internet + Phone":
            j_q('#tvfilterdiv').hide();
            j_q('#internetfilterdiv').show();
            j_q('#phonefilterdiv').show();
            break;
    }
}


