function getobj(id) {
    return document.getElementById(id);
}
function getobjvalue(id) {
    return document.getElementById(id).value;
}
//item为判断的对象，text为报错内容
function validempty(item, text) {//判断字段是否为空
    if (item.value == "")
        error(item, text);
}

function error(item, text) {//弹公共调用函数－－－－出警告窗口，并重新设定光标
    if (errfound) return;
    window.alert(text);
    item.select();
    item.focus();
    errfound = true;
}

function validemail(item) {// 检测Email地址是否合法
    if (!validlength(item.value.length, 5)) return false;
    if (item.indexof('@', 0) == -1) return false;
    return true;
}

function e_mail(item) {//检查Email输入是否有误 
    var checkStr = item.value;
    for (i = 0; i < checkStr.length; i++) {
        ch = checkStr.charAt(i);
        if (ch == '@')
            break;
    } if ((i == checkStr.length && i != 0) || (i == 0 && checkStr.length != 0) || (i == checkStr.length - 1))
        return false;
    return true;

}

//校验是否等于指定长度
function char_length(item, item_len) {
    var str = item.value
    if (str.length != item_len)
        return false;
    return true;
}

//校验是否大于最大长度
function max_length(item, max_len) {
    var str = item.value
    if (str.length > max_len)
        return false;
    return true;
}

function card_id(item) {//判断身份证号码中是否输入15位或18位有效数字

    var d
    d = item.value.length
    if ((d < 15 && d > 0) || (d > 15 && d < 18) || d > 18)
        return false;

    var checkOK = "0123456789";
    var checkStr = item.value;

    var decPoints = 0;
    var allNum = "";
    for (i = 0; i < checkStr.length; i++) {
        ch = checkStr.charAt(i);
        for (j = 0; j < checkOK.length; j++)
            if (ch == checkOK.charAt(j))
                break;
        if (j == checkOK.length) {
            allValid = false;
            break;
        }
        allNum += ch;
    }
    return true;
}

function post(item) {//判断邮政编码中是否输入有效数字

    var d
    d = item.value.length
    if ((d < 6 && d > 0) || d > 6)
        return false;

    var checkOK = "0123456789";
    var checkStr = item.value;

    var decPoints = 0;
    var allNum = "";
    for (i = 0; i < checkStr.length; i++) {
        ch = checkStr.charAt(i);
        for (j = 0; j < checkOK.length; j++)
            if (ch == checkOK.charAt(j))
                break;
        if (j == checkOK.length) {
            return false;
            break;
        }
        allNum += ch;
    }
    return true;
}

function telephone(item) {//判断电话号码中是否输入有效数字

    var checkOK = "0123456789-,，";
    var checkStr = item.value;

    var decPoints = 0;
    var allNum = "";
    for (i = 0; i < checkStr.length; i++) {
        ch = checkStr.charAt(i);
        for (j = 0; j < checkOK.length; j++)
            if (ch == checkOK.charAt(j))
                break;
        if (j == checkOK.length) {
            return false;
            break;
        }
        allNum += ch;
    }
    return true;
}

function dot(item) {//判断输入是否是有效数字

    var checkOK = "0123456789.";
    var checkStr = item.value;

    var decPoints = 0;
    var allNum = "";
    for (i = 0; i < checkStr.length; i++) {
        ch = checkStr.charAt(i);
        for (j = 0; j < checkOK.length; j++)
            if (ch == checkOK.charAt(j))
                break;
        if (j == checkOK.length) {
            return false;
            break;
        }
        allNum += ch;
    }
    return true;
}

function dot2(item) {//判断数值输入是否过大
    if (item.value < 999999999)
        return true;
    else
        return false;
}

function shuzi(item) {//判断电话号码中是否输入有效数字

    var checkOK = "0123456789";
    var checkStr = item.value;

    var decPoints = 0;
    var allNum = "";
    for (i = 0; i < checkStr.length; i++) {
        ch = checkStr.charAt(i);
        for (j = 0; j < checkOK.length; j++)
            if (ch == checkOK.charAt(j))
                break;
        if (j == checkOK.length) {
            return false;
            break;
        }
        allNum += ch;
    }
    return true;
}

function validemail(item, text) {//判断是否输入了合法的email地址  
    if (!e_mail(item))
        error(item, text);
}

function validcard(item, text) {//判断是否输入了合法的身份证号码
    if (!card_id(item))
        error(item, text);
}

function validpost(item, text) {
    if (!post(item))
        error(item, text);
}
function validtel(item, text) {
    if (!telephone(item))
        error(item, text);
}
function validdot(item, text) {
    if (!dot(item))
        error(item, text);
}
function validdot2(item, text) {
    if (!dot2(item))
        error(item, text);
}
function validshuzi(item, text) {
    if (!shuzi(item))
        error(item, text);
}

function validlen(item, text, strlen) {//是否输入何指定长度相同
    if (!char_length(item, strlen))
        error(item, text);
}

function validmaxlen(item, text, strlen) {//检测输入是否大于指定长度
    if (!max_length(item, strlen))
        error(item, text + "\n您输入了:" + item.value.length + "个字符");
}

