function appendOptionLast(doc, objSel, sValue, sText)
{
  var elOptNew = doc.createElement('option');
  elOptNew.text = sText;
  elOptNew.value = sValue;

  try {
    objSel.add(elOptNew, null); // standards compliant; doesn't work in IE
  }
  catch(ex) {
    objSel.add(elOptNew); // IE only
  }
}

function strpos(haystack, needle, offset)
{
  var i = (haystack+'').indexOf( needle, offset ); 
  return i===-1 ? false : i;
}

function IsNumeric(sText)
{
  var ValidChars = "0123456789.";
  var Char;
  for (i = 0; i < sText.length; i++)
  { 
    Char = sText.charAt(i);
    if (ValidChars.indexOf(Char) == -1)
      return false;
  }
  return true;
}

function trim(s) 
{
  return s.replace(/^\s+|\s+$/g,"");
}

function str_replace(search, replace, subject, count) 
{
  var i = 0, j = 0, temp = '', repl = '', sl = 0, fl = 0, f = [].concat(search), r = [].concat(replace), s = subject, ra = r instanceof Array, sa = s instanceof Array;
  s = [].concat(s);
  if (count)
    this.window[count] = 0;

  for (i=0, sl=s.length; i < sl; i++)
  {
    if (s[i] === '')
      continue;
    for (j=0, fl=f.length; j < fl; j++) 
    {
      temp = s[i]+'';
      repl = ra ? (r[j] !== undefined ? r[j] : '') : r[0];
      s[i] = (temp).split(f[j]).join(repl);
      if (count && s[i] !== temp)
        this.window[count] += (temp.length-s[i].length)/f[j].length;
    }
  }
  return sa ? s : s[0];
}

function number_format(number, decimals, dec_point, thousands_sep) 
{ 
  var n = number, c = isNaN(decimals = Math.abs(decimals)) ? 2 : decimals;
  var d = dec_point == undefined ? "," : dec_point;
  var t = thousands_sep == undefined ? "." : thousands_sep, s = n < 0 ? "-" : "";
  var i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "", j = (j = i.length) > 3 ? j % 3 : 0;
  return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : "");
}

function Teljesitmenyszamitas()
{
  d=window.document;
  oA=d.getElementById("alapterulet");
  oB=d.getElementById("belmagassag");
  oF=d.getElementById("falszerkezet");
  dA=trim(oA.value);
  dB=trim(oB.value);
  dF=trim(oF.value);
  dA = dA.replace(/\,/g,".");
  dB = dB.replace(/\,/g,".");
  if (!IsNumeric(dA)) dA = 0.0;
  if (!IsNumeric(dB)) dB = 0.0;
  if (!IsNumeric(dF)) dF = 0.0;
  dResult=dA*dB*dF / 1000;
  if (dResult == 0)
  {
    alert("A számításhoz kérjük helyesen töltse ki a kért adatokat!");
    return false;
  }
  return true;
}

// Functions for MarkaMenu
function readCookie(name)
{
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for (var i=0; i < ca.length; i++) 
  {
    var c = ca[i];
    while (c.charAt(0)==' ') 
      c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0)
      return c.substring(nameEQ.length,c.length);
  }
  return null;
}

function getSlideDisplay(sDivIDPrefix, iOpenDivID)
{
  var obj = document.getElementById(sDivIDPrefix + iOpenDivID);
  return obj.style.display;
}

function SlideWithAutoclose(sDivIDPrefix, iOpenDivID)
{
  var obj = document.getElementById(sDivIDPrefix + iOpenDivID);
  if (obj.style.display == 'block')
  {
    // Clear the index of the opened div into a cookie
    document.cookie = 'markamenu=; expires=Tue, 31 Dec 2030 23:59:59 UTC; path=/';

    // Just close the currently selected item up
    slideup(sDivIDPrefix + iOpenDivID);
  }
  else
  {
    // Save the index of the opened div into a cookie
    document.cookie = 'markamenu=' + sDivIDPrefix + iOpenDivID + '; expires=Tue, 31 Dec 2030 23:59:59 UTC; path=/';

    // Open the currently selected item down and close all others up
    for (var i = 1; i <= 8; i++)
    {
      if (iOpenDivID == i)
        slidedown(sDivIDPrefix + i);
       else {
        slideup(sDivIDPrefix + i);
        if (obj != document.getElementById('kep'+i))
          document.getElementById('kep'+i).src = 'gfx/marka_'+kepek['kep'+i]+'_off.jpg';
      }
    }
  }
}

