﻿
try {
    function $(element) {
        return document.getElementById(element);
    }

    $('yuiDataTable').style.display = 'none';
    var div = $('dvSearchResults');

    var BUNDLE = document.createElement('div');
    var TV = document.createElement('div');
    var NET = document.createElement('div');
    var PHONE = document.createElement('div');

    BUNDLE.className = 'msoGroup';
    TV.className = 'msoGroup';
    NET.className = 'msoGroup';
    PHONE.className = 'msoGroup';

    BUNDLE.innerHTML = '<h2 class="msoGroupHeader">Bundle Plans</h2>';
    TV.innerHTML = '<h2 class="msoGroupHeader">Cable TV Plans</h2>';
    NET.innerHTML = '<h2 class="msoGroupHeader">High Speed Internet Plans</h2>';
    PHONE.innerHTML = '<h2 class="msoGroupHeader">Phone Service Plans</h2>';

    div.appendChild(BUNDLE);
    div.appendChild(TV);
    div.appendChild(NET);
    div.appendChild(PHONE);

    BUNDLE.style.display = 'none';
    TV.style.display = 'none';
    NET.style.display = 'none';
    PHONE.style.display = 'none';
}
catch (Error) { }

getBestOfferData = function(myData) { return new Array(); };

_formatOffer = function(elCell, oRecord, oColumn, oData) {

    var Offer = oRecord._oData;
    var HTML = "";

    HTML += '<div class=\"clsOfferContainer\">';
    HTML += '<div class=\"clsOfferTitleContainer\">';        
    HTML += '<div class=\"clsOfferTitle\"><h3 title="' + Offer.Title + '">' + '<div class = \"ellipsis\">' + Offer.Title + '</div></h3></div>\
             <div class=\"clsOfferPrice\">' + ((Offer.Price > 0) ? '<h3>$' + Offer.Price.toFixed(2) + '<span class="perMonth">/mo</span></h3>' : "<h4>price varies by market</h4>") + '</div>';
    HTML += '</div>';
    HTML += '<div class=\"clsOfferDetails\">';

    var provider = getProvider(Offer.ProductKey);
    if (provider == "ATT" || provider == "Verizon" || provider == "Vonage" || provider == "Qwest") {
        HTML += '<div class=\"clCallForOffer\"><h4>Call Now!</h4><p>You are only 4 minutes away from completing your order!</p><h4>' + getPhoneNumber() + '</h4></div>';
    }
    else {
        if (Offer.HasCustomizations) {

            HTML += '<a href=\'javascript:showDetailURL("config.aspx?' + Offer.ProductKey + '");\' class="selectplan_bt" >Select This Plan</a>';
        }
        else {
            HTML += '<a href=\'javascript:addProduct("' + Offer.ProductKey + '");\' class=\"selectplan_bt\" >Select This Plan</a>';
        }
    }
    HTML += '<ul>';
    var marketingDetialHTML = ""
    if (Offer.Description != null && Offer.Description != "") {
        //Insight displays the Description instead of the features
        marketingDetialHTML += "<div class='OfferDescription'>" + Offer.Description + "</div>";
    } else {
        for (var i = 0; i < Offer.TelevisionDetails.length; i++) {
            marketingDetialHTML += '<li>' + Offer.TelevisionDetails[i] + "</li>";
        }
        for (var i = 0; i < Offer.InternetDetails.length; i++) {
            marketingDetialHTML += '<li>' + Offer.InternetDetails[i] + " </li> ";
        }
        for (var i = 0; i < Offer.TelephoneDetails.length; i++) {
            marketingDetialHTML += '<li>' + Offer.TelephoneDetails[i] + " </li> ";
        }
    }
    if (marketingDetialHTML == "")
        marketingDetialHTML += '<li>Yes! Plans are available. Click the link below to learn more.</li>';
    marketingDetialHTML += '<li><a href=\"javascript:showDetailURL(\'detail.aspx?' + Offer.ProductKey + '\');\">Offer Details</a></li>';


    HTML += marketingDetialHTML;
    HTML += "</ul></div>";

    var node = document.createElement('div');
    node.innerHTML = HTML;
    if (Offer.Priority > 3) {
        BUNDLE.appendChild(node)
        BUNDLE.style.display = 'block';
    }
    if (Offer.Priority == 3) {
        TV.appendChild(node)
        TV.style.display = 'block';
    }
    if (Offer.Priority == 2) {
        NET.appendChild(node)
        NET.style.display = 'block';
    }
    if (Offer.Priority == 1) {
        PHONE.appendChild(node)
        PHONE.style.display = 'block';
    }

}

function productSelection(productKey) {
    //myCart.AddItem(productKey);
    checkCustomization(productKey);
}
