/* backward compatibility functions */
function refresh(htmlElement, instanceID, qs, method, postdata, fragment, url, contenttype, rollover) {
  ivy.box.refresh({
    htmlElement : htmlElement, 
    instanceID : instanceID, 
    queryString: qs, 
    method : method,
    postData : postdata, 
    fragment : fragment, 
    url : url,
    contentType: contenttype || (method == 'post' ? 'application/x-www-form-urlencoded' : null), 
    rollOver : rollover || pi
  });
}

function pagerRefresh(htmlElement, instanceID, qs, method, postdata, fragment, url, contenttype, rollover, pagenum) {
    var p = location.href.indexOf('#');
    if (p == -1) p = location.href.length;
    location.href = location.href.substring(0, p) + '#page=' + pagenum;
    document.getElementById('logo').scrollIntoView();
    refresh(htmlElement, instanceID, qs, method, postdata, fragment, url, contenttype, rollover);
}

function submitBox(e, o, target, instanceID, method, rollover, handleErrors, qs) {
  ivy.box.submit({
    event: e,
    source: o,
    target: target,
    instanceID: instanceID,
    fragment: (instanceID == null || instanceID == ''),
    queryString: qs,
    method: method,
    rollOver: pi,
    errorHandler: (handleErrors ? highlightMandantoryFields : null)
  });
}

function submitform(e, o) {
  o.onsubmit(e);
}


function highlightMandantoryFields(o) {
  var e = o.elements;
  var count = 0;
  for (var i = 0; i < e.length; i++) {
    if (e[i].className.indexOf(' mandantory') == -1) continue;
    var p = e[i].parentNode;
    while (p.tagName.toLowerCase() != 'tr') p = p.parentNode;
    errorText = findErrorText(p);
    if (ivy.browser.isIE) {
      e[i].fireEvent('onerrorupdate');
    } else {
      var script = e[i].getAttribute('onerrorupdate');
      if (script != null) {
        script = script.replace('this', 'e[i]');
        eval(script);
      }
    }
    var value = ivy.box.inputValue(e[i]);
    if (!ivy.box.validInput(e[i], value)) {
      if (e[i].getAttribute('forcecommand') == 'submit') {
        removeMandantoryHighlights(o);
        continue;
      }
      if (p.className.indexOf(' error') == -1) p.className += ' error';
      if (errorText != null) errorText.style.display = 'block';
      count++;
    } else {
      p.className = p.className.replace(' error', '');
      if (errorText != null) errorText.style.display = 'none';
    }
  }
  return count;
}

function findErrorText(p) {
  var divs = p.getElementsByTagName('DIV');
  var j = 0;
  while (j < divs.length && divs[j].className != 'errorText') j++;
  if (j < divs.length) return divs[j];
}

function removeMandantoryHighlights(o) {
  var e = o.elements;
  for (var i = 0; i < e.length; i++) {
    removeHighlighting(e[i]);
  }
}

function removeHighlighting(element) {
  var p = element.parentNode;
  while (p != null && p.tagName && p.tagName.toLowerCase() != 'tr') p = p.parentNode;
  if (p == null || !p.tagName) return;
  var divs = p.getElementsByTagName('DIV');
  var errorText = null;
  var j = 0;
  while (j < divs.length && divs[j].className != 'errorText') j++;
  if (j < divs.length) divs[j].style.display = 'none';
  p.className = p.className.replace(' error', '');
}