﻿function IsEmpty(aTextField) 
{
    if ((aTextField.value.length==0) || (aTextField.value==null)) 
    {
        return true;
    }
    else 
    { 
        return false; 
    }
}
 function agree_onclick()
{
    var theForm = document.form1;
    theForm.agree.checked=='';
    if(theForm.agree.checked=='')
    {
        theForm.btn_post.disabled = true;
    }
    else    
    {
        theForm.btn_post.disabled = false;
    }
}
function test_RegisterName(strInput)
{
    var myReg = /^[a-zA-Z][a-zA-Z0-9_]{5,19}$/;
    if(myReg.test(strInput)) return true;
    return false;
}
function test_Password(strInput)
{
    var myReg =/\w{6,20}$/;
    if(myReg.test(strInput)) return true;
    return false;
}

/*
判断是否为电话号码
--------------------------
*/
function test_Tel(strInput)
{
    var reg1=/^(\d{3,4}-)?\d{7,8}$/;//八位电话号码
   if (strInput!="") 
   {
       if (reg1.test(strInput))
       {
           return true;
       }
       else
       {
           return false;
       }
   }
   else
   {
       return false;
   }
}
/*
判断是否为手机号
--------------------------
*/
function test_Mobile(strInput)
{
    var myReg =/^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1}))+\d{8})$/;
    if(myReg.test(strInput)) return true;
    return false;
}
/*
判断是否为邮箱或MSN
--------------------------
*/
 function test_Email(strInput){
    var myReg = /^([\S])+[@]{1}([\S])+[.]{1}(\S)+$/;
    if(myReg.test(strInput)) return true;
    return false;
}

function test_Question(strInput)
{
    var myReg = /^.{4,10}$/;
    if(myReg.test(strInput)) return true;
    return false;
}
function test_Answer(strInput)
{
    var myReg = /^.{4,10}$/
    if(myReg.test(strInput)) return true;
    return false;
}
function test_Number(strInput)
{
    var myReg = /^\d+$/;
    if(myReg.test(strInput)) return true;
    return false;
}

/*
检测字符串长度
----------------------------------
*/
function test_StrLength(value)
{
    var str,Num=0;
    for   (var   i=0;i<value.length;i++)
    {   
      str   =   value.substring(i,i+1);   
      if(str<="~")     //判断是否双字节   
        Num+=1;   
      else   
        Num+=2;   
    }   
    return   Num;   
}

function cc() 
{ 
 var e = event.srcElement; 
 var r =e.createTextRange(); 
 r.moveStart('character',e.value.length); 
 r.collapse(true); 
 r.select(); 
} 

/*
判断是否为日期
----------------------------------
*/

function isDate (theStr) {
    var the1st = theStr.indexOf('-');
    var the2nd = theStr.lastIndexOf('-');
    
    if (the1st == the2nd) { 
        return(false); 
    }
    else {
        var y = theStr.substring(0,the1st);
        var m = theStr.substring(the1st+1,the2nd);
        var d = theStr.substring(the2nd+1,theStr.length);
        var maxDays = 31;
        
        if (fucCheckNUM(m)==false || fucCheckNUM(d)==false || fucCheckNUM(y)==false) {
            return(false); }
        else if (y.length < 4) { return(false); }
        else if ((m<1) || (m>12)) { return(false); }
        else if (m==4 || m==6 || m==9 || m==11) maxDays = 30;
        else if (m==2) {
            if (y % 4 > 0) maxDays = 28;
            else if (y % 100 == 0 && y % 400 > 0) maxDays = 28;
               else maxDays = 29;
        }
        if  ((m<1) || (m>maxDays)) { return(false); }
        else { return(true); }
    }
}

/*
判断是否为电话号码开始（已经完成）
--------------------------
*/
function isTel(telstr)
{
   var reg1=/(\(\d{3}\)|\d{3}-)?\d{8}/g;//八位电话号码
   var reg2=/(\(\d{3}\)|\d{3}-)?\d{7}/g;//七位电话号码
   if (telstr!="") {
           if (reg1.test(telstr)||reg2.test(telstr)){
               return(true);
           }
           else{
               return(false);
           }
   }else{return(false);}
}
