﻿// JScript File

function RoundUp(ctrl)
{
    if(ctrl.id.indexOf('txtLoading') > 0){
        ctrl.value = round_decimals_loading(ctrl.value, 2);
    }
    else {
        ctrl.value = round_decimals(ctrl.value, 2);
    }
}

function Round_Up(ctrl, dec)
{
    if (isNaN(ctrl.value) == false)
        ctrl.value = round_decimals(ctrl.value, dec);
}

function pad_with_zeros(rounded_value, decimal_places) {
    var value_string = rounded_value.toString();
    var decimal_location = value_string.indexOf(".");
    if (decimal_location == -1) {
        decimal_part_length = 0;
        value_string += decimal_places > 0 ? "." : "";
    }
    else {
        decimal_part_length = value_string.length - decimal_location - 1;
    }
    var pad_total = decimal_places - decimal_part_length;
    
    if (pad_total > 0) {
        for (var counter = 1; counter <= pad_total; counter++) 
            value_string += "0";
    }
    return value_string;
}

function round_decimals_loading(original_number, decimals) {
    var result1 = original_number * Math.pow(10, decimals)
    var result2 = result1; //Math.round(result1)
    var result3 = result2 / Math.pow(10, decimals)
    return pad_with_zeros(result3, decimals)
}
    
function round_decimals(original_number, decimals) {
    var result1 = original_number * Math.pow(10, decimals)
    var result2 = Math.round(result1)
    var result3 = result2 / Math.pow(10, decimals)
    return pad_with_zeros(result3, decimals)
}

function IsNumeric(sText)
{
    var ValidChars = "0123456789.";
    var IsNumber=true;
    var Char;
 
    for (i = 0; i < sText.length && IsNumber == true; i++) { 
        Char = sText.charAt(i); 
        if (ValidChars.indexOf(Char) == -1) {
            IsNumber = false;
        }
    }
    return IsNumber;
   
}

function IsNumber(evt){
    var key;
    key = evt.which ? evt.which : evt.keyCode;
    if((key>=48 && key<=57) || key == 46 || key == 45 || key == 9 || key == 8 || (key >= 35 && key <= 40)){
        return true;
    }
    else{
	    return false;
    }
}

function appendZero(strNum)
{
    var newStr;
    if (parseInt(strNum) < 10){
        newStr = "0" + strNum.substr(strNum.length-1, 1);
    }
    else{
        newStr = strNum;
    }
    return newStr;
}

