﻿var successStr = '/design/icon/success.gif';
var failedStr = '/design/icon/failed.gif';
var waitStr = '/design/icon/wait.gif';
var successImg = "<img src='" + successStr + "' /> ";
var failedImg = "<img src='" + failedStr + "' /> ";
var errorStr = "";
window.go = new Object(); 

function verifyUsername(username) {
    $('#usernameContain').html("<img src='/design/icon/wait.gif' />");
    $('#usernameContain').load('/httphandle/reg/verifyReg.ashx', { type: 'un', un: username, anticache: Math.floor(Math.random() * 1000) })
}

function veryifyPassword(password, Repeaterpassword) {
    if (password != '' && password.toString().length > 5) {
        $('#newPasswordContain').html(successImg);
    }
    else {
        errorStr = "密码不得小于6位．";
        $('#newPasswordContain').html(failedImg + errorStr);
        return;
    }

    if (Repeaterpassword != '' && Repeaterpassword.toString().length > 5) {
        $('#repeaterPasswordContain').html(successImg);
    }
    else {
        errorStr = "重复密码不得小于6位．";
        $('#repeaterPasswordContain').html(failedImg + errorStr);
        return;
    }

    if (password == Repeaterpassword) {
        $('#repeaterPasswordContain').html(successImg);
    }
    else {
        errorStr = "密码和重复密码必须相同．";
        $('#repeaterPasswordContain').html(failedImg + errorStr);
        return;
    }
}

function verifyEmail(email) {
    $('#emailContain').html("<img src='/design/icon/wait.gif' />");
    $('#emailContain').load('/httphandle/reg/verifyReg.ashx?type=email&email=' + email)
}

function verifyAll(username, password, repeaterpassword, email) {
    if (window.go == 'bill') {
        return true;
    }
    else
    {
        setTimeout("verifyAllDo('" + username + "','" + password + "','" + repeaterpassword + "','" + email + "')", 500);
        return false;
    }
}

function verifyAllDo(username, password, repeaterpassword, email) {
    username = $('#' + username).val();
    password = $('#' + password).val();
    repeaterpassword = $('#' + repeaterpassword).val();
    email = $('#' + email).val();
    //SName = $('#' + SName).val();
    
    var ispass = 1;
    if (username == '' || password == '' || repeaterpassword == '' || email == '') {
        alert('请认真写填每一项内容');
        ispass = 0;
        return false;
    }

    if ($('#usernameContain').html().toLowerCase().indexOf(waitStr) >= 0 || $('#usernameContain').html().toLowerCase().indexOf('img') < 0) {
        alert('用户名，正在检测请后提交。');
        ispass = 0;
        return false;
    }
    else if ($('#usernameContain').html().indexOf(successStr) < 0) {
        alert('用户名有误，请认真填写');
        ispass = 0;
        return false;
    }

    if ($('#newPasswordContain').html().indexOf(successStr) < 0) {
        alert('密码有误，请认真填写');
        ispass = 0;
        return false;
    }

    if ($('#repeaterPasswordContain').html().indexOf(successStr) < 0) {
        alert('重复密码有误，请认真填写');
        ispass = 0;
        return false;
    }

    if ($('#emailContain').html().toLowerCase().indexOf(waitStr) >= 0 || $('#emailContain').html().toLowerCase().indexOf('img') < 0) {
        alert('电子邮件，正在检测请后提交。');
        ispass = 0;
        return false;
    }
    else if ($('#emailContain').html().indexOf(successStr) < 0) {
        alert('电子邮件有误，请认真填写');
        ispass = 0;
        return false;
    }

    if (ispass == 1)
        window.go = 'bill';
        $('#ctl00_ctl00_rootContent_mainContent_mbtn').click();
}

function CheckDate(INDate) {
    if (INDate == "") { return true; }
    subYY = INDate.substr(0, 4)
    if (isNaN(subYY) || subYY <= 0) {
        return true;
    }
    //转换月份
    if (INDate.indexOf('-', 0) != -1) { separate = "-" }
    else {
        if (INDate.indexOf('/', 0) != -1) { separate = "/" }
        else { return true; }
    }
    area = INDate.indexOf(separate, 0)
    subMM = INDate.substr(area + 1, INDate.indexOf(separate, area + 1) - (area + 1))
    if (isNaN(subMM) || subMM <= 0) { return true; }
    if (subMM.length < 2) { subMM = "0" + subMM }
    //转换日
    area = INDate.lastIndexOf(separate)
    subDD = INDate.substr(area + 1, INDate.length - area - 1)
    if (isNaN(subDD) || subDD <= 0) {
        return true;
    }
    if (eval(subDD) < 10) { subDD = "0" + eval(subDD) }
    NewDate = subYY + "-" + subMM + "-" + subDD
    if (NewDate.length != 10) { return true; }
    if (NewDate.substr(4, 1) != "-") { return true; }
    if (NewDate.substr(7, 1) != "-") { return true; }
    var MM = NewDate.substr(5, 2);
    var DD = NewDate.substr(8, 2);
    if ((subYY % 4 == 0 && subYY % 100 != 0) || subYY % 400 == 0) { //判断是否为闰年
        if (parseInt(MM) == 2) {
            if (DD > 29) { return true; }
        }
    } else {
        if (parseInt(MM) == 2) {
            if (DD > 28) { return true; }
        }
    }
    var mm = new Array(1, 3, 5, 7, 8, 10, 12); //判断每月中的最大天数
    var flag = false;
    for (i = 0; i < mm.length; i++) {
        if (parseInt(MM, 10) == mm[i]) { flag = true; }
    }
    if (flag == true) {
        if (parseInt(DD) > 31) { return true; }
    } else {
        if (parseInt(DD) > 30) { return true; }
    }

    if (parseInt(MM) > 12) { return true; }
    return false;
}

function compare_time(a, b) {//a大于b返回false，a小于等于b返回true  a小  b大
    try {
        var arr = a.split("-");
        var starttime = new Date(arr[0], arr[1], arr[2]);
        var starttimes = starttime.getTime();
        var arrs = b.split("-");
        var endtime = new Date(arrs[0], arrs[1], arrs[2]);
        var endtimes = endtime.getTime();
        if (starttimes > endtimes)//开始大于结束
        {
            return false;
        }
        else {
            return true;
        }
    }
    catch(e){
        return false;
    }
}