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);
}

//Create product comparison label
function createProductComparisonUrl(elem, url, cookieName, errLabelId) {
    var errLabel = document.getElementById(errLabelId);
    var productsToCompare = 0;
    if (readCookie(cookieName) != null) {
        productsToCompare += readCookie(cookieName).toString().split(',').length - 1;
    }

    var link = elem;
    if (productsToCompare < 2 && errLabel != null) {
        document.getElementById(errLabelId).innerHTML = "Less than 2 items have been selected for comparison";
        link.href = "#";
    }
    else {
        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) {
    document.getElementById('tab2').style.display = 'none';
    document.getElementById('tab3').style.display = 'none';
    document.getElementById('tab1').style.display = 'none';
    document.getElementById(tab).style.display = 'block';
    return false;
}

var browser = null;
var newbrowser = true;
var check = false;
function init() {
    if (document.layers) {
        layerRef = "document.layers";
        styleSwitch = "";
        screenSize = window.innerWidth;
        browser = "ns4";
    }
    else if (document.all) {
        layerRef = "document.all";
        styleSwitch = ".style";
        screenSize = document.body.clientWidth + 18;
        browser = "ie4";
    }
    else if (document.getElementById) {
        layerRef = "document.getElementByID";
        styleSwitch = ".style";
        browser = "dom1";
    }
    else {
        browser = "none";
        newbrowser = false;
    }
    check = true;
}

function showHover(buttonHover, onSrc, boxName) {
    if (!check)
        init();

    if (browser == "none") { return; }
    if ($get(boxName).style.visibility != "visible") {
        setSrc($get(buttonHover), onSrc);
    }
    else if (browser == "dom1") {
        if ($get(boxName).style.visibility != "visible") {
            setSrc($get(buttonHover), onSrc);
        }
        else {
            eval(layerRef + '["' + boxName + '"]' + styleSwitch + '.visibility="visible"');
            setSrc($get(buttonHover), onSrc);
        }
    }
}

function Box(visibility, buttonClick, selectedSrc, boxName) {
    if (!check)
        init();

    if (browser == "none") { return; }
    else if (browser == "dom1") {
        $get(boxName).style.visibility = visibility;
        setSrc($get(buttonClick), selectedSrc);
    }
    else {
        eval(layerRef + '["' + boxName + '"]' + styleSwitch + '.visibility="' + visibility + '"');
        setSrc($get(buttonClick), selectedSrc);
    }
}

function setSrc(controlName, srcTarget) {
    controlName.src = srcTarget;
}

function setClass(controlName, classTarget) {
    controlName.className = classTarget;
}

/* Check maxlength of a multiple-line textbox*/
function checkMaxLen(txt, maxLen) {
    try {
        if (txt.value.length > maxLen) {
            var cont = txt.value;
            txt.value = cont.substring(0, maxLen);
            return false;
        };
    } catch (e) {
    }
}