// alert message

(function($) {

$.hoverurl = {
    verticalOffset: -75,                // vertical offset of the dialog from center screen, in pixels 
    horizontalOffset: 0,                // horizontal offset of the dialog from center screen, in pixels/ 
    repositionOnResize: true,           // re-centers the dialog on window resize 

    // Private methods 
    _createElement: function(obj) { 
        return $(document.createElement(obj)); 
    },
    _showDialogClose: function(divID, callback) { 
        if(callback) callback();
        $('#divBg' + divID).remove(); 
        $('#divOut' + divID).remove();
    },
    
    _height: function() {
        var scrollHeight,
            offsetHeight;
        // handle IE 6
        if ($.browser.msie && $.browser.version < 7) {
                 scrollHeight = Math.max(
                          document.documentElement.scrollHeight,
                          document.body.scrollHeight
                 );
                 offsetHeight = Math.max(
                          document.documentElement.offsetHeight,
                          document.body.offsetHeight
                 );

                 if (scrollHeight < offsetHeight) {
                          return $(window).height() + 'px';
                 } else {
                          return scrollHeight + 'px';
                 }
        // handle "good" browsers
        } else {
                 return $(document).height() + 'px';
        }
    },

    _outerMove: function(outerID, titleID) { 
        var _x;
        var _y;
        var _xx;
        var _yy;

        titleID.mousedown(function(event){
            var offset = $(this).offset();
            _x=event.clientX-offset.left;
            _y=event.clientY-offset.top+20;
            $(this).bind('mousemove', (function(event){
                _xx=event.clientX-_x;
                _yy=event.clientY-_y;
                outerID.css('top',_yy);
                outerID.css('left',_xx);
                })
            );
        });
        
        titleID.mouseup(function(event){
            $(this).unbind('mousemove');
        });
        
        titleID.mouseout(function(event){
            $(this).unbind('mousemove');
        });
    },
    showDialog: function(divID, dialogTitle, dialogWidth, dialogHeight, index, callback) {
    	var width; 
        var height;
        var title;
        var zindex;
        if (index){
            zindex = 5000 + parseInt(index);
        } else {
            zindex = 5000;
        }
        if(dialogWidth) {
            width = dialogWidth;
        } else {
            width = document.documentElement.clientWidth / 2;
        }
        
        if(dialogHeight) {
            height = dialogHeight;
        } else {
            height = document.documentElement.clientHeight / 2;
        }
        
        if(dialogTitle) {
            title = dialogTitle;
        } else {
            title = 'Dialog';
        }
        

        $('#divBg' + divID).remove(); 
        $('#divOut'+ divID).remove(); 
        $('#' + divID).attr('style', 'display:true');
        
        //NEW NEW
        $.hoverurl._createElement('div')
        .attr('id', 'divBg'+ divID)
        .attr('class', 'popdivBg')
        .css({ 'position': 'absolute', 'top': '0', 'left': '0', 'z-index': String(zindex), 
            'filter': 'alpha(opacity=70)', 'opacity': '0.5', 
            'width': '100%',
            'height': $.hoverurl._height() })
        .appendTo('body'); 
        
        var top = 10;
        var left = 10;
        if (($(window).height() - height) / 2 + $(window).scrollTop() >= 10) {
        	top = ($(window).height() - height) / 2 + $(window).scrollTop();
        	
        }
        
        if (($(window).width() - width) / 2 + $(window).scrollLeft() >= 10) {
        	left = ($(window).width() - width) / 2 + $(window).scrollLeft();
        }

        $.hoverurl._createElement('div')
        .attr('id', 'divOut'+divID)
        .attr("class","popdivOut")
        .css({ 'position': 'absolute', 
          'top': top + 'px', 
          'left': left + 'px', 
           'zIndex': String(zindex + 1), 'width': width + 'px', 
          'height': height + 'px', 'overflow': 'hidden' }) 
        .appendTo('body'); 

        $.hoverurl._createElement('table')
        .attr('id', 'tblOut' + divID)
        .attr("width","100%")
        .attr("height","100%")
        .attr("cellspacing","0")
        .attr("cellpadding","0")
        .appendTo($('#divOut' + divID)); 

        $.hoverurl._createElement('tr')
        .attr('id', 'trTitle0' + divID)
        .css({ 'height': '20px'})
        .appendTo($('#tblOut' + divID));

        $.hoverurl._createElement('td')
        .attr('id', 'tdTitle01' + divID)
        .css({'width': '18px'})
        .attr('background', getMsgBGImage1())
        .appendTo($('#trTitle0' + divID));

        $.hoverurl._createElement('td')
        .attr('id', 'tdTitle02' + divID)
        .attr('background', getMsgBGImage2())
        .appendTo($('#trTitle0' + divID));

        $.hoverurl._createElement('td')
        .attr('id', 'tdTitle03' + divID)
        .css({'width': '18px'})
        .attr('background', getMsgBGImage3())
        .appendTo($('#trTitle0' + divID));

        $.hoverurl._createElement('tr')
        .attr('id', 'trTitle1' + divID)
        .css({ 'height': '26px'})
        .appendTo($('#tblOut' + divID));

        $.hoverurl._createElement('td')
        .attr('id', 'tdTitle11' + divID)
        .attr('align', 'left')
        .attr('rowspan', '2')
        .attr('background', getMsgBGImage4())
        .appendTo($('#trTitle1' + divID));
        $.hoverurl._createElement('td')
        .attr('id', 'tdTitle12' + divID)
        .attr('align', 'left')
        .css({'background-color': "#FFFFFF"})
        .attr("class", "trTitle1211")
        .appendTo($('#trTitle1' + divID));

        $.hoverurl._createElement('div')
        .attr('id', 'divMsg' + divID)
        .html(title) 
        .css({'display': 'inline', 'float': 'left', 'padding-left': '8px', 'color' : '#ffffff', 'font-weight': 'bold'})
        .appendTo($('#tdTitle12' + divID));
        
        $.hoverurl._createElement('div')
        .attr('id', 'divCloseBtn' + divID)
        .css({'cursor': 'pointer', 'float': 'right', 'padding-right': '4px', 'z-index': '10002'})
        .appendTo($('#tdTitle12' + divID));
        
        $.hoverurl._createElement('a')
        .attr('id', 'imgClose' + divID)
        .attr('href','javascript:void(0);')
        .attr('class', 'popAlertImageClose')
        .click(function () { $.hoverurl._showDialogClose(divID, callback); })
        .appendTo($('#divCloseBtn' + divID));

        $.hoverurl._createElement('td')
        .attr('id', 'tdTitle13' + divID)
        .attr('align', 'left')
        .attr('rowspan', '2')
        .attr('background', getMsgBGImage6())
        .appendTo($('#trTitle1' + divID));

        $.hoverurl._createElement('tr')
        .attr('id', 'trTitle2' + divID)
        .appendTo($('#tblOut' + divID));
        //.attr('height', $.hoverurl.messageHeight - 92 + 'px')

        $.hoverurl._createElement('td')
        .attr('id', 'tdTitle22' + divID)
        .attr('align', 'left')
        .css({'vertical-align': 'middle', 'padding-left': '8px', 'padding-right': '8px', 'padding-top': '8px', 'background-color': '#ffffff'})
        .appendTo($('#trTitle2' + divID));
        
        $.hoverurl._createElement('div')
        .attr("class","popDilogDiv")
        .css({'textAlign': 'center', 'padding': '12px', 
        'height': height - 100, 'overflow': 'auto'})
        .html($('#' + divID))
        .appendTo($('#tdTitle22' + divID));
        
        $.hoverurl._createElement('tr')
        .attr('id', 'trTitle4' + divID)
        .css({ 'height': '20px'})
        .appendTo($('#tblOut' + divID));

        $.hoverurl._createElement('td')
        .attr('id', 'tdTitle41' + divID)
        .attr('background', getMsgBGImage7())
        .attr('align', 'left')
        .appendTo($('#trTitle4' + divID));

        $.hoverurl._createElement('td')
        .attr('id', 'tdTitle42' + divID)
        .attr('background', getMsgBGImage8())
        .attr('align', 'left')
        .appendTo($('#trTitle4' + divID));

        $.hoverurl._createElement('td')
        .attr('id', 'tdTitle43' + divID)
        .attr('background', getMsgBGImage9())
        .attr('align', 'left')
        .appendTo($('#trTitle4' + divID));
        
        //$.hoverurl._maintainPosition(true);
        //$.hoverurl._outerMove($('#divOut' + divID), $('#trTitle1' + divID));
        
    }
}

JdialogForUrl = function(divID, dialogTitle, dialogWidth, dialogHeight, index, callback) {
    $.hoverurl.showDialog(divID, dialogTitle, dialogWidth, dialogHeight, index, callback);
};

JdialogCloseForUrl = function(divID, callback) {
    $.hoverurl._showDialogClose(divID, callback);
};
})(jQuery);


