//
// Globals
//
var lrend = "nev";
//
//
// Functions for Download Applet
//
function doInit()
{
		var vault = document.applets.vault;
		var dir = "C:\\Downloads";
		vault.mkDir(dir);
		vault.setWorkingDir(dir);
		vault.setDownloadBaseURL("http://localhost/temp/orders/");
}
//
function onButtonClick(strButton, strFiles, strAttr)
{
	if (strButton == "Download") {
		return true;  // false - to cancel downloading
	}
	if (strButton == "Download OK") {
		// make your server job here
		// return false;  // false - to cancel this downloading
		// then call vault.downloadFiles(false); after you prepared all your files on server
	}
	if (strButton == "Download Complete") {
    // strFiles here contains the download report
                parent.main.document.orders.submit()
		//alert(strFiles);
		// location = "new_url.jsp"; // so you can redirect to a new location after download complete
	}
	if (strButton == "Remove") {
		alert("Removing: "+strFiles);
  }
}
//
function download_orders()
{
  with ( parent.main.document ) {
    var i, err = 1, k = orders.elements.length, flist = '';
    for ( i = 0; i < k; i++ ) {
        if ( orders.elements[i].name.substring(0,3) == 'kiv' && orders.elements[i].checked ) {
          flist = flist+orders.elements[i].value+';';
        }
    }
//    alert(flist);
    vault.addFilesToDownloadList(flist,null,';');
    vault.downloadFiles(false);
  }
}
//
//

function get_order(kiv, ohtml_path)
{
  with ( parent.main.document.orders ) {
    var i, err = 1, k = elements.length;
    for ( i = 0; i < k; i++ ) {
        if ( elements[i].name == kiv ) {
          elements[i].checked = true;
        } else {
          if (elements[i].checked) {            // csak a 'kiv' lehet checked!!!
            elements[i].click();
          }
        }
    }
    submit();
    openPopup1( ohtml_path );
  }
}
//
//

function print_only_order(kiv, ohtml_path)
{
  with ( parent.main.document.orders ) {
    var i, err = 1, k = elements.length;
    for ( i = 0; i < k; i++ ) {
        if ( elements[i].name == kiv ) {
          elements[i].checked = true;
        } else {
          if (elements[i].checked) {            // csak a 'kiv' lehet checked!!!
            elements[i].click();
          }
        }
    }
//    submit();
    openPopup1( ohtml_path );
  }
}
//
//
function cim_to_szcim()
{
  with ( document.newpart ) {
    u_irszam_sz.value = u_irszam.value;
    u_varos_sz.value = u_varos.value;
    u_utca_sz.value = u_utca.value;
  }
}
//
//
function check_newpart()
{
  with ( document.newpart ) {
    var err =0;
    if ( u_nev.value == "" || u_irszam.value == "" || u_varos.value =="" || u_utca.value =="" ) {
      err = 1;
      alert ( "A név és a cím mezőket feltétlenűl ki kell tölteni!" );
    }
    if ( (u_korz_t.value == "" || u_telefon.value == "") &&
         (u_korz_m.value == "" || u_mobil.value == "") ) {
      err = 1;
      alert ( "Valamelyik telefonszámot feltétlenűl meg kell adni!" );
    }
    if ( u_email.value == "" ) {
      err = 1;
      alert ( "Az E-mail címet feltétlenűl meg kell adni!" );
    }
    if ( u_irszam_sz.value == "" || u_varos_sz.value == "" || u_utca_sz =="" ) {
      err = 1;
      alert ( "A szállítási cím mezőket feltétlenűl ki kell tölteni!" );
    }
    if ( !err ) {
      submit();
    }
  }
}


//
// Visible header of hidden text with arrow
// hdtext - text of header
// ntext  - layer name of hidden text
// height - height of hidden text
// narrow - name of arrow picture
//
function hiddentext_header(hdtext,ntext,height,narrow)
{
  document.write("<tr><td onclick=show_hidd_layer('"+ntext+"','"+height+"','"+narrow+"') class='text_hd' colspan='4'>");
  document.write("<div id='hid_hd'>");
  document.write(hdtext);
  arrow_layer(narrow);
  document.write("</div></td></tr>");
}
//
// Show / hide hid_text layer
//
function show_hidd_layer(text_id, h, pic) {
  with ( parent.main ) {
    if ( document.getElementById(text_id).style.visibility=='' ||
         document.getElementById(text_id).style.visibility=='hidden' ) {
      document.getElementById(text_id).style.visibility='visible';
      document.getElementById(text_id).style.height=h+'px';
      document.images[pic].src = "/img/up-trans.png";
      document.images[pic].title = "Elrejt";
    } else {
      document.getElementById(text_id).style.visibility='hidden';
      document.getElementById(text_id).style.height='0px';
      document.images[pic].src = "/img/down-trans.png";
      document.images[pic].title = "Mutat";
    }
  }
}
//
function hidd_layer() {
    hid_text.style.visibility='hidden';
    hid_text.style.height='0';
}
//
function show_layer(h) {
    hid_text.style.visibility='visible';
    hid_text.style.height=h;
}
//
// Arrow layer for header of hidden text
//
function arrow_layer(n)
{
  browser = navigator.appName;
  //alert("Browser: "+browser);
  if ( browser == "Microsoft Internet Explorer" ) {
    document.write( "<div id='down_ie'>" );
  } else {
    document.write( "<div id='down'>" );
  }
  document.write("<img name='"+n+"' style='width:13px; border-width:0px;' src='/img/down-trans.png' title='Mutat'>");
  document.write("</div>");
}
function arrow_layer1(n)
{
  browser = navigator.appName;
  //alert("Browser: "+browser);
  if ( browser == "Microsoft Internet Explorer" ) {
    document.write( "<div id='down1_ie'>" );
  } else {
    document.write( "<div id='down1'>" );
  }
  document.write("<img name='"+n+"' style='width:13px; border-width:0px;' src='/img/down-trans.png' title='Mutat'>");
  document.write("</div>");
}
//
// Open TD tag for column of text
//
function td_text_bd()
{
  document.write( '<td class="text_bd" colspan="4">' );
}

