/* Minification failed. Returning unminified contents.
(9,10): run-time error CSS1031: Expected selector, found 'mod('
(9,10): run-time error CSS1025: Expected comma or open brace, found 'mod('
(18,10): run-time error CSS1031: Expected selector, found 'leap_gregorian('
(18,10): run-time error CSS1025: Expected comma or open brace, found 'leap_gregorian('
(23,21): run-time error CSS1031: Expected selector, found '='
(23,21): run-time error CSS1025: Expected comma or open brace, found '='
(24,10): run-time error CSS1031: Expected selector, found 'gregorian_to_jd('
(24,10): run-time error CSS1025: Expected comma or open brace, found 'gregorian_to_jd('
(37,10): run-time error CSS1031: Expected selector, found 'jd_to_gregorian('
(37,10): run-time error CSS1025: Expected comma or open brace, found 'jd_to_gregorian('
(65,10): run-time error CSS1031: Expected selector, found 'leap_islamic('
(65,10): run-time error CSS1025: Expected comma or open brace, found 'leap_islamic('
(69,19): run-time error CSS1031: Expected selector, found '='
(69,19): run-time error CSS1025: Expected comma or open brace, found '='
(70,10): run-time error CSS1031: Expected selector, found 'islamic_to_jd('
(70,10): run-time error CSS1025: Expected comma or open brace, found 'islamic_to_jd('
(78,10): run-time error CSS1031: Expected selector, found 'jd_to_islamic('
(78,10): run-time error CSS1025: Expected comma or open brace, found 'jd_to_islamic('
(90,10): run-time error CSS1031: Expected selector, found 'leap_persian('
(90,10): run-time error CSS1025: Expected comma or open brace, found 'leap_persian('
(94,19): run-time error CSS1031: Expected selector, found '='
(94,19): run-time error CSS1025: Expected comma or open brace, found '='
(95,10): run-time error CSS1031: Expected selector, found 'persian_to_jd('
(95,10): run-time error CSS1025: Expected comma or open brace, found 'persian_to_jd('
(112,10): run-time error CSS1031: Expected selector, found 'jd_to_persian('
(112,10): run-time error CSS1025: Expected comma or open brace, found 'jd_to_persian('
(141,10): run-time error CSS1031: Expected selector, found 'JalaliDate('
(141,10): run-time error CSS1025: Expected comma or open brace, found 'JalaliDate('
(222,1): run-time error CSS1019: Unexpected token, found 'jQuery('
(222,8): run-time error CSS1019: Unexpected token, found 'function('
(222,17): run-time error CSS1019: Unexpected token, found '$'
(222,18): run-time error CSS1019: Unexpected token, found ')'
(222,19): run-time error CSS1019: Unexpected token, found '{'
(223,2): run-time error CSS1019: Unexpected token, found '$'
(223,24): run-time error CSS1030: Expected identifier, found ''fa''
(223,24): run-time error CSS1033: Expected closing bracket, found ''fa''
(223,28): run-time error CSS1031: Expected selector, found ']'
(223,28): run-time error CSS1025: Expected comma or open brace, found ']'
(244,2): run-time error CSS1019: Unexpected token, found '$'
(244,15): run-time error CSS1030: Expected identifier, found 'setDefaults('
(244,15): run-time error CSS1031: Expected selector, found 'setDefaults('
(244,15): run-time error CSS1025: Expected comma or open brace, found 'setDefaults('
(245,1): run-time error CSS1019: Unexpected token, found '}'
(245,2): run-time error CSS1019: Unexpected token, found ')'
(246,10): run-time error CSS1031: Expected selector, found 'AddToWishList('
(246,10): run-time error CSS1025: Expected comma or open brace, found 'AddToWishList('
(273,10): run-time error CSS1031: Expected selector, found 'priceinquery('
(273,10): run-time error CSS1025: Expected comma or open brace, found 'priceinquery('
(293,12): run-time error CSS1031: Expected selector, found '='
(293,12): run-time error CSS1025: Expected comma or open brace, found '='
(294,10): run-time error CSS1031: Expected selector, found 'CHmessagebox('
(294,10): run-time error CSS1025: Expected comma or open brace, found 'CHmessagebox('
(340,10): run-time error CSS1031: Expected selector, found 'CHmessageClose('
(340,10): run-time error CSS1025: Expected comma or open brace, found 'CHmessageClose('
(361,10): run-time error CSS1031: Expected selector, found 'addToCart('
(361,10): run-time error CSS1025: Expected comma or open brace, found 'addToCart('
(409,10): run-time error CSS1031: Expected selector, found 'removeFromCart('
(409,10): run-time error CSS1025: Expected comma or open brace, found 'removeFromCart('
(443,10): run-time error CSS1031: Expected selector, found 'AddToCompressionList('
(443,10): run-time error CSS1025: Expected comma or open brace, found 'AddToCompressionList('
(469,10): run-time error CSS1031: Expected selector, found 'LoadSendMethods('
(469,10): run-time error CSS1025: Expected comma or open brace, found 'LoadSendMethods('
(497,10): run-time error CSS1031: Expected selector, found 'LoadSendMethodPrice('
(497,10): run-time error CSS1025: Expected comma or open brace, found 'LoadSendMethodPrice('
(519,10): run-time error CSS1031: Expected selector, found 'LoadPaymentTypePrice('
(519,10): run-time error CSS1025: Expected comma or open brace, found 'LoadPaymentTypePrice('
(534,10): run-time error CSS1031: Expected selector, found 'Discount('
(534,10): run-time error CSS1025: Expected comma or open brace, found 'Discount('
(570,10): run-time error CSS1031: Expected selector, found 'deleteAddress('
(570,10): run-time error CSS1025: Expected comma or open brace, found 'deleteAddress('
(588,10): run-time error CSS1031: Expected selector, found 'editAddress('
(588,10): run-time error CSS1025: Expected comma or open brace, found 'editAddress('
(611,10): run-time error CSS1031: Expected selector, found 'loginbtn('
(611,10): run-time error CSS1025: Expected comma or open brace, found 'loginbtn('
(624,1): run-time error CSS1019: Unexpected token, found '$'
(624,2): run-time error CSS1019: Unexpected token, found '('
(624,3): run-time error CSS1019: Unexpected token, found '"#filter_name"'
(624,17): run-time error CSS1019: Unexpected token, found ')'
(624,19): run-time error CSS1030: Expected identifier, found 'keyup('
(624,19): run-time error CSS1019: Unexpected token, found 'keyup('
(624,34): run-time error CSS1031: Expected selector, found '('
(624,34): run-time error CSS1025: Expected comma or open brace, found '('
(663,2): run-time error CSS1019: Unexpected token, found ')'
(665,1): run-time error CSS1019: Unexpected token, found 'jQuery('
(665,8): run-time error CSS1019: Unexpected token, found '"document"'
(665,18): run-time error CSS1019: Unexpected token, found ')'
(665,20): run-time error CSS1030: Expected identifier, found 'ready('
(665,20): run-time error CSS1019: Unexpected token, found 'ready('
(665,35): run-time error CSS1031: Expected selector, found '('
(665,35): run-time error CSS1025: Expected comma or open brace, found '('
(681,2): run-time error CSS1019: Unexpected token, found ')'
(683,10): run-time error CSS1031: Expected selector, found 'ProductQuickview('
(683,10): run-time error CSS1025: Expected comma or open brace, found 'ProductQuickview('
(710,10): run-time error CSS1031: Expected selector, found 'showMyadditional('
(710,10): run-time error CSS1025: Expected comma or open brace, found 'showMyadditional('
(715,10): run-time error CSS1031: Expected selector, found 'extrasaleLoad('
(715,10): run-time error CSS1025: Expected comma or open brace, found 'extrasaleLoad('
(731,10): run-time error CSS1031: Expected selector, found 'extrasaleselect('
(731,10): run-time error CSS1025: Expected comma or open brace, found 'extrasaleselect('
(757,10): run-time error CSS1031: Expected selector, found 'extraslidernext('
(757,10): run-time error CSS1025: Expected comma or open brace, found 'extraslidernext('
(773,10): run-time error CSS1031: Expected selector, found 'extrasliderprev('
(773,10): run-time error CSS1025: Expected comma or open brace, found 'extrasliderprev('
 */
