﻿//去掉空格
String.prototype.Trim = function()
{
    return this.replace(/(^\s*)|(\s*$)/g, "");
}
String.prototype.LTrim = function()
{
    return this.replace(/(^\s*)/g, "");
}
String.prototype.Rtrim = function()
{
    return this.replace(/(\s*$)/g, "");
}

function $(val)
{
    return document.getElementById(val);
}

var IsPass=true;
var list=new Array();

//检查表单
function FormCheck()
{
    //获取要检查的表单数据
    FormCheckDate();
    for(i = 0 ; i < list.length;i++)
    {
        if(!IsPassCheck(list[i].split('|')[0],list[i].split('|')[1],list[i].split('|')[2],list[i].split('|')[3]))
        {
            IsPass = false;
            break;
        }
        else
        {
            IsPass = true;
        }
    }
    return IsPass;
}

//数据检查
//AlertStr    提示信息
//ControlID   控件ID
//DataType    数据类型
//IsNull      是否可空
function IsPassCheck(AlertStr,ControlID,DataType,IsNull)
{
    if(document.getElementById(ControlID) !=null)
    {
        document.getElementById(ControlID).value=document.getElementById(ControlID).value.Trim();
        //document.getElementById(ControlID).value=document.getElementById(ControlID).value.replace(/ /g,"");
        var ControlValue=document.getElementById(ControlID).value;
        if(ControlValue != "")
        {
            var RegExpression=new RegExp();
            switch(DataType)
            {            
                case "Num_Decimal"://验证数字和小数
                    RegExpression = /(^\d+$)|(^\d+\.\d+$)/;
                    break;
                case "Num"://验证数字
                    RegExpression=/^[\d]+$/;
                    break;
                case "Email"://驗證電郵
                    RegExpression=/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;
                    break;
                case "Date"://验证日期
                    RegExpression=/^((((1[6-9]|[2-9]\d)\d{2})-(0?[13578]|1[02])-(0?[1-9]|[12]\d|3[01]))|(((1[6-9]|[2-9]\d)\d{2})-(0?[13456789]|1[012])-(0?[1-9]|[12]\d|30))|(((1[6-9]|[2-9]\d)\d{2})-0?2-(0?[1-9]|1\d|2[0-8]))|(((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))-0?2-29-))$/;
                    break;
                case "EnTableName"://验证英文表名
                    RegExpression=/^\w+$/;
                    break;
                case "EnFieldName"://验证英文字段名
                    RegExpression=/^\w+$/;
                    break;
                case "None"://验证不为空
                    RegExpression=/\w*/;
                    break;
            }            
            if(!RegExpression.test(ControlValue))
            {
                alert("請輸入格式正確的：" + AlertStr);
                document.getElementById(ControlID).focus();
                return false;
            }
            else
            {
                return true;
            }
        }
        else
        {
            if(IsNull=="NotNull")
            {
                alert("請輸入：" + AlertStr);
                if (ControlID != "FCKContent" || ControlID != "FCKContentEn")
                {
                    document.getElementById(ControlID).focus();
                }
                return false;
            }
            else
            {
                return true;
            }
        }
    }
}

function ImgClick(ImgSrc)
{
    $('ImagePath').src = ImgSrc;
}

//清除页面上所有文本框的值
function TextBoxReset(TempControl)
{
    var obj = TempControl;
    elem=obj.form.elements;
    for(i=0;i<elem.length-1;i++)
    {
        
        if(elem[i].type=="text" || elem[i].type=="textarea")
        {
            elem[i].value="";
        }
    }
}