//
//
var ModalDialogWindow;
var ModalDialogInterval;
var ModalDialogEventHandler = '';

function ModalDialogMaintainFocus()
{
  try {
    if (ModalDialogWindow.closed) {
      window.clearInterval(ModalDialogInterval);
      eval(ModalDialogEventHandler);
      return;
    }
    ModalDialogWindow.focus();
  }
catch (everything) { }
}
//
function ModalDialogRemoveWatch()
{
  ModalDialogEventHandler = '';
}
//
function ModalDialogShow(Title)
{
  ModalDialogRemoveWatch();
  ModalDialogEventHandler = ModalDialogRemoveWatch();
//
  var args='width=350,height=120,left=325,top=300,toolbar=0,';
  args+='location=0,status=0,menubar=0,scrollbars=0,resizable=0';
//
  ModalDialogWindow=window.open("","",args);
  ModalDialogWindow.document.open();
  ModalDialogWindow.document.write('<html>');
  ModalDialogWindow.document.write('<head>');
  ModalDialogWindow.document.write('<title>' + Title + '</title>');
  ModalDialogWindow.document.write("<" + "script language=javascript" + ">");
  ModalDialogWindow.document.write('var ctr = 1; var ctrMax = 20; var intervalId;');
  ModalDialogWindow.document.write('intervalId = window.setInterval("ctr=UpdateIndicator(ctr, ctrMax)", 600);');
  ModalDialogWindow.document.write('function UpdateIndicator(curCtr, ctrMaxIterations) {');
  ModalDialogWindow.document.write('if (!window.opener.document.Form1 || window.opener.document.Form1.progress.value != "waiting" ) window.close();');
  ModalDialogWindow.document.write('curCtr += 1;');
  ModalDialogWindow.document.write('if (curCtr <= ctrMaxIterations) {');
  ModalDialogWindow.document.write('indicator.style.width = curCtr*10 +"px";');
  ModalDialogWindow.document.write('return curCtr;}');
  ModalDialogWindow.document.write('else {indicator.style.width=0; return 1;}}');
  ModalDialogWindow.document.write("<" + "/" + "script" + ">");
  ModalDialogWindow.document.write('</head>');
  ModalDialogWindow.document.write('<body onblur="window.focus();" margintop="0">');
//
  ModalDialogWindow.document.write('<table border=0 width="95%" align=center cellspacing=0 cellpadding=2>');
  ModalDialogWindow.document.write('<tr><td style="FONT-SIZE: 14px; COLOR: #000000; FONT-FAMILY: verdana,arial,helvetica,sans-serif;font-weight: bold">');
  ModalDialogWindow.document.write('<div align=center>Kapcsolódás az adatbázishoz, <br>kérem várjon...</div>');
  ModalDialogWindow.document.write('<table border="0" width="100%"><tr><td width="10%"></td><td width="80%">');
//
  ModalDialogWindow.document.write('<table id=indicator border="0" cellpadding="0" cellspacing="0" width="0" height="20">');
  ModalDialogWindow.document.write('<tr><td bgcolor="red" width="100%"></td></tr></table>');
//
  ModalDialogWindow.document.write('</td><td width="10%"></td></tr></table>');
  ModalDialogWindow.document.write('</td></tr>');
//
  ModalDialogWindow.document.write('<tr><td style="FONT-SIZE: 9px; COLOR: #000000; FONT-FAMILY: verdana,arial,helvetica,sans-serif" align=center>');
//  ModalDialogWindow.document.write('<a href=javascript:window.close();>Bezárás</a> ');
  ModalDialogWindow.document.write('</td></tr>');
  ModalDialogWindow.document.write('</table>');
  ModalDialogWindow.document.write('</body>');
  ModalDialogWindow.document.write('</html>');
  ModalDialogWindow.document.close();
  ModalDialogWindow.focus();
  ModalDialogInterval = window.setInterval("ModalDialogMaintainFocus()",5);
}
//
function WaitingOnClick(form)
{
  if ( document.login.pcode != 'undefined' && document.login.pcode.value != '' ) {
    document.Form1.progress.value = "waiting";
    ModalDialogShow("Kapcsolódás...");
  }
  eval("document."+form+".submit()");
  return true;
}
function OnClick(form)
{
  eval("document."+form+".submit()");
  return true;
}
//
function WaitingOnEnter(event,form)
{
  var bolOldBrowser = (document.layers) ? true : false;
  var intKeyCode = 0;
  if (bolOldBrowser)
    intKeyCode = event.which;
  else
    intKeyCode = event.keyCode;
  if (intKeyCode == 13) {
    if ( document.login.pcode != 'undefined' && document.login.pcode.value != '' ) {
      document.Form1.progress.value = "waiting";
      ModalDialogShow("Kapcsolódás...");
    }  
    eval("document."+form+".submit()");
  }
  return true;
}
//
// Submit on enter
//
function onEnter(event,form)
{
  var bolOldBrowser = (document.layers) ? true : false;
  var intKeyCode = 0;
  if (bolOldBrowser)
    intKeyCode = event.which;
  else
    intKeyCode = event.keyCode;
  if (intKeyCode == 13)
    eval("document."+form+".submit()");
}
//
// Submit on enter with handler
//
function onEnterH(event,handler)
{
  var bolOldBrowser = (document.layers) ? true : false;
  var intKeyCode = 0;
  if (bolOldBrowser)
    intKeyCode = event.which;
  else
    intKeyCode = event.keyCode;
  if (intKeyCode == 13)
//    alert("handler");
    eval(handler);
}
//
function WaitingDatabase()
{
//  if ( document.login.pcode != 'undefined' && document.login.pcode.value != '' ) {
    document.Form1.progress.value = "waiting";
    ModalDialogShow("Kapcsolódás...");
//  }
//  eval("document."+form+".submit()");
  return true;
}
  //
  // Send 'msgform' as circular letter
  //
  function send_cletter() {
    with ( parent.main.document.msgform ) {
      var i, err = 1, k = elements.length;
      for ( i = 0; i < k; i++ ) {
        if ( elements[i].name.substring(0,1) == 'k' && elements[i].checked ) {
          err = 0;
        }
      }
      if ( err ) {
        alert('Nincs egy címzett sem kiválasztva !');
        return false;
      }
      if (!err) {
        submit();             // Submit the checked letter
      }
    }
  }
  //
  // Clear/set checkbox 'k'
  //
  function clr_ert() {
    with ( parent.main.document.msgform ) {
      var i, err = 1, k = elements.length;
      for ( i = 0; i < k; i++ ) {
        if ( elements[i].name.substring(0,1) == 'k' && elements[i].checked ) {
          elements[i].checked = false;
        }
      }
    }
  }
  //
  function set_ert() {
    with ( parent.main.document.msgform ) {
      var i, err = 1, k = elements.length;
      for ( i = 0; i < k; i++ ) {
        if ( elements[i].name.substring(0,1) == 'k' && !elements[i].checked ) {
          elements[i].checked = true;
        }
      }
    }
  }
  //
  // Clear/set checkbox 'm'
  //
  function clr_mel() {
    with ( parent.main.document.msgform ) {
      var i, err = 1, k = elements.length;
      for ( i = 0; i < k; i++ ) {
        if ( elements[i].name.substring(0,1) == 'm' && elements[i].checked ) {
          elements[i].checked = false;
        }
      }
    }
  }
  //
  function set_mel() {
    with ( parent.main.document.msgform ) {
      var i, err = 1, k = elements.length;
      for ( i = 0; i < k; i++ ) {
        if ( elements[i].name.substring(0,1) == 'm' && !elements[i].checked ) {
          elements[i].checked = true;
        }
      }
    }
  }
  //
  // Send 'msgform' and get addressee
  //
  function addree_cletter() {
    with ( parent.main.document.msgform1 ) {
      var i, err = 0, k = elements.length;
      for ( i = 0; i < k; i++ ) {
        if ( elements[i].name == 'circsubj' && elements[i].value == '' ) {
          alert('A Tárgy: mező nem lehet üres !');
          return false;
        }
        if ( elements[i].name == 'circmsg' && elements[i].value == '' ) {
          alert('Az Üzenet: mező nem lehet üres !');
          return false;
        }
        if ( elements[i].name == 'fname' && elements[i].value == '' ) {
          alert('Az Feladó: névmező nem lehet üres !');
          return false;
        }
        if ( elements[i].name == 'faddr' && elements[i].value == '' ) {
          alert('Az Feladó: E-mail címmező nem lehet üres !');
          return false;
        }
      }
      cl.value = '1';
      circsubj.value = parent.main.document.msgform.circsubj.value; // save value in this form
      circmsg.value = parent.main.document.msgform.circmsg.value;   //
      attfile_sel.value= parent.main.document.attach.attfile_sel.value;
      if (!err) {
        submit();             // Submit the checked letter
      }
    }
  }
  //
  //
  function get_att_file() {
    with ( document.attach ) {
      var i, n, err = 0, j = 1;
      circsubj.value = parent.main.document.msgform.circsubj.value; // save value in this form
      circmsg.value = parent.main.document.msgform.circmsg.value;   //
      if ( attfile_br.value != '' ) {
        submit();
      } else {
        alert( 'Nem adott meg melléklet file-t !');
        return false;
      }
    }
  }
