
// Onload function

var OnLoadFunctions = new Array();
var OnLoadFunctionsEx = new Array();
function AddOnLoadFunction(OnLoadFunction, OnLoadFunctionEx)
{
    OnLoadFunctions.push(OnLoadFunction);
    OnLoadFunctionsEx.push(OnLoadFunctionEx);
}
window.onload = OnBodyLoad;
function OnBodyLoad()
{
	for (var i = 0; i < OnLoadFunctions.length; i++)
    {
        var cfunction = OnLoadFunctions[i];
        var cfunctionex = OnLoadFunctionsEx[i];
        eval("if (window." + cfunction + ") { " + cfunctionex + "; }");
    }
}

// Blur Anchors
// Description: Remove anchor outlines from all links in the document

function blurAnchors(){
  if(document.getElementsByTagName){
    var a = document.getElementsByTagName("a");
    for(var i = 0; i < a.length; i++){
      a[i].onfocus = function(){this.blur()};
    }
  }
}
AddOnLoadFunction("blurAnchors", "blurAnchors()");

// Dollar function
function $() {
	var elements = new Array();
	for (var i = 0; i < arguments.length; i++) {
		var element = arguments[i];
		if (typeof element == 'string')
			element = document.getElementById(element);
		if (arguments.length == 1)
			return element;
		elements.push(element);
	}
	return elements;
}

//Get By Class
function $$(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

/* TAB navigation in products -------------- */

AddOnLoadFunction("prepareDownloadTabs", "prepareDownloadTabs()");

function prepareDownloadTabs() {

    if(document.tabloading) return;
    document.tabloading = true;
	
	var titles = $$('hide');
	for (var j=0; j < titles.length; j++)
	{
		titles[j].style.display = "none";
	}

    var tabs = $$('tab');
    var divs = Array();
    for(var i=0; i < tabs.length; i++)
    {
        var idDiv = tabs[i].href;
        var sepPos = idDiv.lastIndexOf('#');
        var div = $(idDiv.substring(sepPos+1));
        if(div)
        {
            divs.push(div);
            
            if(divs.length > 1)
                div.style.display = 'none';
                
            tabs[i].href = 'javascript:void(showTab(\''+div.id+'\')); void(selectTab('+i+'));';
            
            div.otherdivs = divs;
        }
    }
    document.tabs = tabs;
}


function showTab(iddiv) {
    var div = $(iddiv);
    if(!div) return;
    
    for(var i=0; i < div.otherdivs.length; i++)
    {
        div.otherdivs[i].style.display = div.otherdivs[i].id == iddiv ? 'block' : 'none';
    }
	return false;
}

function selectTab(it)
{
    var tabs = document.tabs;
    if(tabs && it < tabs.length)
    {
        for(var i=0; i < tabs.length; i++)
        {
            tabs[i].parentNode.className = (i == 0 ? 'first ': '') + (it == i ? 'selected': '');
        }
    }
}