/**
 * Persian translation & Convert to Jalali Calendar for bootstrap-datepicker
 * Rahman Mousavian	<mousavian.rahman@gmail.com>
 *  Using jQuery Datepicker (Jalali Calendar) By:
 * 	Mahdi Hasheminezhad. email: hasheminezhad at gmail dot com (http://hasheminezhad.com)
 */
;

function mod(a, b) {return a - (b * Math.floor(a / b));}
/*
       JavaScript functions for the Fourmilab Calendar Converter

                  by John Walker  --  September, MIM
              http://www.fourmilab.ch/documents/calendar/

                This program is in the public domain.
*/
function leap_gregorian(year)
{
    return ((year % 4) == 0) &&
            (!(((year % 100) == 0) && ((year % 400) != 0)));
}
var GREGORIAN_EPOCH = 1721425.5;
function gregorian_to_jd(year, month, day)
{
    return (GREGORIAN_EPOCH - 1) +
           (365 * (year - 1)) +
           Math.floor((year - 1) / 4) +
           (-Math.floor((year - 1) / 100)) +
           Math.floor((year - 1) / 400) +
           Math.floor((((367 * month) - 362) / 12) +
           ((month <= 2) ? 0 :
                               (leap_gregorian(year) ? -1 : -2)
           ) +
           day);
}
function jd_to_gregorian(jd) {
    var wjd, depoch, quadricent, dqc, cent, dcent, quad, dquad,
        yindex, dyindex, year, yearday, leapadj;

    wjd = Math.floor(jd - 0.5) + 0.5;
    depoch = wjd - GREGORIAN_EPOCH;
    quadricent = Math.floor(depoch / 146097);
    dqc = mod(depoch, 146097);
    cent = Math.floor(dqc / 36524);
    dcent = mod(dqc, 36524);
    quad = Math.floor(dcent / 1461);
    dquad = mod(dcent, 1461);
    yindex = Math.floor(dquad / 365);
    year = (quadricent * 400) + (cent * 100) + (quad * 4) + yindex;
    if (!((cent == 4) || (yindex == 4))) {
        year++;
    }
    yearday = wjd - gregorian_to_jd(year, 1, 1);
    leapadj = ((wjd < gregorian_to_jd(year, 3, 1)) ? 0
                                                  :
                  (leap_gregorian(year) ? 1 : 2)
              );
    month = Math.floor((((yearday + leapadj) * 12) + 373) / 367);
    day = (wjd - gregorian_to_jd(year, month, 1)) + 1;

    return new Array(year, month, day);
}

