/* -----------------------------------

     Zusatz-Parameter für Nedstat

----------------------------------- */

stat_add = "";

/* -----------------------------------

     OCS Kategorie auswählen

----------------------------------- */

function setCategoryLink (flex_id, name, id) {
    var nameElem = document.getElementById('idLinkText' + flex_id);
    nameElem.value = name;
    var idElem = document.getElementById('idLinkId' + flex_id);
    idElem.value = id;
    
}

/* -----------------------------------

     OCS Produkt auswählen

----------------------------------- */

function setProductLink (flex_id, name, ccat_id, prod_id) {
    var nameElem = document.getElementById('idLinkText' + flex_id);
    nameElem.value = name;
    var ccatIdElem = document.getElementById('idCcatID' + flex_id);
    ccatIdElem.value = ccat_id;
    var prodIdElem = document.getElementById('idProdID' + flex_id);
    prodIdElem.value = prod_id;
}

function setProductInfos(flex_id, name, ccat_id, prod_id, positioning, title, ub1, ub2, ub3) {
    //alert(flex_id + ' ' + name + ' ' +  ccat_id  + ' ' + prod_id  + ' ' + positioning  + ' ' + title  + ' ' + ub1 + ' ' + ub2 + ' ' + ub3);
    var nameElem = document.getElementById('idName' + flex_id);
    var ccatIdElem = document.getElementById('idCcatID' + flex_id);
    var prodIdElem = document.getElementById('idProdID' + flex_id);
    var posElem = document.getElementById('idPositioning' + flex_id);
    var titleElem = document.getElementById('idTitle' + flex_id);
    var ub1Elem = document.getElementById('idUserBenefit1' + flex_id);
    var ub2Elem = document.getElementById('idUserBenefit2' + flex_id);
    var ub3Elem = document.getElementById('idUserBenefit3' + flex_id);
    nameElem.value = name;
    ccatIdElem.value = ccat_id;
    prodIdElem.value = prod_id;
    posElem.value = positioning;
    titleElem.value = title;
    ub1Elem.value = ub1;
    ub2Elem.value = ub2;
    ub3Elem.value = ub3;
}


/* -----------------------------------

   Print-Function for layered PopUps

----------------------------------- */

function printDiv(id) {
    var els = ['top', 'agbsPopup', 'materiallistePopup', 'boschheader', 'boschnavi', 'boschcontent', 'stage', , 'TB_overlay', 'TB_window #materialliste' , 'TB_window'];
    //var elsStyle = [];
    for (var i=0; i!=els.length; ++i)
    {
        if (els[i]!=id) {
            $('#'+els[i]).addClass('noPrint');
            if (els[i]=='TB_window') $('#'+els[i]).css("display","none");
            continue;
        }

        $('#'+els[i]).addClass('printOnly').removeClass('hidden');
    }

    window.onfocus = function() {
        window.onfocus = function () {};
        window.setTimeout(function () {
            for (var i=0; i!=els.length; ++i){
                if (els[i]!=id) {$('#'+els[i]).removeClass('noPrint');
                if (els[i]=='TB_window') $('#'+els[i]).css("display","block");
                continue;}
                $('#'+els[i]).removeClass('printOnly').addClass('hidden');
            }
            $('#'+id).removeClass('printOnly').addClass('hidden');
            }, 1000);
    };
    window.setTimeout(function () {window.print();}, 100);
}

/* $(document).ready(function()
{
    $('#agbsPopup').appendTo('body');
    $('#materiallistePopup').appendTo('body');
});*/

/* -----------------------------------

   IE - Out of memory

----------------------------------- */

function onUnloaded() {
    window.onunload = null;
}

/* -----------------------------------

   Funktionen für Such-Formular

----------------------------------- */

function submitForm () {

  searchWin = openWindow ('/res/bosch-pt/common/media/blank.htm', 438, 410, 20, 20, 'searchwin', wReturnWinHandle, wScrollBars + wResizable + wLocationBar + wMenuBar + wStatusBar);
  document.forms.searchform.submit ();
    searchWin.focus();
    return true;

} // function submitForm

