var LoadingDisplay = '<div id="LoadingDisplay"></div>';
var LoadingDisplay2 = '<div id="LoadingDisplay2"></div>';
var LoadingDisplay3 = '<div id="LoadingDisplay3"></div>';
var LoadingDisplay5 = '<div id="LoadingDisplay5"></div>';

function change_button_bg(ID, IMAGE)
{
		document.getElementById(ID).style.background = "url(/images/"+IMAGE+")";
}

var Field = null;
var Step = 0;

function ar_szamolo()
	{

	var euro = document.getElementById('jseuro').value;

//	document.getElementById('parkolo').innerHTML += '<hr>'+document.geplista.length;		
		 //alert(document.forms['geplista'].length);
		  
		  for(i=0; i<document.forms['geplista'].length; ++i) 
			  {
			
				Tmp = document.forms['geplista'].elements[i].id;
					if(Tmp.match(/akcar_/)) 
					{
						Field = document.getElementById(Tmp);
						fID = Tmp.replace('akcar_','');
						Step = document.getElementById('akcar-step_'+fID).value;
					
						 if(Field && Step) Price =  Math.round((Field.value-Step)*100)/100;				
						 
						 Field.value = Price;

						 document.getElementById('akcar_span_'+fID).innerHTML = 	 szamformazo(Price)+' &euro; + ÁFA <br>('+szamformazo(Math.round(Price*euro))+' Ft.-)';		 
					}
				}
			setTimeout("ar_szamolo()", 1000);
	}



function szamformazo(num)
	{
	  var SZ = new Array();
	  var counterke = 0;
	  var tmp_numstr = '';
	  var new_numstr = '';
	  var maradek = '';

	 numstr = String(num);

	 // TIZEDESNEL ELVALASZTAS
	 var BONTAS = new Array();
	  BONTAS = numstr.split('.');

	 tmp_numstr = BONTAS[0];


	// SZETBONTAS HAROM SZAMJEGYENKENT
	for(a = tmp_numstr.length-1; a >= 0; a--)
		{
				counterke++;
			    SZ.push(tmp_numstr.charAt(a));				
					
				if(counterke == 3) 
					{
					counterke = 0; 
					SZ.push(' ');
					} 
		}

		// TOMB MEGFORDITASA
		SZ.reverse();

	// AZ UJ SZAM MEGALKOTASA
	for(a = 0; a < SZ.length; a++)
		{
			 new_numstr += SZ[a];
		}

	if(BONTAS[1])
		{
			maradek = BONTAS[1];
			if(maradek.length == 1)
				maradek += '0';
		}
		else maradek = '00';

	// ITT AZ UJ FORMATUM
	new_numstr += '.'+maradek;
	return new_numstr;
	}
	var Field = null;
	var Step = 0;



function change_menu_bg(ID, CLASSNAME)
{
		document.getElementById(ID).className = CLASSNAME;
}


// #### AJAX UPDATER OBJ. #### 
// url: a hivatkozas :)
// pars: url utáni hivasparameter
// container: ahova a tartalom urul ;)
// method: POST, GET ofkoz
// successFunc: sikeres hivas eseten a lefuttatott fv. vagy program kod

//myAjaxUpdater = function(var_url, var_pars, var_container, var_method, var_successFunc)  
function myAjaxUpdater(var_url, var_pars, var_container, var_method, var_successFunc)  
{
			var myAjax_inner = new Ajax.Updater(var_container, var_url,
			{ 
				method: var_method, 
				parameters: var_pars,
				onComplete: getResponse
			});
}
/*
				onSuccess: function(transport)
				{
					if(transport.status == 200)
						{
							if(var_successFunc) var_successFunc;
						}
					else
						alert('Hiba a szoftvercsatornában! :D');
				}
*/


 /* ajax.Response */  
 function getResponse(oReq) {  
   $('result').innerHTML = oReq.responseText;  
 }  
// #### AJAX UPDATER OBJ. #### 



function gep_sorrendezes(MODE, GID)
{
	document.getElementById('content').innerHTML = LoadingDisplay;
	myAjaxUpdater('doAjax.php', '?p=gep&a='+MODE+'&gid='+GID, 'content', 'post', '');
}