function leap_islamic(year)
{
    return (((year * 11) + 14) % 30) < 11;
}
var ISLAMIC_EPOCH = 1948439.5;
function islamic_to_jd(year, month, day)
{
    return (day +
            Math.ceil(29.5 * (month - 1)) +
            (year - 1) * 354 +
            Math.floor((3 + (11 * year)) / 30) +
            ISLAMIC_EPOCH) - 1;
}
function jd_to_islamic(jd)
{
    var year, month, day;

    jd = Math.floor(jd) + 0.5;
    year = Math.floor(((30 * (jd - ISLAMIC_EPOCH)) + 10646) / 10631);
    month = Math.min(12,
                Math.ceil((jd - (29 + islamic_to_jd(year, 1, 1))) / 29.5) + 1);
    day = (jd - islamic_to_jd(year, month, 1)) + 1;
    return new Array(year, month, day);
}

function leap_persian(year)
{
    return ((((((year - ((year > 0) ? 474 : 473)) % 2820) + 474) + 38) * 682) % 2816) < 682;
}
var PERSIAN_EPOCH = 1948320.5;
function persian_to_jd(year, month, day)
{
    var epbase, epyear;

    epbase = year - ((year >= 0) ? 474 : 473);
    epyear = 474 + mod(epbase, 2820);

    return day +
            ((month <= 7) ?
                ((month - 1) * 31) :
                (((month - 1) * 30) + 6)
            ) +
            Math.floor(((epyear * 682) - 110) / 2816) +
            (epyear - 1) * 365 +
            Math.floor(epbase / 2820) * 1029983 +
            (PERSIAN_EPOCH - 1);
}
function jd_to_persian(jd)
{
    var year, month, day, depoch, cycle, cyear, ycycle,
        aux1, aux2, yday;


    jd = Math.floor(jd) + 0.5;

    depoch = jd - persian_to_jd(475, 1, 1);
    cycle = Math.floor(depoch / 1029983);
    cyear = mod(depoch, 1029983);
    if (cyear == 1029982) {
        ycycle = 2820;
    } else {
        aux1 = Math.floor(cyear / 366);
        aux2 = mod(cyear, 366);
        ycycle = Math.floor(((2134 * aux1) + (2816 * aux2) + 2815) / 1028522) +
                    aux1 + 1;
    }
    year = ycycle + (2820 * cycle) + 474;
    if (year <= 0) {
        year--;
    }
    yday = (jd - persian_to_jd(year, 1, 1)) + 1;
    month = (yday <= 186) ? Math.ceil(yday / 31) : Math.ceil((yday - 6) / 30);
    day = (jd - persian_to_jd(year, month, 1)) + 1;
    return new Array(year, month, day);
}

