function cal_pre(article, fileds, max_word)
{
	theForm = eval('document.' + fileds);
	var tmpStr;
	tmpStr = eval("document.getElementById('excerpt_" + article + "')").value;
	cal_byte(article, fileds, tmpStr, max_word);
}

function cal_byte(article, fileds, aquery, max_word) 
{
	theForm = eval('document.' + fileds);
    var tmpStr;
    var temp=0;
    var onechar;
    var tcount;
    tcount = 0;
    
    tmpStr = new String(aquery);
    temp = tmpStr.length;

    for (k=0;k<temp;k++)
    {
        onechar = tmpStr.charAt(k);

        if (escape(onechar).length > 4) {
            tcount += 2;
        }
        else if (onechar!='\r') {
            tcount++;
        }
    }

    theForm.cbyte.value = tcount;
    if(tcount>max_word) {

        reserve = tcount-max_word;
        alert("Max " + max_word + "words letters"); 
        cutText(article, fileds, max_word);
        return;
    } 
}

function cutText(article, fileds, max_word)
{
   theForm = eval('document.' + fileds);
   nets_check(article, fileds, eval("document.getElementById('excerpt_" + article + "')").value, max_word);
}


function nets_check(article, fileds, aquery,max_word)
{
	theForm = eval('document.' + fileds);
    var tmpStr;
    var temp=0;
    var onechar;
    var tcount;
    tcount = 0;
    
    tmpStr = new String(aquery);
    temp = tmpStr.length;

    for(k=0;k<temp;k++)
    {
        onechar = tmpStr.charAt(k);
        
        if(escape(onechar).length > 4) {
            tcount += 2;
        }
        else if(onechar!='\r') {
            tcount++;
        }
        if(tcount>max_word) {
            tmpStr = tmpStr.substring(0,k); 
            break;
        }
    }
    
    if (max_word == max_word) {
        eval("document.getElementById('excerpt_" + article + "')").value = tmpStr;
        cal_byte(article, fileds, tmpStr, max_word);
    }
    
    return tmpStr;
}
