﻿
function cCheckLogin() {
    if ($.cookie("member").length < 5) {
        window.location.href = "/Account/SignIn.aspx"
    }
}

$(document).ready(function() {
    $("#ddlItemMessage").bind("mouseleave", function() { CloseItem(); });
    $("#MessagesBg").bind("mouseleave", function() {
    });

    $("#AccountSet").bind("mouseleave", function() { ClosePostion(); });
    $("#AccountBg").bind("mouseleave", function() {
    });

    $("#FavSet").bind("mouseleave", function() { CloseFav(); });
    $("#FavBg").bind("mouseleave", function() {
    });

    $("#NewSet").bind("mouseleave", function() { CloseNew(); });
    $("#NewSet").bind("mouseleave", function() {
    });

    $("#SourcSet").bind("mouseleave", function() { CloseSourc(); });
    $("#SourcSet").bind("mouseleave", function() {
    });

    $("#SellSet").bind("mouseleave", function() { CloseSell(); });
    $("#SellSet").bind("mouseleave", function() {
    });


    //GET USERNAME
    $("#spWelcome").text($("#spWelcome").text() + cGetcookie($.cookie("member"), "UserName"));

    if (cGetcookie($.cookie("member"), "UserName") == "") {
        $("#ShowLog").html("<a href='/Account/Signin.aspx' style=' color:#017abf; text-decoration:none;'>Sign in</a> | <a href='/Account/Join.aspx' style=' color:#017abf; text-decoration:none;'>Join Free</a>");
    }
    //if has email
    var hasEmail = cGetcookie($.cookie("member"), "HasEmail");
    if (hasEmail > 0) {
        $("#unReadPic").css("visibility", "visible");
    }

    //if is supplier
    var MemberLevel = cGetcookie($.cookie("member"), "MemberLevel");
    if (MemberLevel == "10" || MemberLevel == "20" || MemberLevel == "30") {
        $("#RecommendationsBg").hide();
        $("#AskTheExpertsBg").hide();
        $("#MessagesBg").css("margin-left","0px");
        $("#unReadPic").css("margin-left", "455px");
        $("#AccountBg a").attr("href", "/SupplierOffice/CompanyProfile/CompanyProfileEdit.aspx");
        ChangeLink();
    }
    else {
        $("#RecommendationsBg").show();
        $("#AskTheExpertsBg").show();
        $("#unReadPic").css("margin-left", "475px");
    }
    //GET TIME
    $.post("/BuyerOffice/Ajax/Products.ashx", { action: "GetTime" }, function(result) { var arrStr = result.split("|"); $("#ChinaTime").text(arrStr[0]); $("#ScandinaviaTime").text(arrStr[1]); showtime("0"); ScandinaviaTime("0"); });
    //GET DATE
    GetMonth();

});

function LinkHome() {
    if ($.cookie("member") == null || $.cookie("member").length < 5) {
        window.location.href = "/";
    }
    else {
        window.location.href = "/BuyerOffice/Default.aspx";
    }
}