//
// Popup help
//
function openPopup(help) {
  HelpWin = window.open("","Help","toolbar=no,directories=no,menubar=no,height=700,width=520,scrollbars=1,resizable=1");
  HelpWin.location.href = help;
  return false;
}
//
// Popup order
//
function openPopup1(ohtml_path) {
  OrderWin = window.open("","Megrendelő","toolbar=no,directories=no,menubar=yes,height=700,width=760,scrollbars=1,resizable=1");
  OrderWin.location.href = ohtml_path;
  return false;
}
//
// Popup picture
//
function openPic(pic) {
  var closeOnclick = 1;          // closing mode
  picwin = window.open("","Kép","toolbar=0,directories=0,menubar=0,scrollbars=1,resizable=1,height=438,width=438");
  with (picwin.document) {
    if ( !closeOnclick ) {       // fitting in the window  and close by x
      location.href=pic;
    } else {                     // keep the size of the picture and close by click on the picture
      write("<html><head><title>"+pic+"</title>");
      write("<script language='JavaScript'>");
      write("function close_pic() {window.close();}");
      write("</script>");
      write("</head><body bgcolor=ffffff>");
      write("<div style='position:relative; visibility:visible; z-index:4; left:0px; width:400px; top:0px;'>" );
      write("<img style='width:400px; border-width:1px; border-color:#203a96; border-style:solid;' src='"+pic+"' onclick='close_pic()' title='Bezáráshoz kattintson ide' border='0'>");
      write("</div/body></html>");
    }
  close();
  }
  return true;
}
//
// Print ordering list
//
function print_order() {
  with ( parent.main ) {
    focus();
    print();
  }
}
//
// Check passwords
//
function check_pw() {
  with ( document.regist ) {
    var pword1 = elements[0].value;
    var pword2 = elements[1].value;
    if ( (pword1 == "") || (pword2 == "") ) {   // Nem lehet üres
      elements[0].focus();
      alert ("Mind a két jelszó mezőben kell adatnak lenni!");
      return false;
    }
    if ( pword1 != pword2 ) {                   // Nem lehet különböző
      elements[0].focus();
      alert ("A két jelszó nem egyezik! Próbálja újra!");
      return false;
    } else {
      pass.value = pword1;                      // A megerősített jelszó
      submit();
    }
  }
}
//
function check_mpw() {
  with ( document.regist ) {
    var pword1 = elements[0].value;
    var pword2 = elements[1].value;
    var opw    = leavepw.checked;
    if ( !opw ) {                               // Ha nincs bejelölve a 'Marad a régi jelszó'
      if ( (pword1 == "") || (pword2 == "") ) { // Nem lehet üres
        elements[0].focus();
        alert ("Mind a két jelszó mezőben kell adatnak lenni! Ha nem akar jelszót változtatni: jelölje be!");
        return false;
      }
      if ( pword1 != pword2 ) {                 // Nem lehet különböző
        elements[0].focus();
        alert ("A két jelszó nem egyezik! Próbálja újra!");
        return false;
      } else {
        newpw.value = pword1;                   // A megerősített jelszó
        submit();
      }
    }
    var i, j, em = 0, ck = 0, et = 0,  k = elements.length;
    for ( i = 0; i < k; i++ ) {
      if ( elements[i].name == 'eaddr' && elements[i].value != '' ) {
        if ( eaddr.value.indexOf('\@') == -1 ){
          alert ("Érvénytelen E-mail cím!");
          elements[i].focus();
          elements[i].select();
          return false;                         // Hiba ha nincs @
        }
        em = 1;
      }
      if ( elements[i].name == 'kiv' && elements[i].checked ) {
        ck = 1;
      }
      if ( elements[i].name == 'p_et' ) {
        j = 3;
        for ( j = 0; j < elements[i].length; j++ ) {
          if ( elements[i][j].selected ) {
            if ( elements[i][j].value != ' ') {
              et = 1;
            }
          }
        }
      }

    }
    if ( !em && !ck ) {
      alert('Ha nem akar E-mail címet megadni, akkor jelölje be a jelölő négyzetet!');
      kiv.focus();
      return false;     // Hiba ha nincs érvényes e-mail cím, vagy checkbox
    }
    if ( !et ) {
      alert('Elfelejtett kedvenc telephelyet választani!');
      p_et.focus();
      return false;         // Hiba ha nincs érvényes e-mail cím, vagy checkbox
    }
    submit();
  }
}
//
function check_chpw() {
  with ( document.regist ) {
    var pword1 = elements[0].value;
    var pword2 = elements[1].value;
//    var opw    = leavepw.checked;
//    if ( !opw ) {                               // Ha nincs bejelölve a 'Marad a régi jelszó'
      if ( (pword1 == "") || (pword2 == "") ) { // Nem lehet üres
        elements[0].focus();
        alert ("Mind a két jelszó mezőben kell adatnak lenni! Ha nem akar jelszót változtatni: jelölje be!");
        return false;
      }
      if ( pword1 != pword2 ) {                 // Nem lehet különböző
        elements[0].focus();
        alert ("A két jelszó nem egyezik! Próbálja újra!");
        return false;
      } else {
        newpw.value = pword1;                   // A megerősített jelszó
        submit();
      }
//    }
  }
}
//
// E-mail address exists
//
function check_email() {
  with ( document.emform ) {
    var i, j, em = 0, ck = 0, et = 0,  k = elements.length;
    for ( i = 0; i < k; i++ ) {
      if ( elements[i].name == 'eaddr' && elements[i].value != '' ) {
        if ( eaddr.value.indexOf('\@') == -1 ){
          alert ("Érvénytelen E-mail cím!");
          elements[i].focus();
          elements[i].select();
          return false;                         // Hiba ha nincs @
        }
        em = 1;
      }
      if ( elements[i].name == 'kiv' && elements[i].checked ) {
        ck = 1;
      }
      if ( elements[i].name == 'p_et' ) {
        j = 3;
        for ( j = 0; j < elements[i].length; j++ ) {
          if ( elements[i][j].selected ) {
            if ( elements[i][j].value != ' ') {
              et = 1;
            }
          }
        }
      }

    }
    if ( !em && !ck ) {
      alert('Ha nem akar E-mail címet megadni, akkor jelölje be a jelölő négyzetet!');
      kiv.focus();
      return false;         // Hiba ha nincs érvényes e-mail cím, vagy checkbox
    }
    if ( !et ) {
      alert('Elfelejtett kedvenc telephelyet választani!');
      p_et.focus();
      return false;         // Hiba ha nincs érvényes e-mail cím, vagy checkbox
    }
    if ( (em || ck) && et ) {
      submit();             // Submit the checked data
    }
  }
}
//
// Save 'olist' form
//
function save_order(ord_price_n, ord_price_b, sid) {
  document.Form1.progress.value = "waiting";
  ModalDialogShow("Kapcsolódás...");
  eval( "parent.main.location.href=\'/cgi-bin/form_prn.pl?ne="+ord_price_n+"&br="+ord_price_b+"&sid="+sid+"\'" );
}
function save_order_nowait(ord_price_n, ord_price_b, sid) {
  eval( "parent.main.location.href=\'/cgi-bin/form_prn.pl?ne="+ord_price_n+"&br="+ord_price_b+"&sid="+sid+"\'" );
}
//
// Reset 'olist' form
//
function aband_order() {
  with ( parent.main.document.olist ) {
    var i,k = elements.length;
    for ( i = 0; i < k; i++ ) {
      if ( elements[i].name.substring(0,2) == 'pc' ) {
        elements[i].value='0';
      }
    }
    parent.main.document.promt.note.value='';
    note.value = '';
    submit();             // Submit the cleared items
  }
}
//
// Refres 'olist' items
//
function refres_order() {
  with ( parent.main.document.olist ) {
    var i, n, err = 0, j = 1, k = elements.length;
    for ( i = 0; i < k; i++ ) {
      if ( elements[i].name.substring(0,2) == 'pc' ) {
        if ( elements[i].value != '' ) {
          n = parseInt( elements[i].value,10 );
          if ( isNaN( n ) ) {
            err = 1;
            alert( 'A mennyiségi adat a(z) '+j+'. sorban nem szám !');
            elements[i].focus();
            elements[i].select();
            return false;
          } else {
            if ( 0 ) {
              err = 1;
              alert( 'Rossz mennyiségi adat a(z) '+j+'. sorban: '+n+' !');
              elements[i].focus();
              elements[i].select();
              return false;
            }
            elements[i].value = n;
          }
        }
        j++;
      }
    }
    note.value = parent.main.document.promt.note.value;
    if (!err) {
      submit();             // Submit the checked items
    }
  }
}
//
// Reset 'clist' form
//
function reset_form() {
  with ( parent.main.document.clist ) {
    var i,k = elements.length;
    for ( i = 0; i < k; i++ ) {
      if ( elements[i].name.substring(0,2) == 'pc' ) {
        elements[i].value='';
      }
    }
  }
}
//
// Add 'clist' items to ordering list
//
function add_to_order() {
  with ( parent.main.document.clist ) {
    var i, n, err = 1, j = 1, k = elements.length;
    for ( i = 0; i < k; i++ ) {
      if ( elements[i].name.substring(0,2) == 'pc' ) {
        if ( elements[i].value != '' ) {
          err = 0;
        }
      }
    }
    if ( err == 1 ) {
      alert('Nincs mit hozzáadni !');
      return false;
    }
    for ( i = 0; i < k; i++ ) {
      if ( elements[i].name.substring(0,2) == 'pc' ) {
        if ( elements[i].value != '' ) {
          n = parseInt( elements[i].value,10 );
          if ( isNaN( n ) || n == 0 ) {
            err = 1;
            alert( 'A mennyiségi adat a(z) '+j+'. sorban nem szám !');
            elements[i].focus();
            elements[i].select();
            return false;
          } else {
            //if ( 0 ) {
            if ( n < 1  || n > 99999 ) {
              err = 1;
              alert( 'Rossz mennyiségi adat a(z) '+j+'. sorban: '+n+' !');
              elements[i].focus();
              elements[i].select();
              return false;
            }
            elements[i].value = n;
          }
        }
        j++;
      }
    }
    if (!err) {
      submit();             // Submit the checked items
    }
  }
}
//
// Add 'clist' items to ordering list
//
function WaitingAddToOrder() {
  with ( parent.main.document.clist ) {
    var i, n, err = 1, j = 1, k = elements.length;
    for ( i = 0; i < k; i++ ) {
      if ( elements[i].name.substring(0,2) == 'pc' ) {
        if ( elements[i].value != '' ) {
          err = 0;
        }
      }
    }
    if ( err == 1 ) {
      alert('Nincs mit hozzáadni !');
      return false;
    }
    for ( i = 0; i < k; i++ ) {
      if ( elements[i].name.substring(0,2) == 'pc' ) {
        if ( elements[i].value != '' ) {
          n = parseInt( elements[i].value,10 );
          if ( isNaN( n ) || n == 0 ) {
            err = 1;
            alert( 'A mennyiségi adat a(z) '+j+'. sorban nem szám !');
            elements[i].focus();
            elements[i].select();
            return false;
          } else {
            //if ( 0 ) {
            if ( n < 1  || n > 99999 ) {
              err = 1;
              alert( 'Rossz mennyiségi adat a(z) '+j+'. sorban: '+n+' !');
              elements[i].focus();
              elements[i].select();
              return false;
            }
            elements[i].value = n;
          }
        }
        j++;
      }
    }
  }
  if (!err) {
    document.Form1.progress.value = "waiting";
    ModalDialogShow("Kapcsolódás...");
    parent.main.document.clist.submit();             // Submit the checked items
  }
}
//
function AddToOrder() {
  with ( parent.main.document.clist ) {
    var i, n, err = 1, j = 1, k = elements.length;
    for ( i = 0; i < k; i++ ) {
      if ( elements[i].name.substring(0,2) == 'pc' ) {
        if ( elements[i].value != '' ) {
          err = 0;
        }
      }
    }
    if ( err == 1 ) {
      alert('Nincs mit hozzáadni !');
      return false;
    }
    for ( i = 0; i < k; i++ ) {
      if ( elements[i].name.substring(0,2) == 'pc' ) {
        if ( elements[i].value != '' ) {
          n = parseInt( elements[i].value,10 );
          if ( isNaN( n ) || n == 0 ) {
            err = 1;
            alert( 'A mennyiségi adat a(z) '+j+'. sorban nem szám !');
            elements[i].focus();
            elements[i].select();
            return false;
          } else {
            //if ( 0 ) {
            if ( n < 1  || n > 99999 ) {
              err = 1;
              alert( 'Rossz mennyiségi adat a(z) '+j+'. sorban: '+n+' !');
              elements[i].focus();
              elements[i].select();
              return false;
            }
            elements[i].value = n;
          }
        }
        j++;
      }
    }
  }
  if (!err) {
    parent.main.document.clist.submit();             // Submit the checked items
  }
}
//
//
function res_note() {
  with ( parent.main.document.olist ) {
      parent.main.document.promt.note.value = '';
      note.value = '';
      submit();
  }
}
//
//
function get_ord_file() {
  with ( document.upload ) {
    var i, n, err = 0, j = 1;
    if ( ordfile.value != '' ) {
      if ( (n = ordfile.value.lastIndexOf(".")) > 0 ) {
        i = ordfile.value.substring(n,ordfile.value.length);
        if ( i == ".txt" || i == ".TXT" || i == ".dbf" || i == ".DBF" ) {
          submit();
        } else {
          err = 1;
          alert( 'A rendelési file-nak Szöveg (tabulátorral tagolt), vagy DBF (dBASE IV vagy III) file-típusúnak kell lenni !');
          ordfile.focus();
          ordfile.select();
          return false;
        }
      } else {
        err = 1;
        alert( 'A rendelési file-nak .txt vagy .dbf file-típusúnak kell lenni !');
        ordfile.focus();
        ordfile.select();
        return false;
      }
    } else {
      err = 1;
      alert( 'Nem adott meg rendelési file-t !');
      ordfile.focus();
      ordfile.select();
      return false;
    }
  }
}
//
//
function get_one_item() {
  with ( document.promt ) {
    var i, n, err = 0, j = 1, k = elements.length;
    if ( prme.value != '' ) {
      n = parseInt( prme.value,10 );
      if ( isNaN( n ) || n == 0 ) {
        err = 1;
        alert( 'A mennyiségi adat a beviteli sorban nem szám !');
        prme.focus();
        prme.select();
        return false;
      } else {
        if ( n == 0  || n > 99999 ) {
        //if ( n < 1  || n > 99999 ) {
          err = 1;
          alert( 'Rossz mennyiségi adat a beviteli sorban: '+n+' !');
          prme.focus();
          prme.select();
          return false;
        }
        prme.value = n;
      }
    }
    submit();
  }
}
//
//
function WaitingGetOneItem() {
  with ( document.promt ) {
    var i, n, err = 0, j = 1, k = elements.length;
    if ( prme.value != '' ) {
      n = parseInt( prme.value,10 );
      if ( isNaN( n ) || n == 0 ) {
        err = 1;
        alert( 'A mennyiségi adat a beviteli sorban nem szám !');
        prme.focus();
        prme.select();
        return false;
      } else {
        if ( n == 0  || n > 99999 ) {
        //if ( n < 1  || n > 99999 ) {
          err = 1;
          alert( 'Rossz mennyiségi adat a beviteli sorban: '+n+' !');
          prme.focus();
          prme.select();
          return false;
        }
        prme.value = n;
      }
    }
  }
  document.Form1.progress.value = "waiting";
  ModalDialogShow("Kapcsolódás...");
  document.promt.submit();
}
//
function GetOneItem() {
  with ( document.promt ) {
    var i, n, err = 0, j = 1, k = elements.length;
    if ( prme.value != '' ) {
      n = parseInt( prme.value,10 );
      if ( isNaN( n ) || n == 0 ) {
        err = 1;
        alert( 'A mennyiségi adat a beviteli sorban nem szám !');
        prme.focus();
        prme.select();
        return false;
      } else {
        if ( n == 0  || n > 99999 ) {
        //if ( n < 1  || n > 99999 ) {
          err = 1;
          alert( 'Rossz mennyiségi adat a beviteli sorban: '+n+' !');
          prme.focus();
          prme.select();
          return false;
        }
        prme.value = n;
      }
    }
  }
  document.promt.submit();
}
//
//
//
function MakeArray(n)
{
  this.length= n;
  for (var x=1; x<=n; x++) {
    this[x]=0;
  }
  return this;
}
//
function datum()
{
  var aDatum=new Date();
  var aEv=aDatum.getYear();
  var aHo=aDatum.getMonth();
  var aNap=aDatum.getDate();
  month = new MakeArray(12);
  month[0]="január"; month[1]="február"; month[2]="március"; month[3]="április"; month[4]="május"; month[5]="június";
  month[6]="július"; month[7]="augusztus"; month[8]="szeptember"; month[9]="október"; month[10]="november"; month[11]="december";
  if ( aEv < 1000) {
    aEv += 1900;
  }
  document.writeln(aEv+". "+month[aHo]+" "+aNap+". ");
  return;
}
//
// Append to href the order of listing parameter
//
function appendULR(href)
{
  return href+"&prend="+lrend;
}
//
// Go to list by gived search key
//
function append_src(href, sid) {
  var kulcs, kulcs1='';
  kulcs = parent.topbar.document.flink.srch.value;
  for ( x = 0; x < kulcs.length; x++ ) {
    if ( kulcs.charAt(x) == 'ű' || kulcs.charAt(x) == 'Ű' || kulcs.charAt(x) == 'ő' || kulcs.charAt(x) == 'Ő' ) {
      kulcs1 += ' ';
    } else {
      kulcs1 += kulcs.charAt(x);
    }
  }
  kulcs = escape( kulcs1 );
  if ( kulcs != "") {
    return href+"&prend="+lrend+"&key="+kulcs ;
  } else {
    return "/cgi-bin/catl_sh.pl?fnum=mall&sid="+sid;
  }
}
//
function href_(targ, hrefer)
{
  if ( targ != "" ) {
    eval("parent."+targ+".location.href=\'"+hrefer+"\'");
  } else {
    eval("location.href=\'"+hrefer+"\'");
  }
  return true;
}
//
function href_kiv(targ, hrefer)
{
  var kiv, j, i;
  j=eval("parent."+targ+".document.olist.kiv.length");
  if ( j > 0 ) {
    for (i=0; i<j; i++){
      if(eval("parent."+targ+".document.olist.kiv[i].checked")) {
        kiv = eval("parent."+targ+".document.olist.kiv[i].value");
        if ( targ != "" ) {
          eval("parent."+targ+".location.href=\'"+hrefer+"&kiv="+kiv+"\'");
        } else {
          eval("location.href=\'"+hrefer+"&kiv="+kiv+"\'");
        }
      }
    }
  } else {
    if (eval("parent."+targ+".document.olist.kiv.checked")) {
        kiv = eval("parent."+targ+".document.olist.kiv.value");
        if ( targ != "" ) {
          eval("parent."+targ+".location.href=\'"+hrefer+"&kiv="+kiv+"\'");
        } else {
          eval("location.href=\'"+hrefer+"&kiv="+kiv+"\'");
        }
    }
  }
  return true;
}
//
function href_lrend(targ, hrefer)
{
  if ( targ != "" ) {
    eval("parent."+targ+".location.href=\'"+hrefer+"&prend="+lrend+"\'");
  } else {
    eval("location.href=\'"+hrefer+"&prend="+lrend+"\'");
  }
  return true;
}
//
function href_lrend_kulcs(targ, hrefer, sid) {
  var kulcs, kulcs1='';
  kulcs = parent.topbar.document.flink.srch.value;
  for ( x = 0; x < kulcs.length; x++ ) {
//    if ( kulcs.charCodeAt(x) == 'ű' || kulcs.charCodeAt(x) == 'Ű' || kulcs.charCodeAt(x) == 'ő' || kulcs.charCodeAt(x) == 'Ő' ) {
    if ( kulcs.charCodeAt(x) == 369 || kulcs.charCodeAt(x) == 368 || kulcs.charCodeAt(x) == 337 || kulcs.charCodeAt(x) == 336 ) {
      kulcs1 += ' ';
    } else {
      kulcs1 += kulcs.charAt(x);
    }
  }
//  alert("kulcs="+kulcs+" kod="+kulcs.charCodeAt(0));
  kulcs = escape( kulcs1 );
  if ( kulcs != "" && targ != "" ) {
    eval("parent."+targ+".location.href=\'"+hrefer+"&prend="+lrend+"&key="+kulcs+"\'");
  } else if ( targ != "" ) {
    eval("parent."+targ+".location.href=\'/cgi-bin/catl_sh.pl?fnum=mall&sid="+sid+"\'");
  } else {
    eval("location.href=\'/cgi-bin/catl_sh.pl?fnum=mall&sid="+sid+"\'");
  }
  return true;
}
//
function href_lrend_kulcs_onenter(event, targ, hrefer, sid) {
  var kulcs, kulcs1='';
  kulcs = parent.topbar.document.flink.srch.value;
  var bolOldBrowser = (document.layers) ? true : false;
  var intKeyCode = 0;
  if (bolOldBrowser)
    intKeyCode = event.which;
  else
    intKeyCode = event.keyCode;
  if (intKeyCode == 13) {
    for ( x = 0; x < kulcs.length; x++ ) {
//    if ( kulcs.charCodeAt(x) == 'ű' || kulcs.charCodeAt(x) == 'Ű' || kulcs.charCodeAt(x) == 'ő' || kulcs.charCodeAt(x) == 'Ő' ) {
      if ( kulcs.charCodeAt(x) == 369 || kulcs.charCodeAt(x) == 368 || kulcs.charCodeAt(x) == 337 || kulcs.charCodeAt(x) == 336 ) {
        kulcs1 += ' ';
      } else {
        kulcs1 += kulcs.charAt(x);
      }
    }
//  alert("kulcs="+kulcs+" kod="+kulcs.charCodeAt(0));
    kulcs = escape( kulcs1 );
    if ( kulcs != "" && targ != "" ) {
      eval("parent."+targ+".location.href=\'"+hrefer+"&prend="+lrend+"&key="+kulcs+"\'");
    } else if ( targ != "" ) {
      eval("parent."+targ+".location.href=\'/cgi-bin/catl_sh.pl?fnum=mall&sid="+sid+"\'");
    } else {
      eval("location.href=\'/cgi-bin/catl_sh.pl?fnum=mall&sid="+sid+"\'");
    }
  return true;
  }
}
//
function menny_onenter(event, targ, hrefer, sid) {
  var kulcs, kulcs1='';
  kulcs = parent.topbar.document.flink.srch.value;
  var bolOldBrowser = (document.layers) ? true : false;
  var intKeyCode = 0;
  if (bolOldBrowser)
    intKeyCode = event.which;
  else
    intKeyCode = event.keyCode;
  if (intKeyCode == 13) {
    parent.main.document.promt.prme.focus();
    parent.main.document.promt.prme.select();
  return true;
  }
}
//
function href_lrend_kulcs_H(sid) {
  var kulcs, kulcs1='';
  kulcs = parent.topbar.document.flink.srch.value;
  for ( x = 0; x < kulcs.length; x++ ) {
//    if ( kulcs.charCodeAt(x) == 'ű' || kulcs.charCodeAt(x) == 'Ű' || kulcs.charCodeAt(x) == 'ő' || kulcs.charCodeAt(x) == 'Ő' ) {
    if ( kulcs.charCodeAt(x) == 369 || kulcs.charCodeAt(x) == 368 || kulcs.charCodeAt(x) == 337 || kulcs.charCodeAt(x) == 336 ) {
      kulcs1 += ' ';
    } else {
      kulcs1 += kulcs.charAt(x);
    }
  }
//  alert("sid="+sid);
  kulcs = escape( kulcs1 );
  if ( kulcs != "" ) {
    eval("parent.main.location.href=\'/cgi-bin/catl_sh.pl?fnum=src&prend="+lrend+"&key="+kulcs+"&sid="+sid+"\'");
  } else {
    eval("parent.main.location.href=\'/cgi-bin/catl_sh.pl?fnum=mall&sid="+sid+"\'");
  }
  return true;
}
//
//
//
function attent() {
  with ( document.clist ) {
    var i, n = 0, err = 1, j = "", k = elements.length;
    for ( i = 0; i < k; i++ ) {
      if ( elements[i].name.substring(0,2) == 'pc' ||
           elements[i].name.substring(0,2) == 'pa' ) {
        if ( elements[i].value != '' ) {
          n++;
          j = j+elements[i].name.string(2,6)+'. ';
          err = 0;
        }
      }
    }
    if ( err ) {
      return;
    } else {
      if ( alert('FIGYELEM!   Ön  '+n+'  tételt: '+j+' kiválasztott, de nem adta hozzá a rendeléshez. Sajnos erre már nincs lehetőség. Később visszatérhet erre az oldalra, hogy kiegészítse a megrendelést.') ) {
      }
    }
  }
  return true;
}
//
// Go to the URL from selection
//
function gotoURL(form) {
  parent.main.location.href = form.options[form.selectedIndex].value+'&prend='+lrend;
  return true;
}
//
// Refres 'listing by' in selection
//
function refr_prend() {
  if ( parent.logo.document.flag.prend.value == "kod" ) {
    parent.topbar.document.flink.rend[0].selected = true;
  } else {
    parent.topbar.document.flink.rend[1].selected = true;
  }
  return true;
}
//
// Change 'listing by' value in variable
//
function change_prend() {
  if ( parent.topbar.document.flink.rend[0].selected ) {
    parent.logo.document.flag.prend.value = "kod";
  } else {
    parent.logo.document.flag.prend.value = "nev";
  }
  return true;
}
/**
 * Sets/unsets the pointer and marker in browse mode
 *
 * @param   object   the table row
 * @param   string   the action calling this script (over, out or click)
 * @param   string   the default background color
 * @param   string   the color to use for mouseover
 * @param   string   the color to use for marking a row
 *
 * @return  boolean  whether pointer is set or not
 */
