﻿Date.DaysCS = function(val) { var dp = val.split('.'); if(dp.length != 3) return -1;  return Date.UTC(dp[2],dp[1] - 1,dp[0]) / 86400000; }

Date.prototype.ToCS = function() { return this.getDate() + '.' + (this.getMonth() + 1) + '.' + this.getFullYear(); }
Date.InstanceDays = function(val) { return new Date(val * 86400000); }
Date.DiffDays = function(d1, d2) { return (d2 - d1) / 86400000; }
Date.prototype.AddDays = function(days) { var d = new Date(this); d.setDate(d.getDate() + days); return d; }
Date.prototype.InRange = function(from, to) { return from <= this && this <= to; }

function $(id) { return document.getElementById(id); }
function getTableRows(id)
{
  var c = $(id).childNodes;
  if(c.length <= 0) return undefined;
  
  var i = -1, r = [], tbf = false;
  while(++i < c.length)
  {
		if(c[i].nodeName.match(/tr/i)) { r.push(c[i]); continue; }
		if(!tbf && c[i].nodeName.match(/tbody/i)) { c = c[i].childNodes; i=-1; tbf = true; continue; }
  }
  return r;
}

function parseint(text,def) { var c = Number(text);if (isNaN(c)) return def; return c; }
function setallcb(root, checked) { var it = document.getElementById(root).getElementsByTagName('input'); for(i = 0; i < it.length; i++) it[i].checked = checked; }

function SelectByValue(ddl, val) { if(ddl.options.length <= 0) return false; for(var i = 0; i < ddl.options.length; i++) if(ddl.options[i].value == val) { ddl.selectedIndex = i; return true; } return false; }
function IndexOfValue(ddl, val) { if(ddl.options.length <= 0) return -1; for(var i = 0; i < ddl.options.length; i++) if(ddl.options[i].value == val) return i; return -1; }
