//--------termek mennyiseg ellenorzese-----------
function determinateKeypress(e, o) {
  if (e.keyCode < 32) return true;
  var s = o.value + String.fromCharCode(e.keyCode);
  var r = new RegExp(o.getAttribute('pattern'), 'gi');
  if (!s.match(r)) {
    window.event.returnValue = false;
    return false;
  }
}
//--------termek mennyiseg ellenorzese END-----------


//--------rendeles adatok ellenorzese-----------
function doDisBefore() {
  var c = document.getElementById('check_shippingoption');

  if (c.value == '') {
    document.getElementById('umustdothis').style.display = 'inline';
    document.getElementById('imeanthis').style.display = 'inline';
    document.getElementById('sendMessageNameRow').style.background = '#FFD3D2';
  }

  var aa = document.getElementById('chzip_0');
  var ab = document.getElementById('chcity_0');
  var ac = document.getElementById('chstreet_0');

  if (c.value != '81A57FC3-D62B-4460-924B-4D36021D6CA7' && (aa.value == '' || ab == '' || ac == '')) {
    document.getElementById('imeanthis').style.display = 'inline';
  }

  if (c.value == '' || (c.value != '81A57FC3-D62B-4460-924B-4D36021D6CA7' && (aa.value == '' || ab == '' || ac == ''))) {
    return 0;
  }

  document.push_address.comment.value = document.ordernow.comment.value;
  document.getElementById('dynamic_save').value = 'true';
  document.push_address.submit();
}
//--------rendeles adatok ellenorzese END-----------

//--------rendeles adatok modositasa-----------
function submitOrderForm(o, instanceID, form) {
  if (form != null) {
    var data = queryStringBuilder(form);
    //        refresh(o, instanceID, data);
    refresh(o, instanceID, null, 'post', data, null, null, 'application/x-www-form-urlencoded');
  }
}
//--------rendeles adatok modositasa END-----------

//---megrendeles oldalra link beleptetessel--------
function goOrderPage(url, oid) {
  var o = document.getElementById(oid);
  if (o != null) {
    var re = new RegExp("(^.*?&LandingUrl=)(.*?)(&.*?)$", "g");
    location.href = o.href.replace(re, '$1' + url + '$3');
  } else {
    //location.href = url;
  }
}
//---megrendeles oldalra link beleptetessel END----


//--------innentol merc----------------------------

function bagIn(e, o, productid, price) {
  //ha nincs ar, akkor itt üzenünk, hogy belebutt a gyasz
  if (price == '') {
    alert('Kerem toltse ki a szukseges adatokat!');
    return false;
  }
  var cart = document.getElementById('eshopcart');
  cart.scrollIntoView();
  var rlt = new RegExp('&lt;', 'gi');
  var rgt = new RegExp('&gt;', 'gi');
  data = o.nextSibling.nextSibling.innerHTML.replace(rlt, '<').replace(rgt, '>');
  //alert(data);
  var qs = 'pageloader.parsecontent=true&productid=' + productid + '&action=add&external=true';
  refresh(cart, cart.getAttribute('instance-id'), qs, 'post', data, null, null, 'text/plain', false);
  //submitBox(e, o.form, cart, cart.getAttribute('instance-id'), 'exml', false, false, 'productid=' + productid + '&action=add&external=true');
}

//--------minikosar frissitese----------------
function refreshMiniCart(wr) {
  ivy.box.refreshCallback(wr);
  if (document.getElementById('minicart') == null) return;
  ivy.box.refresh({
    htmlElement: document.getElementById('minicart'),
    rollOver: progressIndicator
  });
}
//--------minikosar frissitese END------------

//------------kosar--------------------------
function addCart(e, pid, o, id) {
  id = (id == '' || id == null) ? 'eshopcart' : id;
  ivy.box.refresh({
    htmlElement: document.getElementById(id),
    rollOver: progressIndicator,
    queryString: 'action=add&cartdisp=block&productid=' + pid + '&productnum=' + o.value,
    callback: refreshMiniCart
  });
}

function modCart(e, pid, o, id) {
  id = (id == '' || id == null) ? 'eshopcart' : id;
  ivy.box.refresh({
    htmlElement: document.getElementById(id),
    rollOver: progressIndicator,
    queryString: 'action=modify&cartdisp=block&relationid=' + pid + '&productnum=' + o.value,
    callback: refreshMiniCart
  });
}

function delCart(e, rid, o, id) {
  id = (id == '' || id == null) ? 'eshopcart' : id;
  ivy.box.refresh({
    htmlElement: document.getElementById(id),
    rollOver: progressIndicator,
    queryString: 'action=delete&relationid=' + rid,
    callback: refreshMiniCart
  });
}

//------megrendelo oldal-----------------
function setOrder(e, source, iid, qs) {
  ivy.box.submit({
    event: e,
    source : source,
    instanceID: iid,
    rollOver: progressIndicator,
    queryString : qs
  });
}

//----------lapozas-------------------------
function flippage(e, pid, o, id) {
  id = (id == '' || id == null) ? 'eshopcart' : id;
  ivy.box.refresh({
    htmlElement: document.getElementById(id),
    rollOver: progressIndicator,
    queryString: 'action=modify&cartdisp=block&relationid=' + pid + '&productnum=' + o.value,
    callback: refreshMiniCart
  });
}

/*admin*/

var _roli;

function showRollover() {
  var o = document.getElementById('pReadContent');
  var dim = ivy.box.createRolloverDiv(o, ivy.box.defaultRollOverProperties);
  _roli = dim.element;
}

function resendEmail(o, pid) {
  ivy.box.refresh({
    htmlElement: ivy.dom.getParentByTagName(o, 'TR'),
    fragment: true,
    rollOver: true,
    url: '/xslt/posta-search-identity.xslt',
    queryString: 'cmd=resend&pid=' + pid,
    callback: function() { alert('Az aktiváló email-t újraküldtük.'); }
  });
}

function removeEntity(o, pid) {
  if (confirm('Figyelem! A felhasználó összes adata törlődik. Biztosan törölni szeretné a felhasználót?')) ivy.box.refresh({
    htmlElement: ivy.dom.getParentByTagName(o, 'TR'),
    fragment: true,
    rollOver: true,
    url: '/xslt/posta-search-identity.xslt',
    queryString: 'cmd=remove&pid=' + pid,
    callback: removeEntityCallback
  });
}

function removeEntityCallback(wr) {
  var xml = wr.requester.responseXML;
  if (ivy.xml.xpath.valueOf(xml.documentElement) == '200 OK') wr.srcElement.parentNode.removeChild(wr.srcElement);
}

function onFocusEditEmailChange(span) {
  var input = ivy.dom.nextSibling(span);

  span.style.display = 'none';
  input.style.display = 'inline';
  input.focus();
}

function onBlurEditEmailChange(input, pid) {
  var span = ivy.dom.previousSibling(input);

  input.style.display = 'none';
  span.style.display = 'inline';
  span.innerHTML = input.value;

  ivy.box.refresh({
    htmlElement: ivy.dom.getParentByTagName(input, 'TR'),
    fragment: true,
    rollOver: true,
    url: '/xslt/posta-search-identity.xslt',
    queryString: 'cmd=set&pid=' + pid + '&prop=EmailAddress&value=' + input.value,
    callback: function() { }
  });
}



/*admin END*/