$(function() {
    $().mousemove(function(e) {
        if (e.pageX < $("#MessagesBg").offset().left && e.pageY < $("#MessagesBg").offset().top + 25) {
            CloseItem();
        }
        if (e.pageY < $("#MessagesBg").offset().top) {
            CloseItem();
        }
        if (e.pageX > $("#MessagesBg").offset().left + 80 && e.pageY < $("#MessagesBg").offset().top + 25) {
            CloseItem();
        }

        if (e.pageX < $("#AccountSet").offset().left && e.pageY < $("#AccountSet").offset().top + 25) {
            ClosePostion();
        }
        if (e.pageY < $("#AccountSet").offset().top - 20) {
            ClosePostion();
        }
        if (e.pageX > $("#AccountSet").offset().left + 150 && e.pageY < $("#AccountSet").offset().top + 25) {
            ClosePostion();
        }

        if (e.pageX < $("#FavSet").offset().left && e.pageY < $("#FavSet").offset().top + 25) {
            CloseFav();
        }
        if (e.pageY < $("#FavSet").offset().top - 20) {
            CloseFav();
        }
        if (e.pageX > $("#FavSet").offset().left + 100 && e.pageY < $("#FavSet").offset().top + 25) {
            CloseFav();
        }

        if (e.pageX < $("#NewSet").offset().left && e.pageY < $("#NewSet").offset().top + 25) {
            CloseNew();
        }
        if (e.pageY < $("#NewSet").offset().top - 20) {
            CloseNew();
        }
        if (e.pageX > $("#NewSet").offset().left + 70 && e.pageY < $("#NewSet").offset().top + 25) {
            CloseNew();
        }

        if (e.pageX < $("#SourcSet").offset().left && e.pageY < $("#SourcSet").offset().top + 25) {
            CloseSourc();
        }
        if (e.pageY < $("#SourcSet").offset().top - 20) {
            CloseSourc();
        }
        if (e.pageX > $("#SourcSet").offset().left + 100 && e.pageY < $("#SourcSet").offset().top + 25) {
            CloseSourc();
        }
      

        if (e.pageX < $("#SellSet").offset().left && e.pageY < $("#SellSet").offset().top + 25) {
            CloseSell();
        }
        if (e.pageY < $("#SellSet").offset().top - 20) {
            CloseSell();
        }
        if (e.pageX > $("#SellSet").offset().left + 100 && e.pageY < $("#SellSet").offset().top + 25) {
            CloseSell();
        }

    })
})
//获取COOKIE
function cGetcookie(cookies, name) {
    if (cookies == null) {
        return "";
    }

    var arrStr = cookies.split("&");
    for (var i = 0; i < arrStr.length; i++) {
        var temp = arrStr[i].split("=");
        if (temp[0] == name) {
            Str = decodeURIComponent(temp[1]).toString();
            return Str.replace("\\+", "%20");
        }
    }
}
//页面跳转
function getUrlSellingOffers() {
    var url = location.href;

    if (url.indexOf('/products-') > 0) {
        url = url.replace("/products-", "/suppliers-")
        location.href = url.substring(0, url.lastIndexOf('-') + 1) + "1.html";
    }
    else {
        url = url.replace("/products/", "/suppliers/")
        location.href = url.substring(0, url.lastIndexOf('-') + 1) + "1.html";
    }
}
function DrawImage(ImgD) {
    width = 100;
    height = 100;
    var image = new Image();
    image.src = ImgD.src;
    if (image.width > 0 && image.height > 0) {
        flag = true;
        if (image.width / image.height >= width / height) {
            if (image.width > width) {
                ImgD.width = width;
                ImgD.height = (image.height * width) / image.width;
            } else {
                ImgD.width = image.width;
                ImgD.height = image.height;
            }
        }
        else {
            if (image.height > height) {
                ImgD.height = height;
                ImgD.width = (image.width * height) / image.height;
            } else {
                ImgD.width = image.width;
                ImgD.height = image.height;
            }
        }
    }
}

function showtime(DoTime) {
    var today = $("#ChinaTime").html();
    var Time = today.split(':');
    var hour = Time[0];
    var minute = Time[1];
    var ibegin = 0;
    if (DoTime == 1) {
        minute = Number(minute) + Number(1);
    }
    if (minute == 60) {
        hour = Number(hour) + Number(1);
        minute = 0;
    }
    if (hour == 24) {
        hour = 0;
        minute = 0;
    }
    if (hour < 10) hour = "0" + Number(hour);
    if (minute < 10) minute = "0" + Number(minute);
    $("#ChinaTime").html(hour + ":" + minute);
    setTimeout("showtime(1);", 60000);
}

function ScandinaviaTime(DoTime) {
    var today = $("#ScandinaviaTime").html();
    var Time = today.split(':');
    var hour = Time[0];
    var minute = Time[1];
    var ibegin = 0;
    if (DoTime == 1) {
        minute = Number(minute) + Number(1);
    }
    if (minute == 60) {
        hour = Number(hour) + Number(1);
        minute = 0;
    }
    if (hour == 24) {
        hour = 0;
        minute = 0;
    }
    if (hour < 10) hour = "0" + Number(hour);
    if (minute < 10) minute = "0" + Number(minute);
    $("#ScandinaviaTime").html(hour + ":" + minute);
    setTimeout("ScandinaviaTime(1);", 60000);
}