function JalaliDate(p0, p1, p2) {
    var gregorianDate;
    var jalaliDate;

	if (!isNaN(parseInt(p0)) && !isNaN(parseInt(p1)) && !isNaN(parseInt(p2))) {
        var g = jalali_to_gregorian([parseInt(p0, 10), parseInt(p1, 10), parseInt(p2, 10)]);
		setFullDate(new Date(g[0], g[1], g[2]));
    } else {
        setFullDate(p0);
    }

    function jalali_to_gregorian(d) {
		var adjustDay = 0;
		if(d[1]<0){
			adjustDay = leap_persian(d[0]-1)? 30: 29;
			d[1]++;
		}
        var gregorian = jd_to_gregorian(persian_to_jd(d[0], d[1] + 1, d[2])-adjustDay);
        gregorian[1]--;
        return gregorian;
    }

    function gregorian_to_jalali(d) {
        var jalali = jd_to_persian(gregorian_to_jd(d[0], d[1] + 1, d[2]));
        jalali[1]--;
        return jalali;
    }

    function setFullDate(date) {
        if (date && date.getGregorianDate) date = date.getGregorianDate();
        gregorianDate = new Date(date);
		gregorianDate.setHours(gregorianDate.getHours() > 12 ? gregorianDate.getHours() + 2 : 0)
        if (!gregorianDate || gregorianDate == 'Invalid Date' || isNaN(gregorianDate || !gregorianDate.getDate())) {
            gregorianDate = new Date();
        }
        jalaliDate = gregorian_to_jalali([
            gregorianDate.getFullYear(),
            gregorianDate.getMonth(),
            gregorianDate.getDate()]);
        return this;
    }

    this.getGregorianDate = function() { return gregorianDate; }

    this.setFullDate = setFullDate;

	this.setMonth = function(e) {
		jalaliDate[1] = e;
        var g = jalali_to_gregorian(jalaliDate);
        gregorianDate = new Date(g[0], g[1], g[2]);
        jalaliDate = gregorian_to_jalali([g[0], g[1], g[2]]);
	}

    this.setDate = function(e) {
        jalaliDate[2] = e;
        var g = jalali_to_gregorian(jalaliDate);
        gregorianDate = new Date(g[0], g[1], g[2]);
        jalaliDate = gregorian_to_jalali([g[0], g[1], g[2]]);
    };

    this.getFullYear = function() { return jalaliDate[0]; };
    this.getMonth = function() { return jalaliDate[1]; };
    this.getDate = function() { return jalaliDate[2]; };
    this.toString = function() { return jalaliDate.join(',').toString(); };
    this.getDay = function() { return gregorianDate.getDay(); };
    this.getHours = function() { return gregorianDate.getHours(); };
    this.getMinutes = function() { return gregorianDate.getMinutes(); };
    this.getSeconds = function() { return gregorianDate.getSeconds(); };
    this.getTime = function() { return gregorianDate.getTime(); };
    this.getTimeZoneOffset = function() { return gregorianDate.getTimeZoneOffset(); };
    this.getYear = function() { return jalaliDate[0] % 100; };

    this.setHours = function(e) { gregorianDate.setHours(e) };
    this.setMinutes = function(e) { gregorianDate.setMinutes(e) };
    this.setSeconds = function(e) { gregorianDate.setSeconds(e) };
    this.setMilliseconds = function(e) { gregorianDate.setMilliseconds(e) };
}