/* -----------------------------------

   Allgemeine Funktionen

----------------------------------- */

var wScrollBars = 1;
var wResizable = 2;
var wLocationBar = 4;
var wMenuBar = 8;
var wStatusBar = 16;
var wDependent = 32;
var wReturnWinHandle = 64;

function openWindow (winUrl, winWidth, winHeight, winX, winY, winName, winPropsEnable, winPropsDisable) {

  winScrollBars = (winPropsEnable & wScrollBars) ? 'scrollbars=yes,' : ( (winPropsDisable & wScrollBars ) ? 'scrollbars=no,' : '' );
  winResizable = (winPropsEnable & wResizable) ? 'resizable=yes,' : ( (winPropsDisable & wResizable ) ? 'resizable=no,' : '' );
  winLocationBar = (winPropsEnable & wLocationBar) ? 'location=yes,' : ( (winPropsDisable & wLocationBar ) ? 'location=no,' : '' );
  winMenuBar = (winPropsEnable & wMenuBar) ? 'menubar=yes,' : ( (winPropsDisable & wMenuBar ) ? 'menubar=no,' : '' );
  winStatusBar = (winPropsEnable & wStatusBar) ? 'status=yes,' : ( (winPropsDisable & wStatusBar ) ? 'status=no,' : '' );
  winDependent = (winPropsEnable & wDependent) ? 'dependent=yes,' : ( (winPropsDisable & wDependent ) ? 'dependent=no,' : '' );

  newWin = window.open (winUrl, winName, 'left=' + winX + ',top=' + winY + ',innerWidth=' + winWidth + ',width=' + winWidth + ',innerHeight=' + winHeight + ',height=' + winHeight + ',' + winScrollBars + winResizable + winLocationBar + winMenuBar + winStatusBar + winDependent);

  return (winPropsEnable & wReturnWinHandle) ? newWin : false;

} // function openWindow


/* Funktionen openWindow (neu) und OpenWindow (alt) */

/*
function openWindow (winUrl, winWidth, winHeight, winX, winY, winName, winPropsEnable, winPropsDisable)

Öffnet ein neues Fenster mit den angegebenen Eigenschaften. Dabei werden die Rechenfehler des IE weit gehend ausgeglichen.
Zudem soll das Fenster nie über den Bildschirmrand hinausgehen, wird also ggf. kleiner geöffnet als angegeben.

Beispielaufruf:
<a href="seite.htm" onclick="return openWindow (this, 400, 500, 20, 20, 'winNew', wSetFocus + wDependent, wResizable);">

Anleitung:
- Alles ab dem nächsten /* ins Javascript des Webs kopieren
- In winPropsEnable alle Eigenschaften des zu öffnenden Fensters geben, die es unbedingt haben soll
- In winPropsDisable alle Eigenschaften des zu öffnenden Fensters geben, die es auf keinen Fall haben soll
- Nicht übergebene Eigenschaften besitzt das Fenster abhängig von den Grundeinstellungen des anzeigenden Browsers
*/

/*
function openWindow (winUrl, winWidth, winHeight, winX, winY, winName, winPropsEnable, winPropsDisable)

(c) 2002 whe Kittelberger media solutions GmbH, www.kittelberger.de

2002-08-22 whe  Version 0.5 in EW Advertising Pool Green eingebaut
2003-01-17 whe  Version 1 auf \\enterprise\www\_javascript veröffentlicht

*/

var wReturnWinHandle = 1;
var wSetFocus = 2;
var wDependent = 4;
var wResizable = 8;
var wScrollbars = 16;
var wMenubar = 32;
var wToolbar = 64;
var wLocationbar = 128;
var wStatusbar = 256;
var wBookmarks = 512;
var wHotkeys = 1024;

