﻿function PengValidator(sender, args)
{
    var v = args.Value;
    var s = "";
    var e;
    var i;
    var c;
    
    if (v.length > 0)
    {
        for (i = 0; i < v.length; i++)
        {
            if (isNaN(v.charAt(i)))
            {
                args.IsValid = false;
                return;
            }
            else
            {
                if (v.charAt(i) != " ")
                {
                    s = s + v.charAt(i);
                }                
            }
        }    

        v = ""
        c = 0;
        for (i = s.length; i >= 0; i--)
        {
            if (c == 4)
            {
                v = " " + v;
                c = 1;
            }
            v = s.charAt(i) + v;
            c = c + 1;
        }
        s = v; 
            
        v = sender.id;
        v = v.substring(v.length - 2, v.length);
        
        e = document.getElementById("ctl00_CPH1_txtF" + v);
        if (e != null)
        {
            e.value = s;
        }                
    }
    args.IsValid = true;
}

function PengCalc666()
{
    var e;
    var f01,f02,f03,f04,f05,f06,f07,f08,f09,f10,f11;

    e = document.getElementById("ctl00_CPH1_txtF01");
    if (e != null)
    {
        f01 = CInt(e.value);
    }    
    e = document.getElementById("ctl00_CPH1_txtF02");
    if (e != null)
    {
        f02 = CInt(e.value);
    }
    e = document.getElementById("ctl00_CPH1_txtF04");
    if (e != null)
    {
        f04 = CInt(e.value);
    }    
    e = document.getElementById("ctl00_CPH1_txtF06");
    if (e != null)
    {
        f06 = CInt(e.value);
    }    
    e = document.getElementById("ctl00_CPH1_txtF08");
    if (e != null)
    {
        f08 = CInt(e.value);
    }    
    e = document.getElementById("ctl00_CPH1_txtF09");
    if (e != null)
    {
        f09 = CInt(e.value);
    }    
    e = document.getElementById("ctl00_CPH1_txtF11");
    if (e != null)
    {
        f11 = CInt(e.value);
    }

    f03 = "";
    if(f01 > 0 && f02 > 0)
    {
        f03 = CInt((f02 / f01) * 100);
    }
    
    f05 = "";
    if(f02 > 0 && f04 > 0)
    {
        f05 = CInt(f02 * f04);
    }
    
    f07 = "";
    if(f05 > 0 && f06 > 0)
    {
        f07 = CInt(f05 * f06);
    }
    
    f10 = "";
    if(f07 > 0 && f09 > 0)
    {
        f10 = CInt(f07 - f09);
    }
        
    e = document.getElementById("ctl00_CPH1_txtF03");
    if (e != null)
    {
        e.value = f03;
    }        
    e = document.getElementById("ctl00_CPH1_txtF05");
    if (e != null)
    {
        e.value = f05;
    }        
    e = document.getElementById("ctl00_CPH1_txtF07");
    if (e != null)
    {
        e.value = f07;
    }        
    e = document.getElementById("ctl00_CPH1_txtF10");
    if (e != null)
    {
        e.value = f10;
    }                    
}

function TrapEnter(e) 
{
    if (window.event) 
    {
        if (window.event.keyCode == 13)
        {
            window.event.keyCode = 9;
        }    
    }
    else if (e)
    {
        if (e.which == 13)
        {
            //e.which = 9;
            e.preventDefault();
        }        
    }
}