jQuery(function($){
	$.datepicker.regional['fa'] = {
		calendar: JalaliDate,
		closeText: 'بستن',
		prevText: 'قبل',
		nextText: 'بعد',
		currentText: 'امروز',
		monthNames: ['فروردین','اردیبهشت','خرداد','تیر','مرداد','شهریور','مهر','آبان','آذر','دی','بهمن','اسفند'],
		monthNamesShort: ['فروردین','اردیبهشت','خرداد','تیر','مرداد','شهریور','مهر','آبان','آذر','دی','بهمن','اسفند'],
		dayNames: ['یکشنبه', 'دوشنبه', 'سه شنبه', 'چهارشنبه', 'پنجشنبه', 'جمعه', 'شنبه'],
		dayNamesShort: ['یک', 'دو', 'سه', 'چهار', 'پنج', 'جمعه', 'شنبه'],
		dayNamesMin: ['ی','د','س','چ','پ','ج','ش'],
		weekHeader: 'ه',
		dateFormat: 'yy/mm/dd',
		firstDay: 6,
		isRTL: true,
		showMonthAfterYear: false,
		yearSuffix: '',
		calculateWeek: function(date) {
			var checkDate = new JalaliDate(date.getFullYear(), date.getMonth(), date.getDate() + (date.getDay() || 7) - 3);
			return Math.floor(Math.round((checkDate.getTime() - new JalaliDate(checkDate.getFullYear(), 0, 1).getTime()) / 86400000) / 7) + 1;
		}};
	$.datepicker.setDefaults($.datepicker.regional['fa']);
});
function AddToWishList(id) {
    $.ajax({
        url: '/Customer/AddWishList',
        data: { id: id },
        type: 'Get',


    }).done(function (data) {
        if (data.status == "loginerror") {
            CHmessagebox(data.message, 2);
        }
        else if (data.status != "error") {
            $('.wishlistcount').html(data.wishcount);
            if (data.status == "add") {
                $(".button-addtowishlist-" + id).addClass("back-red")
            }
            else if (data.status == "remove") {
                $(".button-addtowishlist-" + id).removeClass("back-red")
            }

        }
        else {
            CHmessagebox(data.message);
        }
    })
}

function priceinquery(id) {
    $.ajax(
        {
            url: '/Catalog/ProductPriceInquery',
            data: { id: id },
            type: 'Get',
            success: function (data) {
                if (data == "loginerror") {
                    CHmessagebox("لطفا ابتدا وارد حساب کاربری خود شوید", 2);
                }
                else {
                    CHmessagebox(data);
                }

            }

        });

}

CHfunction = undefined;
function CHmessagebox(message, messagetype, outputfunction) {
    if (messagetype == undefined) {
        messagetype = 1;
    }
    CHmessageClose();
    CHfunction = outputfunction;

    var ch_messa = '<div id="MyDialogModel" class="CH-message">' +
                   '<div id="MyDialogModelBody" class="CH-message-body">' +
                   '<h4>' + message + '</h4>';
    if (messagetype == 3) {
        ch_messa = ch_messa + '<div class="row">' +
                                        '<div class="col col-xs-6"><button class="btn btn-primary btn-lg" onclick="CHmessageClose(\'YES\',this);" style="width:100%;">' + "بله" + "</button></div>" +
                                        '<div class="col col-xs-6"><button class="btn btn-danger btn-lg" onclick="CHmessageClose(\'NO\');" style="width:100%;">' + "خیر" + "</button></div>" +
                                '</div>';
    }
    else if (messagetype == 2) {
        ch_messa = ch_messa + '<div id="loginformdiv" class="row no-margin">' +
                                 '<button class="btn btn-default m-progress no-background" ></button>' +
                                '</div>';

        
    }
    else {
        ch_messa = ch_messa + '<button class="btn btn-primary btn-lg" onclick="CHmessageClose();">' + "باشه" + "</button>";
    }
    ch_messa = ch_messa +
                   '</div>' +
                   '<div class="CH-message-background" onclick="CHmessageClose();"></div>' +
                   '</div>';


    $('body').append(ch_messa);
    if (messagetype == 2) {
        $.ajax({
            url: '/Customer/SmallLogin',
            data: { location: window.location.href },
            type: 'Get',
            success: (function (data) {

                $('#loginformdiv').html(data);

            })
        });
    }
}
function CHmessageClose(dresualt, sender) {
    if (dresualt == undefined) {
        dresualt == "OK";
    }

    if (dresualt == "YES" && CHfunction != undefined) {
        if (sender != undefined) {
            $(sender).addClass("m-progress");
        }

        CHfunction();

        if (sender != undefined) {
            $(sender).removeClass("m-progress");
        }
    }
    CHfunction = undefined;

    $('#MyDialogModel').remove();
}

