﻿/// --------------------------------------------------------------------------------------
/// 说明:判断是否含有中文字符
/// 返回:返回bool值, 指示是否含有.
function HasChineseWords(inputString) {
    var i = 0;
    var result = false;

    // Chinese words begin at 13312
    // Chinese words begin at 64106

    var str_Chinese = inputString;

    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(inputString) {
    var result = true;
    var temp = inputString;
    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();
    }
}

//验证邮箱
function IsEmail(strEmail)
{
   var regm=/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
    if(!regm.test(strEmail))
    {
       return true;
    }
    else
    {
       return false;
    }
}

//去除字符串中的空格
function Trim(inputString)
{
 return inputString.replace(/(^\s*)|(\s*$)/g, "");
}

//验证输入是否是网站的格式
function IsWebSite(strWebSite)
{
  var regm=/^(http:\/\/)?([\w-]+\.)+[\w-]+(\/[\w-\.\/\?%&=]*)?$/;
  if((strWebSite).length<=0)
  {
    return false;
  }
  else if((strWebSite)=="http://")
  {
   return false;
  }
  else if(regm.test(strWebSite))
  {
    return false;
  }
  else
  {
    return true;
  }
}