function setPointer(theRow, theAction, theDefaultColor, thePointerColor, theMarkColor)
{
  var theCells = null;
  var theInput = null;
  var theImg   = null;
  //
  //  Open the picture if click on it in the row
  if (typeof(window.opera) == 'undefined'
      && typeof(theRow.getAttribute) != 'undefined') {
      theImg   = theRow.getAttribute('src');
  }
  // 3.2 ... with other browsers
  else {
      theImg = theRow.src;
  } // end 3

  if (theAction == 'click' && theImg != null) {
      openPic(theImg);
      return true;
  //
  } else if (theAction == 'click' && typeof(picwin) != 'undefined' && !picwin.closed) {
      picwin.focus();
      return true;
  }
  // Continue setPointer
  // 1. Pointer and mark feature are disabled or the browser can't get the
  //    row -> exits
  if ((thePointerColor == '' && theMarkColor == '')
      || typeof(theRow.style) == 'undefined') {
      return false;
  }

  // 2. Gets the current row and exits if the browser can't get it
  if (typeof(document.getElementsByTagName) != 'undefined') {
      theCells = theRow.getElementsByTagName('td');
      theInput = theRow.getElementsByTagName('input');
  }
  else if (typeof(theRow.cells) != 'undefined') {
      theCells = theRow.cells;
  }
  else {
      return false;
  }
  //
  // 3. Gets the current color... az első <TD>,<TH>-nak kell saját BGCOLOR tulajdonság!
  //                              a Firefox nem adja vissza, ha a <TR>-től örökölte!
  var rowCellsCnt  = theCells.length;
  var domDetect    = null;
  var currentColor = null;
  var newColor     = null;
  // 3.1 ... with DOM compatible browsers except Opera that does not return
  //         valid values with "getAttribute"
  if (typeof(window.opera) == 'undefined'
      && typeof(theCells[0].getAttribute) != 'undefined') {
      currentColor = theCells[0].getAttribute('bgcolor');
      domDetect    = true;
  }
  // 3.2 ... with other browsers
  else {
      currentColor = theCells[0].style.backgroundColor;
      domDetect    = false;
  } // end 3
  // 4. Defines the new color
  // 4.1 Current color is the default one
  if (currentColor == ''
      || currentColor.toLowerCase() == theDefaultColor.toLowerCase()) {
      if (theAction == 'over' && thePointerColor != '') {
          newColor = thePointerColor;
      }
      else if (theAction == 'click' && theMarkColor != '') {
          newColor = theMarkColor;
          if (theInput[0] != null) {
            theInput[0].focus();
          }
      }
      else if (theAction == 'down' && theMarkColor != '') {
          newColor = theMarkColor;
      }
  }
  // 4.1.2 Current color is the pointer one
  else if (currentColor.toLowerCase() == thePointerColor.toLowerCase()) {
      if (theAction == 'out') {
          newColor = theDefaultColor;
      }
      else if (theAction == 'click' && theMarkColor != '') {
          newColor = theMarkColor;
          if (theInput[0] != null) {
            theInput[0].focus();
          }
      }
      else if (theAction == 'down' && theMarkColor != '') {
          newColor = theMarkColor;
      }
  }
  // 4.1.3 Current color is the marker one
  else if (currentColor.toLowerCase() == theMarkColor.toLowerCase()) {
      if (theAction == 'click') {
          newColor = (thePointerColor != '')
                   ? thePointerColor
                   : theDefaultColor;
          if (theInput[0] != null) {
            theInput[0].focus();
          }
      }
      else if (theAction == 'up' && theMarkColor != '') {
          newColor = thePointerColor;
      }
  } // end 4

  // 5. Sets the new color...
  if (newColor) {
      var c = null;
      // 5.1 ... with DOM compatible browsers except Opera
      if (domDetect) {
          for (c = 0; c < rowCellsCnt; c++) {
              theCells[c].setAttribute('bgcolor', newColor, 0);
          } // end for
      }
      // 5.2 ... with other browsers
      else {
          for (c = 0; c < rowCellsCnt; c++) {
              theCells[c].style.backgroundColor = newColor;
          }
      }
  } // end 5
  return true;
} // end of the 'setPointer()' function
//
//
//

