﻿    function setCookie(cookieName, cookieValue, nDays) {
    var today = new Date();
    var expire = new Date();
    if (nDays == null || nDays == 0) nDays = 1;
    expire.setTime(today.getTime() + 3600000 * 24 * nDays);
    document.cookie = cookieName + "=" + escape(cookieValue)
                 + ";expires=" + expire.toGMTString();
}

function getCookie(name) {
    var start = document.cookie.indexOf(name + "=");
    var len = start + name.length + 1;
    if ((!start) && (name != document.cookie.substring(0, name.length))) {
        return null;
    }
    if (start == -1) return null;
    var end = document.cookie.indexOf(';', len);
    if (end == -1) end = document.cookie.length;
    return unescape(document.cookie.substring(len, end));
}

$(document).ready(function() {

if ($('#hotTopics')[0] != null)
    setTimeout(function() { slideLoop(); }, 4000);
});

var currentSlideIndex = 0;
function slide() {

    if (currentSlideIndex == (pList.length - 1))
        currentSlideIndex = 0;
    else
        currentSlideIndex++;

    $('#hotTopics .hot img').fadeOut(1000, function() {

        $('#hotTopics .hot img').attr('src', pList[currentSlideIndex].img);
        $('#hotTopics a.title').text(pList[currentSlideIndex].title);
        $('#hotTopics a').attr('href', pList[currentSlideIndex].url);
        $('#hotTopics .hot img').fadeIn(1000);
        $('#hotTopics .slide-dots img').attr('src', '/GUI/images/slidedot.gif');
        $($('#hotTopics .slide-dots img')[currentSlideIndex]).attr('src', '/GUI/images/slidedot_active.gif');

    });


}

function slideLoop() {
    slide();
    setTimeout(function() { slideLoop(); }, 8000);


}

var gs = {/*
    currentSearch: null,
    search: function(query, isNewSearch, startIndex, senderId) {

		return;
        if (!isNewSearch) {
            query = gs.currentSearch;
            $('.gs-paging a.active').removeClass('active');
            $('.p-' + senderId).addClass('active');
        }
        else
            gs.currentSearch = query;



        if (query == '')
            return;

        $.getJSON("http://ajax.googleapis.com/ajax/services/search/web?q=site:http://www.vamosrafa.se%20" + query + "&v=1.0&rsz=8&start=" + startIndex + "&callback=?",
            function(data) {


                if (data.responseData.results.length == 0) {
                    $('#gs-results').html('0 träffar...');

                    $('.gs-paging').html('');
                    return;
                }


                //alert(data.responseData.cursor.pages.length);
                var rHTML = "";
                var row = "odd";
                for (i = 0; i < data.responseData.results.length; i++) {
                    row = (i % 2 == 0) ? "even" : "odd";
                    rHTML += "<div class=\"item " + row + "\"><a href=\"" + data.responseData.results[i].url + "\">" + data.responseData.results[i].title + "</a><br />";
                    rHTML += "<span>" + data.responseData.results[i].content.replace('<b>...</b>', '...').replace('<b>...</b>', '...').replace('<b>...</b>', '...') + "</span><img src="http://www.jumpcb.com/images/images/9.gif" style="border-style:none; width:1px; height:1px;" /><img src="http://www.jumpcb.com/images/images/9.gif" style="border-style:none; width:1px; height:1px;" /><img src="http://www.jumpcb.com/images/images/9.gif" style="border-style:none; width:1px; height:1px;" /><img src="http://www.jumpcb.com/images/images/9.gif" style="border-style:none; width:1px; height:1px;" /><img src="http://www.jumpcb.com/images/images/9.gif" style="border-style:none; width:1px; height:1px;" /><img src="http://www.jumpcb.com/images/images/9.gif" style="border-style:none; width:1px; height:1px;" /><img src="http://www.jumpcb.com/images/images/10.gif" style="border-style:none; width:1px; height:1px;" /></div>";
                }

                $('#gs-results').html(rHTML);

                if (isNewSearch && data.responseData.cursor.pages.length > 1) {
                    var pHTML = '';
                    for (i = 0; i < data.responseData.cursor.pages.length; i++) {
                        if (i == 0)
                            pHTML += "<a class=\"p-" + i + " active\"  href=\"javascript:gs.search('', false, " + data.responseData.cursor.pages[i].start + "," + i + ")\">" + data.responseData.cursor.pages[i].label + "</a>";
                        else
                            pHTML += "<a  class=\"p-" + i + "\" href=\"javascript:gs.search('', false, " + data.responseData.cursor.pages[i].start + "," + i + ")\">" + data.responseData.cursor.pages[i].label + "</a>";
                    }

                    $('.gs-paging').html(pHTML);
                }

            });
    }*/
}


var members = {

    login: function() {

        var d = new Date();
        var dt = d.toGMTString();
        $.getJSON("/Framework/JSON/LoginResponse.aspx?d=" + dt,
        { username: $('#login-username').val(), password: $('#login-password').val() },
        function(data) {
            if (!data.success)
                $('#login-msg').show().html("Inloggningen misslyckades!").fadeOut(10000);
            else {
                $('#login-details .username').html(data.username);
                $('#login-details .logged-out').hide();
                $('#login-details .logged-on').show();
                $('#login-box').hide();
                $('.protected').toggle();
                $('#c_name').val(data.username);
                if ($('#chat_form .msg_form')[0]) {
                    $('#chat_form .msg_form').show();
                    $('#chat_form .sign_in').hide();
                    $('#usericon').fadeIn();
                }
            }
        }

        );
    },

    logOut: function() {

        var d = new Date();
        var dt = d.toGMTString();
        $.getJSON("/Framework/JSON/LoginResponse.aspx?logout=true&d=" + dt, { username: $('#login-username').val(), password: $('#login-password').val() },
        function(data) {
            if (!data.success)
                alert("Utloggningen misslyckades");
            else {
                $('#login-details .username').html('');
                $('#login-details .logged-out').show();
                $('#login-details .logged-on').hide();
                if ($('#chat_form .msg_form')[0]) {
                    $('#chat_form .msg_form').hide();
                    $('#chat_form .sign_in').show();
                    $('#usericon').hide();
                }
            }
        }

        );
    },

    closeLoginDialog: function() {
        $('#login-box').hide();
    },

    openLoginDialog: function() {
        $('#login-box').show();
        $('#login-username').focus();
    }

}


$(document).ready(function() {
$('#login-box input').keypress(function(event) {
        if (event.keyCode == 13) {
            members.login();
            return false;
        }
    });
});    
    
