function findInList(searchWhat, searchIn)
{
    if(!searchIn)
        return;
    
    for(i=0; i<searchIn.childNodes.length; i++)
        if ( searchIn.childNodes[i].value == searchWhat )
            return i;
    return 0;
}

// Element zentrieren
var IEPopUpFix = null;  // Für den IE < 7.0
function centerElem(what)
{
    if ( !what )
        return;
    
    what.style.display = "block";
    what.style.left    = Math.floor( (document.body.offsetWidth  - what.offsetWidth ) / 2 ) + "px";
    
    if ( window.scrollY )
        what.style.top = Math.floor( (document.body.offsetHeight - what.offsetHeight) / 2 ) + window.scrollY + "px";    // FFox
    else
        // Since IE < 7.0 switches to strict mode, "document.body.offsetHeight" would fail here! It returns the document height itself (scrollable area) ...
        what.style.top = Math.floor( (document.documentElement.clientHeight - what.offsetHeight) / 2 ) + document.documentElement.scrollTop + "px";
    
    //if ( what.className == "loadingAnimation" )
        //what.style.left = Math.floor( (document.body.offsetWidth  - what.offsetWidth ) / 2 ) + 200 + "px";
} // centerElem()


// HTML-Site modal schalten
var modalElem = null;
var popUpElem = null
function centerModalElem(){ centerElem(popUpElem); }
function makeModal( state, objPopUp )
{
    popUpElem = objPopUp;
    if ( state )
    {
        modalElem           = document.createElement( "div" );
        modalElem.className = "modalOverlay";
        modalElem.style.height = document.body.parentNode.scrollHeight + "px";
        document.body.appendChild(modalElem);
        
        if ( window.navigator.appName.toLowerCase().indexOf("microsoft") != -1 )
        {
            if ( ! IEPopUpFix )
            {
                IEPopUpFix = document.createElement("iframe");
                IEPopUpFix.frameBorder  = "0";
                IEPopUpFix.scrolling    = "no";
                IEPopUpFix.className    = "IEPopUpFix";
                IEPopUpFix.style.height = document.body.parentNode.scrollHeight + "px";
                document.body.appendChild(IEPopUpFix);
            }
        }
        
        
        //if ( !window.scrollY )
        //{
            //window.onresize = new Function( centerModalElem() );
            //window.onscroll = new Function( centerModalElem() );
        //}
        //else
        //{
            window.onresize = centerModalElem;
            window.onscroll = centerModalElem;
        //}
    }
    else
    {
        document.body.removeChild(modalElem);
        if ( IEPopUpFix )
		{
            document.body.removeChild(IEPopUpFix);
			IEPopUpFix = null;
		}
    }
} // makeModal()


// DIV zusammelklappen
function foldUnfold( what )
{
    if (( ! what ) || ( ! what.parentNode ))
        return;
    
    minHeight = what.offsetHeight + 1;
    parentObj = what.parentNode;
    
    if ( parentObj.style.height == minHeight + "px" )
        if ( parentObj.style.removeProperty )
            parentObj.style.removeProperty( "height" );
        else
            parentObj.style.removeAttribute( "height" );
    else
        if ( parentObj.style.setProperty )
            parentObj.style.setProperty( "height", minHeight + "px", null );
        else
            parentObj.style.setAttribute( "height", minHeight + "px", null );
} // foldUnfold()


// AJAX-Vorschläge für die Suche
function suggestSearchTerm( obj, onComplete )
{
    if (( !obj ) || ( !onComplete ))
        return; 
    
    ajax = new AJAXObj();
    ajax.requestAsync( "suggestSearchTerm.php?w="+obj.value, function callBack(xml)
                                                          {
                                                            entries = xml.getElementsByTagName("entry");
                                                            
                                                            if ( entries.length == 0 )
                                                            {
                                                                onComplete( new Array() );
                                                                return;
                                                            }
                                                            
                                                            opts = new Array();
                                                            for(i=0; i< entries.length; i++)
                                                                opts.push( entries[i].firstChild.nodeValue );
                                                            
                                                            onComplete(opts);
                                                          }
                     );
} // suggestSearchTerm()


