function OpenInfo(url, width, height) {
    OpenPopup(RootUrl + "Front/Info/" + url + ".aspx", width, height);
}

function OpenInfoStandard(url) {
    OpenInfo(url, 850, 750);
}

function OpenInfoContact() {
    OpenInfo("ContactUs", 440, 550);
}

function OpenNewsletter() {
    OpenInfo("Newsletter", 345, 250);
}

function OpenContactForm(codeDestination, subject, email) {
    var addEmail = "";
    var addDestination = "&Destination=contact";
    if (!(email == undefined || email == null)) {
        addEmail = "&Email=" + encodeURIComponent(email);
    }
    if (!(codeDestination == undefined || codeDestination == null)) {
        addDestination = "&Destination=" + codeDestination;
    }
    var url = RootUrl + "Front/Info/ContactForm.aspx?Subject=" + encodeURIComponent(subject) + addDestination + addEmail;
    OpenPopup(url, 440, 550);
}

function OpenPopup(url, width, height) {
    var openUrl = url;
    if (url.indexOf('?') >= 0) {
        openUrl = openUrl + "&";
    }
    else {
        openUrl = openUrl + "?";
    }

    openUrl = openUrl + "TB_iframe=true&modal=true&width=" + width + "&height=" + height;
    tb_show(null, openUrl, null);
}

function OpenPopupWindows(url, width, height) {
    window.open(url, "_blank", "width=" + width + ",height=" + height + ",resizable=yes,scrollbars=yes,location=no,menubar=no,status=no,tollbar=no");
}

function OpenWarningTravelerData() {
    OpenInfo("WarningTravelerData", 700, 600);
}

var NewsAnimateBarWidth = -1;

function NewsAnimateInit() {
    var newsBar = $("div#M_NewsBar");
    if (newsBar.length > 0) {
        NewsAnimateBarWidth = $("div#M_NewsBar").outerWidth();
        $("div#M_NewsBar ul li:not(:first)").fadeOut(0);
        NewsAnimateProcess();
    }
}

function NewsAnimateProcess() {
    var elemWork = $("div#M_NewsBar ul li:first");
    var widthElem = elemWork.outerWidth();
    if (widthElem > NewsAnimateBarWidth) {
        var widthMove = widthElem - NewsAnimateBarWidth;
        var timeMove = widthMove * 20;
        var xmove = "-" + (widthMove) + "px";
        elemWork.animate({ marginTop: "0px" }, 4000, function() { // Attente de 4s
            elemWork.animate({ marginLeft: xmove }, timeMove, function() { // Déplacement
                elemWork.animate({ marginTop: "0px" }, 2000, function() { // Attente de 2s
                    NewsAnimateSwap();
                });
            });
        });
    }
    else {
        elemWork.animate({ marginTop: "0px" }, 6000, function() { // Attente de 6s
            NewsAnimateSwap();
        });
    }
}

function NewsAnimateSwap() {
    var elemWork = $("div#M_NewsBar ul li:first");
    elemWork.fadeOut(300, function() { // FadeOut de 300ms
        // Décalage des LI
        $("div#M_NewsBar ul li:last").after("<li>" + elemWork.html() + "</li>");
        elemWork.remove();
        $("div#M_NewsBar ul li:last").fadeOut(0);
        $("div#M_NewsBar ul li:first").fadeIn(250, function() { // FadeIn de 300ms
            if (jQuery.browser.msie) { // Correction Bug ClearType IE
                $(this).get(0).style.removeAttribute('filter');
            }
            NewsAnimateProcess(); // On relance;
        });
    });
}

