﻿function none() {
    return false;
}
/*
 * Валютный конвертр
 */ 
function changeTab(tab, val) {
    $('a.idx-tab span').css('color', '#004B9A');
    $(tab).find('span').css('color', '#ED1C24');
    $('table.tbl_conv').css('display', 'none');
    $('#tbl' + val).css('display', 'table');
}

function convert(typeId) {
    var sum = $("#from_value_" + typeId).val();
    var course = $("#from_" + typeId).val();
    var to = $("#to_" + typeId).val();
    $("#to_value_" + typeId).val(calc(sum, course, to));
}

function calc(sum, course, to) {
    if (sum != '') {
        return (Number(sum.replace(",", ".")) * Number(course.replace(",", ".")) / Number(to.replace(",", "."))).toFixed(2);
    }
    return '';
}

/* Листалка дайджеста блогов */
var pageIndex = 1;
var postsCount = 0;

var digestMarkUp = "<div class='cell'> \
                            <a href='${author_url}' class='cell-image'> \
                                <img src='${author_image_url}' align='left' width='86' height='122' class='cell-image' alt='${author_full_name}' title='${author_full_name}'> \
                            </a> \
                            <a title='${author_full_name}' class='no-underline lh15' href='${author_url}'> \
                                <b>${author_full_name}</b> \
                            </a> \
                            <br/> \
                            <a href='${author_blog_url}' class='redbold' target='_blank' rel='nofollow' title='${author_blog_title}'>${author_blog_title}</a> \
                            <br/>                            \
                            <a title='${author_full_name}' class='no-underline lh15' href='${blog_post_url}'> \
                                <small class='color-black'> \
                                ${blog_post_quote}\
                                </small> \
                            </a> \
                        </div>";
                        
$(document).ready(function() { $.template("digestTemplate", digestMarkUp); });


function moveCell(value) {
     
    pageIndex = pageIndex + value;
    $.get('/Client/Handler/BlogsPostsHandler.ashx', { "p": pageIndex, "count": postsCount },
            function(data) {
                if (data != '') { 
                    var respObj = jQuery.parseJSON(data); 
                    pageIndex = respObj.page_index;
                    postsCount = respObj.posts_count;
                    var cell1 = $('#blogs_posts .cell')[0];
                    $(cell1).hide();
                    $.tmpl("digestTemplate", respObj).appendTo("#blogs_posts");
                    $(cell1).remove();
                    $('#move_cell_left').unbind('click');
                    $('#move_cell_left').click(function() { moveCell(-1) });
                }
            }
        );
}

$(function() {
    $('#move_cell_left').click(function() { moveCell(-2) });
    $('#move_cell_right').click(function() { moveCell(1) });
});