function openWindow (winUrl, winWidth, winHeight, winX, winY, winName, winPropsEnable, winPropsDisable) {

    // Default-Werte für Zahlenvariablen setzen, wenn Parameter nicht oder falsch übergeben wurden. Variablen auf numerischen Typ festlegen
    winWidth = (!winWidth || isNaN (winWidth)) ? 400 : parseInt (winWidth);
    winHeight = (!winHeight || isNaN (winHeight)) ? 400 : parseInt (winHeight);
    winX = (!winX || isNaN (winX)) ? 20 : parseInt (winX);
    winY = (!winY || isNaN (winY)) ? 20 : parseInt (winY);

    // Fenster verkleinern, wenn größer als darstellbarer Bereich
    if ( (winWidth + winX) > (screen.availWidth - 10) ) winWidth = screen.availWidth - winX - 10;
    if ( (winHeight + winY) > (screen.availHeight - 30) ) winHeight = screen.availHeight - winY - 30;

    // Dreistatus-Attribute (An/Aus/Unbestimmt) in Variablen definieren
  var winDependent = (winPropsEnable & wDependent) ? 'dependent=yes,' : ( (winPropsDisable & wDependent) ? 'dependent=no,' : '' );
  var winResizable = (winPropsEnable & wResizable) ? 'resizable=yes,' : ( (winPropsDisable & wResizable) ? 'resizable=no,' : '' );
  var winScrollbars = (winPropsEnable & wScrollbars) ? 'scrollbars=yes,' : ( (winPropsDisable & wScrollbars) ? 'scrollbars=no,' : '' );
  var winMenubar = (winPropsEnable & wMenubar) ? 'menubar=yes,' : ( (winPropsDisable & wMenubar) ? 'menubar=no,' : '' );
    var winToolbar = (winPropsEnable & wToolbar) ? 'toolbar=yes,' : ( (winPropsDisable & wToolbar) ? 'toolbar=no,' : '' );
  var winLocationbar = (winPropsEnable & wLocationbar) ? 'location=yes,' : ( (winPropsDisable & wLocationbar) ? 'location=no,' : '' );
  var winStatusbar = (winPropsEnable & wStatusbar) ? 'status=yes,' : ( (winPropsDisable & wStatusbar) ? 'status=no,' : '' );
    var winBookmarks = (winPropsEnable & wBookmarks) ? 'directories=yes,' : ( (winPropsDisable & wBookmarks) ? 'directories=no,' : '' );
    var winHotkeys = (winPropsEnable & wHotkeys) ? 'hotkeys=yes,' : ( (winPropsDisable & wHotkeys) ? 'hotkeys=no,' : '' );

    // IE verändert die Fenstergröße ganz speziell ... deswegen wieder "von Hand" zurückberechnen
    if (document.all) {

        winWidth = (winPropsEnable & wScrollbars) ? winWidth + 16 : winWidth;

        winWidth = ( (winPropsEnable & wMenubar)
            && (winPropsEnable & wToolbar)
            && (winPropsEnable & wLocationbar)
            && (winPropsEnable & wStatusbar)
            && (winPropsEnable & wBookmarks)
            && (winPropsEnable & wResizable) )
            ? winWidth + 12 : winWidth;

        winWidth = ( (winPropsEnable & wMenubar)
            && (winPropsEnable & wToolbar)
            && (winPropsEnable & wLocationbar)
            && (winPropsEnable & wStatusbar)
            && (winPropsEnable & wBookmarks)
            && ( (winPropsDisable & wResizable) || !(winPropsEnable & wResizable) ) )
            ? winWidth + 10 : winWidth;

        winHeight = (winPropsEnable & wMenubar) ? winHeight - 19 : winHeight;

        winHeight = ( (winPropsEnable & wMenubar)
            && (winPropsEnable & wToolbar)
            && (winPropsEnable & wLocationbar)
            && (winPropsEnable & wStatusbar)
            && (winPropsEnable & wBookmarks)
            && (winPropsEnable & wResizable) )
            ? winHeight + 171 : winHeight;

        winHeight = ( (winPropsEnable & wMenubar)
            && (winPropsEnable & wToolbar)
            && (winPropsEnable & wLocationbar)
            && (winPropsEnable & wStatusbar)
            && (winPropsEnable & wBookmarks)
            && ( (winPropsDisable & wResizable) || !(winPropsEnable & wResizable) ) )
            ? winHeight + 169 : winHeight;

        // Nach der IE-Neuberechnung wieder auf maximale Größe reduzieren, wenn notwendig
        if ( (winWidth + winX) > (screen.availWidth - 10) ) winWidth = screen.availWidth - winX - 10;
        if ( (winHeight + winY) > (screen.availHeight - 30) ) winHeight = screen.availHeight - winY - 30;

    } // if (document.all)

  // Fenster öffnen
  newWin = window.open (winUrl, winName,
    'left=' + winX +
    ',top=' + winY +
    ',width=' + winWidth +
    ',height=' + winHeight +
    ',' + winDependent + winResizable + winScrollbars + winMenubar + winToolbar
    + winLocationbar + winStatusbar + winBookmarks + winHotkeys);

    if (winPropsDisable ^ wSetFocus) newWin.focus();
  return (winPropsEnable & wReturnWinHandle) ? newWin : false;

} // function openWindow


