﻿var current_page = 1;



 //Pour la pagination
function pageselectCallback(page_index, jq) {
    var new_content = jQuery('#hiddenresult div.result:eq(' + page_index + ')').clone();
    $('#Searchresult').empty().append(new_content);
    return false;
}

     
//Initialisation function for pagination
        
function initPagination() {
    // count entries inside the hidden content
    var num_entries = jQuery('#hiddenresult div.result').length;

    // Create content inside pagination element
    $("#Pagination").pagination(num_entries, {
        callback: pageselectCallback,
        items_per_page: 1,
        next_text:">",
        prev_text:"<"
    });
}

$(window).load(function () {
    //Pour le scroll
    $("#makeMeScrollable").smoothDivScroll({ autoScroll: "onstart", autoScrollDirection: "backandforth", autoScrollStep: 1, autoScrollInterval: 30, startAtElementId: "startAtMe", visibleHotSpots: "always" });


    $("#mdlApplicationiPhone:ui-dialog").dialog("destroy");
    var dialogOpts = {
        bgiframe: true,
        autoOpen: false,
        modal: true,
        resizable: false,
        width: 664,
        height: 575
    };



    var dlg = $("#mdlApplicationiPhone").dialog(dialogOpts);
    $("#mdlApplicationiPhone").siblings(".ui-dialog-titlebar").hide();


    $('.ui-widget-overlay').live('click', function () {
        $('#mdlApplicationiPhone').dialog("close");
        $("#ContentPlaceHolder1_idMPh").html("1");
    });

    $('#fermer_iphone').click(function () {
        $('#mdlApplicationiPhone').dialog("close");
        return false;
    });
    $('#dl_iphone').click(function () {
        $('#mdlApplicationiPhone').dialog("close");
    });


    if ($("#ContentPlaceHolder1_idMPh").html() == '0') $('#mdlApplicationiPhone').dialog("open");
});



    function ChangePage() {
    //$('#Pagination').trigger('nextPage');
    if ($.browser.msie) {
    if ($.browser.version < 9) {

    $('#Pagination').trigger('setPage', current_page);

    current_page += 1;
    if (current_page >= (jQuery('#hiddenresult div.result').length)) {
    current_page = 0;}
    }
    }
    else {
    $('#Searchresult').fadeOut();
    $('#Pagination').trigger('setPage', current_page);
    $('#Searchresult').fadeIn();

    current_page += 1;
    if (current_page >= (jQuery('#hiddenresult div.result').length)) {
    current_page = 0;}
    }

    }

    function OnFocus_BtnRecherche() {
    $("#ContentPlaceHolder1_sidebar1_tbVille").removeClass("Highlight");
    }


    $(document).ready(function () {

    //Pour la pagination
    initPagination();

    setInterval("ChangePage()", 10000);

    var href;
    href = window.location.protocol + "//" + window.location.host + window.location.pathname.substring(0, window.location.pathname.indexOf("/", 1)) + "/";


    $("#ContentPlaceHolder1_tbRechercheAgence").watermark("ex : St André de Cubzac");

    //    /*Autocompelete du textbox nego*/
    $("#ContentPlaceHolder1_tbRechercheAgence").autocomplete({

        source: function (request, response) {
            $.ajax({
                url: href + "webservice/ville_fr.asmx/jsonfville_fr",
                data: "{ 'Ville': '" + request.term + "' }",
                dataType: "json",
                type: "POST",
                contentType: "application/json; charset=utf-8",
                // dataFilter: function (data) { return data; },
                success: function (data) {
                    // $("#json").html(data.d);
                    response($.map(data.d, function (item) {
                        return {

                            label: item.value,
                            value: item.value

                        }
                    }))

                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    alert(errorThrown);
                }
            });
        },
        minLength: 4,
        select: function (event, ui) {
            //alert(ui.item.label);
            //            Chargement();
            //            window.location.href = ui.item.url;
        },
        open: function () {
            $(this).removeClass("ui-corner-all").addClass("ui-corner-top");
        },
        close: function () {
            $(this).removeClass("ui-corner-top").addClass("ui-corner-all");
        },
        width: "600px"
    }).data("autocomplete")._renderItem = function (ul, item) {
        return $("<li></li>")
			    .data("item.autocomplete", item)
			    .append("<a>" + item.value + "</a>")
			    .appendTo(ul);
    };
});

