var current_form = new Array();
current_form[1] = 'car';

var myTabHandlers = {
		onCreate: function(){
			Element.show('systemWorking');
			Element.hide('tabcontainer');
		},

		onComplete: function() {
			if(Ajax.activeRequestCount == 0){
				Element.hide('systemWorking');
				Element.show('tabcontainer');
			}
		}
};

function changeTabContainer(t) {
	var url_tmp = location.href.split('.hu');
	var url = url_tmp[0] + '.hu/ajaxResponder.php';
	if (url_tmp[0] == '') url_tmp = location.href.split('.eu');
	//var url = 'http://r-magnet.hu/ajaxResponder.php';
	var pars = 'account=ajax&request_type=get_town&id=' + t;

	Ajax.Responders.unregister(myTabHandlers);
	Ajax.Responders.register(myTabHandlers);
	var myAjax = new Ajax.Updater(
					{success: 'tabcontainer'}, 
					url, 
					{
						method: 'get', 
						parameters: pars
					});

	if (!null($("tab_"+current_tab))) {
		$("tab_"+current_tab).className = '';
		$("href_"+current_tab).className = '';
	}
	$("tab_"+t).className = 'current';
	$("href_"+t).className = 'current';

	current_tab = t;
	return false;
}

function showFormDetails(t, i) {
 if (t == current_form[i]) return;
 switch (current_form[i]) {
  case 'car':
	  $('car_details_1_'+i).style.display = 'none';
	  $('car_details_2_'+i).style.display = 'none';
	  break;
  case 'gas':
	  $('gas_details_'+i).style.display = 'none';
	  break;
  case 'water':
	  $('water_details_'+i).style.display = 'none';
	  break;
 }
 switch (t) {
  case 'car':
	  $('car_details_1_'+i).style.display = 'block';
	  $('car_details_2_'+i).style.display = 'block';
	  break;
  case 'gas':
	  $('gas_details_'+i).style.display = 'block';
	  break;
  case 'water':
	  $('water_details_'+i).style.display = 'block';
	  break;
 }
 current_form[i] = t;
}

function fNull() {
}

function copyAddress(i) {
	$('final_town_id_'+i).value = $('o_town_id').value;
	$('final_town_'+i).value = $('o_town').value;
	$('final_addr_'+i).value = $('o_addr').value;
}

function addFieldContent(t) {
        var url_tmp = location.href.split('.hu');
	if (url_tmp[0] == '') url_tmp = location.href.split('.eu');
	var url = url_tmp[0] + '.hu/ajaxResponder.php';
	//	var url = 'http://localhost/r-magnet/ajaxResponder.php';
	var pars = 'account=ajax&request_type=add_field&num=' + t;

	var myAjax = new Ajax.Updater(
					{success: 'app_details_'+t}, 
					url, 
					{
						method: 'get', 
						parameters: pars
					});

	return false;
}

function addPanel() {
	var i =	Math.round($('app_panel_num').value);
	i = i + 1;
	$('app_panel_num').value = i;
	current_form[i] = 'car';
	try	{
		var my_div = document.createElement('<div class="app_field">');
		my_div.setAttribute('id','app_details_'+i);
		my_div.setAttribute('name','app_details_'+i);
	}
	catch (err)	{
		var my_div = document.createElement('div');
		my_div.setAttribute('id','app_details_'+i);
		my_div.setAttribute('name','app_details_'+i);
		my_div.setAttribute('class','app_field');
	}
	$('app_field_holder').appendChild(my_div); 
	addFieldContent(i);
}

function removePanel(t) {
	$('app_field_holder').removeChild($('app_details_'+t)); 
}

function checkValues(l) {
	if ($('o_name').value == '') {
		alert('A név megadása kötelező!');
		setField('o_name');
		return false;
	}
	if ($('o_tel').value == '') {
		alert('A telefonszám megadása kötelező!');
		setField('o_tel');
		return false;
	}
	if ($('o_email').value == '') {
		alert('Az e-mail cím megadása kötelező!');
		setField('o_email');
		return false;
	}
	return true;
}

function setField(f) {
 $(f).select();
 $(f).focus();
}

function submitFilterBox() {
	window.frames['orders'].document.forms['status_form'].elements['filter'].value = document.getElementById('status_filter').value;
	window.frames['orders'].document.forms['status_form'].submit();
} 