function GetMonth() {
    var strDate = "";
    var today = new Date();
    var Month = today.getMonth();
        if (Month == 0) { strDate = "January "; }
        if (Month == 1) { strDate = "February "; }
        if (Month == 2) { strDate = "March "; }
        if (Month == 3) { strDate = "April "; }
        if (Month == 4) { strDate = "May "; }
        if (Month == 5) { strDate = "June "; }
        if (Month == 6) { strDate = "July "; }
        if (Month == 7) { strDate = "August "; }
        if (Month == 8) { strDate = "September "; }
        if (Month == 9) { strDate = "October "; }
        if (Month == 10) { strDate = "November "; }
        if (Month == 11) { strDate = "December "; }
    strDate += today.getDate() + ", " + today.getFullYear() + "&nbsp;&nbsp;";
    if (today.getDay() == 5) { strDate += " Friday"; }
    if (today.getDay() == 6) { strDate += " Saturday"; }
    if (today.getDay() == 0) { strDate += " Sunday"; }
    if (today.getDay() == 1) { strDate += " Monday"; }
    if (today.getDay() == 2) { strDate += " Tuesday"; }
    if (today.getDay() == 3) { strDate += " Wednesday"; }
    if (today.getDay() == 4) { strDate += " Thursday"; }
    $("#MonthDate").html(strDate);
}
function MySearch() {
    var keyword = $("#KeyWord").val();
    if (keyword != "Search here..." && $("#KeyWord").val().length != 0) {
        var type = $("#Type").val();

        keyword = $.trim(keyword);
        if (keyword == "") { return; }
        var url = '/Search/';

        if (type == "1") { url = url + 'Sellofferslist.aspx'; }
        if (type == "2") { url = url + 'ProductsList.aspx'; }
        if (type == "3") { url = url + 'SupplierList.aspx'; }
        if (type == "4") { url = url + 'BuyOffersList.aspx'; }
        if (type == "5") { url = url + 'BuyersList.aspx'; }


        url = url + "?select=&keyword=" + keyword.replace("&", "%$");
        location.href=url;
    }
}


function openFav() {
    CloseItem(); ClosePostion(); CloseNew(); CloseSourc(); CloseFav();
    $("#FavSet").css("display", "block");
    FavPostion();
}
function FavPostion() {
    var offhw = $("#FavoriteBg").offset();
    $("#FavSet").css("z-index", "10");
    $("#FavSet").css("position", "absolute");
    $("#FavSet").css("left", offhw.left );
    $("#FavSet").css("top", offhw.top + 24);
    $("#iframFav").css("z-index", "5");
    $("#iframFav").css("position", "absolute");
    $("#iframFav").css("left", offhw.left);
    $("#iframFav").css("top", offhw.top + 18);
}

function CloseFav() {
    $("#FavSet").css("display", "none");
}

function openDdlItemMessage() {
    $("#ddlItemMessage").css("display", "block");
    $("#ifmddlItemMessage").css("display", "block");
    ddlItemMessagePostion();
}
function ddlItemMessagePostion() {
    var offhw = $("#MessagesBg").offset();
    $("#ddlItemMessage").css("z-index", "10");
    $("#ddlItemMessage").css("position", "absolute");
    $("#ddlItemMessage").css("left", offhw.left);
    $("#ddlItemMessage").css("top", offhw.top + 24);
    $("#ifmddlItemMessage").css("z-index", "5");
    $("#ifmddlItemMessage").css("position", "absolute");
    $("#ifmddlItemMessage").css("left", offhw.left);
    $("#ifmddlItemMessage").css("top", offhw.top + 40);
}

function CloseItem() {
    $("#ddlItemMessage").css("display", "none");
    $("#ifmddlItemMessage").css("display", "none");
}

function openProfile() {
    CloseItem(); ClosePostion(); CloseNew(); CloseSourc(); CloseFav();
    AccountPostion();
    $("#AccountSet").css("display", "block");
}
function AccountPostion() {
    var offhw = $("#AccountBg").offset();
    $("#AccountSet").css("z-index", "10");
    $("#AccountSet").css("position", "absolute");
    $("#AccountSet").css("left", offhw.left);
    $("#AccountSet").css("top", offhw.top + 24);
}

function ClosePostion() {
    $("#AccountSet").css("display", "none");
}

function openNew() {
    CloseItem(); ClosePostion(); CloseNew(); CloseSourc(); CloseFav();
    $("#NewSet").css("display", "block");
    NewPostion();
}
function NewPostion() {
    var offhw = $("#NewBg").offset();
    $("#NewSet").css("z-index", "10");
    $("#NewSet").css("position", "absolute");
    $("#NewSet").css("left", offhw.left);
    $("#NewSet").css("top", offhw.top + 24);
}

function CloseNew() {
    $("#NewSet").css("display", "none");
}

function openSourc() {
    CloseItem(); ClosePostion(); CloseNew(); CloseSourc(); CloseFav();
    $("#SourcSet").css("display", "block");
    SourcPostion();
}
function SourcPostion() {
    var offhw = $("#SoucingBg").offset();
    $("#SourcSet").css("z-index", "10");
    $("#SourcSet").css("position", "absolute");
    $("#SourcSet").css("left", offhw.left);
    $("#SourcSet").css("top", offhw.top + 24);
}

