var dlm_openPops = new Array();
var dlm_popupId    = "popup";
var dlm_popupClass = "popup";
function dlm_popupWindow( url, width, height, popHandle )
{
  if ( typeof(popHandle)=="undefined" )
  {
    popHandle = dlm_popupId;
  }
  dlm_openPops[dlm_openPops.length] = popHandle;
  var popOuter = popHandle + "Frame";
  $.dimScreen( 100, 0.7 );
  var el = $("#"+popOuter);
  if ( el.size()==0 )
  {
    var content = '<div><div id="close"><a href=\"javascript:dlm_popupClose(\''+popHandle+'\')\">close [X]</a></div><div id=\"'+popHandle+'" class=\"popupInner\"></div></div>';
    el = $(content)
         .attr({id: popOuter})
         .css({ display:"none" })
         .addClass( dlm_popupClass )
         .appendTo(document.body);
  }
  if ( typeof(width)=="undefined" )
  {
    width = $("#__dimScreen").width()-200;
  }
  if ( typeof(height)=="undefined" )
  {
    height = $("#__dimScreen").height()-200;
  }
  el.css({
            position:"absolute"
            ,background: '#fff'
            ,display:"block"
            ,height: height + 'px'
            ,left: (($("#__dimScreen").width()-width)/2)+"px"
            ,position: 'absolute'
            ,top: (($("#__dimScreen").height()-height)/2)+"px"
            ,width: width + 'px'
            ,zIndex: 500
        })
  el.find("#"+popHandle).css( { height:$("#"+popHandle).parent().height()- ( $("#"+popOuter+" #close:visible").height() ) - parseInt( $("#"+popOuter).css("padding-bottom") ) } );
  $("#"+popHandle).html("<iframe width=\"" + width + "\" height=\"" + height + "\" border=\"0\" frameborder=\"0\" src=\"" + url + "\" />");
  return false;
}

function dlm_popupClose( popHandle )
{
  if ( typeof(popHandle)=="undefined" )
  {
    popHandle = dlm_popupId;
  }
  var popOuter = popHandle + "Frame";
  $("#"+popOuter).remove();
  var dimOff = true;
  for ( var i=0; i<dlm_openPops.length; i++ )
  {
    if ( dlm_openPops[i]==popHandle )
    {
      dlm_openPops.splice( i, 1 );
    }
  }
  if ( typeof(dlm_openPops)=="undefined" || dlm_openPops==null || dlm_openPops.length==0 )
  {
    $.dimScreenOff();
  }
}

function dlm_gotoPageNumber( url, handle )
{
  return dlm_prompt(
    { text: "Enter page number", title: "Go to page" },
    function(val)
    {
      if ( val==null || typeof(val)=="undefined" )
      {
        return;
      }
      if ( url.indexOf("##pageNumber##")!=-1 )
      {
        url = url.replace( /\#\#pageNumber\#\#/gi, escape(val) );
      }
      else
      {
        url += (url.indexOf("?")==-1 ? "?" : "&") + "pageNumber="+escape(val);
      }
      dlm_displayContent( url, handle );
    } );
}

function dlm_redoRowColors( table )
{
  table = (!table?$("table"):$(table))

  $("tr:odd",  table).each(function(){ if($(this).hasClass("listLine0")){$(this).removeClass("listLine0").addClass("listLine1")}})
  $("tr:even", table).each(function(){ if($(this).hasClass("listLine1")){$(this).removeClass("listLine1").addClass("listLine0")}})

  $("tr:has(td.listLine0,td.listLine1):visible:odd",  table).children("td").removeClass("listLine0").addClass("listLine1");
  $("tr:has(td.listLine0,td.listLine1):visible:even", table).children("td").removeClass("listLine1").addClass("listLine0");
}



jQuery.extend({
    //dims the screen
    dimScreen: function(speed, opacity, callback) {
        if(jQuery('#__dimScreen').size() > 0) return;

        if(typeof speed == 'function') {
            callback = speed;
            speed = null;
        }

        if(typeof opacity == 'function') {
            callback = opacity;
            opacity = null;
        }

        if(speed < 1) {
            var placeholder = opacity;
            opacity = speed;
            speed = placeholder;
        }

        if(opacity >= 1) {
            var placeholder = speed;
            speed = opacity;
            opacity = placeholder;
        }

        speed = (speed > 0) ? speed : 500;
	var ie6 = (jQuery.browser.msie && jQuery.browser.version < 7);
	var b = (ie6)? jQuery(document.body):jQuery("body");

        opacity = (opacity > 0) ? opacity : 0.5;
//		jqif.css({ position: "absolute", height: (ie6)? "100%":b.height(), width: "100%", top: (ie6)? getfoffset():0, left: 0, right: 0, bottom: 0, zIndex: 998, display: "none", opacity: o.opacity });

        var el = jQuery("<div></div>").attr({
                id: '__dimScreen'
                ,fade_opacity: opacity
                ,speed: speed
            }).css({
            background: '#000000'
            ,border:"0px"
            ,bottom:"0px"
            ,height: (ie6)? "100%":"auto"
            ,left: '0px'
            ,opacity: 0
            ,position: 'absolute'
            ,top: '0px'
            ,width: "100%"
            ,zIndex: 499
        }).appendTo(document.body).fadeTo(speed, opacity, callback);
        if (( jQuery.browser.msie && jQuery('object, applet').length > 0) || ie6 )
        {
          jQuery("<iframe></iframe>").css( { backgroundColor:"#000", width: $(el).css("width"), height: $(el).css("height"), opacity:0 } ).appendTo("#__dimScreen");
        }
        return el;
    },

    //stops current dimming of the screen
    dimScreenOff: function(callback) {
        var x = jQuery('#__dimScreen');
        var opacity = x.attr('fade_opacity');
        var speed = x.attr('speed');
        x.fadeOut(speed, function() {
            x.remove();
            $("#__dimScreenIFrame").remove();
            if(typeof callback == 'function') callback();
        });
    }
});