﻿//***SearchBox***
//prototype object: SearchBox
function SearchBox(sContainerNodeID) {
	this.ContainerNodeID = sContainerNodeID;
	this.nodeContainer = null;
	this.horTabs = null;
	this.verTabs = null;
	this.arrTabs = new Array();
	this.searchWord = ""; //use this if you want to fill the searchbox with any search word on startup
	this.lastActiveTab = 1;
	var SearchBox = this;
	
	//CSS definitions
	this.ActiveClass = "Active";
	this.LastClass = "Last";
	this.HorTabsID = "horTabs";
	this.VerTabsID = "morelist";
	this.NoSearchTabID = "NoSearchTab";
	this.HiddenDivID = "shadow_gray";
	this.ArrowName = "arrow";
	this.ArrowUp = "http://www.vol.at/SysRes/R1024VOLSkin/Img/SearchBox/Buttons/arrowUp.png";
	this.ArrowDown = "http://www.vol.at/SysRes/R1024VOLSkin/Img/SearchBox/Buttons/arrowDown.png";
	this.VerTabsItemID = "listitem";
	this.VerTabsSpaceholderItemID = "spaceholder";
	this.SearchFormID = "searchbox";
	this.PageBodyID = "R1024VOL_Body";
	
	if (document.getElementById(sContainerNodeID))
		this.nodeContainer = document.getElementById(sContainerNodeID);
	
	if (this.nodeContainer != null)	
    {
        this.horTabs = document.getElementById(this.HorTabsID);
        this.verTabs = document.getElementById(this.VerTabsID);
        
        
        this.horLIs = this.horTabs.getElementsByTagName("li");
        this.verLIs = this.verTabs.getElementsByTagName("li");
        


        // Traverse through horizontal li elements
        for (var i = 0; i < this.horLIs.length; ++i) {
            this.horLIs[i].className = '';
            
            var TabTitle = this.FindFirstChild(this.horLIs[i], "H3");
            var Content = this.FindFirstChild(this.horLIs[i], "FORM");
            
            this.CleanUp(this.horLIs[i]);
             
            if (TabTitle != null && Content != null)
            {
                this.AddTab("HorTab" + i, TabTitle.innerHTML, TabTitle.className, Content);
                
                var a = document.createElement("a");
                
                if (this.horLIs[i].id != this.NoSearchTabID)
                {
                    var OnClickEvent = function () { SearchBox.CopySearchWord(); SearchBox.Activate(this.id, true); SearchBox.Visibility("off"); }; 
                }
                else
                {
                    var OnClickEvent = function () { 
                        SearchBox.Activate(this.id, false);
                        
                        if ("none" == document.getElementById(SearchBox.HiddenDivID).style.display || document.getElementById(SearchBox.HiddenDivID).style.display == "")
                        {
                            SearchBox.Visibility("on"); 
                        }
                        else
                        {
                            SearchBox.Visibility("off"); 
                        }
                    }; 
                }
                a.href = "javascript:void(0);";
                a.onclick = OnClickEvent;
                a.id = "HorTab" + i;
                a.style.cursor = "pointer";
                
                a.innerHTML = TabTitle.innerHTML;
                this.horLIs[i].appendChild(a);
            }
        }
        
        
        // Traverse through vertical li elements
        for (var i = 0; i < this.verLIs.length; ++i) {
            this.verLIs[i].className = '';
            
            var Tab = this.FindFirstChild(this.verLIs[i], "A");
            
            this.CleanUp(this.verLIs[i]);
            
            if (Tab != null)
            {
                this.verLIs[i].appendChild(Tab);
                
                if (this.verLIs[i].innerHTML != "")
                {
                    this.verLIs[i].className = this.VerTabsItemID;
                }
                else
                {
                    //blank LI is used as spaceholder for seperating list
                    this.verLIs[i].className = this.VerTabsSpaceholderItemID;
                }
            }
        }
        
    
        //define MouseEvents for Morelist
        var MoreListON = function () { 
            if (typeof moreListTimeout != "undefined")
                clearTimeout(moreListTimeout); 
            
            SearchBox.Visibility("on"); 
        };
        
        var MoreListOFF = function () { 
            if (typeof moreListTimeout != "undefined")
                clearTimeout(moreListTimeout);
                
            SearchBox.reactivateLastActiveTab();
            SearchBox.Visibility("off");
        };
        
        var delayedMoreListOFF = function () { 
            if (typeof moreListTimeout != "undefined")
                clearTimeout(moreListTimeout);
            
            moreListTimeout = setTimeout(function(){SearchBox.Visibility("off");SearchBox.reactivateLastActiveTab();},1500);     
        };
          
              
	    //event for click on SearchBox (either textBox or button)
        var searchFormular = document.getElementById(this.SearchFormID);
        searchFormular.onmouseup = MoreListOFF;  //close list immediately if there was a click on the searchbox
            
        //events for LIs in morelist
        var ULMorelist = document.getElementById(this.VerTabsID);
        ULMorelist.onmouseover = MoreListON; //if mouse is over Morelist, fire this event to prevent closing the list
        ULMorelist.onmouseout = delayedMoreListOFF; //do not close list immediately, give the user a second, perhaps he slipped out
        ULMorelist.onclick = MoreListOFF; //close list, although the page will be left...


        //events for the whole page
        var pageBody = document.getElementById(this.PageBodyID);
        pageBody.onmouseup = delayedMoreListOFF;
        
        //prevent, that the H3s and FORMs on load of page are visible -> set visibility to visible in order to make the A elements visible
        this.horTabs.style.visibility = 'visible';
    }
}



			//activate this tab including form an background onload
			SearchBox.prototype.ActivateOnLoad = function (iNumber)
			{
				if (this.nodeContainer != null)	
                {
				    TabIdByNumber = this.arrTabs[iNumber-1].sTabID;
    				
				    this.Activate(TabIdByNumber,true);				
				}
			}
			
			
			//method for finding the first child node with a certain node name
			SearchBox.prototype.FindFirstChild = function (nodeParent, sNodeName) {
				var nodeChild = nodeParent.firstChild;
				do {
					if (nodeChild && nodeChild.nodeName == sNodeName)
						return nodeChild;
					
					nodeChild = nodeChild.nextSibling;
				}
				while (nodeChild);
				return null;
			}
			
			
			//method for adding a Tab to Array
			SearchBox.prototype.AddTab = function(sTabID, sTabName, sBackgroundClass, ContentNode) {
					var newtab = new SearchBoxTab (sTabID, sTabName, sBackgroundClass, ContentNode);
					this.arrTabs.push(newtab);
			}
			
				
			//method for assigning a tab to class "Active"
			SearchBox.prototype.SetActiveTab = function(iNumber) {
			    //active tab is in class "Active"
			    for (var i = 0; i <= this.horLIs.length-1; i++)
			    {
			        this.horLIs[i].className = "";
			        
			        if (i == iNumber-1)
			        {
			            this.horLIs[iNumber-1].className = this.ActiveClass;
			        }
			    }
			    
			    //last tab is in class "Last"
			    this.horLIs[this.horLIs.length-1].className += " " + this.LastClass;
			}
			
			
			//method for reactivating the last active tab
			SearchBox.prototype.reactivateLastActiveTab = function() {
					TabIdByNumber = this.arrTabs[this.lastActiveTab-1].sTabID;
				    this.Activate(TabIdByNumber,false);	
			}
			
			
			//method for activating or deactivating the morelist
			SearchBox.prototype.Visibility = function(sOption) {
					var SearchBox = this;
	
					divChanger = document.getElementById(this.HiddenDivID); 
					arrowPicture = document.getElementsByName(this.ArrowName);
								
					if (sOption == "on")
					{
						divChanger.style.display = 'block';
						arrowPicture[0].src = this.ArrowUp;
					}
								 
					if (sOption == "off")
					{
						divChanger.style.display = 'none';
						arrowPicture[0].src = this.ArrowDown;
					}
			}
							
			
			//method for cleaning up the H3 and FORM elements which are replaced by an A element
			SearchBox.prototype.CleanUp = function(nodeContainer) {
			    //clean up and remove all childs in container
			    while (nodeContainer.firstChild)
			        nodeContainer.removeChild(nodeContainer.firstChild)
			}
			
			
			//if user clicks on a Tab, this method looks in array which tab has been clicked and sets the active tab and changes the background
			SearchBox.prototype.Activate = function(id, bDrawContent) {
			    this.id = id;
			    this.bDrawContent = bDrawContent;
			    
			    var iIndex = this.GetIndexOfTabID(this.id);
			    this.SetActiveTab(iIndex+1);
			    
			    //change background image
		        var searchBackground = document.getElementById(this.ContainerNodeID);
		        
		        bgClass = this.arrTabs[iIndex].sBackgroundClass;
		        searchBackground.className = bgClass;
			        
			    if (this.bDrawContent)
			    {
			        this.lastActiveTab = iIndex+1;
			        this.DrawContent(iIndex);
			    }
			}
			
			
			//this method puts the content of the FORM in an DIV (searchbox)
			SearchBox.prototype.DrawContent = function(iIndex) {
			    if (iIndex != null)
			    {
			        //includes the html elements for the new search 
			        newSearch = this.arrTabs[iIndex].nodeContent;
			            
			        var eSearchForm = document.getElementById(this.SearchFormID);
			        this.CleanUp(eSearchForm);
			        
			        //repleace the current search form
			        eSearchForm.appendChild(newSearch);
			        
			        //pastes the copy of the last active search to the new search
			        this.PasteSearchWord();
			    }
			}
			
			
			//this method finds the index of a Tab by TabID
			SearchBox.prototype.GetIndexOfTabID = function (sTabID) {
			    for (var i = 0; i <= this.arrTabs.length-1; i++)
			    {
			        var iIndex = this.arrTabs[i].sTabID == sTabID ? i : null;
			        
			        if(iIndex != null)
			            return iIndex;
			    }
			}
			
			
			//this method creates a copy of the last active search
			SearchBox.prototype.CopySearchWord = function () {
			    for (var i = 0; i < document.searchForm.length; ++i) {
                  if (document.searchForm.elements[i].type == "text")
                  {
                    this.searchWord = document.searchForm.elements[i].value;
                  }
                }
			}
			
			
			//this method pastes the copy of the last active search to the new search
			SearchBox.prototype.PasteSearchWord = function () {
			    for (var i = 0; i < document.searchForm.length; ++i) {
                  if (document.searchForm.elements[i].type == "text")
                  {
                    document.searchForm.elements[i].value = this.searchWord;
                  }
                }
			}
			
			//this method redirects to host as a result of no entered searchwords
			SearchBox.prototype.CheckSearchWord = function () {
			    for (var i = 0; i < document.searchForm.length; ++i) {
                  if (document.searchForm.elements[i].type == "text")
                  {
                     if (document.searchForm.elements[i].value == "")
                     {
			            actionUrl = document.searchForm.action;
			            redirectUrl = actionUrl.substring(0,actionUrl.lastIndexOf("/"));
			            window.open(redirectUrl);
			         }
			         else
			         {
			            document.searchForm.submit();
			         }
			            
			         break;
                  }
                }
			}
			




