function showAlert() {
    alert('test');
}

//if checks adds the value to cookie, if unchecked removes the value from cooki
function manageCheckboxvalues(elem, name, days) {
    var checkbox = elem;
    if (checkbox.checked) {
        if (readCookie(name) != null) {
            createCookie(name, days, readCookie(name) + checkbox.value);
        }
        else {
            createCookie(name, days, checkbox.value);
        }
    }
    else {
        var cookieValue = readCookie(name);
        if (cookieValue.indexOf(checkbox.value) >= 0) {
            var checkBoxValueRemovedCookieString = ReplaceAll(cookieValue, checkbox.value, ' ');
            createCookie(name, days, checkBoxValueRemovedCookieString);
        }
    }
}

//Remove value from cookie
function removeValuefromCookie(cookieName, valueToBeRemoved) {
    valueToBeRemoved = ReplaceAll(valueToBeRemoved, "+", " ");
    var cookieValue = readCookie(cookieName);
    var checkBoxValueRemovedCookieString = ReplaceAll(cookieValue, valueToBeRemoved, ' ');
    createCookie(cookieName, 2, checkBoxValueRemovedCookieString);
}

//Create product comparison
function createProductComparisonUrl(elem, url, cookieName) {
    var link = elem;
    link.href = url + readCookie(cookieName);
}

//creates the cookie
function createCookie(name, days, value) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        var expires = "; expires=" + date.toGMTString();
    }
    else var expires = "";
    document.cookie = name + "=" + value + expires + "; path=/";
}

//reads the cookie value
function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') c = c.substring(1, c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
    }
    return null;
}

//removes the cookie with specified name
function eraseCookie(name) {
    createCookie(name, -1, "");
}

//function that goes through the cookie and check the values
function parseCookieAndCheckComparisonBoxes(name) {
    var cookieValue = readCookie(name);
    for (var index = 0; index < document.forms[0].comparison.length; index++) {
        var currentcheckbox = document.forms[0].comparison[index];
        if (cookieValue.indexOf(currentcheckbox.value) >= 0) {
            document.forms[0].comparison[index].checked = true;
        }
    }
}

//replace all funcction
function ReplaceAll(Source, stringToFind, stringToReplace) {
    var temp = Source;
    var index = temp.indexOf(stringToFind);
    while (index != -1) {
        temp = temp.replace(stringToFind, stringToReplace);
        index = temp.indexOf(stringToFind);
    }

    return temp;

}
/*
function showTab(tab) {
    PDPTabsHideTab('tab1');
    PDPTabsHideTab('tab2');
    PDPTabsHideTab('tab3');
    PDPTabsHideTab('tab4');

    PDPTabsRemoveClass('ttab1');
    PDPTabsRemoveClass('ttab2');
    PDPTabsRemoveClass('ttab3');
    PDPTabsRemoveClass('ttab4');

    PDPTabsShowTab(tab);
    
    return false;
}

function PDPTabsHideTab(elemId) {

    var elem = document.getElementById(elemId);

    if (elem != null) {
        elem.style.display = 'none'
    }
}

function PDPTabsRemoveClass(elemId) {

    var elem = document.getElementById(elemId);

    //    if (elem != null) {
    //        elem.setAttribute((document.all ? 'className' : 'class'), " ");
    //        //elem.setAttribute("class", "")
    //    }
}

function PDPTabsShowTab(elemId) {

    var elem = document.getElementById(elemId);
    var elem2 = document.getElementById('t' + elemId);

    if (elem != null) {
        elem.style.display = 'block';
    }

    //    if (elem2 != null) {
    //        elem2.setAttribute((document.all ? 'className' : 'class'), "active");
    //        //elem2.setAttribute("class", "active");
    //    }    
}

*/