// V3

function OpenWindow (URL, Width, Height, Left, Top, Name, Resizable, ScrollBars, MenuBar, ToolBar, LocationBar, BookmarkBar, StatusBar, Dependent, HotKeys) {

    // Vorsicht bei NN: Wird die MenuBar angezeigt, wird ab Breiten kleiner 303 die Fensterhöhe vom NN falsch berechnet.

    // Testen, ob Positions- und Größen-Parameter angegeben und nicht zu groß sind
    if ( (Top == null) || isNaN (Top) ) Top = 20;
    if ( (Left == null) || isNaN (Left) ) Left = 20;
    if ( (Height == null) || isNaN (Height) || (Height + Top > screen.availHeight - 10) ) Height = screen.availHeight - 10 - Top;
    if ( (Width == null) || isNaN (Width) || (Width + Left > screen.availWidth - 10) ) Width = screen.availWidth - 10 - Left;
    Name = (Name == null) ? '' : Name; // Name = Leerstring, wenn kein Name angegeben ist
    // Testen, ob alle Parameter vorhanden sind, sonst Default-Werte vergeben

    Resizable = ((Resizable == null) || (Resizable == true)) ? 'yes' : 'no';
    ScrollBars = ((ScrollBars == null) || (ScrollBars == true)) ? 'yes' : 'no';
    MenuBar = ((MenuBar == null) || (MenuBar == false)) ? 'no' : 'yes';
    ToolBar = ((ToolBar == null) || (ToolBar == false)) ? 'no' : 'yes';
    LocationBar = ((LocationBar == null) || (LocationBar == false)) ? 'no' : 'yes';
    BookmarkBar = ((BookmarkBar == null) || (BookmarkBar == false)) ? 'no' : 'yes';
    StatusBar = ((StatusBar == null) || (StatusBar == true)) ? 'yes' : 'no';
    Dependent = ((Dependent == null) || (Dependent == true)) ? 'yes' : 'no';
    HotKeys = ((HotKeys == null) || (HotKeys == true)) ? 'yes' : 'no';

    // Für IE Fenstergrößen extra berechnen, da IE "innerWidth" und "InnerHeight" nicht beachtet.
    if (document.all) {
        Height += 31; // 31 Pixel höher für Fensterrahmen und Titelleiste des Fensters
        Width = Width + 12; // 12 Pixel breiter für den Fensterrahmen
        Height = (Resizable == 'no') ? Height - 2 : Height; // Der Fensterrahmen von Nicht-"Resizable"-Fenstern ist 2 Pixel schmaler.
        Width = (Resizable == 'no') ? Width - 2 : Width; // dto.
        Width = (ScrollBars == 'yes') ? Width + 16 : Width;
        Height = (MenuBar == 'yes') ? Height + 29 : Height;
        Height = (ToolBar == 'yes') ? Height + 47 : Height;
        Height = (LocationBar == 'yes') ? Height + 29 : Height;
        var BarCompensation = (MenuBar == 'yes') ? 1 : 0; // je "Bar"-Paar werden wiederum 5 Pixel eingespart
        BarCompensation = (ToolBar == 'yes') ? BarCompensation + 1 : BarCompensation;
        BarCompensation = (LocationBar == 'yes') ? BarCompensation + 1 : BarCompensation;
        BarCompensation = (BarCompensation < 1) ? 1 : BarCompensation;
        Height -= ( (BarCompensation - 1) * 5);
        Height = (StatusBar == 'yes') ? Height + 20 : Height;
        // Fenster wieder verkleinern, falls es jetzt wieder zu groß ist
        if (!Width || isNaN (Width) || (Width > screen.availWidth - 10)) Width = screen.availWidth - 10;
        if (!Height || isNaN (Height) || (Height > screen.availHeight - 10)) Height = screen.availHeight - 10;
    }

    // Fenster mit den gegebenen Parametern öffnen
    NewWindow = window.open(URL, Name, 'screenX=' + Left + ',screenY=' + Top
    + ',height=' + Height + ',width=' + Width + ',innerHeight=' + Height + ',innerWidth=' + Width
    + ',resizable=' + Resizable + ',scrollbars=' + ScrollBars + ',menubar=' + MenuBar
    + ',toolbar=' + ToolBar + ',location=' + LocationBar + ',directories=' + BookmarkBar
    + ',status=' + StatusBar + ',dependent=' + Dependent);

    if (navigator.appVersion.indexOf ('MSIE 5.0')) NewWindow.focus (); // IE 5.0 bricht hier sonst ab

    URL += ''; // IE versteht die URL nur so als String ...

    // Für IE muss extra positioniert. Der Fenster-Zugriff wird aber verweigert, wenn eine
    // komplette HTTP-Adresse aufgerufen wird ...

    if (!NewWindow.innerWidth && (URL.indexOf ('http://') < 0)) {
        NewWindow.moveTo (Left, Top);
    }

    NewWindow.focus (); // Fenster ganz nach vorn stellen, also Focus auf das Fenster

    return false; // damit der HREF-Link nicht ausgeführt wird

} // function OpenWindow

