﻿ 
 
 

;(function($) {
		  $ieframe = $('<iframe class="popupwinieframe" frameborder="0" src="#"></iframe>').css({ position: "absolute", display: "none", zIndex: -1});
jQuery.msgbox={ //弹出窗口
//	a:$('<iframe class="popupwinieframe" frameborder="0" src="#"></iframe>').css({ position: "absolute", display: "none", zIndex: -1}),
	confirmbox:function(title,content,leftto,topto){
///alert( $ieframea.attr("class"));
		var popwinstr="<div id=\"popwincontainer\">";//<div id=\"header\"></div>
		popwinstr+="<div class=\"border\"><div id=\"content\"><table border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr><td>$content</td></tr></table></div></div></div>";
		$.msgbox.closemsgbox();
		
		//this.ieframe = $('<iframe class="popupPanel_ieframe" frameborder="0" src="#"></iframe>').css({ position: "absolute", display: "none", zIndex: -1});
		$("#container").before(popwinstr.replace("$content",content).replace("$title",title));
		$("#popwincontainer").prepend($ieframe);
		$("#close").click(function(){
								   $.msgbox.closemsgbox();
								   })
		tablewidth=$("#popwincontainer > .border > #content > table").width()+16;
		$ieframe.css({height:($("#popwincontainer").height())+"px",width:($("#popwincontainer").width())+"px"});
		$ieframe.show();
		$("#popwincontainer").css({"left":leftto+"px","top":topto+"px","position":"absolute","width":tablewidth+"px"});
		$("#popwincontainer").draggable({cursor:"move",revert: false,ghosting: true, opacity: 0.7,handle:"#popwincontainer"});
		return $("#popwincontainer");
		
		},
	msgbox:function(width,height,title,content){
		
		var popwinstr="<div id=\"popwincontainer\">";//<div id=\"header\"></div>
		popwinstr+="<div class=\"border\"><div id=\"title\"><span id=\"close\" title=\"关闭\">X</span>$title</div>";
		popwinstr+="<div id=\"content\"><table style=\"width:100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr><td align=\"center\" valign=\"middle\">$content</td></tr></table></div></div></div>";
		this.ieframe = $('<iframe class="popupPanel_ieframe" frameborder="0" src="#"></iframe>').css({ position: "absolute", display: "none", zIndex: -1});
		$.msgbox.closemsgbox();
		$("#container").before(popwinstr.replace("$title",title).replace("$content",content));
		$("#popwincontainer").prepend(this.ieframe);
		$("#popwincontainer > .border > #title > #close").click(function(){
															   $.msgbox.closemsgbox();
															   })
		this.ieframe.css({height:(height/1+4)+"px",width:(width/1+4)+"px"});
		$("#popwincontainer").css({height:(height/1+4)+"px",width:(width/1+4)+"px"});
		$("#popwincontainer > .border").css({height:(height/1)+"px",width:(width/1)+"px"});
		this.ieframe.show();		
		$("#popwincontainer > .border > #content").css({height:(height/1-35)+"px",width:(width/1-10)+"px"});
		//$("#popwincontainer > #content > table").css({height:(height/1-65)+"px"});
		scrolltop=$(window).scrollTop()
		leftto=$("#popwincontainer").offset().left-(width/2);
		if (($(window).height()/2) > (height/2)) {
			topto=$("#popwincontainer").offset().top-(height/2);
		}else{
			topto=$(window).height()/2;//-((height/2) - ((height/2) - (document.body.clientHeight/2)));
		}		
		topto=(topto+scrolltop);
		$("#popwincontainer").css({"left":leftto+"px","top":topto+"px","position":"absolute"});
		//$("#popwincontainer").animate({opacity:1},3000);
		$("#popwincontainer").draggable({cursor:"move",revert: false,ghosting: true, opacity: 0.7,handle:"#popwincontainer > #title"});
		return $("#popwincontainer");
		
		},		
	popupwin:function(width,height,title,content){
		var popwinstr="<div id=\"popwincontainer\">";//<div id=\"header\"></div>
		popwinstr+="<div class=\"border\"><div id=\"title\"><span id=\"close\" title=\"关闭\">X</span>$title</div>";
		popwinstr+="<div id=\"content\"><table border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr><td align=\"center\" valign=\"top\">$content</td></tr></table></div></div></div>";	//<div id=\"footer\"></div>
		this.ieframe = $('<iframe class="popupPanel_ieframe" frameborder="0" src="#"></iframe>').css({ position: "absolute", display: "none", zIndex: -1});
		
		$.msgbox.closemsgbox();
		$("#container").before(popwinstr.replace("$title",title).replace("$content",content));
		$("#popwincontainer").prepend(this.ieframe);
		$("#popwincontainer > .border > #title > #close").click(function(){
															   $.msgbox.closemsgbox();
															   })
		
		//$("#popwincontainer > #content").css({height:(height/1-54)+"px",width:(width/1-10)+"px"});
		
		

		
		//表格内写内容读取中
		
		//判断是否有图片
		
		//判断图片是否读取完成
		
		
		//取得内容具体的宽高
		innerheight=$("#popwincontainer > .border > #content > table").height()+34;
//		if (height<innerheight){
//			height=innerheight+34;
//			}
		//宽未定义
		innerwidth=$("#popwincontainer > .border > #content > table").width()+16;		
		
		
		height=innerheight;//height<innerheight?innerheight:height;
		width=width>innerwidth?width:innerwidth;
		
		$("#popwincontainer > .border > #content > table").css({height:(height/1)+"px",width:(width/1-8)+"px"});
	
		this.ieframe.css({height:(height/1+4)+"px",width:(width/1+4)+"px"});
		$("#popwincontainer").css({height:(height/1+4)+"px",width:(width/1+4)+"px"});
		$("#popwincontainer > .border").css({height:(height/1)+"px",width:(width/1)+"px"});
		
		
		
		
//		marginleft=-(width/2);
//		if (($(window).height()/2) > (height/2)) {
//			marginto=-(height/2);
//		}else{
//			marginto=-($(window).height()/2);//-((height/2) - ((height/2) - (document.body.clientHeight/2)));
//		}	
		scrolltop=$(window).scrollTop()
		leftto=$("#popwincontainer").offset().left-(width/2);
		if (($(window).height()/2) > (height/2)) {
			topto=$("#popwincontainer").offset().top-(height/2);
		}else{
			topto=$(window).height()/2;//-((height/2) - ((height/2) - (document.body.clientHeight/2)));
		}		
		topto=(topto+scrolltop);
		$("#popwincontainer").css({"left":leftto+"px","top":topto+"px","position":"absolute"});
		//this.ieframe.css({"left":leftto+"px","top":topto+"px","position":"absolute"});
		this.ieframe.show();
		//$("#popwincontainer").animate({opacity:1},3000);#popwincontainer > 
		$("#popwincontainer").draggable({cursor:"move",revert: false,ghosting: true, opacity: 0.7,handle:"#popwincontainer > #title"});
		return $("#popwincontainer");
		},
	closemsgbox:function(time,callbackfunction){
		//$("#popwincontainer").animate({opacity:0},2000,function(){$("#popwincontainer").remove()})//.remove()
		if (time){
			window.setTimeout(function(){$("#popwincontainer").hide("fast",callbackfunction).remove()},time)
			}
		else{
			$("#popwincontainer").remove();
			}
		
		}
	
	}
})(jQuery);