/**
 * 
 * 
 * 
 */
TWyborRodzajuOgloszenia = function()
{
	var param =	{className:'rodzaje_ogloszen'};	
	for (var i in arguments[0]) if (typeof(arguments[0][i]!= 'function')) param[i]=arguments[0][i];
	
	this.obj			= _c('div',param);
	this.obj.AJAXsrc	= '/strona_v2/ajax/wybor_rodzaju_ogloszenia/';	
	this.obj.rysuj = function( dane )
	{
		this.opcje_w	=_c('div',{parent:this,className:'opcje_w'});

		this.naglowek	= _c('h4',{className:'naglowek_opcje'});
		
		this.bezplatne	= new TRodzajIkona( {parent:this, tytul:'drobne', title:'ogłoszenie drobne' });
		this.pogrubione	= new TRodzajIkona( {parent:this, tytul:'pogrubione',title:'ogłoszenie pogrubione'} );
		this.z_haslem 	= new TRodzajIkona( {parent:this, tytul:'z hasłem',title:'ogłoszenie z hasłem'} );
		this.podswietlone 	= new TRodzajIkona( {parent:this, tytul:'z tłem',title:'ogłoszenie z tłem'} );
		this.z_malejaca = new TRodzajIkona( {parent:this, tytul:'z ceną malejącą',title:'ogłoszenie z ceną malejącą'} );
		this.z_aukcja	= new TRodzajIkona( {parent:this, tytul:'aukcja',title:'ogłoszenie z aukcją'} );
		
		this.link_do_podgladu = new TOprawkaDefault();
		
		this.hideAll();
		this.setActive();
		
		this.naglowek.apC(_cTxt('Wybierz rodzaj ogłoszenia'));
		
		this.opcje_w.apC(this.naglowek);
		this.opcje_w.apC(this.bezplatne);
		this.opcje_w.apC(this.pogrubione);
		this.opcje_w.apC(this.z_haslem);
		this.opcje_w.apC(this.podswietlone);
		//this.opcje_w.apC(this.z_malejaca);
		//this.opcje_w.apC(this.z_aukcja);
		
		this.wyr	= _c('div',{className:'wyroznienia_ogloszenia'});
		this.oglB1	= _c('div',{className:'ogloszenie_b',id:'ogloszenie_b1'});
		this.oglB2	= _c('div',{className:'ogloszenie_b',id:'ogloszenie_b2'});

		this.wyroznienie	= _c('div',{className:'wyroznienie'});
		this.naglowek1 = _c('h4',{parent:this,className:'naglowek_haslo'});
		this.naglowek1.apC( _cTxt('Podgląd ogłoszenia'));
		this.wyr.apC(this.naglowek1);
				
		this.lupa	= _c('a',{parent:this,href:'/strona_v2/form/fullpodglad',className:'fullview',title:'pełny widok ogłoszenia'});
		
		this.tol	= _c('div',{className:'twoje_ogloszenie_l'});
		this.top	= _c('div',{className:'twoje_ogloszenie_p'});
		
		this.to_txt = _c('div',{className:'twoje_ogloszenie_text_l'});
		this.to_txt.apC( _cTxt('Twoje ogłoszenie') );
		
		this.to2_txt = _c('div',{className:'twoje_ogloszenie_text_p'});
		this.to2_txt.apC( _cTxt('Twoje ogłoszenie') );
		
		this.tol.apC( this.to_txt );
		this.top.apC( this.to2_txt );
		
		this.wyr.apC(this.oglB1);
		//this.wyr.apC(this.lupa);
		this.wyr.apC(this.tol);
		this.wyr.apC(this.wyroznienie);
		this.wyr.apC(this.top);
		this.wyr.apC(this.oglB2);
		
		
		this.haslo = new TFormHaslo();
		this.haslo.hide();
		
		this.apC(this.wyr);
		this.apC(this.link_do_podgladu);
		this.apC( this.haslo );
		this.apC(this.opcje_w);
		
				
		this.bezplatne.onclick = function()
		{
			this.parent.setActive( 0 );
			//try {motyw.play('ogl_bezplatne')} catch(e){ }
			this.parent.setTyp(0);
			this.parent.oglWyroznione.setBezplatne();
			this.parent.haslo.hide();
			//--
			//szczegoly_emisji.handle.show();
			//szczegoly_emisji.zmiana_emisji.hide();
			_get('oprawa_kalendaria').style['display'] = "none";
		}
		this.pogrubione.onclick = function()
		{
			this.parent.setActive( 1 );
			//try {motyw.play('ogl_pogrubione')} catch(e){ }
			this.parent.haslo.hide();
			this.parent.setTyp(1);
			this.parent.oglWyroznione.setPogrubione();
			//--
			//szczegoly_emisji.handle.show();
			//szczegoly_emisji.zmiana_emisji.show();
			_get('oprawa_kalendaria').style['display'] = "none";
		}
		this.z_haslem.onclick = function()
		{
			this.parent.setActive( 2 );
			//try {motyw.play('ogl_z_haslem')} catch(e){ }
			this.parent.setTyp(2);			
			this.parent.oglWyroznione.setZdjecieHasloTextPogrubione();
			this.parent.haslo.show();
			//--
			//szczegoly_emisji.handle.show();
			//szczegoly_emisji.zmiana_emisji.show();
			_get('oprawa_kalendaria').style['display'] = "none";
		}
		this.podswietlone.onclick = function()
		{
			this.parent.setActive( 30 );
			//try {motyw.play('ogl_z_haslem')} catch(e){ } //-- niema dzwieku do tego produktu
			this.parent.setTyp(30);			
			//this.parent.oglWyroznione.setZdjecieHaslo();
			//this.parent.oglWyroznione.setZdjecie();
			this.parent.oglWyroznione.setPodswietlone();
			this.parent.haslo.hide();
			//this.parent.haslo.show();
			//--
			//szczegoly_emisji.handle.show();
			//szczegoly_emisji.zmiana_emisji.show();
			_get('oprawa_kalendaria').style['display'] = "none";
		}
		this.z_malejaca.onclick = function()
		{
			this.parent.setActive( 9 );
			//try {motyw.play('ogl_z_cena_malejaca')} catch(e){ }
			this.parent.setTyp(9);
			this.parent.oglWyroznione.setMalejaca();
			this.parent.haslo.hide();
			//--
			//szczegoly_emisji.handle.show();
			//szczegoly_emisji.zmiana_emisji.show();
			_get('oprawa_kalendaria').style['display'] = "none";
		}
		this.z_aukcja.onclick = function()
		{
			this.parent.setActive( 10 );
			//motyw.play('ogl_z_aukcja')
			this.parent.setTyp(10);
			this.parent.oglWyroznione.setAukcja();
			this.parent.haslo.hide();
			//--
			//szczegoly_emisji.handle.show();
			//szczegoly_emisji.zmiana_emisji.show();
			_get('oprawa_kalendaria').style['display'] = "none";
		}
			
		if (dane != undefined){	this.update( dane ); }
	}

	/** Wysłanie rodzaju ogłoszenia do sesji */
	this.obj.setTyp = function(value)	
	{
		setByAjax( '/strona_v2/ajax/set/', this, {'typ' : encodeURI(value)} );
	}	
	
	
	this.obj.load = function( dane ){ this.update( dane ); }
	
	this.obj.update = function( dane )
	{
		if (dane == undefined) return false;

		this.oglBezplatne	= new TOgloszenie({link_aktiv:false,kropki:false});
		this.oglBezplatne.AJAXsrc = '/strona_v2/ajax/ogloszenie_do_podgladu/';
		this.oglBezplatne.getByAjax();
		this.oglBezplatne.setBezplatne();
		this.oglB1.apC(this.oglBezplatne);

		this.oglWyroznione	= new TOgloszenie({parent:this,link_aktiv:false,kropki:false});
		this.oglWyroznione.load( dane['ogloszenie'] );
		this.wyroznienie.apC(this.oglWyroznione);

		this.oglBezplatne2	= new TOgloszenie({link_aktiv:false,kropki:false});
		this.oglBezplatne2.AJAXsrc = '/strona_v2/ajax/ogloszenie_do_podgladu';
		this.oglBezplatne2.getByAjax();
		this.oglBezplatne2.setBezplatne();
		this.oglB2.apC(this.oglBezplatne2);
		
	
	
		
		if(dane['typ'] != undefined) this.setActive(dane['typ']);
		
		this.hideAll();
		//-- ukryj przyciski niedostępne;
		for (var i in dane['dostepne_rodzaje_ogloszen'])
		{
			var d = dane['dostepne_rodzaje_ogloszen'][i];
			if (typeof(d)=='function') continue;
			switch (parseInt(d))
			{
				case 0	: this.bezplatne.show(); break; 
				case 1	: this.pogrubione.show(); break;
				case 2	: this.z_haslem.show(); break; 
				case 30	: this.podswietlone.show(); break;
				case 9	: this.z_malejaca.show(); break;
				case 10	: this.z_aukcja.show(); break; 
			}
		}
		
	}
	this.obj.hideAll	= function()
	{
		this.bezplatne.hide();
		this.pogrubione.hide();
		this.z_haslem.hide();
		this.z_malejaca.hide();
		this.z_aukcja.hide();
		this.podswietlone.hide();
	}	
	this.obj.setActive = function( val )
	{
		this.bezplatne.setClassName( 'bezplatne' );
		this.pogrubione.setClassName( 'pogrubione' );
		this.z_haslem.setClassName('z_haslem');
		this.podswietlone.setClassName('podswietlone');
		this.z_malejaca.setClassName('z_malajaca');
		this.z_aukcja.setClassName('z_aukcja');
		
		switch ( parseInt(val) )
		{
			case 0: this.bezplatne.setClassName('c_bezplatne'); break;
			case 1: this.pogrubione.setClassName('c_pogrubione'); break;
			case 2: this.z_haslem.setClassName('c_z_haslem');	break;
			case 30: this.podswietlone.setClassName('c_podswietlone');	break;
			case 9: this.z_malejaca.setClassName('c_z_malajaca'); break;
			case 10: this.z_aukcja.setClassName('c_z_aukcja'); break;
		}
	}
	this.obj.onSetByAjaxEnd = function(){ szczegoly_emisji.getByAjax();	}
	
	this.obj.rysuj();
	return this.obj;
}