function getNextTab(tab, maxItems) {
    var ttab = "t" + tab;
    var tabNum = 1;
    while ($get(ttab.concat(tabNum))) {
        var selected = $get(ttab.concat(tabNum)).className.indexOf("active");
        if (selected >= 0) {
            var index = tabNum + 1;
            if (index > maxItems) index = maxItems;
            return tab.concat(index);
            break;
        }
        tabNum++;
    };
    return tab.concat(maxItems);
}
function getPreviousTab(tab, maxItems) {
    var ttab = "t" + tab;
    var tabNum = maxItems;
    while ($get(ttab.concat(tabNum))) {
        var selected = $get(ttab.concat(tabNum)).className.indexOf("active");
        if (selected >= 0) {
            var index = tabNum - 1;
            if (index < 1) index = 1;
            return tab.concat(index);
            break;
        }
        tabNum--;
    };

    return tab.concat(1);
}


function showCategoryTab(tab) {
    CategoryTabsHideTab('tab1');
    CategoryTabsHideTab('tab2');
    CategoryTabsHideTab('tab3');
    CategoryTabsHideTab('tab4');
    CategoryTabsHideTab('tab5');
    CategoryTabsHideTab('tab6');

    CategoryTabsRemoveClass('ttab1');
    CategoryTabsRemoveClass('ttab2');
    CategoryTabsRemoveClass('ttab3');
    CategoryTabsRemoveClass('ttab4');
    CategoryTabsRemoveClass('ttab5');
    CategoryTabsRemoveClass('ttab6');

    CategoryTabsShowTab(tab);

    return false;
}

function CategoryTabsHideTab(elemId) {

    var elem = document.getElementById(elemId);

    if (elem != null) {
        elem.style.display = 'none'
    }
}

function CategoryTabsRemoveClass(elemId) {

    var elem = document.getElementById(elemId);
      
    // don't remove "first" class
    if (elem != null) {
        var pos = elem.className.indexOf("first");
        if (pos >= 0) {
            elem.className = "first";
            elem.setAttribute((document.all ? 'className' : 'class'), "first");
        }
        else {
            elem.className = " ";
            elem.setAttribute((document.all ? 'className' : 'class'), " ");
        }
     }
}

function CategoryTabsShowTab(elemId) {
  
    var elem = document.getElementById(elemId);
    var ttab = "t" + elemId;

    
    if (elem != null) {
        elem.style.display = 'block';
    }

    var myelem = document.getElementById(ttab);
    
    if (myelem != null) {
        //myelem.className = "active";
        var pos = myelem.className.indexOf("first");
        if (pos >= 0) {
        	myelem.className = 'first active';
        	myelem.setAttribute((document.all ? 'className' : 'class'), "first active");        	
        }
        else {
        	myelem.className = 'active';
        	myelem.setAttribute((document.all ? 'className' : 'class'), "active");        	
            
        }
    }    
}

function turnAllCssOffExceptPrint(parentWin) {
    while (parentWin.document.readyState != "complete") { }
    for (i = 0; i < parentWin.document.styleSheets.length; i++) {
        if (parentWin.document.styleSheets.item(i).media != 'print') {
            parentWin.document.styleSheets.item(i).disabled = true;
        }
        else {
            parentWin.document.styleSheets.item(i).media = "";
        }
    }
}

function toggleDescription() {
    var shortElem = document.getElementById("lblShortDescription");
    var longElem = document.getElementById("lblLongDescription");
    if (shortElem != null && longElem != null) {
        if (shortElem.style.display.indexOf("none") >= 0) {
            shortElem.style.display = 'inline';
            longElem.style.display = 'none';
            }
        else {
            shortElem.style.display = 'none';
            longElem.style.display = 'inline';
            }
    }
}


