
	/*
	 *    Beviteli mezőkben lévő szöveg eltűnés/megjelenítés
	 * 	  written by Profartis Design Kft.
	 */
	function inputToggle(event,text)
	{		
		var El = Event.element(event);		
		if(!text){ text = El.readAttribute('title'); }
		if(event.type == 'focus' && El.value == text){  El.value = ''; if(El.name=='s'){ El.addClassName('active'); }  }	
		if(event.type == 'blur' && El.value.blank()){  El.value = text; if(El.name=='s'){ El.removeClassName('active'); } }		
	}
	
	
	/*
	 *    A "Ft" típusú beviteli mezőkhöz ár-formázás
	 * 	  written by Profartis Design Kft.
	 */
	function priceFormat(event)
	{	
		var e = Event.element(event);				
		var formats = [[],[],[],[],[0],[1],[2],[0,3],[1,4],[2,5]], r = '', nn = new Array;
		var n = String(e.value.strip().replace(' ','')).toArray();				
		n.each(function(s){ if (s!=' '){nn.push(s);} });
		nn.each(function(s,i){ r += s + ( ( formats[nn.length].indexOf(i) != -1 ) ? ' ' : '' ); });
		e.value = r;
	}	


	/*
	 *    Deviza árfolyamok lekérdezése
	 * 	  written by Profartis Design Kft.
	 */
	function changeRate(obj)
	{
		var spans = $('displayRateBox').select('span');
	
		// Loading...
		spans[0].update(obj.value);
		spans[1].update('Betöltés...');
		
		// ide jön az ajax kérés...
		new Ajax.Request('/deviza.php?d='+obj.value,{
			method: 'get',
			onComplete: function(t){
				spans[1].update(t.responseText);
			}
		});
		
	}
	
	
	/*
	 *    Form ellenőrzés
	 * 	  written by Profartis Design Kft.
	 */
	function checkForm(f,send,t)
	{
		var filled = true, validEmail = true, accepted = true;
		var focusThis = false;
				
		//
		$(f).select('*').invoke('removeClassName','error');
		//					
				
		$(f).select(".required").each(function(item)
		{						
			if (!item.value){ filled = false; }
			if (item.title && item.title == item.value){ filled = false; }
			if (item.name.search('email') > -1)
			{
				if(validEmail){ validEmail = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/.test(item.value); }
			}
			if( item.type == 'checkbox' && !item.checked ){ accepted = false; }
			if( (!filled || !accepted || !validEmail) && !focusThis){ 
				focusThis = item; 
				item.addClassName('error');
				
				/* kieg. */
				if(f=='request-form'){
					item.parentNode.select('label')[0].addClassName('error');
				}
				/* */
				
			}
		});																				
	
		if(filled && validEmail && accepted){ 			
			if($(f+'-captcha')){ var nr = $(f+'-captcha').value; }
			if ($(f + '-captcha')) {
				new Ajax.Request('/captcha', {
					method: 'post',
					parameters: '&n=' + nr + '&t=' + t,
					onComplete: function(t){
						if (t.responseText == 1) {
							if (send) {
								$(f).submit();
							}
						}
						else {
							alert('Hibás ellenőrző kód!');
						}
					}
				});
			}
			else {
				if (send) {
					$(f).submit();
				}
			}
			return true; 
		}
		else 
		{			
			if(!filled){ alert('A *-al jelölt mezők kitöltése kötelező!'); } 
			else if( !validEmail ){ alert('Hibás e-mail cím!'); }
			else { alert('A továbblépéshez be kell kattintania a kötelező jelölőnégyzetet!'); }			
			//alert(focusThis.value);
			focusThis.focus();
			return false;
		}	
	}
	
	
	
	
	/*
	 *    TabSlideShow 1.0
	 *    written by Profartis Design Kft.
	 */
		
	var SlideTabs;
	var TabSlideShow = function(options)
	{
			
		this.active = 0;
		this.counter = 0;
		this.executer = null;
		this.elements = options.elements;
		this.contents = options.contents;
		this.step = options.step ? options.step : 10;						
		
		this.play = function(t)
		{
			this.counter = $$(this.elements).length-2;
			this.executer = new PeriodicalExecuter(this.next.bind(this), this.step);
			$$(this.elements+'.controls .play')[0].hide();
			$$(this.elements+'.controls .pause')[0].show();
		}						
		
		this.pause = function()
		{				
			this.executer.stop();
			$$(this.elements + '.controls .pause')[0].hide();
			$$(this.elements + '.controls .play')[0].show();	
		}
			
		this.next = function(manual)
		{				
			if(manual=='m' && this.executer){ this.pause(); }
			this.active = (this.active != this.counter) ? this.active+1 : 0;				
			this.doIt();
		}
			
		this.prev = function(manual)
		{
			if(manual=='m' && this.executer){ this.pause(); }
			this.active = (this.active != 0) ? this.active-1 : this.counter;
			this.pause();
			this.doIt();
		}
			
		this.jump = function(nr)
		{
			this.active = nr;
			if(this.executer){ this.pause(); }			
			this.doIt();
		}
			
		this.doIt = function()
		{						
			// Change tab
			$$(this.elements).invoke('removeClassName','active');
			$$(this.elements)[this.active].addClassName('active');
			
			// Change content
			$$(this.contents).invoke('hide');
			if ($$(this.contents)[this.active]) {
				$$(this.contents)[this.active].setStyle({ display: 'block' });
			}
	
		}
			
		// Auto start 
		if(options.autoplay){ this.play(); }
			
		// onClick events			
		$$(this.elements).each(function(e,i){
			if (!e.hasClassName('controls')) {
				e.observe('click', function(){ this.jump(i); }.bind(this));
			}
		}.bind(this));
			
	}
	
	
	/*
	 *    PostIcons
	 *    written by Profartis Design Kft.
	 */
	
	var PostIcons = {
		
		texts : [
			'KAPCSOLÓDÓ MŰVELETEK:',
			'KÜLDJE EL ÖN IS CIKKÜNKET ISMERŐSÉNEK!',
			'NYOMTASSA KI CIKKÜNKET!',
			'ELAKADT? KÉRDEZZE SZAKÉRTŐNKET!'
		],
				
		showText : function(i)
		{
			$$('.post-iconbox div')[0].update(PostIcons.texts[i]);
		},
		
		hideText : function()
		{
			$$('.post-iconbox div')[0].update(PostIcons.texts[0]);
		}
		
	}
	
	
	/*
	 *    Popup
	 *    written by Profartis Design Kft.
	 */
	
	var Popup = {
		
		Show : function(id,i)
		{
			var overlay = $$('.popup-overlay')[i];
		    var width = document.body.scrollWidth;
		    var height = document.body.scrollHeight;

		    var top = document.viewport.getScrollOffsets().top + Math.round((document.viewport.getDimensions().height - 500) / 2);
			
		    overlay.setStyle({
				display: 'block',
		        width: width + "px",
		        height: height+10 + "px"
		    });
			
		    $('popup-'+id).setStyle({
				display: 'block',
		        top: top + 'px'
		    });
			
		},
		
		Hide : function(id,i)
		{
			$('popup-'+id).hide();
			$$('.popup-overlay')[i].hide();
		},
		
		Send : function(id)
		{
			if (checkForm(id + '-form'))
			{			
			
				if($(id+'-captcha')){ var nr = $(id+'-captcha').value; }
				new Ajax.Request('/captcha',{
					method: 'post',
					parameters: '&n='+nr+'&t='+id,
					onComplete: function(t){
						if (t.responseText == 1) {
							$(id + '-form').getInputs('text').each(function(i){
								if(i.title && i.value == i.title){ i.value=''; }		
							});
							$(id + '-form').request({					
								onComplete: function(t){
									alert(t.responseText);
									if (t.responseText.search('nem sikerült') == -1) {
										Popup.Hide(id,( id=='for-friends' ? 0 : 1 ));
									}
								}
							});	
						} else {
							alert('Hibás ellenőrző kód!');
						}
					}
				});		
			
						
			}
		}
						
	}
	
	
	/*
	 *    Regisztráció
	 *    written by Profartis Design Kft.
	 */
	var Registration = {
		
		Show : function()
		{
			var overlay = $('popup-registration-overlay');
		    var width = document.body.scrollWidth;
		    var height = document.body.scrollHeight;

		    var top = document.viewport.getScrollOffsets().top + Math.round((document.viewport.getDimensions().height - 500) / 2);
			
		    overlay.setStyle({
				display: 'block',
		        width: width + "px",
		        height: height+10 + "px"
		    });
			
		    $('popup-registration').setStyle({
				display: 'block',
		        top: top + 'px'
		    });
			
		},
		
		Hide : function(id,i)
		{
			$('popup-registration').hide();
			$('popup-registration-overlay').hide();
		},
		
		Send : function(id)
		{
			if (checkForm(id + '-form')) {
				$(id + '-form').getInputs('text').each(function(i){
					if(i.title && i.value == i.title){ i.value=''; }		
				});
				$(id + '-form').request({					
					onComplete: function(t){
						alert(t.responseText);
						if (t.responseText.search('nem sikerült') == -1) {
							Popup.Hide(id);
						}
					}
				});
			}
		}
						
	}
	
	
	/*
	 *    Google Maps
	 *    written by Profartis Design Kft.
	 */
	
	var GoogleMaps = {
	
		address : '',
		content : '',
		zoom : 15,
		
		// FUNC: Beállítás
		Set : function(o)
		{
			GoogleMaps.address = o.addr;
			GoogleMaps.content = o.content;
			GoogleMaps.zoom = o.zoom ? o.zoom : 15;
			if(o.autoShow){ GoogleMaps.Show(); }
		},
	
		// FUNC: Map betöltése
		Load : function(){
	
	    	if (GBrowserIsCompatible()) {
				var map = new GMap2($("GMapHere"));
				var G = new GClientGeocoder();				
				G.getLocations(GoogleMaps.address, function(result){				
					if (result.Status.code == G_GEO_SUCCESS) {					
						var p = result.Placemark[0].Point.coordinates;
						var loc = new GLatLng(p[1], p[0]);
						map.setCenter(loc, 13);
						map.setZoom(GoogleMaps.zoom)
						map.addOverlay(new GMarker(loc));
						map.enableScrollWheelZoom();
						map.addControl(new GLargeMapControl())
						map.openInfoWindow(map.getCenter(), GoogleMaps.content);
					}
				});
			}
		
		},
		
		// FUNC: Show
		Show : function()
		{			
			var overlay = $('mapOverlay');
		    var width = document.body.scrollWidth;
		    var height = document.body.scrollHeight;

		    var top = document.viewport.getScrollOffsets().top + Math.round((document.viewport.getDimensions().height - 460) / 2);
		    overlay.setStyle({
		        width: width + "px",
		        height: height+10 + "px"
		    });
		    $('GMap_Box').setStyle({
		        display: 'block',
		        width: width + "px",
		        height: 0 + "px"
		    });
		    $('mapDiv').setStyle({
		        top: top + 'px'
		    });
			GoogleMaps.Load();		    
		},
		
		// FUNC: Hide
		Hide : function()
		{
			$('GMap_Box').setStyle({ display: 'none' });	
		}
				
    }

	
	/*
	 *    Kalkulátorok
	 *    written by Profartis Design Kft.
	 */
	
	var Calculator = {
		
		// Ár-formázás
		priceFormat : function(number)
		{
			var formats = [[],[],[],[],[0],[1],[2],[0,3],[1,4],[2,5]], r = '', nn = new Array;
			var n = String(number).toArray();				
			n.each(function(s){ if (s!=' '){nn.push(s);} });
			nn.each(function(s,i){ r += s + ( ( formats[nn.length].indexOf(i) != -1 ) ? ' ' : '' ); });
			return r;
		},
		
		// Ingatlan-adó kalkulátor
		RealEstateTax: function()
		{
			// FUNKCIÓ: Adatok megjelenítés
			var DisplayResults = function(results)
			{
				$('taxbase').update( Calculator.priceFormat(results.taxbase) + ' Ft' );
				$('taxable_part').update( results.taxable_part + '%' );
				$('taxable_earnings').update( Calculator.priceFormat(results.taxable_earnings) + ' Ft' );
				$('paying_tax').update( Calculator.priceFormat(results.paying_tax) + ' Ft' );
			}
			
			// FUNKCIÓ: Adóköteles rész kiszámolása
			var TaxablePercent = function()
			{
				switch((selling.date-buying.date))
				{
					case 0:
					case 1: return 100; break;
					case 2: return 90; break;
					case 3: return 60; break;
					case 4: return 30; break;
					default: return 0; break;
				}
			}		
			
			// Eladási adatok
			var selling = {
				date : new Date().getFullYear(),
				price : parseInt($('selling_price').value.replace(/ /gi,''))
			}

			// Vásárlási adatok
			var buying = {
				date: parseInt($('buying_date').value.replace(/ /gi,'')),
				price: parseInt($('buying_price').value.replace(/ /gi,''))
			}
			
			// Megszerzéssel kapcsolatok költségek
			var other_costs = !$('other_costs').value.replace(/ /gi,'') ? 0 : parseInt($('other_costs').value.replace(/ /gi,''))
			
			// Kiszámolt adatok
			var taxbase = ((selling.price-buying.price-other_costs) < 0) ? 0 : (selling.price-buying.price-other_costs);
			var taxable_part = TaxablePercent();
			var taxable_earnings = (taxable_part/100) * taxbase;
			
			// Eredmények
			var results = {
				
				// Adóalap
				'taxbase' : (taxable_part==0) ? 0 : taxbase,
				
				// Adóköteles rész
				'taxable_part' : (taxbase==0) ? 0 : taxable_part,
				
				// Adóköteles jövedelem
				'taxable_earnings' : taxable_earnings,
				
				// Fizetendő adó
				'paying_tax' : (taxable_earnings*0.25)
				
			}
			
			DisplayResults(results);
			
		},
		
		// Ingatlan-illeték kalkulátor
		RealEstateDuty: function()
		{
			
			// FUNKCIÓ: Alap illeték számolás
			var Advantage_Base = function(price,type)
			{
				if (type == 'L') {
					if (price > 4000000) { return Math.ceil((4000000 * 0.02) + ((price - 4000000) * 0.06)); }
					else { return Math.ceil(price * 0.02); }
				} else {
					return Math.ceil(price * 0.1);
				}
			}					
			
			// Ingatlan típusa
			var realestate_type = $('realestate-type').value;
			if(!realestate_type){ alert("'Az ingatlanvagyon típusa' mező kitöltése kötelező!"); return; }
					
			// Ingatlan érték
			var buying_price = parseInt($('buying_price').value.replace(/ /gi,''))
			var selled_price = parseInt($('selled_price').value.replace(/ /gi,''))
			
			if(!buying_price){ alert("'A vásárolt ingatlan forgalmi értéke' mező kitöltése kötelező!"); return; }
			
			// Végleges ár
			var price = (selled_price > 0) ? Math.abs(buying_price-selled_price) : buying_price;
			
			// Számolás
			//
			if( $('adv1').checked && realestate_type == 'L' && price <= 8000000 )
			{
				var duty = Advantage_Base(price,realestate_type)-40000;
				if( duty < 0 ){ duty = 0; }
			}	
			else if( $('adv2').checked && realestate_type == 'L' )
			{
				var duty = (price > 15000000) ? Math.ceil((price-15000000)*0.06) : 0;
			}	
			else if( $('adv3').checked && realestate_type == 'T' )
			{
				var duty = 0;	
			}							
			else 
			{
				var duty = Advantage_Base(price,realestate_type);
			}
			
			$('duty').update( Calculator.priceFormat(duty) + ' Ft' );
			
		}
		
	}
