﻿function AppelWebService(laDiv, leService, lesParametres) {
    //dans le vide interciéral
    //var webMethod = "http://proweb.gotdns.com:82/gestionacri/WebService.asmx/" + leService;  //'http://MyWebService/Web.asmx/GetInfoByDates'
    //var webMethod = "http://localhost/gestionacri/WebService.asmx/" + leService;
    var webMethod = "WebService.asmx/" + leService;
    //var cestbon = false;
    $.ajax({
        type: "POST",
        url: webMethod,
        data: lesParametres,
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (msg) {
            $(laDiv).html(msg.d);
            //passer une fonction callback à AppelServiceWeb à la place...
            if (msg.d != "erreur") location.href = "extranet/bienvenue.aspx";
            // cestbon = true; //une chance j'ai mon async=false sinon ça aurait passer droit
        },
        error: function (e, status, error) {
            $(laDiv).html("Non disponible");
            //alert(webMethod + " e.statusText:" + e.statusText + " status:" + status + " erreur:" + error + " param:" + lesParametres);
        },
        async: true
    });
    //return cestbon;
}

function showMenu(dro, dlb) {
	hideMenu();    

	var $divRollOver = $(dro);
	var $divLoginBox = $(dlb);

	$divRollOver.css("background-color", "#373737");

	//get the position of the placeholder element
	var pos = $divRollOver.offset();
	var width = $divRollOver.width();
	//show the menu directly over the placeholder
	$divLoginBox.css({ "left": (pos.left) + "px" });

	$divLoginBox.slideDown('slow');
}

function hideMenu() {
   	$(".popup").slideDown().stop(true, true);
   	$(".popup").hide();
   	$(".bande_bas_rollOver").css("background-color", "transparent");
}

jQuery(document).ready(function () {
    $("#image_bande_haut_bas>ul").superfish({
        animation: { height: 'show' },
        delay: 300,
        dropShadows: false,
        autoArrows: false
    });

    if ($.browser.msie && jQuery.browser.version == 6.0) {
        $('#acces_client').click(function () { location.href = 'extranet/Default.aspx?from=Client'; });
        $('#acces_sous-traitant').click(function () { location.href = 'extranet/'; });
    } else {
        $('#acces_client').click(function () { showMenu("#acces_client", "#login_acces_client"); return false; });
        $('#acces_sous-traitant').click(function () { showMenu("#acces_sous-traitant", "#login_acces_sous-traitant"); return false; });
        $(".close_menu").click(function () { hideMenu(); return false; });

        /*Le Login Sous-Traitant!*/
        $("#imbConnexionAccesSousTraitant").click(function () {
            //$.post("accueil.aspx", { username: "test", password: "password" });
            var params = "{'username':'" + $("#txtUsernameAccesSousTraitant").val() + "', " +
        "'password':'" + $("#txtPasswordAccesSousTraitant").val() + "', " +
        "'persistent':'" + $("#cbRememberMeAccesSousTraitant").val() + "'}";
            if (AppelWebService("#erreurConnexionSousTraitant", "Login", params)) {
                //location.href = "extranet/bienvenue.aspx";
                //window.location.replace("extranet/bienvenue.aspx");
            } else {
                $("form").submit(function () { return false; }); // so it won't submit
            }
        });
        /*Le Login Client!*/
        $("#imbConnexionAccesClient").click(function () {
            //$.post("accueil.aspx", { username: "test", password: "password" });
            var params = "{'username':'" + $("#txtUsernameAccesClient").val() + "', " +
        "'password':'" + $("#txtPasswordAccesClient").val() + "', " +
        "'persistent':'" + $("#cbRememberMeAccesClient").val() + "'}";
            AppelWebService("#erreurConnexionClient", "Login", params)
            $("form").submit(function () { return false; }); // so it won't submit
        });
    }
});

