var loadingDiv;
var divContent;
var modal;
var modalShadow;
var fbNotice;



function fbMessage(textToShow)
{
    if (window.console != '[object Object]')
    {
    
        if (!document.getElementById("fb_div"))
        {
            fbNotice = document.createElement("div");
            fbNotice.id = 'fb_div';
            fbNotice.className = 'fb';
            fbNotice.innerHTML = textToShow;
            document.documentElement.appendChild(fbNotice);
        }
        document.getElementById("fb_div").style.display = 'inline';
    }
}


/*
* Use:
* <div class="mdlDivContent" id="some_name">any content for modal dialog</div>
* 
* Calling modal dialog:
* <a onclick="showModalDlgOptions('name_of_the_above_div'); return false;" href="#">text you want to write</a>
*/
function showModalDlgOptions(contentDiv)
{
    if (!document.getElementById('mdlDivShadow') || !document.getElementById('mdlDiv'))
    {
        var divInnerHtml = document.getElementById(contentDiv);
        
        divContent = document.createElement("div");
        divContent.id = "content_" + contentDiv;
        
        modalShadow = document.createElement("div");
        modalShadow.id = 'mdlDivShadow';
        modalShadow.className = 'mdlDivShadow';

        modal = document.createElement("div");
        modal.id = 'mdlDiv'
        modal.className = 'mdlDiv mdlDiv1';
//        modal.innerHTML = divInnerHtml.innerHTML;
        
        modalShadow.setAttribute("onclick", "hideModalDlgOptions();");
        
        // creating tamle for the modal div
        var btn = document.createElement("input");
        btn.setAttribute("type", "button");
        btn.setAttribute("value", str_close);
        btn.setAttribute("onclick", "hideModalDlgOptions();");
        
        var btnRefresh = document.createElement("input");
        btnRefresh.setAttribute("type", "button");
        btnRefresh.setAttribute("value", str_refresh);
        btnRefresh.setAttribute("onclick", "OptionsGet();");
        
        // div za prikaz uspesnosti snimanja opcija
        var divResult = document.createElement("div");
        divResult.id = "save_options_result";
        divResult.setAttribute("style", "color: #C60000; display: inline; font-weight: bold;");
        
        var table = document.createElement("table");
        table.setAttribute("cellapadding", "0");
        table.setAttribute("cellspacing", "0");
        table.setAttribute("border", "0");
        table.setAttribute("width", "100%");
        
        // div
        var d = document.createElement("div");
        d.id = "opt";
        d.setAttribute("class", "iframes_y");
        
        
        var tr = document.createElement("tr");
        
        var td = document.createElement("td");
        td.appendChild(document.createTextNode(str_admin_panel_options));
        td.setAttribute("class", "registeredUsersTD");
        tr.appendChild(td);
        
        table.appendChild(tr);
        
        tr = document.createElement("tr");
        td = document.createElement("td");
        td.appendChild(d);
        tr.appendChild(td);
        
        table.appendChild(tr);
        
        tr = document.createElement("tr");
        td = document.createElement("td");
        td.appendChild(btnRefresh);
        td.appendChild(btn);
        td.appendChild(divResult);
        tr.appendChild(td);
        
        table.appendChild(tr);
        
//        body.appendChild(table);

        document.body.appendChild(divContent);
        divContent.appendChild(modalShadow);
        divContent.appendChild(modal);
        modal.appendChild(table);
    }
    else
        divContent.style.display = '';
        
    OptionsGet();
}


function hideModalDlgOptions()
{
    divContent.style.display = 'none';
    document.getElementById("save_options_result").innerHTML = "";
}


function showLoadingWindow(textToShow)
{
    if (!document.getElementById("loading_div"))
    {
        loadingDiv = document.createElement("div");
        loadingDiv.id = 'loading_div';
        loadingDiv.className = 'load';
        loadingDiv.innerHTML = "<img src='images/progress_active.gif'> " + textToShow + "...";
        document.documentElement.appendChild(loadingDiv);
    }
    document.getElementById("loading_div").style.display = 'inline';
}

function hideLoadingWindow()
{
    loadingDiv.style.display = 'none';
}