/*
 * spreadJavaScript
 * MVC model
 * 
 * (c) Lukasz Krawczyk
 * email: lukasz.krawczyk@dotagency.pl
 */
function spreadJS()
{
	this._c = null;
	this._a = null;
	this._uid = null;
	
	this.init = function()
	{	
		
		if( this._c != null && this._a != null )
		{
			var funcname = 'this.' + this._c + '_' + this._a;
			if( eval('typeof '+funcname) == 'function' )
				eval( funcname + '()' );			
		}
		
	};
	this._redirect = function( u )
	{
		window.location.href = this._baseHref + u;
	};
	// 68116022442250000000032692
	// abonament 02.2010 za #33244
	// 41zl
	this.getParam = function(name)
	{
		var s = name+'/[^/]+';
		var o = window.location.href;
		o=o.match(s);
		o=o.toString();
		x = o.split("/");
		x = parseInt(x[1]);
		return x;
	};
	
	this.urlencode = function(str) 
	{
		return escape(str).replace(/\+/g,'%2B').replace(/%20/g, '+').replace(/\*/g, '%2A').replace(/\//g, '%2F').replace(/@/g, '%40');
	};
	
	this.index_index = function()
	{
		$('#btn_login').click( function() {
			$('#form_login').submit();
		});
	};
	
	this.file_show = function()
	{
		$('#cform').submit( function() {
			var fields = $(this).serialize();
			var url = $(this).attr('action');
			$.post( url , fields, function(d) {
				if( d == '0' )
					alert('Muszą minąc 2minuty zanim dodasz kolejny komentarz');
				else if( d == '-1' )
					alert('Aby dodać komentarz - musisz być zalogowany !');
				else
				{
					$('#comments').html( d );
					$('#itarea').val('');
					//alert('Dodano komentarz');
				}
			}, 'html');
			return false;
		});
	};
	
};

var sJS = new spreadJS();