function CloseSourc() {
    $("#SourcSet").css("display", "none");
}


function openSell() {
    CloseItem(); ClosePostion(); CloseFav(); CloseNew();
    $("#SellSet").css("display", "block");
    $("#IfrSell").css("display", "block");
    SellPostion();
}

function CloseSell() {
    $("#SellSet").css("display", "none");
    $("#IfrSell").css("display", "none");
}

function SellPostion() {
    var offhw = $("#WantTo").offset();
    $("#SellSet").css("z-index", "10");
    $("#SellSet").css("position", "absolute");
    $("#SellSet").css("left", offhw.left);
    $("#SellSet").css("top", offhw.top + 24);
    $("#IfrSell").css("z-index", "5");
    $("#IfrSell").css("position", "absolute");
    $("#IfrSell").css("left", offhw.left);
    $("#IfrSell").css("top", offhw.top + 40);
}



//==============================================================

function changeColor(obj, type) {
    if (type == "over") { obj.style.backgroundColor = "#578CCE"; }
    else { obj.style.backgroundColor = "#FFFFFF"; }
}

/*firefox*/
function __firefox() {
    HTMLElement.prototype.__defineGetter__("runtimeStyle", __element_style);
    window.constructor.prototype.__defineGetter__("event", __window_event);
    Event.prototype.__defineGetter__("srcElement", __event_srcElement);
}
function __element_style() {
    return this.style;
}
function __window_event() {
    return __window_event_constructor();
}
function __event_srcElement() {
    return this.target;
}
function __window_event_constructor() {
    if (document.all) {
        return window.event;
    }
    var _caller = __window_event_constructor.caller;
    while (_caller != null) {
        var _argument = _caller.arguments[0];
        if (_argument) {
            var _temp = _argument.constructor;
            if (_temp.toString().indexOf("Event") != -1) {
                return _argument;
            }
        }
        _caller = _caller.caller;
    }
    return null;
}
if (window.addEventListener) {
    __firefox();
}
/*end firefox*/

//在鼠标显示一个层，该层的内容为div2的内容
function showTip(flag) {
    $("#ifrShowHere").css("position", "absolute");
    $("#ifrShowHere").css("display", "block");
    $("#ifrShowHere").css("left", $(flag).offset().left + 40);
    $("#ifrShowHere").css("top", $(flag).offset().top - 250);
    $("#ShowHere").css("position", "absolute");
    $("#ShowHere").css("display", "block");
    $("#ShowHere").css("left", $(flag).offset().left + 30);
    $("#ShowHere").css("top", $(flag).offset().top - 250);
    $("#ShowHere").css("zIndex", "100");

}
//关闭层div3的显示 
function closeTip(flag) {
    $("#ifrShowHere").css("display", "none");
    $("#ShowHere").css("display", "none");
}

//控制层div2显示的开关 
function switchDIV() {
    if (div2.style.display == 'block') {
        div2.style.display = 'none';
    }
    else {
        div2.style.display = 'block';
    }
}

function GetBg() {
    var PageName = window.location.href;
    if (window.location.href.toLowerCase().indexOf("/products") > 0) { $("#SoucingBg").attr("class", "hongbeijing"); }
    else if (PageName.toLowerCase().indexOf("/china-suppliers") > 0) { $("#SoucingBg").attr("class", "hongbeijing"); }
    else if (PageName.toLowerCase().indexOf("/supplier-search") > 0) { $("#SoucingBg").attr("class", "hongbeijing"); }
    else if (PageName.toLowerCase().indexOf("/supplier-screening") > 0) { $("#SoucingBg").attr("class", "hongbeijing"); }
    else if (PageName.toLowerCase().indexOf("/supplier-matchmaking") > 0) { $("#SoucingBg").attr("class", "hongbeijing"); }
    else if (PageName.toLowerCase().indexOf("/supplier-sector-analysis") > 0) { $("#SoucingBg").attr("class", "hongbeijing"); }
    else if (PageName.toLowerCase().indexOf("/one-stop-sourcing") > 0) { $("#SoucingBg").attr("class", "hongbeijing"); }
}

function ChangeLink() {
    $("#linkComprofile").attr("href", "/SupplierOffice/CompanyProfile/CompanyProfileEdit.aspx");
    $("#linkAccSet").attr("href", "/SupplierOffice/AccountSetting/ContactInfo.aspx");
    $("#linkPassword").attr("href", "/SupplierOffice/AccountSetting/PasswordSet.aspx");
    $("#linkMyFav").attr("href", "/SupplierOffice/MyFavorite/Products.aspx");

}