function kategoria_sorrendezes(MODE, KID)
{
	document.getElementById('content').innerHTML = LoadingDisplay;
	myAjaxUpdater('doAjax.php', '?p=kat&a='+MODE+'&kid='+KID, 'content', 'post', '');
}


function parkolo_add(GID)
{
	document.getElementById('parkolo').innerHTML = LoadingDisplay3;
	myAjaxUpdater('/parkolo.php', '?do=add&GID='+GID, 'parkolo', 'post', '');
}


function parkolo_remove(GID)
{
	document.getElementById('parkolo').innerHTML = LoadingDisplay3;
	myAjaxUpdater('/parkolo.php', '?do=remove&GID='+GID, 'parkolo', 'post', '');
}


function parkolo_print()
{
  printwin = window.open("/print.php?do=parkolo_print", "printwin", "toolbar=0, status=0, resizable=yes, width=1, height=1");
  printwin.moveTo(100,100);
  printwin.resizeTo(550,500);
}


function parkolo_empty()
{
	if(confirm(LANG_L_0161))
	{
		document.getElementById('parkolo').innerHTML = LoadingDisplay3;
		myAjaxUpdater('/parkolo.php', '?do=parkolo_empty', 'parkolo', 'post', '');
	}
}

// OVERLAY_ALL-NAL ELREJTJUK A FLASHEKET, AMIK FOLOTTE LENNENEK 
function swicth_flash(VISIBILITY)
		{
			if(VISIBILITY == 'hidden')
			{
					//document.getElementById('load_images').style.visibility = 'visible';  # IDEIGLENESEN 
					document.getElementById('banner_felso').style.visibility = 'visible';
			}
			else
			{
					//document.getElementById('load_images').style.visibility = 'hidden'; # IDEIGLENESEN 
					document.getElementById('banner_felso').style.visibility = 'hidden';
			}
		}

function switch_overlay_all(MODE)
{
		OA = document.getElementById('overlay_all');

		OA.style.height = get_innerheight()+'px';
		
		if(MODE == 1)
		{
				OA.style.visibility = 'visible';
				swicth_flash('visible');
				return true;
		}
		else if(MODE == 0)
		{
				OA.style.visibility = 'hidden';
				swicth_flash('hidden');
				return true;
		}

		if(OA.style.visibility == 'hidden')
		{
				OA.style.visibility = 'visible';
				swicth_flash('visible');
		}
		else if(OA.style.visibility == 'visible')
		{
				OA.style.visibility = 'hidden';
				swicth_flash('hidden');
		}
		else
		{
				OA.style.visibility = 'visible';
				swicth_flash('visible');
		}
}


function ajanlo_show(GID)
{
	switch_overlay_all(1);
	document.getElementById('ajanlo').innerHTML = LoadingDisplay2;
	document.getElementById('ajanlo').style.top = tempY-245+'px';
	document.getElementById('ajanlo').style.left = tempX-100+'px';
	document.getElementById('ajanlo').style.visibility = 'visible';
	myAjaxUpdater('/ajanlo.php', '?GID='+GID, 'ajanlo', 'post', '');
}


function ajanlo_post(GID)
{
	FELADO	= document.getElementById('felado');	
	CIMZETT	= document.getElementById('cimzett');	
	MEGJ		= document.getElementById('megj');	

	var ErrStr = '';

	if(!CIMZETT.value)
	{
	  CIMZETT.focus();
	  CIMZETT.select();
	  ErrStr += LANG_L_0162+"\n";
	}	
	else if(!check_email(CIMZETT.value))
	{
	  CIMZETT.focus();
	  CIMZETT.select();
	  ErrStr += LANG_L_0163+"\n";
	}


	if(!FELADO.value)
	{
	  FELADO.focus();
	  FELADO.select();
	  ErrStr += LANG_L_0164+"\n";
	}	
	else if(!check_email(FELADO.value))
	{
	  FELADO.focus();
	  FELADO.select();
	  ErrStr += LANG_L_0165+"\n";
	}

	if(ErrStr)
		alert(LANG_L_0166+"\n\n"+ErrStr);
	else
	{
		document.getElementById('ajanlo').innerHTML = LoadingDisplay2;
		myAjaxUpdater('/ajanlo.php', '?do=send&GID='+GID+'&felado='+FELADO.value+'&cimzett='+CIMZETT.value+'&megj='+MEGJ.value, 'ajanlo', 'post', '');
	}
}


