﻿
var createDelegate=function(a,b){return function(){return b.apply(a,arguments)}};

function TextAreaValid()
{
    this.c_list = document.getElementsByTagName("textarea");
    this.valid_list = [];
}
TextAreaValid.prototype.Valid = function ()
{
    for(var i=0;i<this.c_list.length;i++)
    {
          
            var source_event = this.c_list[i]["onblur"];
            this.valid_list.push(new ValidItem(this.c_list[i]["onblur"],this.c_list[i]));
    }

}

function ValidItem(s_event,control)
{
    this.SourceEvent = s_event;
   
    
    var validEvent= function (e)
    {
        var ev = window.event||e;
        var reg = /([\u4e00-\u9fa5]+)/gi;
       if(reg.test(this.value.trim())&&!NoValid.Find(this.id))
       {
         window.alert("Please do not include Chinese Characters");

         this.value=  this.value.trim().replace(reg,"");
       }
       if(this.id.toLowerCase().indexOf('website') == -1)
       {
            var One = this.value.trim().charAt(0).toString().toLocaleUpperCase();
            var slice = "";
            if(this.value.trim().length>1)
                 slice = this.value.slice(1);
            this.value = One+slice;
        }
        if(this.id.toLowerCase().indexOf('tboemno') > 0)
        {
           inputCheck();
        }
   };
    if(control.addEventListener){
        //control["onblur"] = validEvent;
        control.addEventListener("blur",createDelegate(control,validEvent),false);
    }
    else if(control.attachEvent){
        control.attachEvent("onblur",createDelegate(control,validEvent));
    }
    else{
      control["onblur"] =  validEvent;
    }
   
   
   var temp_unload = window.onunload;
   window.onunload =  function ()
   {
        if(temp_unload)
            temp_unload();
        temp_unload = null;
        delete temp_unload;
        control["onblur"] = null;
        if(typeof(CollectGarbage)!="undefined")
        CollectGarbage();
   }

    
}

function TextValid()
{
    this.c_list = document.getElementsByTagName("input");
    this.valid_list = [];
}

TextValid.prototype.Valid =  function ()
{
     for(var i=0;i<this.c_list.length;i++)
    {
     if(this.c_list[i].type=="text")
        {   
        
            this.valid_list.push(new ValidItem(this.c_list[i]["onblur"],this.c_list[i]));
       }
    }
}

var NoValid = {
Find:function (id)
{
    if(typeof(id)=="undefined")
        return false;
    for(var i =0;i<this.List.length;i++)
    {
        if(this.List[i]==id)
            return true;
    }
    return false;
},
List:[]
}



 