﻿var PopMessageBox = 
{
    Load:false,
    Title: "",
    Message: "",
    SelectField :"",
    
    CreateMessageBox : function ()
    {   
        if(!PopMessageBox.Load)
        {        
            $("div.mwrapper").append('<div class="tp_rw"><div class="tp_lf lt_grn title"><strong></strong></div><div class="tp_ry lt_grn close" style="cursor:pointer;"><img src="/images/message/close.gif" />&nbsp;Close</div></div><div class="md_rw"><div class="logo"><img src="/images/message/logo.gif" /></div><div class="msgtxt grey14 message"><strong></strong></div><div class="msgtxt"><img src="/images/message/btn/ok.gif" style="cursor:pointer;" />&nbsp;</div></div><div class="fp_rw"></div>');
            $("div.mwrapper div.close,div.mwrapper div.md_rw div.msgtxt img").click(function(){$("div.mwrapper").hide();$(PopMessageBox.SelectField).show();PopMessageBox.SelectField = "";});
        }
    },
    
    ShowMessage: function()
    {   
    
        $("div.mwrapper div.title strong").html("").html(PopMessageBox.title);
        $("div.mwrapper div.message strong").html("").html(PopMessageBox.message);
        
        var TopLeft = $.fn.popCenter($("div.mwrapper").width(),$("div.mwrapper").height());        

        $("div.mwrapper").css({"top":""+TopLeft[0]+"px","left":""+TopLeft[1]+"px"});
        
      
        var pHeight = parseInt($("div.mwrapper").height());
        
           $.each($("select"), function(i, sel)
            {  
              
              var offset = $(sel).offset();          
             
              if(                           
                    (                    
                    parseInt(offset.top)>=parseInt(TopLeft[0]) && 
                    parseInt(offset.top)<=(parseInt(TopLeft[0])+pHeight) && 
                    parseInt(offset.left)>=parseInt(TopLeft[1]) &&
                    parseInt(offset.left)<=(parseInt(TopLeft[1]) +parseInt($("div.mwrapper").width()))
                    )
                    ||
                    (
                    (parseInt(offset.top)+parseInt($(sel).height()))>=parseInt(TopLeft[0]) && 
                    (parseInt(offset.top)+parseInt($(sel).height()))<=(parseInt(TopLeft[0])+pHeight) && 
                    (parseInt(offset.left)+parseInt($(sel).width()))>=parseInt(TopLeft[1]) &&
                    (parseInt(offset.left)+parseInt($(sel).width()))<=(parseInt(TopLeft[1]) +parseInt($("div.mwrapper").width()))
                    )
                )
                {
                   
                    $(sel).hide();                      
                     PopMessageBox.SelectField += (PopMessageBox.SelectField=="")?("select[id='"+$(sel).attr("id")+"']"):(",select[id='"+$(sel).attr("id")+"']");
                   
                }
                
             });
            
            
       
         
         $("div.mwrapper").show();
         
         
//        $("div.mwrapper").show().oneTime("50ms", function() 
//        {          
//                $(document).bind('keypress', function(e)
//                { 
//                    var code = (e.keyCode ? e.keyCode : e.which);
//                    if(code == 13 || code == 27) 
//                    {
//                        $("div.mwrapper").hide(); 
//                        $(PopMessageBox.SelectField).show();
//                        PopMessageBox.SelectField = "";
//                        $(document).unbind( "keypress" );
//                    }
//                });
//        });
    }
};
//$(document).ready(function () { $("div.mwrapper").hide();PopMessageBox.CreateMessageBox();});
$(document).ready(function () {
 $("div.mwrapper").hide();PopMessageBox.CreateMessageBox();
 
 $("div.alpha").mouseover(function() {   
    $(this).removeClass().addClass("alphatest");  
  }).mouseout(function(){
    	$(this).removeClass().addClass("alpha");		
    });
    
  $("div.alpha1").mouseover(function() {   
    $(this).removeClass().addClass("alphatest1");  
  }).mouseout(function(){
    	$(this).removeClass().addClass("alpha1");		
    });
 
 });
 
  


