﻿/// <reference name="MicrosoftAjax.js"/>
/// <reference path="../../../../_static/clientscripts/Devlopment/jQ/jquery-latest-vsdoc.js" />
/// <reference path="../../Services/General.asmx" />

CustomAutoRidesClass = function (obj) {
    this.Init(obj);
};

CustomAutoRidesClass.prototype = {
    // variables
    carid: 0
    , isRetailer: false
    , hasVoted: false
    , isSet: false
    , vElms: []

    // functions
    , Init: function (obj) {
        var t = this;
        if (!t.isSet) {
            t.isSet = true;
            t.carid = obj.carid;
            t.isRetailer = obj.isRetailer;
        }
    }

    , AddVoteBtn: function (obj) {
        var t = this;
        if (!t.isSet) {
            t.isSet = true;
            t.hasVoted = obj.hasVoted
            t.vElms[0] = $(obj.vElm);
        }
        else {
            t.vElms[t.vElms.length] = $(obj.vElm);

        }

        if (!obj.hasVoted) {
            $(obj.vElm).click($.proxy(t.VoteForRide, t));
        }
    }

    , VoteForRide: function () {
        var t = this;
        if (!t.hasVoted) {
            // var _m = $AMS.$MM.Get_mid(); // t.carid
            CustomAuto.Services.General.VoteForRide(t.carid, $AMS.$MM.Get_mid(), t.isRetailer, function (rtn, uc, mn) { });
            for (var i = 0; i < t.vElms.length; i++) {
                t.vElms[i].html('Thanks for the Vote.');
            }
            t.hasVoted = true;
        }
    }
};

CustomAutoVoteHGHRClass = function (obj) {
    this.Init(obj);
};

CustomAutoVoteHGHRClass.prototype = {
    // variables
    hid: 0
    , voted: false
    // functions
    , Init: function (obj) {
        this.hid = obj.hid;
    }
    , Vote: function () {
        if (this.hid != 0 && !this.voted) {
            CustomAuto.Services.General.VoteForHotGirl(this.hid, $AMS.$MM.Get_mid(), function (rtn, uc, mn) {
                if (rtn) {
                    $('.hghc-vote-btn').each(
                        function () { $(this).text('Thanks for the Vote'); }
                    );
                }
                else {
                    alert('There was an error voting.  Please log off and try again');
                }

            });
            this.voted = true;
        }


        // alert(this.hid);
    }
};

CustomAutoHPPanels = function () {
};

CustomAutoHPPanels.prototype = {
    cTab: 0
    , ridesFunction: []
    , welcomFunction: []
    , retailersFunction: []
    , autoNewsFunction: []
    // functions
    , Init: function () { }
    , TabClick: function (s, idx) {
        $('#btnWelcome').removeClass('ca-hp-active');
        $('#btnRide').removeClass('ca-hp-active');
        $('#btnRetailers').removeClass('ca-hp-active');
        $('#btnAutoNews').removeClass('ca-hp-active');

        $(s).addClass('ca-hp-active');

        $('#pnlWelcome').hide();
        $('#pnlRides').hide();
        $('#pnlRetailers').hide();
        $('#pnlAutoNews').hide();
        switch (idx) {
            case 0:
                $('#pnlWelcome').show();
                break;
            case 1:
                if (this.ridesFunction.length > 0) {
                    for (var i = 0; i < this.ridesFunction.length; i++) {
                        this.ridesFunction[i]();
                    }
                }
                $('#pnlRides').show();
                break;
            case 2:
                $('#pnlRetailers').show();
                break;
            case 3:
                $('#pnlAutoNews').show();
                break;
            default:
                $('#pnlWelcome').show();
        }
    }
    , RegisterRideStartup: function (fun) {
        this.ridesFunction[this.ridesFunction.length] = fun;
    }
};

window.CAHPPanels = new CustomAutoHPPanels();

CustomAutoRidesSerach = function (obj) {
    $.extend(true, this, obj);
    this.Init();
};

