
function executeAction( name, args )
{
	_ajxExecuteAction( name, args );
};

function executeActionSendAll( name )
{
	flushEditors();
	_ajxExecuteAction( name, xajax.getFormValues( { tagName : 'FORM', elements : jQuery( 'body :input' ).get() } ) ); // need this to trick xajax into thinking that it is form node
};

function executeGearSendAll( name, args )
{
	flushEditors();
	_ajxExecuteGear( name, xajax.getFormValues( { tagName : 'FORM', elements : jQuery( 'body :input' ).get() } ), args ); // need this to trick xajax into thinking that it is form node
};

function refreshGear( name, filter )
{
	_ajxRefreshGear( name, filter );
};

function refreshChart( name )
{
	var now = new Date().getTime() / 1000;
	var auxAnchor = document.createElement('a');
	auxAnchor.href = _(name).src;
	var new_chart_source = auxAnchor.protocol + '//' + auxAnchor.hostname + auxAnchor.pathname + '?' + now;
	_(name).src = new_chart_source;
};

function refreshCaptcha( name )
{
	var dt = new Date();
	jQuery('#kcptch_'+name).attr('src', '/kcptch/register?'+dt.getTime());
}

function flushEditors()
{
	for ( var i in CKEDITOR.instances )
	{
		jQuery('#'+CKEDITOR.instances[i].name).val( CKEDITOR.instances[i].getData() );
	}	
}

var CYCImage = function( id )
{
	
	// constructor {
		this._elem = el( id );
		if( this._elem == null )
		{
			this._elem = new Image();
		}
	// }
	
	this.loadImage = function( name )
	{
//		_ajxLoadImage( name, this._elem.id );
	};
	
	this.reload = function()
	{
		var orgSrc = this.src().replace( /([?&])rnd=[0-9.]*/g, '' ); // remove old rnd=
		if( orgSrc.indexOf( '?' ) == -1 )
		{
			orgSrc += '?';
		}
		else
		{
			orgSrc += '&';
		}
		orgSrc += 'rnd=' + Math.random();
		this.setSrc( orgSrc );
	}
	
};

CYCImage.prototype = new CImage();

function _handleEvent( obj, evtname, evt )
{
	if( window.pageLoaded === false )
	{
		return false;
	}
	var mectl, meevt, objname;
	if( obj == document )
	{
		mectl = obj;
		objname = 'application';
		meevt = null;
	}
	else
	{
		mectl = ctl( obj );
		objname = mectl.id();
		if( mectl == null )
		{
			throw new Error( 'No constructor defined for control type: ' + _getCtlType( obj ) );
		}
		meevt = new CEvent( evt );
	}
	var args = [ mectl ];
	switch( evtname )
	{
		case 'onmousemove':
			args.push( meevt.clientX(), meevt.clientY() );
		break;

		case 'onmousedown':
		case 'onmouseup':
			args.push( meevt.clientX(), meevt.clientY(), meevt.mouseButtons() );
		break;

		case 'onmouseover':
			args.push( meevt.fromElement() );
		break;

		case 'onmouseout':
			args.push( meevt.toElement() );
		break;
	}
	args.push( meevt );
	try
	{
		var func = window[ objname + '_' + evtname ];
		if( func )
		{
			return func.apply( window, args );
		}
	}
	catch( e )
	{
		alert(
			'Your script contains an error!\n'
			+ '\n'
			+ '    Please review \'' + evtname + '\' event handler for object \'' + objname + '\'\n'
			+ '\n'
			+ 'Information about this error:\n'
			+ '\n'
			+ '    ' + e.message + '\n'
		);
		return false;
	}
};

/*
 * Try to handle some javascript errors. Unfortunately this doesn't handle syntax errors.
 */
//window.onerror = function( msg, file, line )
//{
//	if( msg == 'uncaught exception: Permission denied to get property HTMLDivElement.nodeName' ) // weird firefox ?bug?
//	{
//		return;
//	}
//	return true; // do not use internal browser error handling
//};

function jooxbrUnsupportedHandler( msg )
{
	alert(
		'Unfortunately you browser doesn\'t support some features used by GYRE.\n'
		+ 'Also there is a possibility that you disabled some of them for security sake.\n'
		+ 'If it is the case then please enable them for application to work correctly.\n'
		+ '\n'
		+ 'The missing features are:\n'
		+ msg
	);
};

function today()
{
	var date = new Date();
	return date.getMonth() + '/' + date.getDay() + '/' + date.getFullYear();
};
