// JavaScript Document

/* testing jquery library */
$(document).ready(function (e) {
//alert('this is the try of framework');

    $("#bankAccountSt").live('click', function (e) {
        var accountNo = $('#accountNo').val();
        if (accountNo == "")
        {
            $('#bankAccountError').css('display', 'block');
        } else
        {
            $('#bankAccountForm').submit();
        }

    });


});
$(document).ready(function () {

    //========================================
    //here the model
    //========================================
    $('body').on('click', '.submitnew', function () {
        if ($("#submitnew").valid() === true) {
            $('.submitnew').prop("disabled", true);
            $('.submitnew').css("background", "red");
            $("#submitnew").submit();
        } else {
            $('.submitnew').prop("disabled", false);
        }
    });

    $('.savemodel').on('click', function () {
// do something…
        $('#myModal2').modal('hide');
        var pos2 = $(this).attr('data-position');
        var id2 = $(this).attr('data-id');
        //alert(pos);
        window.location.href = pos2 + '?id=' + id2;
    });
    $('.conformdel').click(function (e) {
        e.preventDefault();
        var elemid = $(this).data('id');
        var elemposition = $(this).data('position');
        $("#myModal").find(".savemodel").attr('data-id', elemid);
        $("#myModal").find(".savemodel").attr('data-position', elemposition);
        $('#myModal').modal('show');
    });
    $('.savemodel').on('click', function () {
// do something…
        $('#myModal').modal('hide');
        var pos = $(this).attr('data-position');
        var id = $(this).attr('data-id');
        //alert(pos);
        window.location.href = pos + '?id=' + id;
    });
    //========================================
    //here the clock
    //========================================

    $(function () {
        $('#t1').clockface();
    });
    $(function () {
        $('#t2').clockface({
            format: 'HH:mm',
            trigger: 'manual'
        });
        $('#toggle-btn').click(function (e) {
            e.stopPropagation();
            $('#t2').clockface('toggle');
        });
    });
    //========================================
    //here the datapicker
    //========================================

    $('.awdatepicker').datepicker({
        //format: "yyyy-mm-dd",
        autoclose: true,
    });
    $('.awdatepicker2').datepicker({
        format: 'mm-dd-yyyy',
        autoclose: true,
    });
    $('#dp3').datepicker();
    //========================================
    //here the select
    //========================================
    $(".select2").select2();
    $(".select2min2").select2({
        minimumInputLength: 2
    });
    $(".select2").on("change", function (e) {
        $vluof = $(this).val();
    });
    $(".select2ajax").select2({
        placeholder: "ابحث عن",
        minimumInputLength: 1,
        ajax: {// instead of writing the function to execute the request we use Select2's convenient helper
            url: "http://api.rottentomatoes.com/api/public/v1.0/movies.json",
            dataType: 'jsonp',
            data: function (term, page) {
                return {
                    q: term, // search term
                    page_limit: 10,
                    apikey: "ju6z9mjyajq2djue3gbvv26t" // please do not use so this example keeps working
                };
            },
            results: function (data, page) { // parse the results into the format expected by Select2.
                // since we are using custom formatting functions we do not need to alter remote JSON data
                return {
                    results: data.movies
                };
            }
        },
        initSelection: function (element, callback) {
            // the input tag has a value attribute preloaded that points to a preselected movie's id
            // this function resolves that id attribute to an object that select2 can render
            // using its formatResult renderer - that way the movie name is shown preselected
            var id = $(element).val();
            if (id !== "") {
                $.ajax("http://api.rottentomatoes.com/api/public/v1.0/movies/" + id + ".json", {
                    data: {
                        apikey: "ju6z9mjyajq2djue3gbvv26t"
                    },
                    dataType: "jsonp"
                }).done(function (data) {
                    callback(data);
                });
            }
        },
        formatResult: movieFormatResult, // omitted for brevity, see the source of this page
        formatSelection: movieFormatSelection, // omitted for brevity, see the source of this page
        dropdownCssClass: "bigdrop", // apply css that makes the dropdown taller
        escapeMarkup: function (m) {
            return m;
        } // we do not want to escape markup since we are displaying html in results
    });
    function movieFormatResult(movie) {
        var markup = "<table class='movie-result'><tr>";
        if (movie.posters !== undefined && movie.posters.thumbnail !== undefined) {
            markup += "<td valign='top'><img src='" + movie.posters.thumbnail + "'/></td>";
        }
        markup += "<td valign='top'><h5>" + movie.title + "</h5>";
        if (movie.critics_consensus !== undefined) {
            markup += "<div class='movie-synopsis'>" + movie.critics_consensus + "</div>";
        } else if (movie.synopsis !== undefined) {
            markup += "<div class='movie-synopsis'>" + movie.synopsis + "</div>";
        }
        markup += "</td></tr></table>"
        return markup;
    }

    function movieFormatSelection(movie) {
        return movie.title;
    }

//========================================
//here mine select
//========================================
    $(".selectprog").select2({
        placeholder: "اختار منتج",
        minimumInputLength: 3,
        ajax: {
            url: "index.php?do=godo",
            dataType: 'json',
            data: function (term, page) {

                return {
                    q: term
                };
            },
            results: function (data, page) {
                return {results: data};
            },
            formatResult: function formatResult(data) {
                alert(data);
                return '<b>' + ex.name + '</b>';
            }
        }
    })






});





