function onOrderImgChange(on) {
	if (document.getElementById("shopIcon") == null) return; // bugfix for my IE6.0 which complains
																													 //	that element does not exist at startup
																													 // when items are in basket
	if(on) {
		document.getElementById("shopIcon").className ="activeShopIcon";
	} else {
		document.getElementById("shopIcon").className = "inactiveShopIcon";
	}
}

function blink() {
  if(show) {
  	onOrderImgChange(true);
    show = false;  
  } else {
    onOrderImgChange(false);
    show = true;
  }
  i = i+1;
  if(i >= belenusHome.fullBasketTwinkle*2) {
    window.clearInterval(blinky);
    onOrderImgChange(true);
  }
}

// if the cookie has fill the basket
var blinky = null;
var show = false; var i = 0; 
if(belenusHome.belenusBasket[0].length>0 && belenusHome.saveCartOnExit != false) {
	blinky = window.setInterval("blink()",belenusHome.fullBasketDelayOnInit);
}

function changedBasketContent(Filled) {
	if(belenusHome.getQueryField(Filled, "Filled") == "true") {
  	onOrderImgChange(true);
    letsFlash();
	} else onOrderImgChange(false);
}

// letsFlash() parts
// if something is added to the basket, the basket button will be flash for a short moment,
// so that the user will see a reaction on his click at the addToBasket icon...
var currentState = false;
var internalCount = 0;
var normalBgColor = belenusHome.getCSSProperty(belenusHome.document, ".tab", "backgroundColor");
var flashBgColor = belenusHome.getCSSProperty(belenusHome.document, "#flashingLight", "backgroundColor");
function letsFlash() {
  if(document.getElementById("flashZone")) {
  if(internalCount < belenusHome.flashs*2) {
    if((internalCount%2) == 0) {
      document.getElementById("flashZone").style.backgroundColor = flashBgColor;
    } else {
      document.getElementById("flashZone").style.backgroundColor = normalBgColor;
    }
    internalCount++;
      setTimeout("letsFlash("+!currentState+")",belenusHome.flashDelay);
  } else { // reset view to normal view
    internalCount = 0;
    document.getElementById("flashZone").style.backgroundColor = normalBgColor;
  }
  }
}

function treeVisibility() {
	var minWidth = 2;

  var frameSetProps = belenusHome.document.getElementById("PartsFrame").getAttribute("cols").split(",");
  var currentWidth = parseInt(frameSetProps[0])
  var currentMode = (currentWidth <= minWidth) ? "off" : "on";  
  
  if(currentMode == "off") { //tree is not visible
    //set now to visible mode
    frameSetProps[0] = (belenusHome.oldTreeFrameWidth <= minWidth) ? belenusHome.treeFrameWidth : belenusHome.oldTreeFrameWidth;      
    belenusHome.document.getElementById("PartsFrame").setAttribute("cols",frameSetProps.join(","));
    // because ie has a bug in his behavior we need to set the noresize attribute again!
    belenusHome.document.getElementById("TreeFrame").noresize = "false";
    belenusHome.document.getElementById("ContentFrame").noresize = "false";
    belenusHome.document.getElementById("InvisibleFrame").noresize = "true";
  } else { // tree is visible
    //set now to invisible mode
    belenusHome.oldTreeFrameWidth = eval(currentWidth+1);
    if(belenusHome.oldTreeFrameWidth == undef) belenusHome.oldTreeFrameWidth = belenusHome.treeFrameWidth;
    frameSetProps[0] = "0";
    belenusHome.document.getElementById("PartsFrame").setAttribute("cols",frameSetProps.join(","));
  }
}