function addToCart(id, sender, Procount, refresh) {

    if (sender != undefined) {
        $(sender).addClass("m-progress");
    }

    if (Procount == undefined) {
        Procount = 0;
    }
    if (refresh == undefined) {
        refresh = 0;
    }
    Productcount = 0;
    if (Procount == 2) {
        Productcount = document.getElementById("Buycount" + id).value;
    }
    $.ajax(
       {
           url: '/Customer/addtoCart',
           data: { id, count: Productcount },
                   type: 'Get',
                   success: function (data) {
                       if (refresh == 1) {
                           location.reload();
                       }
                       else {
                           CHmessagebox(data);


                           $.ajax(
                              {
                                  url: '/Customer/CartSmall',
                                  data: {},
                                  type: 'Get',
                                  success: function (cartdata) {
                                      $("#cart").html(cartdata);
                                  }

                              })
                       }
                   },
           complete: function () {
               if (sender != undefined) {
                   $(sender).removeClass("m-progress");
               }
           }
       })
}
function removeFromCart(id, refresh) {
    if (refresh == undefined) {
        refresh = 0;
    }
    $.ajax({
        url: '/Customer/removefromCart',
        data: { id },
                type: 'Get',
                success: function (data) {
                    if (refresh == 1) {
                        location.reload();
                    }
                    else {
                        if (refresh == 1) {
                            location.reload();
                        }
                        else {
                            $.ajax({
                                url: '/Customer/CartSmall',
                                data: {},
                                type: 'Get',
                                success: function (cartdata) {
                                    $("#cart").html(cartdata);
                                    $("#smallCartButton").trigger('click');
                                }

                            });

                        }
                    }
                }
    });
}

function AddToCompressionList(id) {
    $.ajax({
        url: '/Customer/addtoCompressionList',
        data: { id: id },
        type: 'Get',
        success: (function (data) {
            if (data.count > 0) {
                $(".CompareCountli").removeClass("hidden")
            }
            else {
                $(".CompareCountli").addClass("hidden")
            }
            $('.CompressionListcount').html(data.count);
            if (data.status == "Add") {
                $(".button-addToCompressionList-" + id).addClass("back-red")
            }
            else if (data.status == "Remove") {
                $(".button-addToCompressionList-" + id).removeClass("back-red")
            }
        })
    });
}




function LoadSendMethods(cityid, checkbox) {
    var canload = false;
    if (checkbox == undefined) {
        canload = true;
    }
    else if (checkbox.checked) {
        canload = true;
    }
    if (canload) {
        $("#SendMethods").html('<button class="btn btn-default m-progress"></button>');

        $.ajax({
            url: '/Customer/LoadSendMethods',
            data: { cityid: cityid },
            type: 'Get',
            success: (function (data) {
                $("#SendMethods").html(data);

                var sendmethodprice = parseInt(document.getElementById("SendMethodPriceselected").value);
                $("#CheckoutPriceSend").html(sendmethodprice.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","));
                var total = parseInt(document.getElementById("CheckoutCartTotal").value);
                total = total + sendmethodprice;
                $("#CheckoutPricePay").html(total.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","));
            })
        });
    }
}

