﻿/// --------------------------------------------------------------------------------------
/// 说明:判断是否含有中文字符
/// 返回:返回bool值, 指示是否含有.
/// 参数:参数str_clientID,客户端控件ID
function HasChineseWords(str_clientID) {
    var i = 0;
    var result = false;

    // Chinese words begin at 13312
    // Chinese words begin at 64106

    var str_Chinese = document.getElementById(str_clientID).value;

    for (i = 0; i < str_Chinese.length; i++) {

        if (str_Chinese.toString().charCodeAt(i) >= 13312 && str_Chinese.toString().charCodeAt(i) <= 64106) {
            result = true;
        }
    }

    return result;
}
/// --------------------------------------------------------------------------------------

//判断客户端控件ID中输入的是否为数字,可以带小数点的
function IsNumber(str_clientID) {
    var result = false;
    var temp = document.getElementById(str_clientID).value;
    if (!isNaN(temp)) {
        return true;
    }
    return result;
}

//纯数字，不带小数点的
function IsNumber1(str_clientID) {
    var result = true;
    var temp = document.getElementById(str_clientID).value;
    var Letters = "1234567890";
    var i, c;
    for (i = 0; i < temp.length; i++) {
        c = temp.charAt(i);
        if (Letters.indexOf(c) < 0) {
            result = false;
            break;
        }
    }
    return result;
}

/**
*预读页面图片；
*
*/

function imagePreload() {
    var imgPreload = new Image();
    for (i = 0; i < arguments.length; i++) {
        imgPreload.src = arguments[i];
    }
}


//图片等比压缩
function proDownImage(ImgD, proMaxWidth, proMaxHeight) {
    var image = new Image();
    image.src = ImgD.src;
    if (image.width > 0 && image.height > 0) {
        var rate = (proMaxWidth / image.width < proMaxHeight / image.height) ? proMaxWidth / image.width : proMaxHeight / image.height;
        if (rate <= 1) {
            ImgD.width = image.width * rate;
            ImgD.height = image.height * rate;
        }
        else {
            ImgD.width = image.width;
            ImgD.height = image.height;
        }
    }
}


//四舍五入函数
//num就是要转换的数据
//n为要转换到的位数
function cheng(num, n) {
    var dd = 1;
    var tempnum;
    for (i = 0; i < n; i++) {
        dd *= 10;
    }
    tempnum = num * dd;
    tempnum = Math.round(tempnum);
    //alert(tempnum / dd);
    return tempnum / dd;
}

//图片等比压缩
function DrawImage(ImgD, width, height) {
    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;

            }
        }
    }
}