CustomAutoRidesSerach.prototype = {
    cMakeID: 0
    , cModelID: 0
    , tarResults: ''

    // functions
    , Init: function () {
        $('#btnSearchRides').click($.proxy(this.Search, this));
        $('#ddMake').change($.proxy(this.MakeSelect, this));
        $('#ddlStartSearchCarYear').change($.proxy(this.StartYearSelect, this));
    }

    , MakeSelect: function () {
        var _this = $('#ddMake');
        var _id = _this.val();
        if (_id != this.cMakeID) {
            if (_id != '0') {
                CustomAuto.Services.General.GetModelsBasedOnMake(_id, function (rtn, uc, mn) {
                    var _ddMod = $('#ddModel');
                    _ddMod.removeAttr("disabled");
                    _ddMod.children().remove();
                    _ddMod.append("<option value='0'>All Models</option>");
                    for (var i = 0; i < rtn.length; i++) {
                        _ddMod.append("<option value='" + rtn[i].modelID + "'>" + rtn[i].name + "</option>");
                    }
                });
            }
            else {
                var _ddMod = $('#ddModel');
                _ddMod.children().remove();
                _ddMod.attr("disabled", "disabled");
                _ddMod.append("<option value='0'>All Models</option>");
            }
            this.cMakeID = _id;
        }
    }

    , StartYearSelect: function () {
        var tEl = $('#ddlStartSearchCarYear');
        var _id = tEl.val();
        if (_id != '0') {
            $('#divEndYear').show();
            $('#ddlEndSearchCarYear').val(_id);
            // $("#ddlEndSearchCarYear option:eq(" + _id + ")").attr('selected', 'selected');
        }
        else {
            $('#ddlEndSearchCarYear').val('0');
            $('#divEndYear').hide();
        }
    }

    , Search: function () {
        var _mkid = $('#ddMake').val();
        var _modid = $('#ddModel').val();
        var _sy = $('#ddlStartSearchCarYear').val();
        var _ey = $('#ddlEndSearchCarYear').val();
        // "/thirdpartycontrols/customauto/members/test.aspx
        window.location = this.tarResults + "?mkid=" + _mkid + "&modid=" + _modid + "&sy=" + _sy + "&ey=" + _ey;
    }
};

CustomAutoRetailerSerach = function (obj) {
    $.extend(true, this, obj);
    this.Init();
};

CustomAutoRetailerSerach.prototype = {
    cMainCat: 0
    , cSubCat: 0
    , zip: ''
    , tarResults: ''
    // functions
    , Init: function () {
        $('#btnSearchRetailers').click($.proxy(this.Search, this));
        $('#ddCatMain').change($.proxy(this.MainCat_Selected, this));
        if (this.zip != '' && this.zip != '0') {
            $('#txtZip').val(this.zip);
        }
    }
    , MainCat_Selected: function () {
        var t = this;
        var tEl = $('#ddCatMain');
        if (t.cMainCat != tEl.val()) {
            t.cMainCat = tEl.val();
            CustomAuto.Services.General.GetSubCatsOnMain(t.cMainCat, function (rtn, uc, mn) {
                var sEl = $('#ddCatSub');
                sEl.children().remove();
                sEl.append("<option value='0'>ALL Sub Categories</option>");
                for (var i = 0; i < rtn.length; i++) {
                    sEl.append("<option value='" + rtn[i].catid + "'>" + rtn[i].name + "</option>");
                }
            });
        }
    }
    , Search: function () {
        var t = this;
        t.cSubCat = $('#ddCatSub').val();
        window.location = t.tarResults + "?catid=" + t.cMainCat + "&subcatid=" + t.cSubCat + "&zip=" + $('#txtZip').val();
    }

};

//function Ajax_Process(path, params, id, tp) {
//    $.ajax({
//        type: tp,
//        url: path,
//        data: params,
//        success: function (msg) {
//            $(id).html(msg);
//        }
//    });
//}
//function Ajax_ExecuteScript(path, params) {
//    $.ajax({
//        type: "POST",
//        dataType: "script",
//        url: path,
//        data: params
//    });
//}

