﻿/// <reference path="../../XIXI.JSDK/XIXIJDK_intellisense.js" />

XIXI.Include(XIXI.ROOTURL + "XIXI.JSDK/XIXI.Helper.js");
XIXI.Include(XIXI.ROOTURL + "XIXI.JSDK/XIXI.Helper.Cookies.js");
XIXI.$(document).ready(function() {
    //    WY.ProductSale.Service.DefaultMaster.GetCompareCount
    //    (
    //        $("#Count").attr("name"),
    //        function(data) {
    //            $("#Count").html(data);
    //        }
    //    );
    var cookiedomain = $("#cookiedomain").val();
    $("a").click(function() {
        //  var adposition = $(this).attr("adpos");
        if ($(this).attr("rel")) {

            var activetrack = XIXI.Helper.Cookies.GetCookie("activetrack");
            if (activetrack)
                activetrack = $.evalJSON(activetrack);
            else
                activetrack = [];
            for (var i = 0; i < activetrack.length; i++) {
                if (activetrack[i].ActiveName == $(this).attr("rel") && activetrack[i].Url == $(this).attr("href"))
                    return true;
            }
            var activeid = $(this).attr("href").match(/weekly-promotion-(\d+).html/);
            activeid = activeid[1] ? activeid[1] : -1;
            activetrack.push({ "ActiveName": $(this).attr("rel"), "Url": $(this).attr("href"), "ActiveID": activeid });
            XIXI.Helper.Cookies.SetCookie("activetrack", $.toJSON(activetrack), null, null, cookiedomain);
            return true;
        }
        return true;
    });
    initEvent();
    //keyWordsFun();
    ClearTryOnCookie();
    FavoritesInit();
    Emial();
});

function Emial() {
    $('#newEmail').click(function() {
        if ($('#newEmail').val() == EnterYourEmailHere) $('#newEmail').val('');
    });
    $('#subscription').click(function() {
        var newEmail = $('#newEmail').val();
        if (newEmail != '' || newEmail != EnterYourEmailHere) {
            $.post('/AjaxSubscribe.aspx?subscribeAction=newsemail',
{ newEmail: newEmail },
function(msg) {
    $('#newEmail').val(msg);
}
);
        }
        return false;
    });
}
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() {
    $('#Logout').click(function() {
        WY.ProductSale.Service.DefaultMaster.LogOut(function(result) {
            if (result == false) {
                return false;
            }
            else {
                location.href = "/";
                return false;
            }
        });
        return false;

    });
    $('#header .header_diversity_div').toggle(
				function() {
				    $(this).children("ul").slideDown("fast");
				},
					function() {
					    $(this).children("ul").slideUp("fast");
					}
				);
    $('#header .header_diversity_div ul a').click(
				function() {
				    if ($(this).attr("currencySymbol")) {
				        var cookiedomain = $("#cookiedomain").val();
				        XIXI.Helper.Cookies.SetCookie("CurrentCurrency", $(this).attr("currencySymbol"), null, null, cookiedomain);
				        if (location.href.indexOf('#') > 0)
				            location.href = location.href.substring(0, location.href.indexOf('#'));

				        //location.href = location.href;    // 施冬峰注释
				        location.reload();                  // 施冬峰添加 ，刷新页面后保留控件的值


				        return false;
				    }
				    location.href = $(this).attr("href");

				    return false;

				}
			);
}
function keyWordsFun() {
    var keywords = $('#navi .search .keywords');
    $('#navi .item').hover(
                    function() {
                        $(this).find('.subject').addClass('focus');
                        $(this).find('.categories').bgIframe().show();
                        $(this).find('.ifr').bgIframe().show();
                    }
                    , function() {
                        $(this).find('.subject').removeClass('focus');
                        $(this).find('.categories').hide();
                        $(this).find('.ifr').hide();
                    }
                );
    keywords.focus(function() {
        if (keywords_text == $(this).val()) {
            $(this).val('');
        }
    });
    keywords.blur(function() {
        if ('' == $(this).val()) {
            $(this).val(keywords_text);
        }
    });
    //    $('#btnSearchKeyword').click(function()
    //    {
    //        if (keywords_text == keywords.val())
    //            return false;
    //        else
    //        {
    //            window.location.href = '/Product/Search.aspx?keywords=' + keywords.val();
    //        }
    //    });

    $('#btnSearchKeyword').click(function() {


        //记录用户查询信息
        var serch = keywords.val();

        if (serch.length > 0) {
            //记录用户信息

            WY.ProductSale.Service.DefaultMaster.UserSearchInfo
    (
    serch,
    function(data) {

    }
    );
        }

        if (keywords_text == keywords.val())
            return false;
        else {
            window.location.href = '/Product/Search.aspx?keywords=' + keywords.val();
        }

    });

    $('#navi .item .more .searchbtn button').click(function() {
        var s = '';
        $('#navi .item .more table input[name*=catalog]').each(function() {
            if (true == $(this).attr("checked")) s += (('' == s) ? '' : '|') + $(this).val();
        });
        if (true == $('#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) {
        $("#" + obj).click();
    }
}

function ImageErr(object, url) {
    if ($(this).attr('erred') == 'true')
        return false;
    this.src = 'http://' + window.location.host + url;
    $(this).attr('erred', 'true');
}