var bgDiv=null;
var alertFram=null;
var _width=0;
var _height=0;
function msgBox(title,msg,width,height,skin){
      //动态创建一个DIV
	  if(document.getElementById('alertFram')!=null){
	      document.body.removeChild(alertFram);
	  };
	  hidenAllSelect();
	  _width=width;
	  _height=height;
	  var scrollPos; 
      if (typeof window.pageYOffset != 'undefined') { 
       scrollPos = window.pageYOffset; 
      } 
     else if (typeof document.compatMode != 'undefined' && 
        document.compatMode != 'BackCompat') { 
        scrollPos = document.documentElement.scrollTop; 
     } 
    else if (typeof document.body != 'undefined') { 
       scrollPos = document.body.scrollTop; 
    }
	  
      LeftPosition=(document.body.clientWidth / 2) - (width / 2)   
      TopPosition=(scrollPos+window.screen.availHeight/2 ) - (height / 2)-100;
	  if(height>500)
	  TopPosition=scrollPos+10;
	  //alert(window.screen.availHeight);
      alertFram = document.createElement("DIV");
	  var bdy=document.documentElement;
	  var h=bdy.scrollHeight>bdy.clientHeight?bdy.scrollHeight:bdy.clientHeight;
      var w=bdy.scrollWidth>bdy.clientWidth?bdy.scrollWidth:bdy.clientWidth;
	  alertFram.id="alertFram";
      alertFram.style.position = "absolute";
	  alertFram.style.background='#666666';
	  alertFram.style.zIndex = "10001";
	  alertFram.style.width = width+'px';
      alertFram.style.height = height+'px';
	  alertFram.style.paddingRight=3+'px';
	  alertFram.style.paddingBottom=2+'px';
	  //设置位置
	  alertFram.style.left=LeftPosition;
      alertFram.style.top=TopPosition;
	  var htmls=null;
	  if(typeof(skin)=="undefined"){
	  htmls='<div  style="background:#FFFFFF;width:'+width+'px;height:'+height+'px;border:#E4549D 1px solid;"><ul style="width:'+width+'px;height:21px;text-align:right;padding:3px;background-image:url(http://baby.jewelchina.com/images/bari.gif);margin:0px;color:#ffffff"><li style="float:left;width:'+(width-25)+'px;list-style-type:none;height:21px;text-align:left;line-height:21px;color:#FFFFFF;font-weight:bold;">'+title+'</li><li style="float:left;width:15px;list-style-type:none;height:20px;"><img src="http://baby.jewelchina.com/images/bt_close.gif"  alt="关闭" style="cursor:hand;" onclick="exit();" align="absmiddle"></li></ul><div>'+msg+'</div></div>';
	  }
	  else{
		  htmls=msg;
	  }
	  alertFram.innerHTML = htmls;
	  document.body.appendChild(alertFram);
	  if(!bgDiv ){
	  bgDiv = document.createElement("DIV");
	  bgDiv.id="BgDiv"
	  bgDiv.oncontextmenu='self.event.returnValue=false'
      bgDiv.style.backgroundColor="transparent";
      bgDiv.style.overflow="hidden";
	  bgDiv.style.position="absolute";
	  bgDiv.style.left="0";
	  bgDiv.style. top="0";
	  bgDiv.style. width="100%";
	  bgDiv.style. height=(scrollPos+h)+'px';
	  bgDiv.style. backgroundColor="#333333";
	  bgDiv.style. filter="blendTrans(duration=1) alpha(opacity=80)";
      document.body.appendChild(bgDiv);
      bgDiv.filters.blendTrans.apply();
      bgDiv.style.visibility="visible";
      bgDiv.filters.blendTrans.play();
	  }
	  
	  
}
//关闭窗口
function exit(){
       document.body.removeChild(alertFram);
	   document.body.removeChild(bgDiv);
	   bgDiv=null;
	   showAllSelect()
   }
function resize(){
	 
      if (typeof window.pageYOffset != 'undefined') { 
       scrollPos = window.pageYOffset; 
      } 
     else if (typeof document.compatMode != 'undefined' && 
        document.compatMode != 'BackCompat') { 
        scrollPos = document.documentElement.scrollTop; 
     } 
    else if (typeof document.body != 'undefined') { 
       scrollPos = document.body.scrollTop; 
    }
	 var bdy=document.documentElement;
	 var w=bdy.scrollWidth>bdy.clientWidth?bdy.scrollWidth:bdy.clientWidth;
	 var h=bdy.scrollHeight>bdy.clientHeight?bdy.scrollHeight:bdy.clientHeight;
	 LeftPosition=(w-_width)/2 ;
	 //alert(LeftPosition);
	 var divId=document.getElementById('alertFram');
     TopPosition==parseInt((document.body.clientHeight-divId.clientHeight)/2)+scrollPos;
	// alert(scrollPos);
	  //设置位置
	  //alert(TopPosition);
       document.getElementById('alertFram').style.top=TopPosition+10;
	   document.getElementById('alertFram').style.left=LeftPosition;
	   document.getElementById('BgDiv').style.height=scrollPos+h;
}
function hidenAllSelect(){
	var selects=document.getElementsByTagName("select");
	//alert(selects);
	for(i=0;i<selects.length;i++){
		selects[i].style.display="none";
	}
}
function showAllSelect(){
	var selects=document.getElementsByTagName("select");
	//alert(selects);
	for(i=0;i<selects.length;i++){
		selects[i].style.display="";
	}
}
window.onscroll=function (){
	if(document.getElementById('alertFram')!=null){
		resize();
	}
}
window.onresize=function (){
	if(document.getElementById('alertFram')!=null){
		resize();
	}
}
 