var AutoListClass = function () { this.Init(); }
AutoListClass.prototype = {
    _automanListStatus: 0
    , Init: function () {
        var _this = this;
        $(document).ready(function () { $('.auto-triget').mouseenter(_this.ShowAutoMan).mouseleave($.proxy(_this.HideAutoMan_fromLink, _this)); $('#auto_list').mouseenter($.proxy(_this.AutoListEntered, _this)).mouseleave($.proxy(_this.AutoListLeave, _this)); });
    }
    , ShowAutoMan: function () { $('#auto_list').show('slow'); this._automanListStatus = 1; }
    , AutoListEntered: function () { this._automanListStatus = 2; }
    , AutoListLeave: function () { var _this = this; this._automanListStatus = 1; setTimeout(function () { _this.HideFromList(); }, 500); }
    , HideAutoMan_fromLink: function () { var _this = this; this._automanListStatus = 1; setTimeout(function () { _this.HideFromList(); }, 500); }
    , HideFromList: function () { if (this._automanListStatus == 1) { $('#auto_list').hide(); } }
}
var BrandListClass = function () { this.Init(); }
BrandListClass.prototype = {
    _brandmanListStatus: 0
    , Init: function () {
        var _this = this;
        $(document).ready(function () { $('.brand-triget').mouseenter(_this.ShowBrandMan).mouseleave($.proxy(_this.HideBrandMan_fromLink, _this)); $('#brand_list').mouseenter($.proxy(_this.BrandListEntered, _this)).mouseleave($.proxy(_this.BrandListLeave, _this)); });
    }
    , ShowBrandMan: function () { $('#brand_list').show('slow'); this._brandmanListStatus = 1; }
    , BrandListEntered: function () { this._brandmanListStatus = 2; }
    , BrandListLeave: function () { var _this = this; this._brandmanListStatus = 1; setTimeout(function () { _this.HideFromList(); }, 500); }
    , HideBrandMan_fromLink: function () { var _this = this; this._brandmanListStatus = 1; setTimeout(function () { _this.HideFromList(); }, 500); }
    , HideFromList: function () { if (this._brandmanListStatus == 1) { $('#brand_list').hide(); } }
}
//var BrandListLargeClass = function () { this.Init(); }
//BrandListClass.prototype = {
//    _brandmanListStatus: 0
//    , Init: function () {
//        var _this = this;
//        $(document).ready(function () { $('.brand-triget').mouseenter(_this.ShowBrandMan).mouseleave($.proxy(_this.HideBrandMan_fromLink, _this)); $('#brand_list').mouseenter($.proxy(_this.BrandListEntered, _this)).mouseleave($.proxy(_this.BrandListLeave, _this)); });
//    }
//    , ShowBrandMan: function () { $('#brand_list').show('slow'); this._brandmanListStatus = 1; }
//    , BrandListEntered: function () { this._brandmanListStatus = 2; }
//    , BrandListLeave: function () { var _this = this; this._brandmanListStatus = 1; setTimeout(function () { _this.HideFromList(); }, 500); }
//    , HideBrandMan_fromLink: function () { var _this = this; this._brandmanListStatus = 1; setTimeout(function () { _this.HideFromList(); }, 500); }
//    , HideFromList: function () { if (this._brandmanListStatus == 1) { $('#brand_list').hide('slow'); } }
//}



var AutoDetailsClass = function () { this.Init(); }
AutoDetailsClass.prototype = {
    Init: function () {
        var _this = this;
        $(document).ready(function () {
            $('.car-link').mouseenter(function (e) {
                var _target = e.currentTarget; _this.ShowAutoDetails(_target.id);
            }).mouseleave(function (e) { var _target = e.currentTarget; _this.HideAutoDetails(_target.id); });
        });
    }
    , ShowAutoDetails: function (id) {
        var _t = id.replace("car_", "carDetails_");
        var _id = id.replace("car_", "");
        if ($('#' + _t).length === 0) {
            // need to created it
            var _dv = $("<div id='" + _t + "' class='car-details'>Loading...</div>");
            _dv.appendTo($("#" + id));
            Ajax_Process('/ThirdPartyControls/CustomAuto/GeneralControls/getautomanudetails.ashx?cmd=getAutoManuPopDetails&manid=' + _id, '', '#' + _t, 'GET');
        }
        $('#' + _t).show('slow');
    }
    , HideAutoDetails: function (id) {
        var _t = id.replace("car_", "carDetails_");
        $('#' + _t).hide();
    }
}

