var AutoberlesKereso = new Class({

	totalchilds: null,
	currentchild: null,
	
	initialize: function(){

		this.odate_auto = new CnaptarAuto('odate_auto',$('omonth_auto'),$('oday_auto'),$('o_date_cont_auto'), datum.shiftDate(_currentdate,3), datum.shiftDate(_currentdate,365), (function(){ this.odate_autoChange(); }).bind(this));
		this.rdate_auto = new CnaptarAuto('rdate_auto',$('rmonth_auto'),$('rday_auto'),$('r_date_cont_auto'), datum.shiftDate(_currentdate,7), datum.shiftDate(_currentdate,34), (function(){ this.rdate_autoChange(); }).bind(this));
		
	this.errorlayer = new CmooErrorLayer();
	
		
	$('autoberles_submit').addEvent('click',(this.onSubmitClick).bind(this));	
		
		$('country_select_felvetel').addEvent('change',function(){
			var option_id = $('country_select_felvetel').value;

			$('destination_felvetel').set('html',"");
			

			var req = new Request.JSON(
			{
				url:'autoberles/ajax/get_destinations.php',
				method: 'post',
				data: 'countrycode='+option_id,
				onComplete: function(result){

					

					
					if (result)
					{
						
						
						
						
						
						new Element('option',{'html':'-- válasszon --', 'value':-1}).inject($('destination_felvetel'));
						
						
						result.each(function(item,index){
							new Element('option',{'html':item['destinationname'], 'value':item['destinationcode']}).inject($('destination_felvetel'));
							 
							
							
							
						});
					}

					
					


				},
				evalScripts:false
			}).send();

		});
		
		
		
		


		
		
		
		
		
		
		
		
		$('destination_felvetel').addEvent('change',function(){
			var option_id = $('destination_felvetel').value;
			
			

			$('office_felvetel').set('html',"");
			

			var req = new Request.JSON(
			{
				url:'autoberles/ajax/get_offices.php',
				method: 'post',
				data: 'citycode='+option_id,
				onComplete: function(result){

					
					
					

					if (result)
					{
						
						
						new Element('option',{'html':'-- válasszon --', 'value':-1}).inject($('office_felvetel'));
						
						result.each(function(item,index){
						
							new Element('option',{'html':item['name'], 'value':$('destination_felvetel').value+"_"+item['code']}).inject($('office_felvetel'));
							

							
						});
					}

					
					$('destination_felvetel').value=option_id;
					


				},
				evalScripts:false
			}).send();

		});
		
		
		
			
		
		
	
				
				
		
		
		
			
		
		
		$('office_felvetel').addEvent('change',function(){
			var option_id = $('office_felvetel').value;
			
			

			$('car_group').set('html',"");

			var req = new Request.JSON(
			{
				url:'autoberles/ajax/get_office_info.php',
				method: 'post',
				data: 'officecode='+option_id,
				onComplete: function(result){

					
					
					
					if (result)
					{
						
						result.each(function(item,index){
						
							new Element('option',{'html':item['name'], 'value':item['code']}).inject($('car_group'));
						});
					}

					
					
					
					


				},
				evalScripts:false
			}).send();

		});
						
		
		
			
		$('office_felvetel').addEvent('change',function(){
			var option_id = $('office_felvetel').value;
			
			

			$('car_group').set('html',"");

			var req = new Request.JSON(
			{
				url:'ajax/get_office_info.php',
				method: 'post',
				data: 'officecode='+option_id,
				onComplete: function(result){

					
					
					
					if (result)
					{
						
						result.each(function(item,index){
						
							new Element('option',{'html':item['name'], 'value':item['code']}).inject($('car_group'));
						});
					}

					
					
					// $("office_leadas").selectedIndex=$("office_felvetel").selectedIndex;
					


				},
				evalScripts:false
			}).send();

		});

		
		
		
		
		

	},
	
	
	
		odate_autoChange: function(){
		this.rdate_auto.setNewRange(datum.shiftDate($A(this.odate_auto.getDate()),1));
	},
	rdate_autoChange: function(){
		
	},	

	onSubmitClick:function()
	{
		var hiba="";





			if (($('country_select_felvetel').value==-1) || ($('country_select_felvetel').value==""))
			{
				hiba+="Nem választott országot <br />";
			}
			
			
			if (($('destination_felvetel').value==-1) || ($('destination_felvetel').value==""))
			{
				hiba+="Nem választott várost <br />";
			}
			
			
			if (($('office_felvetel').value==-1) || ($('office_felvetel').value==""))
			{
				hiba+="Nem választott irodát <br />";
			}
			
			
			
			if ($('hour_felvetel').value==-1)
			{
				hiba+="Nem adta meg a felvétel időpontját (óra)<br />";
			}
			
			if ($('hour_leadas').value==-1)
			{
				hiba+="Nem adta meg a leadás időpontját (óra)<br />";
			}
			
			
			if (hiba!="")
		{
			hiba="Hiba a keresés során<br />"+hiba;

			this.errorlayer.pop(hiba);
			//  alert(hiba);
			return false;

		}
		else
		{
			
			return true;
		}

	}

	
});









document.addEvent('domready',function(){

	new AutoberlesKereso();

	

});
