/* 
 * PROCERGS - Companhia de Processamento de Dados do Estado do Rio Grande do Sul
 * 
 * Desenvolvedor: Márcio Bordim Silveira
 * Data: 23/03/2011
 */

function openModalIframe(url, w, h){

     $('<div></div>')
      .attr('id', '_divModalAjax')
      .width(w)
      .height(h)
      .css('display', 'none')
      .appendTo($(document.body));

    $('<iframe></iframe>')
      .attr('frameborder', '0')
      .width(w)
      .height(h)
      .attr('src', url)
      .appendTo($('#_divModalAjax'));

    openModal('#_divModalAjax');

}

function openModalAjax(url, w, h, parametros){

  $.post(url,
     parametros,
     function(htmlData) {
         $('<div></div>')
          .attr('id', '_divModalAjax')
          .width(w)
          .height(h)
          .css('display', 'none')
          .appendTo($(document.body))
          .html(htmlData);

         openModal('#_divModalAjax');
    }
    );
}
function openModal(id_div){

    var maskHeight = $(document).height();
    var maskWidth = $(window).width();

    var winH = $(window).height();
    var winW = $(window).width();

  //CRIA A MASCARA DE FUNDO
  $('<div></div>')
    .attr('id', '_mask')
    .css('position', 'fixed')
    .css('top', 0)
    .css('z-index', 9000)
    .css('background-color','#000')
    .css('display', 'none')
    .height(maskHeight)
    .width(maskWidth)
    .appendTo($(document.body))
    .fadeTo("fast",0.8)
    .click(function(){
      closeModal();
    });

  //centraliza na tela a janela popup
  $(id_div)
    .css('top',  winH / 2 - $(id_div).outerHeight(true) / 2)
    .css('left', winW / 2 - $(id_div).outerWidth(true) / 2)
    .css('position', 'fixed')
    .css('z-index', 9001)
    .addClass('_JanelaModalAberta')
    //.appendTo($(document.body))
    .fadeIn(500);



}
function closeModal(){
  $('._JanelaModalAberta')
    .hide()
    .removeClass('_JanelaModalAberta');

  $('#_mask, #_divModalAjax').remove();
  return false;

}

