﻿
$(function () {
    InitForm();
});

function InitForm() {
    
    $("form input").keypress(function (e) {
        if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {
            $('.submit').click();
            return false;
        } else {
            return true;
        }
    });    
    
    $('.submit').click(function () {
        $(this).parents('form').submit();
        return false;
    });

    //adicionar jquery.watermark.min.js à página
    $(".inputWatermark").each(function () {
        $(this).watermark({
            cssClass: "lightWatermark"
        });
    });

    if ($(".list-carousel").length)
        $(".list-carousel").carousel({
            dispItems: 3

        });

    //adcionar jquery.checkbox.min.js e jquery.checkbox.css à página
    if ($(".customCheckbox").length)
        $('.customCheckbox').checkbox({ empty: "/Content/Images/empty.png" });

    if ($(".inputData:not(:hidden)").length)
        $('.inputData:not(:hidden)').datepicker({
            showOn: 'button',
            buttonImage: '/Content/Images/icoCalendar.png',
            buttonImageOnly: true,
            constrainInput: true
        });

    //adicionar tiny_mce/jquery.tinymce.js e tiny_mce/tiny_mce.js à página
        $(".textEditor").each(function () {
            $(this).tinymce({

                // General options
                theme: "advanced",
                plugins: "pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,advlist",

                // Theme options
                theme_advanced_buttons1: "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect,fontselect,fontsizeselect",
                theme_advanced_buttons2: "cut,copy,paste,pastetext,pasteword,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,preview,|,forecolor,backcolor",
                theme_advanced_buttons3: "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print",
                theme_advanced_buttons4: "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak,|,ltr,rtl,|,fullscreen",
                theme_advanced_toolbar_location: "top",
                theme_advanced_toolbar_align: "left",
                //theme_advanced_statusbar_location: "bottom",
                theme_advanced_resizing: true,

                // Drop lists for link/image/media/template dialogs
                template_external_list_url: "lists/template_list.js",
                external_link_list_url: "lists/link_list.js",
                external_image_list_url: "lists/image_list.js",
                media_external_list_url: "lists/media_list.js",

                // Replace values for the template plugin
                template_replace_values: {
                    username: "Some User",
                    staffid: "991234"
                }
            });

            $(this).removeClass("textEditor");
        });

    //adicionar jquery.fcbkcomplete.js e jquery.fcbkcomplete.css à página
    if ($(".tags").length)
        $(".tags").fcbkcomplete({
            newel: true,
            complete_text: tagCompleteText,
            json_url: '/' + currentCulture + '/Admin/Tag/GetTags'
        });

    //adicionar jquery.dd.js e jquery.dd.css à página
    if ($(".imageDropDown").length)
        $(".imageDropDown").msDropDown({ mainCSS: 'dd2' });


    //adicionar jquery.dd.js e jquery.dd.css à página
    if ($(".sortable").length) {
        $(".sortable").sortable({
            cancel: ".ui-state-disabled",
            items: "tr:not(.ui-state-disabled)"
        });

        $(".sortable").disableSelection();

        $('.sortable > tr:not(.ui-state-disabled) > td').hover(function () {
            $(this).css('cursor', 'move');
        });

    }

    $(".inputCurrency").each(function () { 
        $(this).priceFormat({
            prefix: '',
            centsSeparator: ',',
            thousandsSeparator: ''
        });
    });

    $(".inputPercent").each(function () {
        $(this).priceFormat({
            prefix: '',
            centsSeparator: '',
            thousandsSeparator: '',
            centsLimit: 0
        });
    });

    $(".realUpload").change(function () {
        $(this).parent().find(".fakeUpload").val($(this).val());
    });
    $(".rakeUpload, .uploadButton").click(function () {
        $(this).parent().find(".realUpload").trigger('click');
    });
}
