﻿var topcategoryurl = "";

$(document).ready(function() {
    //$("#MENU").supersleight();
    $("#imgLogo").supersleight();
    $("#language-selected").supersleight();

    $("#language-selected").bind("click", function() {
        $("#language-selector").animate({ height: "toggle" }, 250);
    });

    $("#txtMasterSearch").val('Sök produkt').StartMessage();
    $("#txtSearchFooter").StartMessage();
});

$(document.body).keyup(function (e) {
    
});

function SetLanguage(senderId, isToggle, language) {
    $("#language-selector").animate({ height: "toggle" }, "fast", function () {
        $("#language-selector").css("top", "24px");
    });
    $("#language-selected").html($("#" + senderId).html());

    CreateCookie('GrytsLanguage', language, 365);

    if (isToggle)
        window.location = ("/" + language);

    $("#language-selector").show();
}

function SetCookie(name, value, expires, path, domain, secure) {
    var curCookie = name + "=" + escape(value) +
		((expires) ? "; expires=" + expires.toGMTString() : "") +
		((path) ? "; path=" + escape(path) : "") +
		((domain) ? "; domain=" + domain : "") +
		((secure) ? "; secure" : "");

    document.cookie = curCookie;
}

function CreateCookie(name, value, days) {
    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=/";
}


function DeleteCookie(name, path, domain) {
    if (true) {
        document.cookie = name + "=" + ((path) ? ";path=" + path : "") + ((domain) ? ";domain=" + domain : "") + ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
    }
}

function getCookie(c_name) {
    if (document.cookie.length > 0) {
        c_start = document.cookie.indexOf(c_name + "=");
        if (c_start != -1) {
            c_start = c_start + c_name.length + 1;
            c_end = document.cookie.indexOf(";", c_start);
            if (c_end == -1) c_end = document.cookie.length;
            return unescape(document.cookie.substring(c_start, c_end));
        }
    }
    return "";
}

function mastersearch() {
    var box = $("#MASTERSEARCH");

    if (box.width() == 0) {
        box.animate({ width: '200px' }, "fast");
    }
    else {
        if ($("#txtMasterSearch").ValidateStartMessage()) {
            var query = $("#txtMasterSearch").val();
            $("#txtMasterSearch").val("");
            window.location = topcategoryurl + "?q=" + query;
        }
        else {
            box.animate({ width: '0px' }, "fast");
        }
    }
}

function SearchFooter() {
    if ($("#txtSearchFooter").ValidateStartMessage()) {
        var query = $("#txtSearchFooter").val();
        $("#txtSearchFooter").val("");
        window.location = topcategoryurl + "?q=" + query;
    }
    else {
        $("#txtSearchFooter").focus();
    }
}
