﻿// JScript 文件
window.onload = function(){
    SelectOne();
    SelectTwo();
    SelectThree();
    SelectThreeBlog();
    SelectSix();
}
function $(objName){
    if(document.getElementById){
	    return eval('document.getElementById("' + objName + '")');
    }else if(document.layers){
	    return eval("document.layers['" + objName +"']");
    }else{
	    return eval('document.all.' + objName);
    }
}
//Radio取值
function GetRadioValue(RadioName){
    var obj;    
    obj=document.getElementsByName(RadioName);
    if(obj!=null){
        var i;
        for(i=0;i<obj.length;i++){
            if(obj[i].checked){
                return obj[i].value;            
            }
        }
    }
    return null;
}
//计算CheckBox个数
function GetCheckBox(CheckBoxID,ItemCount) 
{ 
    var iCount = 0; 
    for(var i=0;i<=ItemCount;i++) 
    { 
        var chk = document.getElementById(CheckBoxID+"_"+i); 
        if(chk != null ) 
        { 
            if(chk.checked) 
                iCount ++; 
        } 
    } 
    return iCount; 
}
//去掉左右空格
function LTrim(str)     
{     
    var i;     
    for(i=0;i<str.length;i++)     
    {     
        if(str.charAt(i)!=" "&&str.charAt(i)!=" ") break;     
    }     
    str=str.substring(i,str.length);     
    return str;     
}     
//去掉左右空格
function RTrim(str)     
{     
    var i;     
    for(i=str.length-1;i>=0;i--)     
    {     
        if(str.charAt(i)!=" "&&str.charAt(i)!=" ") break;     
    }     
    str=str.substring(0,i+1);     
    return str;     
}    
//去掉左右空格 
function Trim(str)     
{     
    return LTrim(RTrim(str));     
}
//检查电子邮件
function IsMail(email)
{
	var Regu,Re,Matches,InfoCout;
	Value = $(email).value;
	Re ="^([0-9a-z]+[_.0-9a-z-]*)@([a-z0-9-]+.)+([a-z]{2}|net|com|gov|mil|org|edu|int)$";
	Regu = new RegExp(Re,"i")
	if (!Value == "" && Value.match(Regu) == null)
	{
		return false;
	}
	return true;
}
//第一题
function SelectOne()
{
    if(GetRadioValue("txtJoin") == "是")
    {
        $("divJoinA").style.display = "block";
        $("divJoinB").style.display = "none";
    }
    else if(GetRadioValue("txtJoin") == "否")
    {
        $("divJoinA").style.display = "none";
        $("divJoinB").style.display = "block";
    }
    else
    {
        $("divJoinA").style.display = "none";
        $("divJoinB").style.display = "none";
    }
    $("labJoin").innerHTML = "";
}
//第二题
function SelectTwo()
{
    if(GetRadioValue("txtActuality") == "在读高中生")
    {
        $("divActualityA").style.display = "block";
        $("divActualityB").style.display = "none";
    }
    else if( GetRadioValue("txtActuality") == "在国外读大学" )
    {
        $("divActualityA").style.display = "none";
        $("divActualityB").style.display = "block";
    }
    else
    {
        $("divActualityA").style.display = "none";
        $("divActualityB").style.display = "none";
    }
}
//第三题
function SelectThree()
{
    if(GetRadioValue("txtShare") == "愿意")
    {
        $("divShare").style.display = "block";
    }
    else
    {
        $("divShare").style.display = "none";
    }
}
function SelectThreeBlog()
{
    if(GetRadioValue("txtShareMode") == "公开自己的博客地址")
    {
        $("divBlog").style.display = "block";
    }
    else
    {
        $("divBlog").style.display = "none";
    }
}
//第六题
function SelectSix()
{
    if($("txtInfoMode_5").checked)
    {
        $("divOtherMode").style.display = "block";
    }
    else
    {
        $("divOtherMode").style.display = "none";
    }
}
//检查表单
function CheckForm()
{
    //1
    if(GetRadioValue("txtJoin") == "" || GetRadioValue("txtJoin") == null )
    {
        window.location.href = "#A1";
        $("labJoin").innerHTML = "请选择";
        return false;
    }
    else
    {
        $("labJoin").innerHTML = "";
    }
    if(GetRadioValue("txtJoin") == "是" && $("txtUserName1").value == "")
    {
        window.location.href = "#A1";
        $("labUserName1").innerHTML = "请输入";
        return false;
    }
    else
    {
        $("labUserName1").innerHTML = "";
    }
    if(GetRadioValue("txtJoin") == "是" && $("txtAddress1").value == "")
    {
        window.location.href = "#A1";
        $("labAddress1").innerHTML = "请输入";
        return false;
    }
    else
    {
        $("labAddress1").innerHTML = "";
    }
    if(GetRadioValue("txtJoin") == "是" && $("txtPostCode").value == "")
    {
        window.location.href = "#A1";
        $("labPostCode").innerHTML = "请输入";
        return false;
    }
    else
    {
        $("labPostCode").innerHTML = "";
    }
    if(GetRadioValue("txtJoin") == "是" && $("txtTelephone").value == "")
    {
        window.location.href = "#A1";
        $("labTelephone").innerHTML = "请输入";
        return false;
    }
    else
    {
        $("labTelephone").innerHTML = "";
    }
    if(GetRadioValue("txtJoin") == "否" && $("txtUserName2").value == "")
    {
        window.location.href = "#A1";
        $("labUserName2").innerHTML = "请输入";
        return false;
    }
    else
    {
        $("labUserName2").innerHTML = "";
    }
    if(GetRadioValue("txtJoin") == "否" && $("txtAddress2").value == "")
    {
        window.location.href = "#A1";
        $("labAddress2").innerHTML = "请输入";
        return false;
    }
    else
    {
        $("labAddress2").innerHTML = "";
    }
    if($("txtEmail").value != "" && IsMail("txtEmail") == false)
    {
        window.location.href = "#A1";
        $("labEmail").innerHTML = "请输入正确的电子邮件地址";
        return false;
    }
    else
    {
        $("labEmail").innerHTML = "";
    }
    //2
    if(GetRadioValue("txtActuality") == "" || GetRadioValue("txtActuality") == null )
    {
        window.location.href = "#A2";
        $("labActuality").innerHTML = "请选择";
        return false;
    }
    else
    {
        $("labActuality").innerHTML = "";
    }
    if(GetRadioValue("txtActuality") == "在读高中生" && (GetRadioValue("txtGrade") == "" || GetRadioValue("txtGrade") == null))
    {
        window.location.href = "#A2";
        $("labGrade").innerHTML = "请选择";
        return false;
    }
    else
    {
        $("labGrade").innerHTML = "";
    }
    if(GetRadioValue("txtActuality") == "在读高中生" && $("txtSchool").value == "" )
    {
        window.location.href = "#A2";
        $("labSchool").innerHTML = "请填写";
        return false;
    }
    else
    {
        $("labSchool").innerHTML = "";
    }
    if(GetRadioValue("txtActuality") == "在国外读大学" && ($("txtWAYear").value == "" || $("txtWAYear").value == null))
    {
        window.location.href = "#A2";
        $("labWATime").innerHTML = "请选择年";
        return false;
    }
    else
    {
        $("labWATime").innerHTML = "";
    }
    if(GetRadioValue("txtActuality") == "在国外读大学" && ($("txtWAMonth").options[$("txtWAMonth").selectedIndex].value == "" || $("txtWAMonth").options[$("txtWAMonth").selectedIndex].value == null))
    {
        window.location.href = "#A2";
        $("labWATime").innerHTML = "请选择月";
        return false;
    }
    else
    {
        $("labWATime").innerHTML = "";
    }
    //3
    if(GetRadioValue("txtShare") == "" || GetRadioValue("txtShare") == null )
    {
        window.location.href = "#A3";
        $("labShare").innerHTML = "请选择";
        return false;
    }
    else
    {
        $("labShare").innerHTML = "";
    }
    if(GetRadioValue("txtShare") == "愿意" && ( GetRadioValue("txtShareMode") == "" || GetRadioValue("txtShareMode") == null))
    {
        window.location.href = "#A3";
        $("labShareMode").innerHTML = "请选择";
        return false;
    }
    else
    {
        $("labShareMode").innerHTML = "";
    }
    if(GetRadioValue("txtShare") == "愿意" && GetRadioValue("txtShareMode") == "公开自己的博客地址" && $("txtBlog").value == "")
    {
        window.location.href = "#A3";
        $("labBlog").innerHTML = "请填写";
        return false;
    }
    else
    {
        $("labBlog").innerHTML = "";
    }
    //4
    if(GetCheckBox("txtAttention",4) == 0)
    {
        window.location.href = "#A4";
        $("labAttention").innerHTML = "至少选一项";
        return false;
    }
    else
    {
        $("labAttention").innerHTML = "";
    }
    //5
    if(GetCheckBox("txtFavor",9) == 0)
    {
        window.location.href = "#A5";
        $("labFavor").innerHTML = "至少选一项";
        return false;
    }
    else
    {
        $("labFavor").innerHTML = "";
    }
    //6
    if(GetCheckBox("txtInfoMode",5) == 0)
    {
        window.location.href = "#A6";
        $("labInfoMode").innerHTML = "至少选一项";
        return false;
    }
    else
    {
        $("labInfoMode").innerHTML = "";
    }
    //6的其他
    if($("txtInfoMode_5").checked && $("txtOtherMode").value == "")
    {
        window.location.href = "#A6";
        $("labOtherMode").innerHTML = "请填写";
        return false;    
    }
    else
    {
        $("labOtherMode").innerHTML = "";
    }
    //7
    if($("txtIdea").value == "")
    {
        window.location.href = "#A7";
        $("labIdea").innerHTML = "请填写";
        return false;
    }
    else
    {
        $("labIdea").innerHTML = "";
    }
    //8
    if($("txtFriendName").value != "" && $("txtFriendAddr").value == "")
    {
        window.location.href = "#A7";
        $("labFriendAddr").innerHTML = "请填写";
        return false;
    }
    else
    {
        $("labFriendAddr").innerHTML = "";
    }
    if($("txtFriendName").value != "" && $("txtFriendPC").value == "")
    {
        window.location.href = "#A7";
        $("labFriendPC").innerHTML = "请填写";
        return false;
    }
    else
    {
        $("labFriendPC").innerHTML = "";
    }
    return true;
}