﻿/// --------------------------------------------------------------------------------------
/// 说明:判断是否含有中文字符
/// 返回:返回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;

            }
        }
    }
}

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)
  {
   location.href="/post-new-project";
  }
  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)
{
    if (top != self) {
        parent.location.href = strurl;
    }
    else {
        window.location.href = strurl
    }
}