$(document).ready(function() {

    if ($('.tab-group').length > 0) {
        Tabs = {
            // INTERNAL METHODS
            _init: function() {
                Tabs._applyUrlParams();

                // AUTO SELECT FIRST TAB OF EACH GROUP
                // Applies only those groups that don't already have a preselected tab
                if ($('.tab-group').length > 1) {
                    $('.tab-group').each(function() {
                        var noPanelsVisible = true;
                        $(this).find('.tab-panel').each(function(i) {
                            if ($(this).is('.tab-panel-visible')) {
                                noPanelsVisible = false;
                            }
                        });
                        if (noPanelsVisible) {
                            var group = $(this);
                            Tabs._click(0, group);
                        }
                    });
                }
                // USER CLICKS A TAB ANY TIME AFTER LOADING
                $('.tab').click(function() {
                    var group = $(this).parent().parent();
                    var tabIndex = group.find('.tab').index(this);
                    Tabs._click(tabIndex, group);
                });
            },
            _click: function(tabIndex, group) {
                // ERROR HANDLING: if group is undefined, then set to first group on the page
                if (typeof group === 'undefined')
                    group = $('.tab-group:first');
                // ERROR HANDLING: if tabIndex is not valid, then set to 0
                tabIndex = Number(!isNaN(tabIndex) ? tabIndex : 0);
                // ERROR HANDLING: if tabIndex is outside normal length, then set to 0
                if (tabIndex < 0 || tabIndex >= group.find('.tab').length) {
                    tabIndex = 0;
                }
                // set tabs
                group.find('.tab').removeClass('tab-selected') // unselect all tabs
                group.find('.tab:eq(' + tabIndex + ')').addClass('tab-selected') // set selected tab
                // set panels
                group.find('.tab-panel').removeClass('tab-panel-visible') // hide all content
                group.find('.tab-panel:eq(' + tabIndex + ')').addClass('tab-panel-visible') // show related content

                if (typeof Tabs.onClick == 'function')
                    Tabs.onClick(tabIndex, group); // Create your own callback function as "Tabs.onClick = function(tabIndex, group){/*do stuff*/}" outside of this class
            },
            _hide: function(tabIndex) {
                $('.tab:eq(' + tabIndex + ')').addClass('hidden');
            },
            _applyUrlParams: function() {
                // simple, returns array, e.g. ["a=1", "b=2", "c=2"]
                var getUrlParams = function() {
                    return (location.href.replace(/.*\?(.*?)/, "$1").split('&'));
                };
                // URL PARAM "hideTab": check if any tabs have been hidden via url
                // can be "hideTab=1" for single or "hideTab=1;hideTab=2;hideTab=3" for multiple (note: ADD ";"... REMOVE "&"... very important!)
                if (location.href.indexOf('hideTab') > -1) {
                    var params = getUrlParams();
                    var hideTabs = [], tabIndex;
                    for (var i = 0; i < params.length; i++) {
                        if (params[i].split('=')[0].toLowerCase() === 'hidetab') {
                            hideTabs = params[i].split(';');
                            for (var j = 0; j < hideTabs.length; j++) {
                                tabIndex = hideTabs[j].split('=')[1] - 1;
                                Tabs._hide(tabIndex);
                            };
                            break;
                        }
                    };
                }
                // URL PARAM "selectTab": check if any tab has been preset as selected via url
                // this url param test must be the LAST url param test
                if (location.href.indexOf('selectTab') === -1) {
                    Tabs._click(0);
                } else {
                    var params = getUrlParams();
                    var tabIndex;
                    for (var i = 0; i < params.length; i++) {
                        if (params[i].split('=')[0].toLowerCase() === 'selecttab') {
                            tabIndex = Number(params[i].split('=')[1]) - 1;
                            Tabs._click(tabIndex);
                            break;
                        }
                    };
                }
            },
            // EXTERNAL METHODS
            click: function(tabGroupID, tabNumber) {
                var tabIndex = tabNumber - 1;
                var group = $('#' + tabGroupID + '.tab-group');
                Tabs._click(tabIndex, group);
            }
        };
        Tabs._init();
    };
    // END COPY
}); // end $(document).ready()
	