
function showFlashMessage( title, message, message_options )
{	
	var sufix = Math.round( new Date().getTime() / 1000 );
	var message_id = "flash_message_" + sufix;
	
	var html_code = '<div id="' + message_id + '" title="' + title + '">';
	html_code += '<p>';
	
	if ( typeof( message_options ) == 'object' && message_options.type != '' )
	{
		html_code += '<span class="ui-icon ui-icon-info" style="float:left; margin:0 7px 50px 0;"></span>';
	}
	html_code += message;
	html_code += '</p>';
	html_code += '</div>';
	
	var width = "auto";
	var height = "auto";
	var modal = true;
	var show_title = true;
	var show_button = true;
	var auto_hide = 0;
	if ( typeof( message_options ) == 'object' )
	{
		if ( typeof( message_options.width ) != "undefined" )
			width = parseInt( message_options.width );
		if ( typeof( message_options.height ) != "undefined" )
			height = parseInt( message_options.height );
		if ( typeof( message_options.modal ) != "undefined" )
			modal = message_options.modal;
		if ( typeof( message_options.show_title ) != "undefined" )
			show_title = message_options.show_title;
		if ( typeof( message_options.show_button ) != "undefined" )
			show_button = message_options.show_button;
		if ( typeof( message_options.auto_hide ) != "undefined" )
			auto_hide = parseInt( message_options.auto_hide );
	}
	
	var buttons = {
				"  ok  ": function() {
					$( this ).dialog( 'close' );
				},
				"  cancel  ": function() {
					$( this ).dialog( 'close' );
				}
			};
	if ( !show_button )
		buttons = null;
	$( "body" ).append( html_code );
	$( "#" + message_id ).dialog( 
		{
			bgiframe: true,
			modal: modal,
			width: width,
			height: height,
			buttons: buttons
		}
	);
	
	if ( show_title == false )
		$( "div.ui-dialog-titlebar" ).remove();
	if ( auto_hide > 0 )
	{
		setTimeout( "hideFlashMessage( '" + message_id + "' )", auto_hide );
	}

}

function hideFlashMessage( message_id )
{
	$( "#" + message_id ).dialog( 'close' );
}

function validate_email(email)
{
	var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (filter.test(email)) 
	{
		return true;
	}
	return false;
}

function showBacktestResults(el)
{
	var href = $(el).attr("href");
	var title = $(el).attr("title");
	var iframe = '<div id="backtest_results" title="' + title + '"><iframe height="400" width="840" src="' + href + '" frameborder="0" marginheight="0" marginwidth="0"></iframe>';
	
	$("#backtest_results").remove();
	$("body").append(iframe);
	$("#backtest_results").dialog( 
		{
			modal: true,
			width: 870,
			//height: 500,
			buttons: {
				Close: function() {
					$( this ).dialog( "close" );
				}
			}
		}
	);
	
	return false;
}

function showBacktestResults2(href, title)
{
	var iframe = '<div id="backtest_results" title="' + title + '"><iframe height="400" width="840" src="' + href + '" frameborder="0" marginheight="0" marginwidth="0"></iframe>';
	
	$("#backtest_results").remove();
	$("body").append(iframe);
	$("#backtest_results").dialog( 
		{
			modal: true,
			width: 870,
			//height: 500,
			buttons: {
				Close: function() {
					$( this ).dialog( "close" );
				}
			}
		}
	);
	
	return false;
}

function showForexComboTradesBigImage()
{
	var trades = '<div id="forex_combo_trades" title="How The Forex COMBO System Trades Look Like"><img src="/images/forex_combo_system_trades_big.png" alt="Forex Combo System Trades" title="Forex Combo System Trades" border="0" /></iframe>';
	
	$("#forex_combo_trades").remove();
	$("body").append(trades);
	$("#forex_combo_trades").dialog( 
		{
			modal: true,
			width: 1050,
			height: 590,
			buttons: {
				Close: function() {
					$( this ).dialog( "close" );
				}
			}
		}
	);
	
	return false;
}

function checkSubscriptionForm( form_name )
{
	var name = $( "#" + form_name + "_subscription_name" ).val();
	var email = $( "#" + form_name + "_subscription_email" ).val();
	var errors = Array();
	
	if( name == "" || name.length < 3 )
	{
		errors[errors.length] = "<li>Your Name is empty or too short!</li>";
	}
	
	if( !validate_email( email ) )
	{
		errors[errors.length] = "<li>Your Email address is not valid!</li>";
	}
	
	if( errors.length > 0 )
	{
		var errors_str = errors.join(" ");
		showFlashMessage( "Attention", "There was a problem with one or more of the form fields!<br><ul>" + errors_str + "</ul>", {"show_title":true,"modal":true,"width":400,"auto_hide":0,"show_button":true} );
		return false;
	}
	else
		return true;
		
}