// EZ A FV JO AZ INFOKERES ABLAK ELREJTESEHEZ IS !! //
function ajanlo_hide()
{
	switch_overlay_all(0);
	document.getElementById('ajanlo').innerHTML = '';
	document.getElementById('ajanlo').style.visibility = 'hidden';
}


function info_show(GID)
{
	switch_overlay_all(1);
	document.getElementById('ajanlo').innerHTML = LoadingDisplay2;
	document.getElementById('ajanlo').style.top = tempY-270+'px';
	document.getElementById('ajanlo').style.left = tempX-10+'px';
	document.getElementById('ajanlo').style.visibility = 'visible';
	myAjaxUpdater('/infokeres.php', '?GID='+GID, 'ajanlo', 'post', '');
}
 

function info_post(GID)
{
	NEV			= document.getElementById('nev');	
	EMAIL		= document.getElementById('email');	
	TEL			= document.getElementById('tel');	
	MEGJ		= document.getElementById('megj');	

	var ErrStr = '';


	if(!NEV.value || NEV.value.length < 4)
	{
	  NEV.focus();
	  NEV.select();
	  ErrStr += LANG_L_0167+"\n";
	}	


	if(!EMAIL.value)
	{
	  EMAIL.focus();
	  EMAIL.select();
	  ErrStr += LANG_L_0168+"\n";
	}	
	else if(!check_email(EMAIL.value))
	{
	  EMAIL.focus();
	  EMAIL.select();
	  ErrStr += LANG_L_0169+"\n";
	}

	if(!TEL.value || TEL.value.length < 9)
	{
	  TEL.focus();
	  TEL.select();
	  ErrStr += LANG_L_0170+"\n";
	}	

	if(ErrStr)
		alert(LANG_L_0171+"\n\n"+ErrStr);
	else
	{
		document.getElementById('ajanlo').innerHTML = LoadingDisplay2;
		myAjaxUpdater('/infokeres.php', '?do=send&GID='+GID+'&nev='+NEV.value+'&email='+EMAIL.value+'&tel='+TEL.value+'&megj='+MEGJ.value, 'ajanlo', 'post', '');
	}
}


function gep_print(GID)
{
  printwin = window.open("/print.php?GID="+GID, "printwin", "toolbar=0, status=0, resizable=yes, width=1, height=1");
  printwin.moveTo(100,100);
  printwin.resizeTo(550,500);
}


/* ******************************* KERESES FUNKCIOK ******************************/
function doSearchReset()
{
	document.getElementById('param0').value = '';
	document.getElementById('param1').value = '';
    document.getElementById('param2').value = '';
	document.getElementById('param3').value = '';


	searchButtonChange();
}

function searchButtonChange()
{
	PARAM0		= document.getElementById('param0').value;
	PARAM1		= document.getElementById('param1').value;
    PARAM2		= document.getElementById('param2').value;
	PARAM3		= document.getElementById('param3').value;

   	if(PARAM0  || PARAM1 || PARAM2 || PARAM3)
	   document.getElementById('search_btn_search').disabled = false;
	else
	   document.getElementById('search_btn_search').disabled = true;
	
   document.getElementById('search_btn_reset').disabled = false;
}


function doSearch()
{
	PARAM0		= document.getElementById('param0').value;
	PARAM1	= document.getElementById('param1').value;
    PARAM2		= document.getElementById('param2').value;
	PARAM3	= document.getElementById('param3').value;

	document.getElementById('content').innerHTML = LoadingDisplay2;
	myAjaxUpdater('/search.php', '?do=search&param0='+PARAM0+'&param1='+PARAM1+'&param2='+PARAM2+'&param3='+PARAM3, 'content', 'post', '');
}

/* ******************************* KERESES FUNKCIOK ******************************/