TRodzajIkona	= function()
{
	var param =	{ tytul:'tytuł', className:'iko', ikona:'bezplatne_iko' };	
	for (var i in arguments[0]) if (typeof(arguments[0][i]!= 'function')) param[i]=arguments[0][i];

	var obj	= _c('div',param);
	obj.ikona		= _c('span',{className:obj.ikona})
	obj.div_tytul	= _c('div',{className:'title'});
	obj.div_tytul.apC( _cTxt( obj.tytul ) );
	obj.apC( obj.ikona );
	obj.apC( obj.div_tytul );
	obj.setClassName = function( className ){ this.ikona.className = className; }
	return obj;
}

TOprawkaDefault = function()
{
	var param =	{ className:'link_podglad',title:'pełny widok ogłoszenia' };	
	for (var i in arguments[0]) if (typeof(arguments[0][i]!= 'function')) param[i]=arguments[0][i];

	//this.obj			= _c('div', param);
	this.obj			= _c('a',{parent:this,href:'/strona_v2/form/fullpodglad',title:'pełny widok ogłoszenia',className:'link_podglad',title:'pełny widok ogłoszenia'});
	this.obj.AJAXsrc	= '';
	
	this.obj.rysuj = function( dane )
	{
		this.d_text		= _c('div',{parent:this,className:'HasloInputTextLinkPodglad'});
		this.ikona		= _c('div',{parent:this,className:'link_podglad_ikonka',title:'Zatwierdź'})
		this.zatwierdz	= _c('img',{parent:this,src:'/images/01/80p/podgladogloszenia.png'});
		
		this.ikona.apC( this.zatwierdz );
	
		this.d_text.apC( _cTxt('pełen podgląd') );
	
		this.dopodgladu	= _c('div',{parent:this,className:'dopodgladu'});
		this.add_h_btn	= _c('div',{parent:this,className:'btn'});
		this.bl	= _c('div',{parent:this,className:'btn btn_l'});
		this.bc	= _c('div',{parent:this,className:'btn btn_c'});
		this.bp	= _c('div',{parent:this,className:'btn btn_p'});
		
		//this.d_text.apC( this.pole_haslo );
		this.bc.apC( this.ikona );
		this.bc.apC(this.d_text);
		
		this.dopodgladu.apC(this.add_h_btn);
		this.add_h_btn.apC( this.bl );
		this.add_h_btn.apC( this.bc );
		this.add_h_btn.apC( this.bp );
		
		this.apC(this.dopodgladu);
	}
	this.obj.onclick = function()
	{
		
	}
	
	
	
	
	this.obj.rysuj();
	return this.obj;	
}

