var SpecKeys  = new Array(8,	//BackSpace
                          46,	//Delete
						  40, 38, 13, 27, 9, 39, 37, 35, 36, 20, 16, 18, 17, 33, 34);
						  
function getTimeZone()
{
		return -(new Date()).getTimezoneOffset();
}

function __do_PostBack(eventTarget, eventArgument)
{
    __doPostBack(eventTarget, eventArgument);
}

function doPostBackWithConfirm(eventTarget, Msg)
{
	if (confirm(Msg)) __doPostBack(eventTarget, '');
}

function ArrayIndexOf(Array, value)
{
	if (Array)
		for (var i = 0; i < Array.length; i++)
			if (Array[i] == value) return i;
	return -1;
}

function __isNaN(numvalue, valueIfNaN)
{
    return isNaN(numvalue) ? valueIfNaN : numvalue;
}

function getStyle(elem, prop)
{
	if (!elem)
		return null;

	if (window.getComputedStyle)
		return window.getComputedStyle(elem, '')[prop];
	else if (elem && elem.currentStyle)
		return elem.currentStyle[prop];
	else
		return elem.style[prop];
		
}

Function.createDelegate = function(instance, method) 
{
    return function() 
    {
    1;
        return method.apply(instance, arguments);
    }
}

function getWindowSize()
{
    var res = {height: 0, width: 0};
    if(window.innerWidth)
    {
       res.width = window.innerWidth;
       res.height = window.innerHeight;
    }
    else if(document.body && document.body.clientWidth)
    {
        res.width = document.body.clientWidth;
        res.height = document.body.clientHeight;
    }
    if(document.documentElement && document.documentElement.clientWidth)
    {
        res.width = document.documentElement.clientWidth;
        res.height = document.documentElement.clientHeight;
    }
    return res;
}
    

function getStylePosition(elem)
{
	if (elem)
		if (window.getComputedStyle)
		{
			if (elem.nodeName != '#document')
			{
				var cs =  window.getComputedStyle(elem, '');
				if (cs)	return cs.position;
			}
		}
		else if (elem.currentStyle)
			return elem.currentStyle.position;

	return '';
}    
    
function getOffsetPosition(elem)
{
	var res = {left: elem.offsetLeft, top: elem.offsetTop};
	var parent = elem.offsetParent;
	while(parent && getStylePosition(parent) == 'static')
	{
		res.left += parent.offsetLeft;
		res.top += parent.offsetTop;
		parent = parent.offsetParent;
	}
	return res;
}

		
function $(elementID) 
{
    return document.getElementById(elementID);
}

function decodeXML(value)
{
   return value.ReplaceAll('&amp;', '&').ReplaceAll('&lt;', '<').ReplaceAll('&gt;', '>');
}

function decodeXML2(value)
{
    return value.replace(/&gt;/gi, '>').replace(/&lt;/gi, '<').replace(/&amp;/gi, '&');
}
function encodeXML(value)
{
    return value.replace(/>/gi, '&gt;').replace(/</gi, '&lt;').replace(/&/gi, '&amp;');
}

if (typeof HTMLElement != 'undefined')
{
    HTMLElement.prototype.__defineGetter__('innerText',
		function()
		{
			var res = '';
			for(var i = 0; i < this.childNodes.length; i++)
				if (this.childNodes[i].hasChildNodes())
					res += this.childNodes[i].innerText;
				else if (this.childNodes[i].nodeValue)
					res += this.childNodes[i].nodeValue;
			return res;
		});

     HTMLElement.prototype.__defineSetter__('innerText',
		function(val)
		{
			while(this.firstChild) this.removeChild(this.firstChild);
		    this.appendChild(this.ownerDocument.createTextNode(val));
		});
}

function IsNumericKey(keyCode)
{
   return (keyCode >= 48 && keyCode <=57) || 
          (keyCode >= 96 && keyCode <=105) ||  
          ArrayIndexOf(SpecKeys, event.keyCode) != -1;
          
}


function IntValidateContol(keyCode, control)
{
  var curPos = 0;
  try
  {
    var sel = document.selection.createRange();
    sel.moveStart('textedit', -1);
    curPos = sel.text.length;
  }
  catch (ex) {}
 
  return IsNumericKey(keyCode) || 
            (curPos == 0 && control.value.indexOf("-") == -1 && control.value.indexOf("+") == -1 && (keyCode == 109 || keyCode == 107 )) ||
                (control.value.split('.').length - 1 == 0 && (keyCode == 110 || keyCode ==  190 || keyCode == 191) ); // dot separator;
         
}
		
function StrToInt(Str)		
{
    return StrToInt(Str, 0);
}

		
function StrToInt(Str, DefaultInt)		
{
    try
    {
        return parseInt(Str);
    }
    catch(ex)
    {
          return 0;
    }
    
}