// AJAX-Vorschläge für die Filialen
function suggestStreet( obj, onComplete )
{
    if (( !obj ) || ( !onComplete ))
        return; 
    
    ajax = new AJAXObj();
    ajax.requestAsync( "suggestStreet.php?w="+obj.value, function callBack(xml)
                                                          {
                                                            entries = xml.getElementsByTagName("entry");
                                                            
                                                            if ( entries.length == 0 )
                                                                return;
                                                            
                                                            opts = new Array();
                                                            for(i=0; i< entries.length; i++)
                                                                opts.push( entries[i].firstChild.nodeValue );
                                                            
                                                            onComplete(opts);
                                                          }
                     );
} // suggestStreet()


// AJAX-Vorschläge für die Filialen
function suggestStoreProf( obj, onComplete )
{
    if (( !obj ) || ( !onComplete ))
        return; 
    
    ajax = new AJAXObj();
    ajax.requestAsync( "suggestStoreProf.php?w="+obj.value, function callBack(xml)
                                                          {
                                                            entries = xml.getElementsByTagName("entry");
                                                            
                                                            if ( entries.length == 0 )
                                                            {
                                                                onComplete( new Array() );
                                                                return;
                                                            }
                                                            
                                                            opts = new Array();
                                                            for(i=0; i< entries.length; i++)
                                                                opts.push( entries[i].firstChild.nodeValue.split('|')[1] );
                                                            
                                                            onComplete(opts);
                                                          }
                     );
} // suggestSearchTerm()


// AJAX-Vorschläge für die Filialen
function suggestStoreProfMaster( obj, onComplete )
{
    if (( !obj ) || ( !onComplete ))
        return; 
    
    ajax = new AJAXObj();
    ajax.requestAsync( "suggestStoreProfMaster.php?w="+obj.value, function callBack(xml)
                                                          {
                                                            entries = xml.getElementsByTagName("entry");
                                                            
                                                            if ( entries.length == 0 )
                                                                return;
                                                            
                                                            opts = new Array();
                                                            for(i=0; i< entries.length; i++)
                                                                opts.push( entries[i].firstChild.nodeValue.split('|')[1] );
                                                            
                                                            onComplete(opts);
                                                          }
                     );
} // suggestSearchTerm()


// AJAX Callback für die Combobox der Kategorien
function callBack_IMG(xml)
{
    if ( !xml )
        return;
    
    entries = xml.getElementsByTagName("entry");
    obj     = document.getElementById( "itemImg" );
    
    if ( entries.length == 0 || !obj )
        return;
    
    while(obj.childNodes.length > 0)
        obj.removeChild(obj.childNodes[0]);
    
    sel           = document.createElement( "option" );
    sel.value     = "";
    sel.innerHTML = "- bitte wählen -";
    obj.appendChild(sel);
    for(i=0; i< entries.length; i++)
    {
        nodeVal   = entries[i].firstChild.nodeValue;
        lSplit    = nodeVal.split("|");
        sel       = document.createElement( "option" );
        
        sel.value     = lSplit[0];
        sel.innerHTML = lSplit[1];
        obj.appendChild(sel);
    }
} // callBack_IMG()


// AJAX Callback für die Combobox der Warengruppe
function callBack_ISG(xml)
{
    if ( !xml )
        return;
    
    entries = xml.getElementsByTagName("entry");
    obj     = document.getElementById( "itemIsg" );
    
    if ( entries.length == 0 || !obj )
        return;
    
    while(obj.childNodes.length > 0)
        obj.removeChild(obj.childNodes[0]);
    
    sel           = document.createElement( "option" );
    sel.value     = "";
    sel.innerHTML = "- bitte wählen -";
    obj.appendChild(sel);
    for(i=0; i< entries.length; i++)
    {
        nodeVal   = entries[i].firstChild.nodeValue;
        lSplit    = nodeVal.split("|");
        sel       = document.createElement( "option" );
        
        sel.value     = lSplit[0];
        sel.innerHTML = lSplit[1];
        obj.appendChild(sel);
    }
} // callBack_ISG()


