Array.prototype.inArray = function (value) {
	var i;
	for (i=0; i < this.length; i++) {
		if (this[i] === value) {
			this.lastInx = i;
			return true;
		}
	}
	return false;
};

function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

var PXC_Request = {

	httpRequest: false,
	reqType: null,

	init: function( type )
	{
		if (window.XMLHttpRequest) {
			this.httpRequest = new XMLHttpRequest();
			if (this.httpRequest.overrideMimeType) {
				this.httpRequest.overrideMimeType(type == 'get' ? 'text/plain'  : 'text/html');
			}
		} else if (window.ActiveXObject) {
			try {
				this.httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
				try {
					this.httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (e) {}
			}
		}
		if (!this.httpRequest) {
			alert('XMLHttpRequest FAIL');
			return false;
		}
	},

	get: function( url, type )
	{
		this.reqType = type;
		this.init('get');
		this.httpRequest.open('GET', url, true);
		this.httpRequest.onreadystatechange = Request.exe;
		this.httpRequest.send(null);
	},

	getSync: function( url )
	{
		this.init('get');
		this.httpRequest.open('GET', url, false);
		this.httpRequest.send(null);
		return this.httpRequest.responseText;
	},

	post: function( url, parameters, type )
	{
		this.reqType = type;
		this.init('post');
		this.httpRequest.open('POST', url, true);
		this.httpRequest.onreadystatechange = this.exe;
		this.httpRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=windows-1250");
		this.httpRequest.setRequestHeader("Content-length", parameters.length);
		this.httpRequest.setRequestHeader("Connection", "close");
		this.httpRequest.send(parameters);
	},

	exe: function()
	{
		if (this.httpRequest.readyState == 4) {
			if (this.httpRequest.status == 200) {
				if ( this.reqType == 'alert' )
					return alert(this.httpRequest.responseText);
				else if ( this.reqType == 'raw')
					return this.httpRequest.responseText;
				else
					return eval(this.httpRequest.responseText);
			} else {
				alert('There was a problem with the request.');
			}
		}
	}
}

var PXC_Event = {

    dispatch: function ( inputObj, inputEvent )
    {
        if ( inputObj.fireEvent ) {
            inputObj.fireEvent( 'on'+inputEvent );
        } else if( document.createEvent ) {
            var evt = document.createEvent( 'HTMLEvents' );
            evt.initEvent( inputEvent, true, true );
            inputObj.dispatchEvent( evt );
        }
    },

    attach: function ( pElement, pEvent, pHandler )
    {
        if ( typeof window.addEventListener != 'undefined' )
            pElement.addEventListener( pEvent, pHandler, false );
        else
            pElement.attachEvent( 'on'+pEvent, function() { pHandler.call( pElement, event ) }, false );
    },

    detach: function setEventHandler( pElement, pEvent, pHandler )
    {
        if ( typeof window.removeEventListener != 'undefined' )
            pElement.removeEventListener( pEvent, pHandler, false );
        else
            pElement.detachEvent( 'on'+pEvent, pHandler);
    }
}

var PXC_Watch = {

	attach: function( objElm, strProperty, callbackFunc )
	{
		objElm['def_'+strProperty] = objElm[strProperty];
		if ( !objElm.iRefWatch )
			objElm.iRefWatch = {};
		if ( !objElm.iRefWatch[strProperty] )
			objElm.iRefWatch[strProperty] = {};
		if ( !objElm.iRefWatch[strProperty].rptCnt )
			objElm.iRefWatch[strProperty].rptCnt = 0;
		if ( !objElm.iRefWatch[strProperty].rptClient )
			objElm.iRefWatch[strProperty].rptClient = 1;
		objElm.iRefWatch[strProperty].rptCnt++;
		objElm.iRefWatch[strProperty][ encodeURI( callbackFunc.toString().substr( 0, 128 ) ) ] = setInterval (
			function() {
				if ( objElm[strProperty] != objElm['def_'+strProperty] ) {
					if ( objElm.iRefWatch[strProperty].rptClient == objElm.iRefWatch[strProperty].rptCnt ) {
						objElm.iRefWatch[strProperty].rptClient = 1;
						objElm['def_'+strProperty] = objElm[strProperty];
					} else
						objElm.iRefWatch[strProperty].rptClient++;

					callbackFunc.call( objElm );
				}
			},
			100
		);
	},

	detach: function( objElm, strProperty, callbackFunc )
	{
		var ref = objElm.iRefWatch[strProperty][ encodeURI( callbackFunc.toString().substr( 0, 128 ) ) ];
		if ( ref ) {
			clearInterval( ref );
			delete objElm.iRefWatch[strProperty][ encodeURI( callbackFunc.toString().substr( 0, 128 ) ) ];
			objElm.iRefWatch[strProperty].rptCnt--;
		}
	}
};

function getObj(id)
{
	return document.getElementById(id);
}

function getObjByName(name)
{
	return document.getElementsByName(name)[0];
}