﻿/*dressilyme类*/
var dressilyme = {};
dressilyme.txtSearchOnblur = function(txt, defaultVal) {
    var t = jQuery.trim(txt.value);
    if (t.length == 0)
        txt.value = defaultVal;
};
dressilyme.txtSearchOnfocus = function(txt, defaultVal) {
    if (txt.value == defaultVal)
        txt.value = "";
};

/*Header（头部）函数*/
var header = {};
header.defualtSearchWorld = "3,000+ STYLES FOR SEARCH";
//搜索
header.Search = function() {
    //当前URL地址
    var url = jQuery("#headRequestUrl").val();
    var txt = jQuery("#txtSearch");
    //记录搜索关键字
    var key = $.trim(txt.val());
    if (key != "" && key != "3,000+ STYLES FOR SEARCH") {
        $.ajax({
            type: "GET",
            url: "/Action/Statistics.ashx",
            data: { Key: key },
            dataType: "json",
            cache: false,
            timeout: 60000,
            success: function(json) { },
            error: function() { }
        });
    }
    if (txt.size() > 0) {
        var t = jQuery.trim(txt.val());
        if (t.length == 0 || t == header.defualtSearchWorld)
            window.location = url;
        else
            window.location = "http://www.dressilyme.com/SearchGrid.aspx?k=" + encodeURIComponent(t);
    }
};

//绑定元素事件
jQuery(document).ready(function() {
    jQuery("#txtSearch").keyup(function(e) {
        //按回车键搜索
        if (e.keyCode == 13) {
            header.Search();
            return false;
        }
    }).blur(function() {
        dressilyme.txtSearchOnblur(this, header.defualtSearchWorld);
    }).focusin(function() {
        dressilyme.txtSearchOnfocus(this, header.defualtSearchWorld);
    });
    $("#imageSeachBtn").click(function() {
        header.Search();
        return false;
    })
});

/*Footer（底部）函数*/
var fooetr = {};
//绑定行业下拉框显示事件
fooetr.showSubNavIndustry = function(obj) {
    var timeId;
    jQuery("." + obj + ">h3").mouseover(function() {
        jQuery("." + obj + ">.SubNavIndustry").addClass("block");
    }).mouseout(function() {
        timeId = setTimeout(function() {
            jQuery("." + obj + ">.SubNavIndustry").removeClass("block");
        }, 100);
    });
    jQuery("." + obj + ">.SubNavIndustry").mouseover(function() {
        clearTimeout(timeId);
        $(this).addClass("block");
    }).mouseout(function() {
        jQuery("." + obj + ">.SubNavIndustry").removeClass("block");
    });
};
fooetr.isEmail = function(str) {
    var strReg = /^\s*\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*\s*/;
    if (strReg.test(str))
        return true;
    return false;
}
fooetr.JoinMail = function(jTxtMail, jMsgBox) {
    var mail = jTxtMail.val();
    var messageBox = jMsgBox;
    mail = jQuery.trim(mail);
    if (mail == "" || mail == "SIGN UP TO DRESSILYME NEWS") {
        messageBox.html("<span class=\"price2\" style=\"float:left;\">* </span><span name=\"spanMsg\" style=\"float:left;\">Please input your E-mail.</span>");
        return;
    }
    if (!fooetr.isEmail(mail)) {
        messageBox.html("<span class=\"price2\" style=\"float:left;\">* </span><span name=\"spanMsg\" style=\"float:left;\">The format is error.</span>");
        return;
    }
    jQuery.ajax({
        type: "GET",
        url: "/Ajax/JoinMailList.ashx",
        data: { mail: mail },
        dataType: "json",
        cache: false,
        timeout: 15000,
        success: function(json) {
            if (json[0].ReferURL != null || json[0].ReferURL != "undefind") {
                if (json[0].ReferURL.length > 0)
                    window.location = json[0].ReferURL;
                return;
            }
            if (json[0].result.length > 0)
                messageBox.html("<span class=\"price2\">* </span><span name=\"spanMsg\">" + json[0].result + "</span>");
        }
    });
};
fooetr.defualtSearchWorld = "SIGN UP TO DRESSILYME NEWS";
//绑定元素事件
jQuery(document).ready(function() {
    //wedding行业（下拉框显示事件）
    fooetr.showSubNavIndustry("SubNavL");
    //Prom行业（下拉框显示事件）
    fooetr.showSubNavIndustry("SubNavR");
    //按回车键订阅
    jQuery("#joinMail").unbind("keypress").bind("keypress", function(e) {
        if (e.keyCode == 13) {
            fooetr.JoinMail(jQuery(this), jQuery("#spnMsg"));
            return false;
        }
    });
    jQuery("#imageField").bind("click", function() {
        fooetr.JoinMail(jQuery("#joinMail"), jQuery("#spnMsg"));
        return false;
    });
    $("#joinMail").blur(function() {
        dressilyme.txtSearchOnblur(this, fooetr.defualtSearchWorld);
    }).focusin(function() {
        dressilyme.txtSearchOnfocus(this, fooetr.defualtSearchWorld);
    });
    $("#PaymentImg").click(function() {
        window.open('https://www.paypal.com/uk/cgi-bin/webscr?cmd=xpt/Marketing/popup/OLCWhatIsPayPal-outside', 'olcwhatispaypal', 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, width=400, height=350');
    });
});
/*newHeaderMenus(菜单)*/
function MenuShow(eventObj, showObj) {
    var timeId;
    var thisObj;
    jQuery(eventObj + ">a").mouseover(function() {
        thisObj = jQuery(this).prev(showObj);
        thisObj.show();
        if ($("#textfield2").size() > 0) {
            $("#textfield2").blur();
        }
    }).mouseout(function() {
        timeId = setTimeout(function() {
            thisObj.hide();
        }, 100);
    });
    jQuery(eventObj + ">" + showObj).mouseover(function() {
        clearTimeout(timeId);
        jQuery(this).show();
    }).mouseout(function() {
        jQuery(this).hide();
    });
};

jQuery(document).ready(function() {

    if (jQuery("#Menu").size() > 0) {
        MenuShow("#Menu>ul>.Promotion", ".SpecialNav");
    }
    var thisObj;
    var boolThisObj;
    $("#SubMenu>ul>li").hover(function() {
        thisObj = $(".Nav", $(this));
        boolThisObj = thisObj != null && thisObj != undefined && thisObj != "";
        if (boolThisObj && thisObj.size() > 0) {
            thisObj.show();
            thisObj.siblings(".ifrmTag").css({
                "height": thisObj.height(),
                "width": thisObj.width(),
                "z-index": thisObj.css("z-index") - 1,
                "padding-bottom": thisObj.css("padding-bottom"),
                "padding-right": thisObj.css("padding-right"),
                "padding-left": thisObj.css("padding-left"),
                "padding-top": thisObj.css("padding-top"),
                "margin-left": thisObj.css("margin-left"),
                "margin-top": thisObj.css("margin-top")
            });
            thisObj.siblings(".ifrmTag").show();
        }
        $(this).children("a").addClass("AHover");
    }, function() {
        thisObj.hide();
        thisObj.siblings(".ifrmTag").hide();
        $(this).children("a").removeClass("AHover");
    });
    //    $("#Menu>ul>.Promotion").hover(function() {
    //        $(".SpecialNav", $(this)).show();
    //    }, function() {
    //        $(".SpecialNav", $(this)).hide();
    //    });
});