var BrandDetailsClass = function () { this.Init(); }
BrandDetailsClass.prototype = {
    Init: function () {
        var _this = this;
        $(document).ready(function () {
            $('.brand-link').mouseenter(function (e) {
                var _target = e.currentTarget; _this.ShowBrandDetails(_target.id);
            }).mouseleave(function (e) { var _target = e.currentTarget; _this.HideBrandDetails(_target.id); });
        });
    }
    , ShowBrandDetails: function (id) {
        var _t = id.replace("brand_", "brandDetails_");
        var _id = id.replace("brand_", "");
        if ($('#' + _t).length === 0) {
            // need to created it
            var _dv = $("<div id='" + _t + "' class='brand-details'>Loading...</div>");
            _dv.appendTo($("#" + id));
            Ajax_Process('/ThirdPartyControls/CustomAuto/GeneralControls/getautomanudetails.ashx?cmd=getBrandManuPopDetails&manid=' + _id, '', '#' + _t, 'GET');
        }
        $('#' + _t).show('slow');
    }
    , HideBrandDetails: function (id) {
        var _t = id.replace("brand_", "brandDetails_");
        $('#' + _t).hide();
    }
}
var AutoListDetailsClass = function () { this.Init(); }
AutoListDetailsClass.prototype = {
    Init: function () {
        var _this = this;
        $(document).ready(function () {
            $('.auto-link').mouseenter(function (e) {
                var _target = e.currentTarget; _this.ShowAutoListDetails(_target.id);
            }).mouseleave(function (e) { var _target = e.currentTarget; _this.HideAutoListDetails(_target.id); });
        });
    }
    , ShowAutoListDetails: function (id) {
        var _t = id.replace("auto_", "autoDetails_");
        var _id = id.replace("auto_", "");
        if ($('#' + _t).length === 0) {
            // need to created it
            var _dv = $("<div id='" + _t + "' class='auto-details'>Loading...</div>");
            _dv.appendTo($("#" + id));
            Ajax_Process('/ThirdPartyControls/CustomAuto/GeneralControls/getautomanudetails.ashx?cmd=getAutoListPopDetails&manid=' + _id, '', '#' + _t, 'GET');
        }
        $('#' + _t).show('slow');
    }
    , HideAutoListDetails: function (id) {
        var _t = id.replace("auto_", "autoDetails_");
        $('#' + _t).hide();
    }
}

var BrandListDetailsClass = function () { this.Init(); }
BrandListDetailsClass.prototype = {
    Init: function () {
        var _this = this;
        $(document).ready(function () {
            $('.brandlist-link').mouseenter(function (e) {
                var _target = e.currentTarget; _this.ShowBrandListDetails(_target.id);
            }).mouseleave(function (e) { var _target = e.currentTarget; _this.HideBrandListDetails(_target.id); });
        });
    }
    , ShowBrandListDetails: function (id) {
        var _t = id.replace("brandlist_", "brandlistDetails_");
        var _id = id.replace("brandlist_", "");
        if ($('#' + _t).length === 0) {
            // need to created it
            var _dv = $("<div id='" + _t + "' class='brandlist-details'>Loading...</div>");
            _dv.appendTo($("#" + id));
            Ajax_Process('/ThirdPartyControls/CustomAuto/GeneralControls/getautomanudetails.ashx?cmd=getBrandListPopDetails&manid=' + _id, '', '#' + _t, 'GET');
        }
        $('#' + _t).show('slow');
    }
    , HideBrandListDetails: function (id) {
        var _t = id.replace("brandlist_", "brandlistDetails_");
        $('#' + _t).hide();
    }
}
var TopBrandListDetailsClass = function () { this.Init(); }
TopBrandListDetailsClass.prototype = {
    Init: function () {
        var _this = this;
        $(document).ready(function () {
            $('.topbrandlist-link').mouseenter(function (e) {
                var _target = e.currentTarget; _this.ShowTopBrandListDetails(_target.id);
            }).mouseleave(function (e) { var _target = e.currentTarget; _this.HideTopBrandListDetails(_target.id); });
        });
    }
    , ShowTopBrandListDetails: function (id) {
        var _t = id.replace("topbrandlist_", "topbrandlistDetails_");
        var _id = id.replace("topbrandlist_", "");
        if ($('#' + _t).length === 0) {
            // need to created it
            var _dv = $("<div id='" + _t + "' class='topbrandlist-details'>Loading...</div>");
            _dv.appendTo($("#" + id));
            Ajax_Process('/ThirdPartyControls/CustomAuto/GeneralControls/getautomanudetails.ashx?cmd=getBrandListPopDetails&manid=' + _id, '', '#' + _t, 'GET');
        }
        $('#' + _t).show('slow');
    }
    , HideTopBrandListDetails: function (id) {
        var _t = id.replace("topbrandlist_", "topbrandlistDetails_");
        $('#' + _t).hide();
    }
}
