﻿jQuery(function () {
    $.validator.addMethod('cpf', function (value) { return isValidCpf(value.replace(/\./g, "").replace("-", "")) });
    $("form").validate({ highlight: function (element, errorClass) {
        $(element).addClass('error');
        $(element).closest("li.question").addClass('error');
    }, unhighlight: function (element, errorClass) {
        $(element).removeClass('error');
        $(element).closest("li.question").removeClass('error');
    }
    });
});


function AjustaImagem(id, imagem) {
    var w = Math.round($(id).width());
    var h = Math.round($(id).height());  
    $(id).attr("src", 'http://admin.webplus.com.br/public/images/Crop.ashx?img=' + imagem + '&w=' + w + '&h=' + h);
}

function imprimir(id) {
    var mywindow = window.open('', '', 'height=400,width=600');
    mywindow.document.write('<html><head><title></title>');
    mywindow.document.write('</head><body >');    
    mywindow.document.write('</body></html>');
    $(mywindow.document).append($(id).clone());    
    mywindow.document.close();
    mywindow.print();
    return true;
}

// Nivo thumbs panel slider
thumbsPanelSlider = function () {    
    var $thumb = jQuery('.nivo-controlNavSpan a');
    var $thumbActive = jQuery('.nivo-controlNavSpan a.active');
    var $thumbFirst = jQuery('.nivo-controlNavSpan a:first');
    var $thumbLast = jQuery('.nivo-controlNavSpan a:last');
    var $thumbsPanel = jQuery('.nivo-controlNavSpan');

    var thIndex = $thumb.index($thumbActive);
    var thIndexFirst = $thumbFirst.index();
    var thIndexLast = $thumbLast.index();

    var numberOfThumbs = $thumb.length;
    var thumbWidth = $thumb.outerWidth(true); //$thumb.innerWidth();
    var p = 0;

    if (numberOfThumbs <= 8 && numberOfThumbs > 4) {
        if (thIndex == 4) {
            p = '-' + thumbWidth * (numberOfThumbs - 4);
            slideThumbsPanel($thumbsPanel, p);
        }
        if (thIndex == (numberOfThumbs - 5)) {
            slideThumbsPanel($thumbsPanel, p);
        }
        if (thIndex == thIndexLast) {
            p = '-' + thumbWidth * (numberOfThumbs - 4);
            slideThumbsPanel($thumbsPanel, p);
        }
        if (thIndex == thIndexFirst) {
            slideThumbsPanel($thumbsPanel, p);
        }
    };

    // Animation
    function slideThumbsPanel($target, x, preferences) {
        //$target.animate({ 'left': x + 'px' }, 1000, 'easeInOutQuad');
        $target.animate({ 'left': x + 'px' }, 1000);
    };
};