TFormHaslo = function()
{
	var param =	{ className:'HasloInput' };	
	for (var i in arguments[0]) if (typeof(arguments[0][i]!= 'function')) param[i]=arguments[0][i];

	this.obj			= _c('div', param);
	this.obj.AJAXsrc	= '';
	var max_liczba_znakow = 20;
	var min_liczba_znakow = 4;
	
	this.obj.rysuj = function( dane )
	{
		this.naglowek	= _c('h4',{className:'naglowek_haslo2'});
		this.d_text		= _c('div',{parent:this,className:'HasloInputText'});
		this.pole_haslo	= _c('input',{parent:this, className:'i',name:'haslo',value:'',maxLength:max_liczba_znakow});
		this.ikona		= _c('div',{parent:this,className:'haslo_ikonka',title:'Zatwierdź'})
		this.zatwierdz	= _c('img',{parent:this,src:'/images/01/80p/j-ok.png'});
		this.div_liczba_znakow	= _c('div',{parent:this,className:'znaki'});
		
		this.ikona.apC( this.zatwierdz );
	
		this.add_haslo	= _c('div',{parent:this,className:'add_haslo'});
		this.add_h_btn	= _c('div',{parent:this,className:'btn'});
		this.bl	= _c('div',{parent:this,className:'btn btn_l'});
		this.bc	= _c('div',{parent:this,className:'btn btn_c'});
		this.bp	= _c('div',{parent:this,className:'btn btn_p'});
		
		this.d_text.apC( this.pole_haslo );
		this.bc.apC(this.d_text);
		this.bc.apC( this.ikona );
		this.add_h_btn.apC( this.bl );
		this.add_h_btn.apC( this.bc );
		this.add_h_btn.apC( this.bp );
		
		this.add_haslo.apC( this.add_h_btn );
		
		this.naglowek.apC( _cTxt( 'dodaj hasło' ) );
		this.apC( this.naglowek );
		this.apC( this.add_haslo );
		
		this.apC( this.div_liczba_znakow );
		
		this.wynik = function(){
			var hasloLength = this.pole_haslo.value.length;
			return max_liczba_znakow - hasloLength;
		}
		this.ikona.onclick = function()	{ this.parent.changeHaslo(); }
		this.pole_haslo.onblur = function()	{ this.parent.changeHaslo(); }
		this.pole_haslo.onfocus = function(){motyw.play('wpisz_haslo');}

		this.pole_haslo.onkeyup	= function(e)		
		{
			this.parent.keydownHandler(e)
			
			if (this.parent.wynik() == 1)
				this.parent.div_liczba_znakow.innerHTML = 'pozostało: ' + this.parent.wynik() + ' znak';
			if (this.parent.wynik() >= 2 && this.parent.wynik() <= 4 )
				this.parent.div_liczba_znakow.innerHTML = 'pozostało: ' + this.parent.wynik() + ' znaki';
			if (this.parent.wynik() > 4)
				this.parent.div_liczba_znakow.innerHTML = 'pozostało: ' + this.parent.wynik() + ' znaków' ;
		}
		if (dane != undefined){	this.update( dane ); }
	}
	
	this.obj.update = function( dane )
	{

	}
	
	this.obj.changeHaslo = function()
	{
		if (this.pole_haslo.value.length >= min_liczba_znakow && this.pole_haslo.value.length <= max_liczba_znakow) {
			this.setHaslo();
		}
		else{ this.unsetHaslo(); }
	}
	this.obj.unsetHaslo = function()
	{
		var h = document.getElementsByClassName('haslo_ogl');
		h[1].innerHTML  = '';
		setByAjax( '/strona_v2/ajax/set/', this.id,{'zatwierdz_haslo' : ''} );
	}
	this.obj.setHaslo = function()
	{
		wz = /[~@#$'`%^&\*":;?=\\[\]\{\}\\(\)\\\/\_\-\<\>+\d]/gi;
		var wynik = this.pole_haslo.value.replace(wz,"");
		var h = document.getElementsByClassName('haslo_ogl');
		
		//-- w przypadku trzech ogłoszeń na podglądzie
		h[1].innerHTML  = wynik.toUpperCase();
		//
		//-- w przypadku jednego ogłoszenia na podglądzie
		//h[0].innerHTML  = wynik.toUpperCase();
		setByAjax( '/strona_v2/ajax/set/', this.id,{'zatwierdz_haslo' : encodeURI(wynik.toLowerCase())} );
	}
	
	this.obj.keydownHandler = function(e)
	{
		var evt = e ? e : event;
		var keyCode = evt.keyCode;
		if (keyCode == 13) 
		{
			if (this.pole_haslo.value.length >= min_liczba_znakow && this.pole_haslo.value.length <= max_liczba_znakow) {
				this.setHaslo();
			}
			else { this.unsetHaslo(); }
		}
		else return false;
	}
	
	this.obj.rysuj();
	return this.obj;	
}



