//ide jonnek majd a cafeterias js-ek
//login oldalon a focust a felhasznalonevhez teszi
function setFocus() {
    if (document.login_form.user.length > 0) {
	document.login_form.pass.focus();
    } else {
	document.login_form.user.focus();
    }
}

var t
var aktiv = 0;
function timedCount()
{
	t=setTimeout("elrejt()",1000);
}

function stopCount()
{
	clearTimeout(t);
}
function elrejt() {
	if(aktiv == 0 )
		return false;
	stopCount();
	var obj = document.getElementById(aktiv);
	obj.style.visibility = "hidden";//alert("ie5");
	aktiv = 0;
}

function vmi(DivID, iState, element_pos)
{
	if(aktiv != 0 ) elrejt();
	
    //document.id.style.visibility="visible";
    if(document.layers)    //NN4+
    {
	document.layers[DivID].visibility = iState ? "show" : "hide"; alert("nn4");
    }
    else if(document.getElementById)   //gecko(NN6) + IE 5+
    {
	if(iState) {
		aktiv = DivID;
		var obj = document.getElementById(DivID);
		obj.style.visibility = iState ? "visible" : "hidden";//alert("ie5");
	} else {
		elrejt();
	}
	obj.style.display='block';
	var element_offsetLeft = 0;
	var element_offsetTop = 0;
	bal = element_pos.offsetLeft; //alert(lll);
	while((element_pos = element_pos.offsetParent) != null)
	    bal += element_pos.offsetLeft;
	bal = bal + element_offsetLeft;
	obj.style.left = (bal+50) + 'px';
    }
    else if(document.all)    // IE 4
    {
	document.all[DivID].style.visibility = iState ? "visible" : "hidden"; alert("ie4");
    }
    return;
}

/* Pénzügyeknél használt javascript */

function focusSelect(focus) {
 var selects = document.getElementsByTagName('select');
 for (var i = 0; i < selects.length; i++) {
  if (selects[i].name == focus) continue;
  var firstIndex = (selects[i].options[0]);
  selects[i].selectedIndex = firstIndex;
 }
 var radio = document.getElementById(focus);
 radio.checked = true;
}

function clearSelects() {
 var selects = document.getElementsByTagName('select');
 for (var i = 0; i < selects.length; i++) {
  var firstIndex = (selects[i].options[0]);
  selects[i].selectedIndex = firstIndex;
 }
}

function checkform_penzugy(f, q) {
 var result = ((f.elements['kozlemeny'].value == '' && !confirm(q)) ? false : true);
 if (result) {
  f.elements['penzugy_submit'].disabled = true;
  return true;
 }
 return false;
}

     function post_cmd(cmd,id,do_confirm) {
      if ((do_confirm==true) && confirm(biztosbenne)) {
       form = document.getElementById('cmdform');
       form.cmd.value=cmd;
       form.id.value=id;
       form.submit();
      }
     }

     function goto_jcs(formname, fieldname)
      {
      var fld=eval('document.'+formname+'.'+fieldname);
      document.location="index.php?l=juttatascsoport_adatok&jcs_id="+fld.value;
      }

     function goto_j(formname, fieldname)
      {
      var fld=eval('document.'+formname+'.'+fieldname);
      document.location="index.php?l=juttatas_adatok&j_id="+fld.value;
      }

     function goto_tcs(formname, fieldname)
      {
      var fld=eval('document.'+formname+'.'+fieldname);
      document.location="index.php?l=term_csop_adatok&term_csop_id="+fld.value;
      }

     function goto_beszall(formname, fieldname)
      {
      var fld=eval('document.'+formname+'.'+fieldname);
      document.location="index.php?l=beszall_adatok&beszall_id="+fld.value;
      }

     function goto_vall(formname, fieldname)
      {
      var fld=eval('document.'+formname+'.'+fieldname);
      document.location="index.php?l=vall_adatok&vallalat_id="+fld.value;
      }

function fillSelect(select, options, noEmpty) {
 if (!select) {
  alert('JS Error: No select given');
  return;
 }
 select.options.length = 0;
 if (noEmpty == null) {
  select.appendChild(new Option('---', 0));
 }
 for (key in options) {
  var option = new Option(options[key], key);   
  select.appendChild(option);
 }
}
function fillSelect2(select, options, noEmpty, selectname) {
 if (!select) {
  alert('JS Error: No select given');
  return;
 }
 select.options.length = 0;
 var deftxt = '---';
 var defval = 0;
 insertOption(selectname, deftxt, defval);
 for (key in options) {
  insertOption(selectname, options[key], key)
 }
}
function insertOption(selectname, option_label, option_value) {
 var y=document.createElement('option');
 y.text = option_label;
 y.value = option_value;
 var x=document.getElementById(selectname);
 try {
  x.add(y,null); // standards compliant
 } catch(ex) {
  x.add(y); // IE only
 }
}
