﻿/// <reference path="../../XIXI.JSDK/XIXIJDK_intellisense.js" />

XIXI.Include("/XIXI.JSDK/XIXI.Helper.js");
XIXI.Include("/XIXI.JSDK/XIXI.Helper.Cookies.js");
XIXI.$(document).ready(function() {
    //    WY.ProductSale.Service.DefaultMaster.GetCompareCount
    //    (
    //        XIXI.$("#Count").attr("name"),
    //        function(data) {
    //            XIXI.$("#Count").html(data);
    //        }
    //    );
    initEvent();
    //keyWordsFun();
    ClearTryOnCookie();
    FavoritesInit();
    XIXI.$('#btnSearchKeyword').click(function() {

        var keyword = XIXI.$("#keywords").val();
        window.location.href = "/All-Products-glasses-keywords-"+keyword+"-1-low/";

    });
});
XIXI.$.fn.extend({ loading: function() {
    /// <summary>设置JQ对象为loading小圈圈图标</summary>
    XIXI.$(this).html("<img src='/App_Themes/Default/images/_loading.gif'>"); 
}
});


function ClearTryOnCookie() {//清除试戴系统页面保存的Cookie值
    var currentUrl = window.location.href;
    if (currentUrl.toString().indexOf("tryon") == -1) {
        XIXI.Helper.Cookies.SetCookie("GlassesPicPicUrl", "");
        XIXI.Helper.Cookies.SetCookie("ModelPicUrl", "");
        XIXI.Helper.Cookies.SetCookie("typeFlag", "");
        XIXI.Helper.Cookies.SetCookie("cProductID", "");
    }
}

function FavoritesInit() {
    var o = "#Dimension_" + XIXI.Helper.Cookies.GetCookie("CurrentDimension");
    if (11 == o.length) {
        o = "#Dimension_mm"
    }
    try {
        XIXI.$(o).attr("class", "focus");
    } catch (ex) { }
}

function initEvent() {
    XIXI.$('#Logout').click(function() {
        WY.ProductSale.Service.DefaultMaster.LogOut(function(result) {
            if (result == false) {
                return false;
            }
            else {
                location.href = "/";
                return false;
            }
        });
        return false;

    });
    XIXI.$('#currency').change(function() {
        WY.ProductSale.Service.CurrencyTService.ChangeCurrency(XIXI.$('#currency option:selected').val(), function() {
            if (location.href.indexOf('#') > 0)
                location.href = location.href.substring(0, location.href.indexOf('#'));
            location.href = location.href;
        });
    });
}
function keyWordsFun() {
    var keywords = XIXI.$('#navi .search .keywords');
    XIXI.$('#navi .item').hover(
                    function() {
                        XIXI.$(this).find('.subject').addClass('focus');
                        XIXI.$(this).find('.categories').show();
                        XIXI.$(this).find('.ifr').show();
                    }
                    , function() {
                        XIXI.$(this).find('.subject').removeClass('focus');
                        XIXI.$(this).find('.categories').hide();
                        XIXI.$(this).find('.ifr').hide();
                    }
                );
    keywords.focus(function() {
        if (keywords_text == XIXI.$(this).val()) {
            XIXI.$(this).val('');
        }
    });
    keywords.blur(function() {
        if ('' == XIXI.$(this).val()) {
            XIXI.$(this).val(keywords_text);
        }
    });

    XIXI.$('#navi .item .more .searchbtn button').click(function() {
        var s = '';
        XIXI.$('#navi .item .more table input[name*=catalog]').each(function() {
            if (true == XIXI.$(this).attr("checked")) s += (('' == s) ? '' : '|') + XIXI.$(this).val();
        });
        if (true == XIXI.$('#bifo').attr("checked")) s += '&products_bifocal=1';
        window.location.href = '/Product/ProductList.aspx?allstyle=' + s;
        return false;
    });
}


function SubmitKeyClick(evt, obj) {
    evt = (evt) ? evt : ((window.event) ? window.event : "")
    keyCode = evt.keyCode ? evt.keyCode : (evt.which ? evt.which : evt.charCode);
    if (keyCode == 13) {
        XIXI.$("#" + obj).click();
    }
}


function backToReffer() {
    XIXI.$("a[rel=back]").click(

    );
}
