Utils = {};

Utils.isIE = function() {
    return navigator.appName.indexOf('Microsoft') > -1;
}

Utils.isIE7 = function() {
    return navigator.userAgent.indexOf("MSIE 7.") > -1;
}

Utils.getPosition = function(pixelPos) {
    return parseInt(pixelPos.replace("px", ""));
}

Utils.justSwapImg = function(imgSrc, id) {
    document.getElementById(id).src = imgSrc;
}

Utils.swapBackground = function(src, id) {
    document.getElementById(id).style.background = "url(" + src + ")";
}

Utils.toggleShowLayer = function(id) {
    if (document.getElementById(id).style.display == 'none' || document.getElementById(id).style.display == '') {
        document.getElementById(id).style.display = 'block';
    } else {
        document.getElementById(id).style.display = 'none';
    }
}

Utils.showLayer = function(id) {
    document.getElementById(id).style.display = "block";
}
Utils.hideLayer = function(id) {
    document.getElementById(id).style.display = "none";
}

Utils.clearInputBox = function(id) {
    if (document.getElementById(id).value == "Search term") {
        document.getElementById(id).value = "";
    }
}

Utils.resetInputBox = function(id, string) {
    if (document.getElementById(id).value == "") {
        document.getElementById(id).value = string;
    }
}


Utils.getWindowWidth = function() {
    if (Utils.isIE()) {
        winW = document.body.offsetWidth;
    } else {
        winW = window.innerWidth;
    }
    return winW;
}

Utils.getWindowHeight = function() {
    if (Utils.isIE()) {
        winH = document.body.offsetHeight;
    } else {
        winH = window.innerHeight;
    }
    return winH
}

Utils.enableStyleSheet = function(name, on) {
    for (var i = 0; (a = document.getElementsByTagName("link")[i]); i++) {
        if (a.getAttribute("rel") &&
            a.getAttribute("rel").indexOf("style") != -1 &&
            a.getAttribute("title")) {
            if (a.getAttribute("title") == name) {
                a.disabled = !on;
                Utils.createCookie(name, on, 365);
            }
        }
    }
}

Utils.createCookie = function (name, value, days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        var expires = "; expires=" + date.toGMTString();
    }
    else expires = "";
    document.cookie = name + "=" + value + expires + "; path=/";
}

Utils.readCookie = function (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;
}


Utils.enableStyleSheet("loRes", Utils.readCookie("loRes") != null && Utils.readCookie("loRes") == 'true');
