function DOMSupport()
{
  if(document.getElementById)
    return true;
  else
    return false;
}

function getAncestorByTag(phNode, pcTagName)
{
  var lcTestTagName = pcTagName.toUpperCase();
  
  while(phNode!=null && typeof(phNode.tagName)!="undefined"){ 
  
    if(phNode.tagName.toUpperCase() == lcTestTagName){
      return phNode;
    }

    phNode = phNode.parentNode;  
  }
  
  return null;
}

function SubmitVariableValue(pcName, piValue)
{
  var lhElem = null;
  var lhForm = null;

  if(DOMSupport())
    lhElem = document.getElementById(pcName);

  // Nav 4.7
  else{
    // Zuerst durch alle Forms iterieren
    for(var i=0;i<document.forms.length && lhForm==null;i++){

      // Nun durch alle Elemente im Form iterieren
      for(var e=0;e<document.forms[i].elements.length && lhElem==null;e++){
        if(document.forms[i].elements[e].name==pcName){
          lhForm = document.forms[i];
          lhElem = lhForm.elements[e];
        }
      }
    }
  }

  if(!lhElem){
    alert("Element mit Id " + pcName + " not found!");  
    return;
  }

  if(lhForm==null){
    lhForm = getAncestorByTag(lhElem, "form");
    if(lhForm==null){
      alert("Form of " + pcName + " not found!");    
      return;
    }
  }
  
  lhElem.value = piValue;
  lhForm.submit();
}

function SubmitVariableIncrement(pcName, piRelValue)
{
  var lhElem = null;
  var lhForm = null;

  if(DOMSupport())
    lhElem = document.getElementById(pcName);

  // Nav 4.7
  else{
    // Zuerst durch alle Forms iterieren
    for(var i=0;i<document.forms.length && lhForm==null;i++){

      // Nun durch alle Elemente im Form iterieren
      for(var e=0;e<document.forms[i].elements.length && lhElem==null;e++){
        if(document.forms[i].elements[e].name==pcName){
          lhForm = document.forms[i];
          lhElem = lhForm.elements[e];
        }
      }
    }
  }

  if(!lhElem){
    alert("Element mit Id " + pcName + " not found!");  
    return;
  }

  var liValue = parseInt(lhElem.value, 10) + parseInt(piRelValue, 10);
  
  SubmitVariableValue(pcName, liValue);
}

function GetParentByTagName(poItem, pcTagName)
{
  var loParent = poItem.parentNode;
  while(loParent!=null && (loParent.tagName==undefined || loParent.tagName.toUpperCase()!=pcTagName.toUpperCase()))
  {
    loParent = loParent.parentNode;
  }
  
  if(loParent!=null)
    return loParent;
  else
    return null;
}

function GetFirstChildByTagName(poItem, pcTagName)
{
  var loChild = poItem.firstChild;
  
  while(loChild!=null && (loChild.tagName==undefined || loChild.tagName.toUpperCase()!=pcTagName.toUpperCase()))
  {
    loChild = loChild.nextSibling;
  }
  
  if(loChild!=null)
    return loChild;
  else
    return null;
}

function GetLastChildByTagName(poItem, pcTagName)
{
  var loChild = poItem.lastChild;
  while(loChild!=null && (loChild.tagName==undefined || loChild.tagName.toUpperCase()!=pcTagName.toUpperCase()))
  {
    loChild = loChild.previousSibling;
  }
  
  if(loChild!=null)
    return loChild;
  else
    return null;
}

// Liste mit "," getrennt von allen Feldern, welche in die URL-kompatible Liste hinzugefügt werden sollen
function CollectFieldsAsUrl(pcFormName, pcFieldsList)
{
  var laFieldsList=pcFieldsList.split(",");
  
  var lcResult="";

  // Durch die Liste der Felder iterieren
  for(var i=0;i<laFieldsList.length;i++)
  {
    var lcValue = eval("document." + pcFormName + "." + laFieldsList[i] + ".value");
    
    // Zur Liste dazu
    // if(lcValue!="")
    {
      if(lcResult!="")
        lcResult = lcResult + "&";
        
      lcResult = lcResult + laFieldsList[i] + "=" + escape(lcValue);
    } 
  }

  return lcResult;
}