function LoadSendMethodPrice(id, checkbox) {

    var canload = false;
    if (checkbox == undefined) {
        canload = true;
    }
    else if (checkbox.checked) {
        canload = true;
    }
    if (canload) {
        $('.sendmethodbox').removeClass("active");
        $('#sendmethodbox-' + id).addClass("active");

        var sendmethodprice = parseInt(document.getElementById("SendMethodPrice" + id).value);
        document.getElementById("SendMethodPriceselected").value = sendmethodprice;
        $("#CheckoutPriceSend").html(sendmethodprice.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","));
        var total = parseInt(document.getElementById("CheckoutCartTotal").value);
        total = total + sendmethodprice;
        $("#CheckoutPricePay").html(total.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","));

    }
}
function LoadPaymentTypePrice(id, checkbox) {


    var canload = false;
    if (checkbox == undefined) {
        canload = true;
    }
    else if (checkbox.checked) {
        canload = true;
    }
    if (canload) {
        $('.paymenttypebox').removeClass("active");
        $('#paymenttypebox-' + id).addClass("active");
    }
}
function Discount() {
    var discountcode = document.getElementById("input-discountCode").value;
    if (discountcode == undefined || discountcode == null || discountcode == "") {
        CHmessagebox("لطفا کد تخفیف را وارد کنید");
    }
    else {
        $.ajax({
            url: '/Customer/CheckDiscountCode',
            data: { code: discountcode },
            type: 'Get',
            success: (function (data) {
                if (data == "Error") {
                    CHmessagebox("کد تخفیف یافت نشد");
                }
                else {

                    var sendmethodprice = parseInt(document.getElementById("SendMethodPriceselected").value);
                    $("#CheckoutPriceSend").html(sendmethodprice.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","));
                    var total = parseInt(document.getElementById("CheckoutCartTotal").value);
                    total = total + sendmethodprice;
                    var discount = parseInt(data);
                    total = total - discount;
                    document.getElementById("CheckoutCartTotal").value = total;
                    $("#CheckoutPriceDiscount").html(discount.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","));
                    $("#CheckoutPricePay").html(total.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","));
                    $("#button-coupon").remove();
                    $("#input-discountCode").attr("readonly", "");
                }
            })
        });
    }

}



function deleteAddress(id) {
    CHmessagebox("آیا از حذف آدرس مطمئن هستید ؟", 3, function () {
        $.ajax({
            url: '/Customer/DeleteAddress',
            data: { id },
                    type: 'Get',
                    success: function (data) {
                        if(data == "") {
                            window.location.reload();
                        }
                        else {
                            CHmessagebox(data);
                        }
                    }

        });
    });
}
function editAddress(id) {
    var ch_messa = '<div id="MyDialogModel" class="CH-message">' +
                  '<div id="MyDialogModelBody" class="CH-message-body ch-address">' +
                    '<button class="btn btn-default m-progress no-background" ></button>' +
                  '</div>' +
                   '<div class="CH-message-background" onclick="CHmessageClose();"></div>' +
                   '</div>';
    $('body').append(ch_messa);

    $.ajax(
        {
            url: '/Customer/EditAddress',
            data: { id },
                    type: 'Get',
                    success: function (data) {
                if (document.getElementById("MyDialogModelBody") != undefined) {
                    $("#MyDialogModelBody").html(data);
                }
                    }

        });
}

function loginbtn(id) {
    if (id == 5) {
        openMymenuleft();
    }
    CHmessagebox("ورود به حساب کاربری", 2);
}







$("#filter_name").keyup(function (e) {


    var search = document.getElementById("filter_name").value;
    if (e.keyCode == 13) {
        window.location.href = "/Catalog/Category/?search=" + search;
    }
    else {



        $('#searchlist').html("");
        if (search == "" || search.length < 1) {


            $("#searchlist").addClass("hidden");
        }
        else if (search.length < 3) {
            $("#searchlist").removeClass("hidden");
            $('#searchlist').html('<div class="searcherror">لطفاً حداقل 3 کاراکتر وارد کنید...</div>');

        }
        else {
            $("#searchlist").removeClass("hidden");
            $('#searchlist').html('<div class="text-center" style="padding:10px;"><button class="btn btn-default m-progress no-background" ></button></div>');

            $.ajax(
            {
                url: '/Catalog/FastSearch',
                data: { search },
                        dataType: 'html',
                        type: 'Get',
                        success: function (data) {
                            $('#searchlist').html(data);
                        }

            })
        }
    }
});

