function makeActive(id) {

    var url = document.location.href;
    var idx = url.indexOf('##');
    if (idx > 0) {
        id = url.substring(idx + 1);
        memorize(id);
        document.location.href = url.substring(0, idx);
        makeActive(id);
        return;
    }

    for (i = 0; i < items.length; i ++) {
        document.getElementById(items[i]).style.display = 'none';
        document.getElementById(items[i] + "_nav").className = 'mitem';
    }

    memorize(id);

    el = document.getElementById(id);
    if (el) {
        el.style.display = 'block';
        document.getElementById(id + "_nav").className = 'current';
    }
}

function memorize(id) {
    setCookie("currentTab", id, 30 * 60, "/");
}

function getCurrentTab() {
    var currentTab = getCookie("currentTab");
    if (!currentTab) {
        currentTab = "who_qualifies";
    }

    var i;
    for (i = 0; i < items.length; i ++) {
        if (items[i] == currentTab) break;
    }
    if (i == items.length) {
        currentTab = "who_qualifies";
    }

    //  alert(currentTab);
    return currentTab;
}


//

function getCurrentTab1() {
    var currentTab1 = getCookie("currentTab1");
    if (!currentTab1) {
        currentTab1 = "business";
    }

    var i;
    for (i = 0; i < items.length; i ++) {
        if (items[i] == currentTab1) break;
    }
    if (i == items.length) {
        currentTab1 = "business";
    }

    //  alert(currentTab);
    return currentTab1;
}


//idea/training/tips/

function getCurrentTab2() {
    var currentTab2 = getCookie("currentTab2");
    if (!currentTab2) {
        currentTab2 = "code_completion";
    }

    var i;
    for (i = 0; i < items.length; i ++) {
        if (items[i] == currentTab2) break;
    }
    if (i == items.length) {
        currentTab2 = "code_completion";
    }

    //  alert(currentTab);
    return currentTab2;
}


/*-----------------------------------mainTabs(idea buy)------------------------------------------*/
var Fabtabs = Class.create();
var heightActivTabs;
var heightContent = null;

Fabtabs.prototype = {
    initialize : function(element) {
        if (!heightActivTabs) {
            heightContent = document.getElementById("content_enclosure").offsetHeight;
        }
        this.element = $(element);
        var options = Object.extend({}, arguments[1] || {});
        this.menu = $A(this.element.getElementsByTagName('a'));
        this.show(this.getInitialTab());
        this.menu.each(this.setupTab.bind(this));
    },
    setupTab : function(elm) {
        Event.observe(elm, 'click', this.activate.bindAsEventListener(this), false)
    },
    activate :  function(ev) {
        var elm = Event.findElement(ev, "a");
        Event.stop(ev);
        this.show(elm);
        this.menu.without(elm).each(this.hide.bind(this));
        location.href = Event.findElement(ev, "a").href;
    },
    hide : function(elm) {
        $(elm).removeClassName('activTab');
        $(this.tabID(elm) + '_').removeClassName('activeTabBody');
        if ($(this.tabID(elm) + "_subcontent") != null)
            $(this.tabID(elm) + "_subcontent").removeClassName('activeTabBody');
    },
    show : function(elm) {
        $(elm).addClassName('activTab');
        $(this.tabID(elm) + '_').addClassName('activeTabBody');
        /*Start for height columns*/
        heightActivTabs = document.getElementById(elm.href.match(/#(\w.+)/)[1] + "_").offsetHeight;
        //heightActivTabs = document.getElementById("content").offsetHeight;
        /*if (heightActivTabs != 0) {
         matchColumns(heightActivTabs + heightContent,'');
         }*/
        /*End for height columns*/
        if ($(this.tabID(elm) + "_subcontent") != null)
            $(this.tabID(elm) + "_subcontent").addClassName('activeTabBody');
    },
    tabID : function(elm) {
        return elm.href.match(/#(\w.+)/)[1];
    },
    getInitialTab : function() {
        if (document.location.href.match(/#(\w.+)/)) {
            var loc = RegExp.$1;
            var elm = this.menu.find(function(value) {
                return (value.href.match(/#(\w.+)/)[1] == loc) || (value.href.match(/#(\w.+)/)[1] == loc.substring(0, loc.indexOf('_')));
            });
            return elm || this.menu.first();
        } else {
            var os = checkOS();
            for(var i=0; i < this.menu.length; i++){
                if(this.menu[i].hash.indexOf(os) > 0){
                    return this.menu[i];
                }
            }
            return this.menu.first();
        }
    }
}
function reloadLink(toLink) {
    //alert(toLink);
    location.replace(toLink);
    location.reload(true);
}
function checkOS(){
 var OSName="unknownOS";
 if (navigator.appVersion.indexOf("Win")!=-1) OSName="win";
 if (navigator.appVersion.indexOf("Mac")!=-1) OSName="mac";
 if (navigator.appVersion.indexOf("Linux")!=-1 || navigator.userAgent.indexOf("Linux")!=-1 || navigator.userAgent.indexOf("Unix")!=-1) OSName="linux";
 return OSName;
 }

/*function selectOS() {
    var os = checkOS();
    document.getElementById(os).style.display = 'block';
    document.getElementById('selectOS').value = os;
}*/
/*-----------------------------------mainTabs------------------------------------------*/
