/**
 * @(#) com.mitac.taglib.MaskInput.js    2003/09/10
 * @author    Hsu Ying Ying / idas
 * @version   1.0.1
 */

function numValid()
{
    if (event.keyCode != 46 && event.keyCode != 39 && event.keyCode != 37 && event.keyCode != 9 && event.keyCode != 8 )
    {
        var A0S = numValid.arguments;
        getP(A0S);
        var re = "^\\d";
        if (A03)
        {
            var pocA03 = A02.indexOf(A03); var chunLast = A02.length-pocA03-1;
            re += "{1," +pocA03+ "}" +A03+ "{0,1}\\d{0," +chunLast+ "}";
        }
        else if (A04 && A04 == "y") re +=  "*\\.?\\d{0," +A05+ "}";
        else re += "{1," +A02.length+ "}";
        re += "$";
        var re_num = new RegExp(re);

        if (!A01.value.match(re_num))
        {
            if (A01.lastMatched) A01.value = ((A01.lastMatched).size == 1) ? "" : A01.lastMatched;
            else A01.value = "";
        }
        else A01.lastMatched = A01.value;
    }
}

function autoStyle(A01, A02, A03, A04, A05, A06)
{
    var inV = A01.value;
    if (inV.length >= 1)
    {
        if (A03)
        {
             var sF = A02.substring(0, (A02.indexOf(A03)));
             var sB = A02.substring(A02.indexOf(A03)+1);
             var iF = inV; var iB = "";
             var poc = inV.indexOf(A03);
             if (poc > 0) { iF = inV.substring(0, poc); iB = inV.substring(poc+1); }
             else { if (inV.length > sF.length) { iF = inV.substring(0, sF.length); iB = inV.substring(sF.length); } }
             A01.value = auto0(sF, iF, A06)+A03+auto0(sB, iB, A06);
        }
        else if (A04) { A05 = (A05 != "") ? A05 : "2"; A01.value = toFloat(inV, A05, A06); }
        else A01.value = auto0(A02, inV, A06);
    }
}

function auto0(a, b, A06, type)
{
    var A06er = "";
    var achun = ( isNaN(a)) ? a.length : a;
    var bchun = b.length;
    for (var i = achun; i > bchun; i--) A06er += A06;
    if (type == "back") return b+A06er;
    else return A06er+b;
}

function toFloat(v, runs, A06)
{
    var intchun = (v.indexOf(".") != -1) ? v.indexOf(".") : v.length;
    var str1 = (v.substring(0, intchun) != "") ? v.substring(0, intchun) : "0";
    var str2 = (v.indexOf(".") != -1) ? v.substring(v.indexOf(".")+1) : "";
    var out = ""; 	var tmp = "";
    var p = intchun;
    if (!(str1.indexOf(",") > 0))  //沒找到  comma  才讓他跑
    {
	     for (var i = intchun; i > 0; i = i-3)
	     {
             p = (i-3 >= 0) ? i-3 : 0; tmp = str1.slice(p, i) ;
             if (p != 0) tmp = ","+tmp;
             out = tmp + out;
	     }
	     out = (out != "") ? out : "0";
    }
    else out = str1;
    return out += "."+auto0(runs, str2, A06, "back");
}

function getP(A0S)
{
    A01 = A0S[0]; A02 = A0S[1]; A03 = A0S[2];
    A04 = A0S[3]; A05 = (A0S[4] != "") ? A0S[4] : "2";
}

function getSpecialValue(v, s)
{
    var strOut = "";
    if (v.type) var a = (v.value).split(s);
    else var a = v.split(s);
    for (var i = 0; i < a.length; i++) strOut += a[i];
    if (v.type) eval("document.all.HD"+v.name).value = strOut;
    else return strOut;
}