function RoundNumber(a,b){b=Math.abs(parseInt(b))||0;var c=Math.pow(10,b);return Math.round(a*c)/c}function CheckValueForUnassignedValue(a){return isNaN(a)||""==a}function StoreOldValue(a,b){b.Find(a);element.attr("oldvalue",b.FindValue(a))}function SandBox(a){this.restrictedContextId;this.parentSandBox;this.contextId=a;this.elements={};this.previousValues={};this.currentValues={}}SandBox.prototype.BeginScope=function(a){a=new SandBox(a);a.parentSandBox=this;return a};SandBox.prototype.EndScope=function(){return this.parentSandBox};
SandBox.prototype.AddValue=function(a,b){this.elements[a]=b};SandBox.prototype.AddValue=function(a,b,c,d){this.elements[a]=b;this.currentValues[a]=c;this.previousValues[a]=d};SandBox.prototype.AddDefaultValue=function(a,b){this.currentValues[a]=b};SandBox.prototype.CreateContainerSandBox=function(a){return this.parentSandBox=a=new SandBox(a)};SandBox.prototype.GetContext=function(){return this.contextId};
SandBox.prototype.Find=function(a){var b=this.elements[a];void 0==b&&void 0!=this.parentSandBox&&(b=this.parentSandBox.Find(a));return b};SandBox.prototype.FindValue=function(a){var b=this.currentValues[a];void 0==b&&void 0!=this.parentSandBox&&(b=this.parentSandBox.FindValue(a));return b};SandBox.prototype.SaveValue=function(a,b){var c=this.Find(a);this.currentValues[a]=b;c.val(b)};
SandBox.prototype.SaveFormatedValue=function(a,b,c){var d=this.Find(a);this.currentValues[a]=b;d.is("span")?d.text(c):d.val(c)};SandBox.prototype.SetPreviousValue=function(a){var b=this.Find(a);void 0!=b&&(a=this.FindValue(a),b.attr("oldvalue",a))};SandBox.prototype.FindOld=function(a){var b=this.previousValues[a];void 0==b&&void 0!=this.parentSandBox&&(b=this.parentSandBox.FindOld(a));return b};function GetContext(a){return $('[contextid="'+a+'"]')}
function GetContextVars(a){return a.find("[contextvarid]")}function GetAllContextVars(a,b){return GetContext(a).find("[contextvarid="+b+"]")}function GetContextVarOldValue(a){a=a.attr("oldvalue");if(void 0==a||""==a)a=0;return a}function GetContextVarValue(a,b){var c=void 0;void 0!=a&&"checkbox"!==a.attr("type")&&(c=a.is("span")?a.text():$.getVal(a),c=$.parseBigDecimal(c),void 0===c||isNaN(c))&&(c=b.Find(GetContextVarIdentifier(a)));return c}
function GetContextIdentifier(a){return a.attr("contextid")}function GetContextVarIdentifier(a){return a.attr("contextvarid")}function FillSandBoxItems(a,b,c){b.restrictedContextId=a.attr("restrictedctxt");a=GetContextVars(a);void 0!=a&&a.each(function(){var a=$(this);b.AddValue(GetContextVarIdentifier(a),a,GetContextVarValue(a,c),GetContextVarOldValue(a))})}
function FillSandBoxItemsPreviousValues(a,b,c){a=GetContextVars(a);void 0!=a&&a.each(function(){var a=$(this);b.AddValue(GetContextVarIdentifier(a),a,GetContextVarOldValue(a,c))})}function GetParentContext(a){a=a.attr("parentcontextid");var b=void 0;void 0!=a&&""!=a&&(b=GetContext(a));return b}
function CreatePreviousValuesSandBox(a,b){var c=GetContext(a);if(void 0!=c){var d=new SandBox(a);FillSandBoxItemsPreviousValues(c,d,b);c=GetParentContext(c);void 0!=c&&CreatePreviousValuesSandBoxRecursive(c,d,b);return d}}function CreatePreviousValuesSandBoxRecursive(a,b,c){b=b.CreateContainerSandBox(GetContextIdentifier(a));FillSandBoxItemsPreviousValues(a,b,c);a=GetParentContext(a);return void 0!=a?CreatePreviousValuesSandBoxRecursive(a,b,c):b}
function CreateSandBox(a,b){var c=GetContext(a);if(void 0!=c){var d=new SandBox(a);FillSandBoxItems(c,d,b);c=GetParentContext(c);void 0!=c&&CreateSandBoxRecursive(c,d,b);return d}}function CreateSandBoxRecursive(a,b,c){b=b.CreateContainerSandBox(GetContextIdentifier(a));FillSandBoxItems(a,b,c);a=GetParentContext(a);return void 0!=a?CreateSandBoxRecursive(a,b,c):b};