jQuery("document").ready(function ($) {

    var nav = $('#topmenuholder');

    $(window).scroll(function () {
        if ($(this).scrollTop() > 159) {
            nav.addClass("myfixedmenu");
            $("#container").addClass("fixmenucontainer");

        } else {
            nav.removeClass("myfixedmenu");
            $("#container").removeClass("fixmenucontainer");

        }
    });

});

function ProductQuickview(id) {
    var ch_messa = '<div id="MyDialogModel" class="CH-message ">' +
                 '<div id="MyDialogModelBody" class="CH-message-body ch-address" style="min-width:90vh;">' +
                  '<button class="CH-message-exitbtn" onclick="CHmessageClose();"><i class="fa fa-close"></i></button>' +
                  '<div id="MyDialogModelBodyinner">' +
                        '<button class="btn btn-default m-progress no-background" ></button>' +
                   '</div>' +
                 '</div>' +
                  '<div class="CH-message-background" onclick="CHmessageClose();"></div>' +
                  '</div>';
    $('body').append(ch_messa);

    $.ajax(
        {
            url: '/catalog/QuickviewProduct',
            data: { id },
                    type: 'Get',
                    success: function (data) {
                if (document.getElementById("MyDialogModelBodyinner") != undefined) {
                    $("#MyDialogModelBodyinner").html(data);
                }
                    }

        });
}


function showMyadditional(id) {
    var sor = document.getElementById("productadditionalimage-" + id).src;
    document.getElementById("productmainimage").src = sor;
}

function extrasaleLoad(id) {
    var sidebaritem = $("#extrasale-sidebar-item-" + id);
    if (sidebaritem.hasClass("active") == false) {
        $(".extrasale-sidebar-item").removeClass("active");
        var oldselected = $(".extrasale-proitem.active");
        if (oldselected != undefined) {
            oldselected.removeClass("active");
            oldselected.fadeOut("fast", "linear", function () {
                extrasaleselect(id);
            });
        }
        else {
            extrasaleselect(id);
        }
    }
}
function extrasaleselect(id) {
    var sidebaritem = $("#extrasale-sidebar-item-" + id);
    var lastitem = $(".extrasale-sidebar-item:last-child");
    var total = parseInt(lastitem.index());
    var topindx = parseInt(sidebaritem.index());
    if (topindx == 0 || topindx == 1) {
        topindx = 2;
    }
    else if (topindx == total || topindx == total - 1) {
        topindx = total - 2;
    }

    topindx = topindx - 2;
    if (topindx < 0)
    {
        topindx = 0;
    }
    var height = 165; 
    height = height * topindx;
    var heightstr= "-" +height + "px";
    $(".extrasale-sidebar-inner").animate({"top":heightstr},300);
    sidebaritem.addClass("active");
    var newselect = $("#extrasale-proitem-" + id);
    newselect.addClass("active");
    newselect.fadeIn("fast", "linear");
}
function extraslidernext() {
    var oldselected = $(".extrasale-sidebar-item.active");
    var newselected;

    newselected = oldselected.next();
    if (newselected.attr("id") == undefined) {
        newselected = $(".extrasale-sidebar-item:first-child");
        var idstr = newselected.attr("id").replace("extrasale-sidebar-item-", "");
        extrasaleLoad(idstr);
    }
    else {
        var idstr = newselected.attr("id").replace("extrasale-sidebar-item-", "");
        extrasaleLoad(idstr);

    }
}
function extrasliderprev() {
    var oldselected = $(".extrasale-sidebar-item.active");
    var newselected;

    newselected = oldselected.prev();
    if (newselected.attr("id") == undefined) {
        newselected = $(".extrasale-sidebar-item:last-child");
        var idstr = newselected.attr("id").replace("extrasale-sidebar-item-", "");
        extrasaleLoad(idstr);
    }
    else {
        var idstr = newselected.attr("id").replace("extrasale-sidebar-item-", "");
        extrasaleLoad(idstr);

    }
}