//object: SearchBoxTab
function SearchBoxTab(sTabID, sTabName, sBackgroundClass, nodeContent) {
    //properties & defaults
    this.sTabName = "New Tab";
    this.nodeContent = null;
    this.sTabID = null;
    this.sBackgroundClass = null;

    //set properties
    if (nodeContent)
	    this.nodeContent = nodeContent;
    if (sTabName)
	    this.sTabName = sTabName;
    if (sTabID)
	    this.sTabID = sTabID;
	if (sBackgroundClass)
	    this.sBackgroundClass = sBackgroundClass;
}




//prototype object: Banner
function Banner(divid) {
    this.DivID = divid;
    this.Height = 45;
    this.i = 0;
}

            //this method calls every 10ms the minimize method
			Banner.prototype.Animate = function() {
			    var Banner = this;
			    
			    //execute function every 10ms
			    setInterval(function() {Banner.Minimize();},10);
			}
			
			
			//this method reduces the height of the DIV and removes it out of DOM
			Banner.prototype.Minimize = function() {
			    this.i = this.i + 1;
			    height = 0 - this.i;
			    bannerdiv = this.DivID;
			
			    bannerNode = document.getElementById(bannerdiv);
			
			    if (bannerNode)
			    {
			        bannerNode.style.backgroundPosition = '0px ' + height + 'px';
			
			        if (height * -1 >= this.Height)
			        {
			            //remove div
			            var parentNode = bannerNode.parentNode;
			            var childNodes = parentNode.childNodes;
			            
			            for (var j = 0; j < childNodes.length; j++) {
			                var a = childNodes[j].id;
			                if (a && a==bannerdiv) {
			                    parentNode.removeChild(childNodes[j]);
			                }
			            }
			            return true;
			        }
			    }
			}