function ttt(ss, aa, ii) //表格显示何隐藏
{
    if (ss.style.display == "none") {
        ss.style.display = "";
        aa.style.display = "";
        ii.src = "/images/go-left.gif";

    }

    else {
        ss.style.display = "none";
        aa.style.display = "none";
        ii.src = "/images/go-right.gif";
    }
}
//确定转入页面，确定则至page_no代表的页面，否则至page_no页面
function gotoaim(iflist, page_yes, page_no) {
    if (iflist == true) {
        location.replace(page_yes);
    } else {
        location.replace(page_no);
    }
}

//检测带有区号的电话号码格式
function longTel(telItem) {
    var filter = /^(0\d{2,3})-(\d{7,8})$/;
    //alert(filter.test(telItem.value.text));
    //alert(telItem.value);
    if (!filter.test(telItem.value)) {
        return false;
    } else {
        return true;
    }
}

function validLongTel(item, text, strlen) {//是否输入带有区号的电话号码
    if (!longTel(item))
        error(item, text);
}

//判断下拉框是否被选中
function validListBox(item, text, controlToValidate) {
    if (controlToValidate.value != "0" && controlToValidate.value != "") {
        if (!errorListBox(item))
            error2(item, text);
    }
}
function emptyListBox(item, text) {
    if (!errorListBox(item))
        error2(item, text);
}
function errorListBox(item) {
    if (item.options[item.selectedIndex].value == -1) {
        return false;
    }
    return true;
}
function error2(item, text) {//弹公共调用函数－－－－出警告窗口，并重新设定光标
    if (errfound) return;
    window.alert(text);
    item.focus();
    errfound = true;
}
function error3(item, text) {//弹公共调用函数－－－－出警告窗口，并重新设定光标
    if (errfound) return;
    window.alert(text);
    //item.focus();
    errfound = true;
}

function validString(item, text) {//判断只能含数字，字母和下划线
    if (item.value.match(/^[^\w\d]+$/g) != null)
        error(item, text);

}

// New Add 日期判断

function fillstring(str) {
    if (str.length == 1) {
        str = "0" + str;
    }
    return (str);
}
function QuickSelDate(type, obj, obj2) {
    var begintime, endtime;
    var oneminute = 60 * 1000;
    var onehour = 60 * oneminute;
    var oneday = 24 * onehour;
    var oneweek = 7 * oneday;

    var todayDate = new Date();
    var date = todayDate.getDate();
    var month = todayDate.getMonth() + 1;
    var year = todayDate.getYear();
    var day = todayDate.getDay();
    if (navigator.appName == "Netscape") {
        year = 1900 + year;
    }

    if (type == "day") {
        begintime = year.toString() + "-" + fillstring(month.toString()) + "-" + fillstring(date.toString());
        date2 = todayDate.getDate();
        endtime = year.toString() + "-" + fillstring(month.toString()) + "-" + fillstring(date2.toString());
    }
    else if (type == "week") {
        var daytoMon = day - 1;
        if (day == 0)
            daytoMon = 6;

        todayDate.setTime(todayDate.getTime() - daytoMon * oneday);
        date = todayDate.getDate();
        month = todayDate.getMonth() + 1;
        year = todayDate.getYear();
        day = todayDate.getDay();

        begintime = year.toString() + "-" + fillstring(month.toString()) + "-" + fillstring(date.toString());

        todayDate.setTime(todayDate.getTime() + 6 * oneday);

        date = todayDate.getDate();
        month = todayDate.getMonth() + 1;
        year = todayDate.getYear();

        endtime = year.toString() + "-" + fillstring(month.toString()) + "-" + fillstring(date.toString());
    }
    else if (type == "month") {
        var dateto1 = date - 1;

        todayDate.setTime(todayDate.getTime() - dateto1 * oneday);
        date = todayDate.getDate();
        month = todayDate.getMonth() + 1;
        year = todayDate.getYear();
        day = todayDate.getDay();

        begintime = year.toString() + "-" + fillstring(month.toString()) + "-" + fillstring(date.toString());

        todayDate.setMonth(month);
        todayDate.setTime(todayDate.getTime() - oneday);

        date = todayDate.getDate();
        month = todayDate.getMonth() + 1;
        year = todayDate.getYear();

        endtime = year.toString() + "-" + fillstring(month.toString()) + "-" + fillstring(date.toString());

    }
    else {
        begintime = "";
        endtime = "";
    }

    obj.value = begintime;
    obj2.value = endtime;

}


function CompareDate(obj, obj2) {
    var begindate, enddate;
    begindate = obj.value;
    enddate = obj2.value;
    if (begindate.replace(' ', '') != '' && enddate.replace(' ', '') != '') {
        if (begindate > enddate) {
            alert('开始时间不能大于结束时间');
            errfound = true;
        }
    }
}

//格式化输入框只能输入整数或带2位小数的数值
function FormatFloat(v) {
    for (var i = v.value.length; i > 0; i--) {
        if (!/^\d*(\.\d*)?$/.test(v.value[i]))
            if (!/^\d*\.?\d{0,3}$/.test(v.value))//只能输入两位小数
            {
                v.value = v.value.substr(0, v.value.length - 1);
            }
    }
}

//格式化输入框只能输入整数
function FormatInt(v) {
    v.value = v.value.replace(/[^\d]/g, '');
}