function DataTableRoundInit() {
    $("table").css("border-collapse", "separate");
    $("table.DataTable[round=both]:has(tr.TblHeader)").each(function() {
        var borderData = $(this).css("border-left-style") + " " + $(this).css("border-left-width") + " " + $(this).css("border-left-color");
        $(this).css("border-top", "none");
        $(this).css("border-left", "none");
        $(this).find(":first > tr:not(:first)").find("td:first").css("border-left", borderData);

        var padTop = parseInt($(this).find("tr.TblHeader").find("td,th").css("padding-top")) + 1; if (isNaN(padTop)) { padTop = 1 };
        var padLeft = parseInt($(this).find("tr.TblHeader").find("td:first,th:first").css("padding-left")) + 1; if (isNaN(padLeft)) { padLeft = 1 };
        var padRight = parseInt($(this).find("tr.TblHeader").find("td:last,th:last").css("padding-right")) + 1; if (isNaN(padRight)) { padRight = 1 };

        $(this).find("tr.TblHeader").find("td,th").css("padding-top", padTop + "px").css("background-image", "url(" + RootUrl + "Images/BackTblHeaderRound.png)").css("background-position", "center top");
        $(this).find("tr.TblHeader").find("td:first,th:first").css("border-left", "none").css("padding-left", padLeft + "px").css("background-image", "url(" + RootUrl + "Images/BackTblHeaderRound.png)").css("background-position", "left top");
        $(this).find("tr.TblHeader").find("td:last,th:last").css("border-right", "none").css("padding-right", padRight + "px").css("background-image", "url(" + RootUrl + "Images/BackTblHeaderRound.png)").css("background-position", "right top");
    });
    $("table.DataTable[round=right]:has(tr.TblHeader)").each(function() {
        $(this).css("border-top", "none");

        var padTop = parseInt($(this).find("tr.TblHeader").find("td,th").css("padding-top")) + 1; if (isNaN(padTop)) { padTop = 1 };
        var padRight = parseInt($(this).find("tr.TblHeader").find("td:last,th:last").css("padding-right")) + 1; if (isNaN(padRight)) { padRight = 1 };

        $(this).find("tr.TblHeader").find("td,th").css("padding-top", padTop + "px").css("background-image", "url(" + RootUrl + "Images/BackTblHeaderRound.png)").css("background-position", "center top");
        $(this).find("tr.TblHeader").find("td:last,th:last").css("border-right", "none").css("padding-right", padRight + "px").css("background-image", "url(" + RootUrl + "Images/BackTblHeaderRound.png)").css("background-position", "right top");
    });
}

function DivWidthAuto() {
    $("div.DivWidthAuto").css("float", "left").after("<div style='height: 0px; clear: both'></div>");
}

function HideDelay(item) {
    $(item).animate({ marginTop: $(item).css("margin-top") }, 2000, function() {
        $(this).fadeOut(2000);
    });
}

$(NewsAnimateInit);
$(DataTableRoundInit);
$(DivWidthAuto);
$(RadEditorInit);

function ShowWaitProcess(message, delay) {
    $("table#WaitProcessTbl span").text(message);
    window.setTimeout("DoShowWaitProcess()", delay);
}

function DoShowWaitProcess() {
    var w = $("table#WaitProcessTbl").outerWidth();
    tb_show(null, "#TB_inline?width=" + w + "&height=78&inlineId=WaitProcessDiv&modal=true", null);
}

function TbActionClose() {
    tb_remove();
}

function TbActionClosePopup() {
    self.parent.tb_remove();
}

function InitCardImg(ddlName) {
    var ddl = $("#" + ddlName);
    ddl.find("label:contains(##)").each(function() {
        var label = $(this).text().substr(2);
        var code = $(this).siblings("input").val();
        $(this)
            .html("<img src='" + RootUrl + "Images/Card_" + code + ".png' class='FixPng' alt='" + label + "' />")
            .find("img").click(function() { $(this).parent().click(); });
    });
}

function RadEditorInit() {
    window.setTimeout("RadEditorInitAfter()", 5);
}

function RadEditorInitAfter() {
    $(".RadEditor_InjectCssContainer iframe").each(function() {
        $(this).contents().find("head link[rel=stylesheet][href*=/RadEditor_]").each(function() {
            var hStyle = $(this).attr("href").replace(/.css/g, "_Container.css");
            $("head").append('<link href="' + hStyle + '" rel="stylesheet" type="text/css" />');
        });
    });
}