function setStatusNoteBox(i) {
}

function setWhat(i, frm) {
    document.forms[frm].elements['what'].value=i;
}

function setAction(a, frm) {
    document.forms[frm].elements['action'].value=a;
    if (a=='del'||a=='del_sch') return confirm('Biztosan törölni akarod?');
    else return true;
}

function doSubmit(frm) {
    document.forms[frm].submit();
}

function setValues(i,a,f) {
    setWhat(i, f);
    if (setAction(a, f)) doSubmit(f);
}

function showModalDlg(url, name, features, forcewindowopen) {
  wheight = 400;
  wwidth = 660;
  wleft = (screen.width - wwidth) / 2;
  wtop = (screen.height - wheight) / 2;
  wcenter = 'no';
  wlocation = 'no';
  wmenubar = 'no';
  wresizable = 'no';
  wscrollbars = 'yes';
  wstatus = 'no';
  wtoolbar = 'no';
  // ez a sor kell debugolashoz:
  //forcewindowopen = 1;
  if (forcewindowopen != 1)
    forcewindowopen = 0;
  featurelist = features.split(';');
  for (i=0;i<featurelist.length;i++) {
    data = featurelist[i].split('=');
    switch (data[0]) {
      case "height": wheight = data[1]; break;
      case "width": wwidth = data[1]; break;
      case "top": if (wcenter != 1) { wtop = data[1]; } break;
      case "left": if (wcenter != 1) { wleft = data[1]; } break;
      case "scrollbar": wscrollbars = data[1]; break;
      case "centered": wcenter = 'yes'; break;
      case "locationbar": wlocation = 'yes'; break;
      case "menubar": wmenubar = 'yes'; break;
      case "statusbar": wstatus = 'yes'; break;
      case "toolbar": wtoolbar = 'yes'; break;
      case "resizable": wresizable = 'yes'; break;
    }
  }
  if (wcenter = 1) {
    wleft = (screen.width - wwidth) / 2;
    wtop = (screen.height - wheight) / 2;
  }
  if ((forcewindowopen == 0) && (window.showModalDialog)) {
    fl = 'dialogHeight: ' + wheight + 'px;dialogWidth=' + wwidth + 'px;dialogLeft=' + wleft + 'px;dialogTop=' + wtop +
         'px;scroll=' + wscrollbars + ';status=' + wstatus + ';resizable=' + wresizable;
    window.showModalDialog(url, '', fl);
  }
  else {
    fl = 'height=' + wheight + ',width=' + wwidth + ',left=' + wleft + ',top=' + wtop +
         ',location=' + wlocation + ',scrollbars=' + wscrollbars + ',menubar=' + wmenubar +
         ',status=' + wstatus + ',toolbar=' + wtoolbar + ',resizable=' + wresizable;
    window.open(url, '', fl);
  }
}

function getElByID(idVal, numofparents) {
   // igy mar elirhatom a fuggveny nevet
   return getElById(idVal, numofparent);
}

function getElById(idVal, numofparents)
  {
  p = '';
  for (i=0;i<numofparents;i++)
    p = p + 'parent.';
  if (document.getElementById != null)
    return eval(p + 'document.getElementById(idVal)');
  if (document.all != null)
    return eval(p + 'document.all[idVal]');

  alert("Hiba! A böngésző nem támogatja: getElById()")
  return null
  }

function PageLoaded() {
  midtop = getElById('middletop');
  midtext = getElById('middletext');
  load = getElById('loading');
  if (load != null) {
    load.style.display = 'none'; }
  if (midtop != null) {
    midtop.style.visibility = 'visible'; }
  if (midtext != null) {
    midtext.style.visibility = 'visible'; }
}

function startCountDown(min) {
  window.setTimeout('timeoutReminder()', (min - 5) * 60 * 1000);
}

function timeoutReminder() {
  alert('Kérem frissítse az oldalt, különben a kapcsolat a kiszolgálóval 3 perc múlva megszakad, és újra be kell jelentkeznie!');
}

function changeDivVisibility(n) {
	_div = getElById(n+'_selector');
	if (_div.style.display == 'none') _div.style.display = 'block';
	else _div.style.display = 'none';
}