function setButton(theCell, theAction, theDefaultColor, thePointerColor, theMarkColor)
{
  var theCells = null;

  // 1. Pointer and mark feature are disabled or the browser can't get the
  //    row -> exits
  if ((thePointerColor == '' && theMarkColor == '')
      || typeof(theCell.style) == 'undefined') {
      return false;
  }

  // 3. Gets the current color...
  var domDetect    = null;
  var currentColor = null;
  var newColor     = null;
  // 3.1 ... with DOM compatible browsers except Opera that does not return
  //         valid values with "getAttribute"
  if (typeof(window.opera) == 'undefined'
      && typeof(theCell.getAttribute) != 'undefined') {
      currentColor = theCell.getAttribute('bgcolor');
      domDetect    = true;
  }
  // 3.2 ... with other browsers
  else {
      currentColor = theCell.style.backgroundColor;
      domDetect    = false;
  } // end 3

  // 4. Defines the new color
  // 4.1 Current color is the default one
  if (currentColor == ''
      || currentColor.toLowerCase() == theDefaultColor.toLowerCase()) {
      if (theAction == 'over' && thePointerColor != '') {
          newColor = thePointerColor;
      }
      else if (theAction == 'click' && theMarkColor != '') {
          newColor = theMarkColor;
      }
      else if (theAction == 'down' && theMarkColor != '') {
          newColor = theMarkColor;
      }
  }
  // 4.1.2 Current color is the pointer one
  else if (currentColor.toLowerCase() == thePointerColor.toLowerCase()) {
      if (theAction == 'out') {
          newColor = theDefaultColor;
      }
      else if (theAction == 'click' && theMarkColor != '') {
          newColor = theMarkColor;
      }
      else if (theAction == 'down' && theMarkColor != '') {
          newColor = theMarkColor;
      }
  }
  // 4.1.3 Current color is the marker one
  else if (currentColor.toLowerCase() == theMarkColor.toLowerCase()) {
      if (theAction == 'click') {
          newColor = (thePointerColor != '')
                   ? thePointerColor
                   : theDefaultColor;
      }
      else if (theAction == 'up' && theMarkColor != '') {
          newColor = thePointerColor;
      }
  } // end 4

  // 5. Sets the new color...
  if (newColor) {
      var c = null;
      // 5.1 ... with DOM compatible browsers except Opera
      if (domDetect) {
          theCell.setAttribute('bgcolor', newColor, 0);
      }
      // 5.2 ... with other browsers
      else {
          theCell.style.backgroundColor = newColor;
      }
  } // end 5

  return true;
} // end of the 'setPointer()' function

