﻿//IsNull(Value)
//getElementById(Id)
//getElementByTag(Owner, Tag)
//createElement(Name)
//createTextNode(Text)
//createTable(className)
//createCaption(className)
//createRow(className)
//createCell(className)
//getAttrValue(ownerAttr, Index)
//addChild(Owner, Child)
//newCell(className, Value) - возвращает новую ячейку с присвоенным значением

//createXMLHttpRequest() - Создать запрос

function IsNull(Value) {
    return Value == null;
}

function getElementById(Id) {
	return document.getElementById(Id);
}

function getElementByTag(Owner, Tag) {
	return Owner.getElementsByTagName(Tag);
}

function createElement(Name) {
	return document.createElement(Name);
}

function createTextNode(Text) {
	return document.createTextNode(Text);
}

function createTable(className) {
	var Result = createElement("table");
	Result.className = className;
	return Result;
}

function createCaption(className) {
    var Result = createElement("caption");
	Result.className = className;
	return Result;
}

function createRow(className) {
    var Result = createElement("tr");
	Result.className = className;
	return Result;
}

function createCell(className) {
    var Result = createElement("td");
	Result.className = className;
	return Result;
}

function getAttrValue(ownerAttr, Index) {
	return ownerAttr.attributes[Index].nodeValue;
}

function addChild(Owner, Child) {
	Owner.appendChild(Child);
}

function newCell(className, Value) {
	var Result = createCell(className);
	addChild(Result, Value);
	return Result;
}

//Создать запрос
function createXMLHttpRequest() {
  var Result = null;
  try {
     Result = new XMLHttpRequest();
  } 
  catch (trymicrosoft) {
    try {
      Result = new ActiveXObject("Msxml2.XMLHTTP");
    } 
    catch (othermicrosoft) {
      try {
        Result = new ActiveXObject("Microsoft.XMLHTTP");
      } 
      catch (failed) { return null; }
    }
  }
  return Result;
}

var pxNum = new pxNumber();

function pxNumber() {

}

pxNumber.prototype.formatCurr = function(value) {
  var result = "";
  var comma = value.indexOf(".");
  var tempValue = value;
  if (comma >= 0) tempValue = value.substring(0, comma);
  var dot = String.fromCharCode(160);  
  var k = 0;
  for(var i = tempValue.length - 1; i >= 0; i--) {
    result = tempValue.charAt(i) + result;
    if (k == 2 && i > 0) {
      result = dot + result;
      k = -1;
    }
    k++;
  }
  if (comma >= 0) return result + "," + value.substring(comma + 1, value.length);
  return result;
}

pxNumber.prototype.creditFee = function(Summa, rate, period, indulgence) {
  if (isNaN(parseFloat(rate))) return "";
  var ps = (rate / 100) / 12;
  var x = ps / (1 - Math.pow((1 + ps), -(period - indulgence) ));
  
  return (Summa * x).toFixed(2);  
}
