﻿// Add to Cart Method OLD
function AddOffer(btnName, offerId) {
    var allInputs = document.getElementsByTagName('input');

    for (i = 0; i < allInputs.length; i++) {

        if (allInputs[i].name.indexOf(btnName) != -1) {
            var btnToClick = document.getElementById(allInputs[i].id);
        }

        if (allInputs[i].name.indexOf('txtOfferId') != -1) {
            var txtOfferId = document.getElementById(allInputs[i].id);
            txtOfferId.value = offerId;
        }

        if (allInputs[i].type == "checkbox")
            allInputs[i].checked = false;
    }

//    //For firing the click event.
//    if (document.createEventObject) {
//        // dispatch for IE
//        var evt = document.createEventObject();
//        return btnToClick.fireEvent('on' + 'click', evt)
//    }
//    else {
//        // dispatch for firefox + others
//        var evt = document.createEvent("HTMLEvents");
//        evt.initEvent('click', true, true); // event type,bubbling,cancelable
//        return !element.dispatchEvent(evt);
//    }

    if ($get(btnToClick.id).dispatchEvent) {
        var e = document.createEvent("MouseEvents");
        e.initEvent("click", true, true);

        $get(btnToClick.id).dispatchEvent(e);
    }
    else {
        $get(btnToClick.id).click();
    }
}

// Delete Offer Method
function DeleteOffer(btnName, offerId) {

    var allInputs = document.getElementsByTagName('input');

    for (i = 0; i < allInputs.length; i++) {

        if (allInputs[i].name.indexOf(btnName) != -1) {
            var btnToClick = document.getElementById(allInputs[i].id);
            alert(btnToClick);
        }

        if (allInputs[i].name.indexOf('txtOfferId') != -1) {
            var txtOfferId = document.getElementById(allInputs[i].id);
            txtOfferId.value = offerId;
        }

        if (allInputs[i].type == "checkbox")
            allInputs[i].checked = false;
    }

    if ($get(btnToClick.id).dispatchEvent) {
        var e = document.createEvent("MouseEvents");
        e.initEvent("click", true, true);

        $get(btnToClick.id).dispatchEvent(e);
    }
    else {
        $get(btnToClick.id).click();
    }
}

function OpenDetails(offer) {
    //alert('offer = ' + offer + ' mso = ' + mso);
    window.open('LearnMore.aspx?offer=' + offer, '', 'scrollbars=1,location=0,menubar=0,resizable=0,status=0,toolbar=0,replace=true,width=710,height=650');
}

// Open Windows, privacy policy, rebate, gc disclaimer etc
function OpenWindow(path) {
    window.open(path, 'CM', 'scrollbars=1,location=0,menubar=0,resizable=1,status=0,toolbar=0,replace=true,width=710,height=680');
}

function OpenGiftCardDetails() {
    window.open('clients/combun/docs/GCDisclaim.html', 'CM', 'scrollbars=1,location=0,menubar=0,resizable=0,status=0,toolbar=0,replace=true,width=710,height=680');
}

function OpenXfinityGiftCardDetails() {
    window.open('clients/comxfn/docs/GCDisclaim.html', 'CM', 'scrollbars=1,location=0,menubar=0,resizable=0,status=0,toolbar=0,replace=true,width=710,height=680');
}

/* Channels Lineup Method for Comcast */
function OpenComcastChannelsLineup() {
    window.open('clients/combun/docs/ChannelLineup.htm', 'CM', 'scrollbars=1,location=0,menubar=0,resizable=0,status=0,toolbar=0,replace=true,width=600,height=500');
}

function OpenXfinityChannelsLineup() {
    window.open('clients/comxfn/docs/ChannelLineup.htm', 'CM', 'scrollbars=1,location=0,menubar=0,resizable=0,status=0,toolbar=0,replace=true,width=600,height=500');
}

function ValidateCart(txtTotal) {
    var total = document.getElementById(txtTotal);
    Page_ClientValidate();
    if (Page_IsValid) {

        if (total.value == 0) {
            alert("No service(s) selected. Order cannot be processed");
            return false;
        }
        else
            return true;
    }
    else
        return false;
}

// WEB AGENT SPECIFIC FUNCTIONS == START

function ShowConfirmation() {
    $find('ModalPopupExtender1').show();
    return false;
}

function ShowRetry(){
    $find('ModalPopupExtender2').show();
    return false;
}

function ShowSelect() {
    $find('mpeSelectMso').show();
    return false;
}

function OpenDetails(offer) {
    //alert('offer = ' + offer + ' mso = ' + mso);
    window.open('LearnMore.aspx?offer=' + offer, '', 'scrollbars=1,location=no,menubar=0,resizable=0,status=0,toolbar=0,replace=true,width=710,height=650');
}

function maxWindow() {
    window.moveTo(0, 0);
    if (document.all) {
        top.window.resizeTo(screen.availWidth, screen.availHeight);
    }

    else if (document.layers || document.getElementById) {
        if (top.window.outerHeight < screen.availHeight || top.window.outerWidth < screen.availWidth) {
            top.window.outerHeight = screen.availHeight;
            top.window.outerWidth = screen.availWidth;
        }
    }
}


// WEB AGENT SPECIFIC FUNCTIONS == END