/*** dropDownBox functions follow now ***\
\*** ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ***/

    
// the follow function allows you, to paint the dropDownBox everywhere
// @ windowObj the window object is needed, use SELF
// @ dropDownBoxID here you must give the dropDownBox an ID "String" expected, so you can use several dropDownBoxs  
// @ usedOptionArray here you must deliver the function a correct array, which defines the content of the dropDownBox
function paintDropDownBox (windowObj, dropDownBoxID, usedOptionArray) 
{
	var w = windowObj.document;
	var ipVersion = belenusHome.interpartsVersion; // static or dynamic
	var lastEntryType = null;
	var selected = "selected"; // used for select the first entry, by default...
  
	if (usedOptionArray.length > 0) 
	{
		w.write('<select id="'+dropDownBoxID+'" onChange="callOptsFn(this.options[this.selectedIndex].value, this.selectedIndex, self, \''+dropDownBoxID+'\')">');
		for (optsIndex in usedOptionArray) 
		{
  			if (usedOptionArray[optsIndex][0] > 0)  // first check if the current entry is visible..
  			{
				if ((usedOptionArray[optsIndex][0] == 1) || (usedOptionArray[optsIndex][0] == 2 && ipVersion == "static") || 
					(usedOptionArray[optsIndex][0] == 3 && ipVersion == "dynamic")) // is the current entry visible (also check if static or dynamic version)
				{ 
					if ((usedOptionArray[optsIndex][1] == "divider" && lastEntryType == "divider") || 
						(usedOptionArray[optsIndex][1] == "divider" && lastEntryType == null)) 
					{
						// do nothing.... because the last entry was also a divider...
					} 
					else 
					{
						// now decide if the entry will be shown...
    					if (usedOptionArray[optsIndex][1] == "language") // check, if more than one language is given... 
    					{ 
							if (belenusHome.getLanguagesCurrentFirst("GUI").split(",").length > 1 || 
                				belenusHome.getLanguagesCurrentFirst("DATA").split(",").length > 1) 
                			{
				            	w.write('<option '+selected+' value="'+usedOptionArray[optsIndex][1]+'" id="'+belenusHome.addLKey("ddb_"+dropDownBoxID+"_language",windowObj,"opts",'ddb_'+usedOptionArray[optsIndex][1])+'">'+ belenusHome.ld['ddb_'+usedOptionArray[optsIndex][1]] +'</option>');
				            	lastEntryType = usedOptionArray[optsIndex][1];
								selected = '';
			                }          
            			} 
            			else if (usedOptionArray[optsIndex][1] == "printServer") 
            			{ 
            				// check if the printServer feature is enabled
              				if (belenusHome.printServerSwitcher == true) 
              				{
				                w.write('<option '+selected+' value="'+usedOptionArray[optsIndex][1]+'" id="'+belenusHome.addLKey("a53"+Math.random(),windowObj,"opts",'ddb_'+usedOptionArray[optsIndex][1]+'_on')+'">'+ belenusHome.ld['ddb_'+usedOptionArray[optsIndex][1]+'_on'] +'</option>');
				                lastEntryType = usedOptionArray[optsIndex][1];
				                selected = '';
              				}
            			} 
            			else 
            			{ 
            				// if none special behavior is wished..
							w.write('<option '+selected+' value="'+usedOptionArray[optsIndex][1]+'" id="'+belenusHome.addLKey("a54"+Math.random(),windowObj,"opts",'ddb_'+usedOptionArray[optsIndex][1])+'">'+ belenusHome.ld['ddb_'+usedOptionArray[optsIndex][1]] +'</option>');
							lastEntryType = usedOptionArray[optsIndex][1];
							selected = '';
						}
					}
				}
			}
		}
	    w.write('</select>');
	}
}


// this function will be called by the dropDownBox itself...
// it contains the different functions which will be called on a user selection in the dropDownBox
// customize !!!
function callOptsFn(switchCase, selectedIndex, windowObj, dropDownBoxID) {
	switch(switchCase) {
    case "normal":
      // do nothing.... unneeded, but for the legibility
      break;
    
    case "tree": // turn tree on/off
      treeVisibility(); 
      break;
     
    case "img": // only show ImageView
      if(belenusHome.getModule("Detail") != null && belenusHome.showImage != "never") belenusHome.eventHandler("SetDetailFrameViews","View=onlyImage");
      else if(belenusHome.getModule("Detail") == null) alert(belenusHome.ld['firstACategory']); 
      break;
      
    case "spl": // only show sparePartsList
      if(belenusHome.getModule("Detail") != null) belenusHome.eventHandler("SetDetailFrameViews","View=onlyTable");
      else alert(belenusHome.ld['firstACategory']);     
      break;
      
    case "imgSpl": // show both together img&spl
      if(belenusHome.getModule("Detail") != null && belenusHome.showImage != "never") belenusHome.eventHandler("SetDetailFrameViews","View=imageAndTable");
      else if(belenusHome.getModule("Detail") == null) alert(belenusHome.ld['firstACategory']);
      break;
      
    case "notes": // open the notes popup
      belenusHome.WM.openWindow("notes","",false);
      break;
      
    case "favs": // open the favs popup
      belenusHome.WM.openWindow("favorites","",false);
      break;
      
    case "language": // open the languageChooser popup
      belenusHome.WM.openWindow("languageChooser");    
      break;
      
    case "printServer": // load the printServer frames
      if(belenusHome.printServer == false) {
        belenusHome.printServer = true;
        belenusHome.document.getElementById("ContentFrame").setAttribute("src","print_server/index.html");
        windowObj.document.getElementById(dropDownBoxID).options[selectedIndex].text = belenusHome.ld["ddb_printServer_off"];
      } else {
        belenusHome.printServer = false;
        var tmp = belenusHome.currentTreePath;
        belenusHome.document.getElementById("ContentFrame").setAttribute("src","about:blank");
        setTimeout("belenusHome.eventHandler('OpenLink','URL=parts:"+tmp+"')",500);
        windowObj.document.getElementById(dropDownBoxID).options[selectedIndex].text = belenusHome.ld["ddb_printServer_on"];
      }    
      break;
      
    case "filter":
      if(belenusHome.getModule("Detail") != null)
        belenusHome.sendMessage("Table", "ToggleFilter", null);
      break;
      
    case "flipArrangement":
      		belenusHome.eventHandler("flipArrangement",null);
      		
    default:
      // do nothing....
      break;    
  } 
  // reset to first entry....    
  windowObj.document.getElementById(dropDownBoxID).selectedIndex = 0;        
}