function closeWindow() {
    window.parent.close();
}


/* -----------------------------------

     Materialliste im Editmode ein-/ausblenden

----------------------------------- */

function showMaterialList(lingua) {
    var divMaterialList = document.getElementById('materiallistePopup_edit_'+lingua);

    divMaterialList.className = divMaterialList.className.replace(/hidden/gi, '');

    //alert(divMaterialList.offsetWidth);
    //alert(divMaterialList.offsetHeight);

    /* var iframeEl = document.getElementById("materiallisteIframe_edit");

    iframeEl.className = divMaterialList.className.replace(/hidden/gi, '');

    iframeEl.style.width = divMaterialList.offsetWidth;
    iframeEl.style.height = divMaterialList.offsetHeight;*/
}


function hideMaterialList(lingua) {
    var divMaterialList = document.getElementById('materiallistePopup_edit_'+lingua);

    divMaterialList.className = divMaterialList.className + ' hidden';
}

/* -----------------------------------

     Setzen der Filter ID für die Imperia Suche

----------------------------------- */

function setFilterID(filter_list, filter_id) {
    var selFilterList = document.getElementById(filter_list);
    var inpFilterID = document.getElementById(filter_id);

    inpFilterID.value = selFilterList.selectedIndex+1;

    if(window.console) {
        window.console.log(inpFilterID.value);
    }
}

/* -----------------------------------

     Edit/Hide Divider in Flex-Modulen

----------------------------------- */

function showHideEditModeDivider(element, flex_index_id)
{
    if (element.checked)
    {
       document.getElementById("editModeDivider_" + flex_index_id).style.display = "block";
    }
    else
    {
       document.getElementById("editModeDivider_" + flex_index_id).style.display = "none";
    }
}

function showHideEditModeDiv(element)
{
    if (element.checked)
    {
       document.getElementById(element).style.display = "block";
    }
    else
    {
       document.getElementById(element).style.display = "none";
    }
}
