﻿// File JScript

function CreateMsgBox(){

    var MsgBox = document.createElement("DIV");
    MsgBox.id = "MsgBox";
    
    var ShadowBackground = document.createElement("DIV");
    ShadowBackground.id = "ShadowBackground";
    ShadowBackground.style.display = "none";
    ShadowBackground.innerHTML = "&nbsp;";
    
    var MsgBoxContainer = document.createElement("DIV");
    MsgBoxContainer.id = "MsgBoxContainer";
    
    var MsgBoxForm = document.createElement("DIV");
    MsgBoxForm.id = "MsgBoxForm";
    MsgBoxForm.style.display = "none";
    
    var MsgBoxTitle = document.createElement("DIV");
    MsgBoxTitle.id = "MsgBoxTitle";
    MsgBoxTitle.innerHTML = "&nbsp;";
    
    var MsgBoxBody = document.createElement("DIV");
    MsgBoxBody.id = "MsgBoxBody";
    MsgBoxBody.innerHTML = "&nbsp;";
    
    var MsgBoxButtons = document.createElement("DIV");
    MsgBoxButtons.id = "MsgBoxButtons";
    MsgBoxButtons.innerHTML = "&nbsp;";
    
    var DivClear = document.createElement("DIV");
    DivClear.style.display = "none";
    DivClear.innerHTML = "&nbsp;";
    
   
    MsgBoxForm.appendChild(MsgBoxTitle);
    MsgBoxForm.appendChild(MsgBoxBody);
    MsgBoxForm.appendChild(MsgBoxButtons);
    MsgBoxForm.appendChild(DivClear);
    
    MsgBoxContainer.appendChild(MsgBoxForm);
    
    MsgBox.appendChild(ShadowBackground);
    MsgBox.appendChild(MsgBoxContainer);
    
    var wrapper = document.getElementById("bodypage");
    
    if (wrapper == null){
        alert("Impossibile creare la MsgBox: non esiste un wrapper page!");
        return false;
    }
    wrapper.appendChild(MsgBox);
    
    return true;
    /*
    document.write("<div id='MsgBox' >");
    document.write("<div id='ShadowBackground' style='display: none;'>&nbsp;</div>");
    document.write("<div id='MsgBoxContainer' >");
    document.write("<div id='MsgBoxForm' style='display: none;'>");
    document.write("<div id='MsgBoxTitle'>");
    document.write("</div>");   //Chiude MsgBoxTitle
    document.write("<div id='MsgBoxBody'>");
    document.write("</div>");   //Chiude MsgBoxBody
    document.write("<div id='MsgBoxButtons'>");
    document.write("</div>");   //Chiude MsgBoxButtons
    document.write("<div style='clear:both;'>&nbsp;</div>");
    document.write("</div>");   //Chiude MsgBoxForm
    document.write("</div>");   //Chiude MsgBoxContainer
    document.write("</div>");   //Chiude MsgBox
    return true;*/
}

// btnOk e btnCancel devono essere due oggetti che hanno le seguenti proprietà
//  title, link
// se btnCancel è null viene creato un button che chiude la MsgBox
// anche btnOk può essere nullo, in questo caso si avrà un solo button

function ShowMsgBox(title, abstractHtml, bodyHtml, btnOk, btnCancel){

    var MsgBoxTitle = document.getElementById('MsgBoxTitle');
    var MsgBoxBody = document.getElementById('MsgBoxBody');
    var MsgBoxButtons = document.getElementById('MsgBoxButtons');
    if (MsgBoxTitle == null || MsgBoxBody == null || MsgBoxButtons == null){
        alert(templateStrings.GetUnableFindDivElement("MsgBox"));
        return false;
    }
    
    MsgBoxTitle.innerHTML = title;
    
    MsgBoxBody.innerHTML = abstractHtml + "<br/><br/>" + bodyHtml + "<br/><br/>";
    
    var webBtnOk = "";
    if (btnOk != null){
        webBtnOk += "<div class='MsgBoxButton'>";
        webBtnOk += "<a href='" + btnOk.link + "' title='" + btnOk.title + "' ";
        if (btnOk.onClickEvent != null && btnOk.onClickEvent != "")
            webBtnOk += "onclick=\"" + btnOk.onClickEvent + "\"";
        webBtnOk += " >" + btnOk.title + "</a>";
        webBtnOk += "</div>";
    }
    var webBtnCancel = "<div class='MsgBoxButton'>";
    if (btnCancel != null)
        webBtnCancel += "<a href='" + btnOk.link + "' title='" + btnOk.title + "'>" + btnOk.title + "</a>";
    else
        webBtnCancel += "<a href='#' onclick='CloseMsgBox(); return false;'>" + templateStrings.GetCloseLabel() + "</a>";
    webBtnCancel += "</div>";
    MsgBoxButtons.innerHTML = webBtnCancel + webBtnOk;
    
    new $('#ShadowBackground').fadeIn();
    new $('#MsgBoxForm').fadeIn();
    return true;
    
}

function CloseMsgBox(){

    new $('#MsgBoxForm').fadeOut();
		new $('#ShadowBackground').fadeOut();
	//new Effect.Fade('MsgBox', { duration: 0.6});

    //document.getElementById('MsgBox').style.display = "none";
    return true;
}


function ErrorMsgBox(errorDescription){

    var title = "<b>" + templateStrings.GetErrorLabel() + "</b>";
    var abstractHtml = (errorDescription != null && errorDescription != "") ? templateStrings.GetErrorLabel() + ":" : templateStrings.GetUnknownErrorLabel();
    var bodyHtml = (errorDescription != null && errorDescription != "") ? errorDescription : "";
    
    ShowMsgBox(title, abstractHtml, bodyHtml);

}

function InfoMsgBox(description){

    var title = templateStrings.GetInfoLabel();
    var abstractHtml = "";
    var bodyHtml = description;
    
    ShowMsgBox(title, abstractHtml, bodyHtml);

}