//JQUERY图片等比压缩由方法DrawImage改写
function JQDrawImage(ImgD, width, height) {
    var image = new Image();
    image.src = ImgD.attr("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 CloseWin() {
    var ua = navigator.userAgent
    var ie = navigator.appName == "Microsoft Internet Explorer" ? true : false
    if (ie) {
        var IEversion = parseFloat(ua.substring(ua.indexOf("MSIE ") + 5, ua.indexOf(";", ua.indexOf("MSIE "))))
        if (IEversion < 5.5) {
            var str = '<object id=noTipClose classid="clsid:ADB880A6-D8FF-11CF-9377-00AA003B7A11">'
            str += '<param name="Command" value="Close"></object>';
            document.body.insertAdjacentHTML("beforeEnd", str);
            document.all.noTipClose.Click();
        }
        else {
            window.opener = null;
            window.close();
        }
    }
    else {
        window.close();
    }
}

/*firefox window.event*/
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.event*/

/**/
function jsOpen(type) {
    if (type == 1) {
        var Usertype = "";

        $("input[name$='HiddenUserType']").each(function (i) {
            Usertype = this.value;
        });

        //Usertype=$("#CommonPageHeadCtrl1_HiddenUserType").val()+"";
        //Usertype=$("#CommonPageHeadCtrlNew1_HiddenUserType").val()+"";

        if (Usertype == "0") {
            window.location.href = "http://www.easy2bid.com/post-new-project";
        }
        if (Usertype.indexOf("Buy") >= 0) {
            window.location.href = "http://www.easy2bid.com/post-sourcing-project";
        }
        if (Usertype.indexOf("Sell") >= 0) {
            var ScrollTop = document.documentElement.scrollTop;
            var gao = document.documentElement.clientHeight;
            var kuan = document.documentElement.clientWidth;
            var msgcontent = "";
            msgcontent += "<div id=\"MSG_PANEL\" style=\"top:0px;left:0px;height:" + document.body.clientHeight + "px;width:" + document.body.clientWidth + "px;position:absolute;display:block;filter:alpha(opacity=10);background-color: #000000;opacity:0.1; z-index:199;\"></div>";
            msgcontent += "<div id='MSG_BOX' style='height:95px;left:" + (kuan - 444) / 2 + "px;top:" + (ScrollTop + (gao - 96) / 2) + "px; width:444px;position:absolute;display:block;background-color:White; z-index:200;border:1px solid #888888;'>";
            msgcontent += "<div style='padding-top:10px; padding-bottom:10px; line-height:20px;'>";
            msgcontent += "<p style='font-size:13px;color:#494949; height:20px;font-family:Tahoma;padding:10px;'>Only buyers can post buying request!</p></div>";
            msgcontent += "<div style='padding-top:8px; padding-left:10px;height:26px;border-top:1px solid #888888;'>";
            msgcontent += "<a href=\"javascript:void(0);\" onclick=\"javascript:$('#MSG_PANEL').remove();$('#MSG_BOX').remove();return false;\"><img style='margin-right:10px;border:0px solid #ffffff;' src='/images/postnew/postnew11.gif'/></a>";
            msgcontent += "</div></div>";
            $("#form1").append(msgcontent);
        }

    }
    else if (type == 2) {
        location.href = "/FAQ/faq-en-1.aspx";
    }
    else if (type == 3) {
        location.href = "/help/buyers-quick-tour.aspx";
    }
    else if (type == 4) {
        location.href = "/buying-requests-directory";
    }
    else if (type == 5) {
        location.href = "/wholesale-offers-directory";
    }
    else if (type == 6) {
        location.href = "/help/private-policy.aspx";
    }
    else if (type == 7) {
        location.href = "/help/terms-conditions.aspx";
    }
    else if (type == 8) {
        location.href = "/quotes.aspx";
    }
    else if (type == 9) {
        location.href = "/press-release.aspx";
    }

    else if (type == 10) {
        location.href = "/buying-requests-directory";
    }
    else if (type == 11) {
        location.href = "/join";
    }
    else if (type == 12) {
        location.href = "/sign-in";
    }
    else if (type == 13) {
        location.href = "/selling-offers-directory";
    }
    else if (type == 14) {
        location.href = "/Account/SignOut.aspx";
    }
    else if (type == 15) {
        location.href = "/BuyersOffice/BuyerProjects.aspx";
    }
    else if (type == 16) {
        location.href = "/SuppliersOffice/SupplierProjects.aspx";
    }
    else if (type == 17) {
        location.href = "/forgot-password";
    }

}

function OpenSendInquiry(type, id) {
    location.href = "/Account/SendInquiryNew.aspx?type=" + type + "&id=" + id + "";
}

function PlaceBidNow(strUrl) {
    location.href = "/buy/" + strUrl + ".html";
}

function HeadContactUs(ProId) {
    location.href = "/Account/SendInquiryNew.aspx?type=prod&id=" + ProId;

}

function Translapage(country, strurl) {
    var url = "http://translate.google.com.hk/translate?hl=zh-CN&sl=en&tl=" + country + "&u=" + strurl;
    if (top != self) {
        parent.location.href = url;
    }
    else {
        window.location.href = url;
    }
}

function GetThisUrl(strurl) {
    deleteCookie("lang", "/", document.domain);
    window.location.href = window.location.href;
    //    if (top != self) {
    //        parent.location.href = strurl;
    //    }
    //    else {
    //        window.location.href = strurl
    //    }
}










function clickCss(id) {
    document.getElementById(id).className = "on";
}

//--------------------
function InviteLog(strurl) {
    location.href = "http://www.easy2bid.com/Account/SignIn.aspx?BackUrl=" + strurl;
}

//----------显示邀请供应商框-----------
function ShowInVite(CID) {
    tb_show('', 'http://www.easy2bid.com/NewGPSP/Invite.aspx?CompanyID=' + CID + '&from=Message&TB_iframe=true&height=460&width=500&modal=true', '');
    $("#TB_window").width(500);
    $("#TB_window").css("background", "transparent");
    $("#TB_window").css("overflow", "hidden");
    $("#TB_iframeContent").width(500);
    $("#TB_iframeContent").height(460);
    $("#TB_iframeContent").css("overflow", "hidden");
    $("#TB_iframeContent").css("background", "transparent");
    $("#TB_iframeContent").attr("allowTransparency", "true");
    $("#TB_window").css("top", 450);
}









//-------------图片放大效果--------------------
var tid;
$(document).ready(function () {
    $("#productUl").find(".divBoxP").each(function (i, liItem) {
        var liId = "#li" + $(liItem).attr("id");
        $(liItem).hover(
                 function () {
                     tid = setTimeout(function () {
                         var p = $(liItem).position();
                         $(liId).css({ background: "#fff" });
                         $(liId).css("left", p.left);
                         $(liId).css("top", p.top); $(liId).show();
                     }, 400);
                 },
                 function () {
                     clearTimeout(tid);
                 }
                );
    });
})

$(document).ready(function () {
    $("#productUl").find("span").each(function (i, liItem) {
        var liId = "#" + $(liItem).attr("id");
        $(liItem).hover(
                 function () {
                 },
                 function () {
                     $(liId).hide();
                 }
                );
    });
})

//---------鼠标移动到显示提示div--------------
$(function () {
    var d1 = $("#dinvite").html();
    var d2 = "<div style ='color:#FFF;margin:0px;padding:6px;margin-bottom:10px;border:1px solid #FFDEAD;word-wrap: break-word; width:187px; height :auto;background-color:#639824;z-Index:300;position:absolute;'>This is verified supplier, if you have already posted a buying request, please invite this supplier to send quotation</div>";

    $("#dinvite").hover(function () {
        $(d2).appendTo($("#dinvite"));
    },
          function () {
              $("#dinvite").html(d1);
          })
});










function SendEmail(strCompanyID) {
    location.href = "http://www.easy2bid.com/Account/SendInquiryNew.aspx?type=gold&id=" + strCompanyID;
}

function SendInquiryNew(id) {
    location.href = "http://www.easy2bid.com/Account/SendInquiryNew.aspx?type=prod&id=" + id;
}

//Google翻译方法Begin
google.load("language", "1");

function trans(obj, lang) {//调用google 翻译
    google.language.translate(obj.html(), "", lang, function (result) {
        if (!result.error) {
            var container = document.getElementById("translation");
            obj.html(result.translation);
        }
    });
}

function transMe(lang) {
    //遍历dom，翻译整个页面
    $(".multilang").each(function (i) {
        trans($(this), lang);
    });
}

function initLang(lang) {
    //定义初始化翻译，在页面调用的时候翻译
    if (lang.length > 1) {
        setCookie("lang", lang, 1, "/", document.domain);
        var _lang = getCookie("lang");
        transMe(_lang);
    }
    else {
        var _lang = getCookie("lang");
        if (_lang != null) {
            transMe(_lang);
        }
    }
}
//Google翻译方法End

// 说明：用 Javascript 操作 Cookie
function getCookie(name) {
    var start = document.cookie.indexOf(name + "=");
    var len = start + name.length + 1;
    if ((!start) && (name != document.cookie.substring(0, name.length))) {
        return null;
    }
    if (start == -1) return null;
    var end = document.cookie.indexOf(';', len);
    if (end == -1) end = document.cookie.length;
    return unescape(document.cookie.substring(len, end));
}

function setCookie(name, value, expires, path, domain, secure) {
    var today = new Date();
    today.setTime(today.getTime());
    if (expires) {
        expires = expires * 1000 * 60 * 60 * 24;
    }
    var expires_date = new Date(today.getTime() + (expires));
    document.cookie = name + '=' + escape(value) +
((expires) ? ';expires=' + expires_date.toGMTString() : '') + //expires.toGMTString()
((path) ? ';path=' + path : '') +
((domain) ? ';domain=' + domain : '') +
((secure) ? ';secure' : '');
}

function deleteCookie(name, path, domain) {
    if (getCookie(name)) document.cookie = name + '=' +
((path) ? ';path=' + path : '') +
((domain) ? ';domain=' + domain : '') +
';expires=Thu, 01-Jan-1970 00:00:01 GMT';
} 
