﻿// JScript File

function $(id)
{
    return document.getElementById(id);
}

var type;
var name;
var sex;
var xueli;
var age;
var jiguan;
var zhuanye;
var mail;
var identity;
var phone;
var adress;
var schoole;
var cstp;

//给变量赋值
function fuzhi()
{
    type=$("ddltype").value;
    name=$("name").value;
    sex=getSex();
    xueli=$("ddlXueLi").value;
    age=$("ddlage").value;
    jiguan=$("ddlJiGuan").value;
    zhuanye=$("txtzhuanye").value;
    mail=$("txtmail").value;
    identity=$("txtidentity").value;
    phone=$("txtphone").value;
    adress=$("txtadress").value;
    schoole=$("txtschoole").value;
    cstp=$("txtcstp").value;
}

//提交数据
function tijiao()
{
    if(testYard())
    {
        fuzhi();
        if(bitian())
        {
            var student=new Array();
            student[0]=type;
            student[1]=name;
            student[2]=sex;
            student[3]=xueli;
            student[4]=age;
            student[5]=jiguan;
            student[6]=zhuanye;
            student[7]=mail;
            student[8]=identity;
            student[9]=phone;
            student[10]=adress;
            student[11]=schoole;
            student[12]=cstp;
            student[13]='';
            
            var insert=OnlineNameplateBX.InsertStudent(student);
            if(insert.error!=null)
                alert('注册失败，请重新注册！');
            else if(insert.value)
            {
                alert('恭喜注册成功！');
                myreset();
                
            }
        }
        else
        {
            alert('请填写所有带*的项！');
        }
    }
    else
    {
        alert('验证码有误，请重新输入！');
    }
}

//重置
function myreset()
{
    getYard();
    $("ddltype").value=2;
    $("name").value="";
    $("man").checked=true;
    $("ddlXueLi").value=2;
    $("ddlage").value=2;
    $("ddlJiGuan").value=2;
    $("txtzhuanye").value="";
    $("txtmail").value="";
    $("txtidentity").value="";
    $("txtphone").value="";
    $("txtadress").value="";
    $("txtschoole").value="";
    $("txtcstp").value="";
    
    $("ddltype").focus();
    $("txtyard").value="";
}

//获取性别
function getSex()
{
    if($("man").checked)
        return "男";
    else if($("woman").checked)
        return "女";
}

//检测必填项
function bitian()
{
    fuzhi();
    if(type=="2")
    {
        $("ddltype").focus();
        return false;
    }
    else if(name.trim()=="")
    {
        $("name").focus();
        return false;
    }
    else if(xueli=="2")
    {
        $("ddlXueLi").focus();
        return false;
    }
    else if(age=="2")
    {
        $("ddlage").focus();
        return false;
    }
    else if(zhuanye.trim()=="")
    {
        $("txtzhuanye").focus();
        return false;
    }
    else if(phone.trim()=="")
    {
        $("txtphone").focus();
        return false;
    }
    else 
    {
        return true;
    }
}


//检测验证码
function testYard()
{
    if($("txtyard").value.trim()==$("lbyard").value)
        return true;
    else
    {
        return false;
    }
}
//校验
function jiaoyan(i)
{
    if(i=="1")
    {
        name=$("name").value;
        if(!isNaN(name)&& name.trim()!="")
        {
            alert('姓名只能为字符或汉字！');
            $("name").focus();
        }
    }
    if(i==2)
    {
        var reg=/^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/;
        email=$("txtmail").value;
        if(!reg.test(email)&& email.trim()!="")
        {
            alert('邮箱格式有误!');
            $("txtmail").focus();
        }
    }
    if(i==3)
    {
        phone=$("txtphone").value;
        if(isNaN(phone))
        {
            alert('电话号码必须为数字！');
            $("txtphone").focus();
        }
    }
}