﻿

function TotalFonts(cf)
{   
    this.Total = cf.total||5000;
    this.InputID = cf.input;
    this.RemainID  =cf.remain;
    this.TextBoxID = cf.txt;
    this.TextBox = $get(this.TextBoxID);
     
    if(this.TextBox==null)
        return ;
    var temp = this;
    var sour_event =this.TextBox["onkeyup"];
    this.TextBox["onkeyup"] =function (e){temp.Press(e,this);if(sour_event)sour_event();};
    this.TextBox["onkeyup"]();
    
}

TotalFonts.prototype.Press = function temp(e,txtbox)
{   
    var current = this.TextBox.value.trim().length;
    var r1 = /[\u4e00-\u9fa5]/gi;
    var maths = this.TextBox.value.trim().match(r1);
    if(maths!=null)
        current += maths.length;
    if(current > this.Total)
    {
        this.TextBox.value =this.TextBox.value.substring(0,this.Total);
    }
    else
    {
       var r = /(\d)(\d{3})/gi;
       if($get(this.InputID)!=null)       
        $get(this.InputID).innerHTML = current.toString().replace(r,"$1,$2");
       if($get(this.RemainID) != null)
       $get(this.RemainID).innerHTML= (this.Total-current).toString().replace(r,"$1,$2");
   }
}





function TotalFontsForHtmlEditor(cf)
{   
    this.Total = cf.total||5000;
    this.InputID = cf.input;
    this.RemainID  =cf.remain;
    this.TextBoxID = cf.txt;
    this.TextBox = $get(this.TextBoxID);
     
    if(this.TextBox==null)
        return ;
    var temp = this;
    var sour_event =this.TextBox["onkeyup"];
    this.TextBox["onkeyup"] =function (e){temp.Press(e,this);if(sour_event)sour_event();};
    this.TextBox["onkeyup"]();
    
}

TotalFontsForHtmlEditor.prototype.Press = function temp(e,txtbox)
{   
    var current = this.TextBox.value.trim().length;
    var r1 = /[\u4e00-\u9fa5]/gi;
    var maths = this.TextBox.value.trim().match(r1);
    if(maths!=null)
        current += maths.length;
    if(current > this.Total)
    {
        this.TextBox.value =this.TextBox.value.substring(0,this.Total);
    }
    else
    {
       var r = /(\d)(\d{3})/gi;
       if($get(this.InputID)!=null)       
        $get(this.InputID).innerHTML = current.toString().replace(r,"$1,$2");
       if($get(this.RemainID) != null)
       $get(this.RemainID).innerHTML= (this.Total-current).toString().replace(r,"$1,$2");
   }
}

function FilterHtml(input)
{
    var filterReg = /<(.[^>]*)>/gi;
    if(input!=null && input.toString()!=null)
    {
        return input.toString().replace(filterReg,"");
    }
    
    return input;
    
}


