Object.prototype.isArray = function()
{
	if (this.assocArray) return true;
	else return this instanceof Array;
}

Object.prototype.extentions = new Array('assocArray', 'isArray', 'extentions');

Array.prototype.inArray = function( item, equality )
{
	if (!equality) equality = function(a, b) { return a == b; }
	var i = this.length;
	if (i > 0) do { --i; if (equality(this[ i ], item)) return true; } while (i);
	return false;
}

if (!Array.prototype.indexOf) Array.prototype.indexOf = function( item, equality )
{
	if ( !equality ) equality = function( a, b ) { return a == b; };
	var i = this.length - 1;
	if ( i >= 0 ) do
	{
		if ( equality( this[ i ], item ) ) return i;
	} while ( i-- );
	return i;
}

Array.prototype.removeAt = function(index)
{
	if (index > 0) return this.slice(0, index).concat(this.slice(index + 1));
	else if (index == 0) return this.slice(1);
	else throw new Exception();
}

Array.prototype.extentions = new Array('assocArray', 'isArray', 'extentions', 'inArray', 'indexOf', 'removeAt');

String.prototype.trim = function()
{
	var result = this.replace(/^\s\s*/, '');
	var ws = /\s/;
	var i = result.length;
	while ( ws.test( result.charAt( --i ) ) );
	return result.slice( 0, i + 1 );
}

function globalOffsetTop( obj )
{
	if ( obj.offsetTop != null )
	{
		var result = obj.offsetTop;
		if ( obj.offsetParent != null ) { var p = obj.offsetParent; while ( p != null ) { result += p.offsetTop; p = p.offsetParent; } }
		return result;
	}
	else return 0;
}

function globalOffsetLeft( obj )
{
	if ( obj.offsetTop != null )
	{
		var result = obj.offsetLeft;
		if ( obj.offsetParent != null ) { var p = obj.offsetParent; while (p) { result += p.offsetLeft; p = p.offsetParent; } }
		return result;
	}
	else return 0;
}

function getScrollY() {
  var scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
  }
  return parseInt(scrOfY);
}

function getScrollX() {
  var scrOfX = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfX = document.documentElement.scrollLeft;
  }
  return parseInt(scrOfX);
}

function applyToAllMatchedElementRec( element, px, ax )
{
	var f = function(element)
	{
		try { if ( element && element.nodeName && element.id && ("" + element.id).search( px ) != -1 ) ax( element ); } catch ( ex ) {  }
		if ( element.childNodes )
		{
			var children = element.childNodes;
			var count = children.length;
			for (var i = 0; i < count; ++i) f(children[i]);
		}
	}
	f(element);
}

function applyToAllMatchedElement( pattern, apply )
{
	applyToAllMatchedElementRec( document.body, pattern, apply );
}

//function ById(id) { return document.getElementById(id); }

Sablon = {};
Sablon.replace = function (arrayObj, string)
{
	for (var i in arrayObj) if (!Object.prototype.extentions.inArray(i)) string = string.replace(eval('/\\{\\$' + i + '\\}/g'), arrayObj[i]);
	return string.replace('\\{', '{');
}

function addOption(select, value, text)
{
	var option = document.createElement('option');
	option.text = text;
	option.value = value;
	try { select.add( option, null ); }
	catch( ex ) { select.add( option ); }
	return option;
}

function alertX(o)
{
	alert('typeof object : ' + typeof(o));
	if (typeof(o) != 'object') alert(o);
	else { var i, s = ''; for (i in o) s += i + ' : ' + o[i] + "\n"; alert(s); }
}

function isIE()
{
  return /msie/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent);
}

function getOpacity(element)
{
	var result = 1.0;
	if (element.style)
	{
		var match;
		if (!isIE() && element.style.opacity) result = parseFloat(element.style.opacity.replace(',','.'));
		else if (element.style.MozOpacity) result = parseFloat(element.style.MozOpacity);
		else if (element.filters && element.filters.alpha && element.filters.alpha.opacity) result = parseFloat(element.filters.alpha.opacity) / 100.0;
		else if (match = element.style.filter.match(/^alpha\(opacity=([0-9]{1,3})\)$/)) result = parseFloat(match[1]) / 100.0;
	}
	return result;
}

function setOpacity(element, opacity)
{
	if (element.style && element.style.display != 'none')
	{
		if (!isIE() && element.style.opacity) { /*alert('xxx');*/ element.style.opacity = opacity; }
		else if (element.style.MozOpacity) element.style.MozOpacity = opacity;
		else if (element.filters && element.filters.alpha && element.filters.alpha.opacity) { element.filters.alpha.opacity = parseInt(opacity * 100.0); /*alert(element.filters.alpha.opacity);*/ }
		else {element.style.filter = 'alpha(opacity=' + parseInt(opacity * 100.0) + ')'; }
	}
}

function postDataTo(uri, data, method)
{
	var form = document.createElement('form');
	var p = document.createElement('p');
	var input;
	if (!method) method = 'GET';
	form.method = method;
	form.action = uri;
	form.appendChild(p);
	p.style.display = 'none';
	for (var x in data) if (!Object.prototype.extentions.inArray(x))
	{
		input = document.createElement('input');
		input.type  = 'hidden';
		input.name  = x;
		input.value = data[x];
		p.appendChild(input);
	}
	document.body.appendChild(form);
	form.submit();
}

FIndexOf = function(arr, item)
{
	var i = arr.length - 1;
	if (i >= 0) do { if (arr[i] == item) return i; } while (i--);
	return i;
}