// Ruft die Folgekategorien ab
function getCatList( what )
{
    itemCat = document.getElementById("itemCat");
    itemImg = document.getElementById("itemImg");
    itemIsg = document.getElementById("itemIsg");
    
    if ( !itemCat || !itemImg || ! itemIsg || !what )
        return;
    
    // Bestehende Selektion entfernen
    AJAX = new AJAXObj();
    switch(what)
    {
        case itemCat:
            itemImg.selectedIndex = 0;
            itemIsg.selectedIndex = 0;
            itemImg.innerHTML     = "";
            itemIsg.innerHTML     = "";
            clearFindItemCategory();
            
            callBack_Properties(null);
            AJAX.requestAsync( "getItemGroups.php?w="+itemCat.value, callBack_IMG );
        break;
        
        case itemImg:
            itemIsg.selectedIndex = 0;
            itemIsg.innerHTML     = "";
            clearFindItemCategory();
            
            callBack_Properties(null);
            AJAX.requestAsync( "getItemGroups.php?w="+itemImg.value, callBack_ISG );
        break;
    }
} // getCatList( )


// AJAX-Vorschläge für die Eigenschaften
function suggestProperty( obj, onComplete )
{
    if (( !obj ) || ( !onComplete ))
        return; 
    
    ajax = new AJAXObj();
    ajax.requestAsync( "suggestItemProperties.php?w="+obj.value+"&i="+obj.id, function callBack(xml)
                                                          {
                                                            entries = xml.getElementsByTagName("entry");
                                                            
                                                            if ( entries.length == 0 )
                                                                return;
                                                            
                                                            opts = new Array();
                                                            for(i=0; i< entries.length; i++)
                                                                opts.push( entries[i].firstChild.nodeValue );
                                                            
                                                            onComplete(opts);
                                                          }
                     );
} // suggestSearchTerm()


// AJAX Callback für die Eigenschaften
function callBack_Properties(xml)
{
    return; // EIGENSCHAFTEN SIND ERST MAL GEPARKT
    obj  = document.getElementById( "itemProps" );
    
    if ( obj )
        obj.style.display = "none";
    
    if ( !xml )
        return;
    
    entries = xml.getElementsByTagName("entry");
    if ( entries.length == 0 || !obj )
        return;
    
    // Alte Elemente killen
    while( obj.childNodes.length > 0 )
        obj.removeChild( obj.childNodes[0] );
    
    obj.style.display = "inline";
    for(i=0; i< entries.length; i++)
    {
        nodeVal = entries[i].firstChild.nodeValue;
        lSplit  = nodeVal.split("|");
        
        // Los geht's ...
		aLabel = document.createElement( "label" );
        aInp  = document.createElement( "input" );
        aLabel.innerHTML = lSplit[1];
		aLabel.innerHTML += ":";
		aInp.className = "formnorm";
        aInp.name       = "item[prop]["+ lSplit[0] +"]";
        aInp.id         = "prop_" + lSplit[0];
        
		obj.appendChild(aLabel);
        obj.appendChild(aInp);
        
        // Autocompleter
        autoSug = new AutoSuggest( document.getElementById(aInp.id), "autoComplete_Props", suggestProperty, function(val){ obj = document.getElementById(aInp.id);
                                                                                                                           if ( obj )
                                                                                                                               obj.value = val;
                                                                                                                         }, 1 );
    }
} // callBack_Properties()
    
    
// Eigenschaften zu einer Warengruppe holen
function getProperties( what )
{
    return; // EIGENSCHAFTEN SIND ERST MAL GEPARKT
    itemPrp = document.getElementById( "itemProps" );
    
    if ( !itemPrp || !what )
        return;
    
    // Bestehende Selektion entfernen
    AJAX = new AJAXObj();
    AJAX.requestAsync( "getItemProperties.php?w="+what.value, callBack_Properties );
} // getProperties()


// AJAX-Vorschläge für Artikelnamen
function suggestItemName( obj, onComplete )
{
    if (( !obj ) || ( !onComplete ))
        return; 
    
    ajax = new AJAXObj();
    ajax.requestAsync( "suggestItemName.php?w="+obj.value+"&i="+obj.id, function callBack(xml)
                                                          {
                                                            entries = xml.getElementsByTagName("entry");
                                                            
                                                            if ( entries.length == 0 )
                                                            {
                                                                onComplete( new Array() );
                                                                return;
                                                            }
                                                            
                                                            opts = new Array();
                                                            for(i=0; i< entries.length; i++)
                                                                opts.push( entries[i].firstChild.nodeValue );
                                                            
                                                            onComplete(opts);
                                                          }
                     );
} // suggestItemName()
