﻿$.fn.getStyleObject = function () {
    var dom = this.get(0);
    var style;
    var returns = {};
    if (window.getComputedStyle) {
        var camelize = function (a, b) {
            return b.toUpperCase();
        };
        style = window.getComputedStyle(dom, null);
        for (var i = 0, l = style.length; i < l; i++) {
            var prop = style[i];
            var camel = prop.replace(/\-([a-z])/g, camelize);
            var val = style.getPropertyValue(prop);
            returns[camel] = val;
        };
        return returns;
    };
    if (style = dom.currentStyle) {
        for (var prop in style) {
            returns[prop] = style[prop];
        };
        return returns;
    };
    if (style = dom.style) {
        for (var prop in style) {
            if (typeof style[prop] != 'function') {
                returns[prop] = style[prop];
            };
        };
        return returns;
    };
    return returns;
}
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');
    }
    }); 
    */ 
});

$(document).ready(function () {    
    $('.usar_como_link').each(function () {        
        $(this).click(function () {            
            var url = $(this).attr('url_link');            
            if (url != null && url != undefined && url != '') {
                window.location = url;
            }
        });
    });
});

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);
    };
};
