﻿function ConfirmDelete(msg) {
    if (msg != undefined)
        return confirm(msg);
    else
        return confirm('Are you sure you want to delete?');
}

function IsValidNumeric(Event, Obj, DecimalPlaces, MaxTotalDigits, MinValue, MaxValue) {

    if(event != undefined)
    Event =event;
    //Obj.maxLength
    var Key = Event.keyCode ? Event.keyCode : Event.which ? Event.which : Event.charCode;
    var RetrunValue = false;
    //alert(Key);
    

    var CurrentValue = Obj.value;
    
    if ((Key < 48 || Key > 57) && Key != 46 && (Key < 37 && Key > 40)) // if pressed key is not a digit or not decimal (.), don't allow it.
        return false;

    if (Key == 46) { // if key is decimal (.)

        if (DecimalPlaces == 0 || CurrentValue.indexOf('.') != -1) // if no decimal places allowed or current value alrady contains a decimal place.
            return false;

        if (CurrentValue.length > (MaxTotalDigits - DecimalPlaces)) // decimal places can be put only before (max total digit - total decimal places allowed )
            return false;
    }
    else if(Key < 48 || Key > 57){ // if key is a digit

        if (CurrentValue.indexOf('.') != -1) { // if decimal place is available within the current value allow only digits after decimal based on decimal places provided
            var arrValue = CurrentValue.split('.');
            if (arrValue[1].length == DecimalPlaces)
                return false;
        }

        if (DecimalPlaces != 0 && CurrentValue.length == (MaxTotalDigits - DecimalPlaces)) { // only decimal place is allowed at this position
            Obj.value = CurrentValue + ".";
            return true;
        }
    }
    //alert('ok');
    return true;
}

function DoNotEdit(Event, Obj) {

    var Key = Event.keyCode ? Event.keyCode : Event.which ? Event.which : Event.charCode;    
    if (Key == 8 || Key == 46 || Key == 37 || Key == 39) {
        Event.returnValue = true;
        return true;
    }
    else {
        Event.returnValue = false;
        return false;
    }
}

function CheckMaxLength(e, txt, max) {
    if (txt.value.length >= max && e.keyCode != 8) {
        txt.value = txt.value.slice(0, max);
        return false;
    }
    else {
        return true;
    }
}
