//***********************************************************************
//		Copyright (c) 2009,mooco  All rights reserved.					*
//		摘　　要：JS锁屏显示对话框											*
//		作　　者：LiMing and quetianhui									*
//		最后修改：quetianhui												*
//		完成日期：2009-5-6												*
//		更新时间：2009-5-6												*
//***********************************************************************

/*
  参数说明
  string:
  show_mes				显示的内容
  show_but1				按钮1
  show_but2				按钮2
  bg_color				背景颜色
  show_button_one()  	显示一个按钮
  show_button_two()  	显示两个按钮
  to_url1 				第一个跳转的URL
  to_url2 				第二个跳转，用于两个按钮
*/
//显示一个按钮
function msgbox_one(show_title,show_mes,to_url1,goback_num,show_but1,bg_color,show_close,css_style)
{
   //如果“to_url1”为“#”时，则不转到其它页面
   if (show_title == '') show_title = '系统提示';			//如果消息标题为空，则给别论值
   if (show_mes == '')
   {
	   show_mes = '<br>欢迎光临！';						//如果消息标题为空，则给别论值
   }else{
	   show_mes = '<br>'+show_mes;						//如果消息标题为空，则给别论值
   }
   //if (to_url1 == '')    to_url1 = '/';				//如果消息标题为空，则给别论值
   if (goback_num == '') goback_num = 1;				//如果消息标题为空，则给别论值
   if (show_but1 == '')  show_but1 = '返回首页';			//如果消息标题为空，则给别论值
   if (bg_color == '')   bg_color = '#999';				//如果传入的颜色为空,默认颜色
   if (show_close == '') show_close = 0;				//是否显示“关闭”按纽
   if (css_style == '') css_style = "green";				//是否显示“关闭”按纽
   
   //处理传入字符串长度
   var str_length	= show_mes.length - 0;
   if (str_length > 100) show_mes = show_mes.slice(0,92) + '...';
   
   var msgw,msgh,bordercolor,txtcolor,titlecolor,bottomcolor;
   msgw					= 532;							//提示窗口的宽度
   msgh					= 245;							//提示窗口的高度
   titleheight			= 35; 							//提示窗口标题高度
   bordercolor			= "#b2cc43";					//提示窗口的边框颜色
   msgtxtcolor			= "#000000"						//前景颜色
   titlecolor			= "#b6d03b";					//提示窗口的标题颜色
   bottomcolor			= "#ffffff";					//提示窗口的标题颜色
   
	var swidth,sheight,swidth1,sheight1;
	swidth				= document.body.scrollWidth; 	//网页正文区域宽
	sheight				= document.body.scrollHeight;	//网页正文区域高
	swidth1				= window.screen.availWidth;
	sheight1				= window.screen.availHeight;
	//屏蔽层大小
	if (swidth<swidth1) swidth = swidth1;
	if (sheight<sheight1) sheight = sheight1;

   //背景层（大小与窗口有效区域相同，即当弹出对话框时）
   var bg_obj	= document.createElement("div");	//创建一个div对象（背景层）
   bg_obj.setAttribute('id','bg_div');
   bg_obj.style.position		= "absolute";
   bg_obj.style.top				= "0";
   bg_obj.style.background	    = bg_color;
   bg_obj.style.filter			= "progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=80)";
   bg_obj.style.opacity			= "0.8";
   bg_obj.style.left			= "0";
   bg_obj.style.width			= swidth + "px";
   bg_obj.style.height			= sheight + "px";
   bg_obj.style.zIndex 			= "10000";
   
   var msg_obj	= document.createElement("div")		//创建一个div对象（提示框层）
   msg_obj.setAttribute("id","msg_div");
   msg_obj.setAttribute("align","center");
   msg_obj.style.padding		= "0px";
   msg_obj.style.background		= "white";
   msg_obj.style.border			= "1px solid " + bordercolor;
   msg_obj.style.position 		= "absolute";
   msg_obj.style.left 			= "50%";
   msg_obj.style.top 			= "50%";				//提示窗口的上边距
   //msg_obj.style.paddingBottom 	= 10+"px";
   msg_obj.style.font			= "12px/1.6em Verdana, Geneva, Arial, Helvetica, sans-serif";
   msg_obj.style.marginLeft 	= "-255px" ;
   msg_obj.style.marginTop 		= document.documentElement.scrollTop-msgh/2-20+"px";
   msg_obj.style.width 			= msgw + "px";
   //msg_obj.style.height   		= msgh + "px";
   msg_obj.style.textAlign 		= "center";
   msg_obj.style.zIndex 		= "10001";
  
   var title	= document.createElement("div");		//创建一个h4对象（提示框标题栏）
   title.setAttribute("id","msg_title");
   title.setAttribute("align","left");
   title.innerText 				= show_title;
   title.style.padding			= "5px 0px 0px 50px";
   title.style.height			= "26px";
   title.style.lineHeight		= "26px";
   title.style.backgroundColor	= titlecolor;
   title.style.background		= "url(sns/public_html/skin/green/img/alert_title_bg.gif) no-repeat left top";
   //title.style.filter			= "progid:DXImageTransform.Microsoft.Alpha(startX=20, startY=20, finishX=100, finishY=100,style=1,opacity=75,finishOpacity=100);";
   //title.style.opacity			= "0.75";
   title.style.font				= "16px Verdana, Geneva, Arial, Helvetica, sans-serif";
   title.style.fontWeight		= "700";
   title.style.color			= "#362E2B";
   title.style.cursor			= "pointer";
   
   
   var msg_img	= document.createElement("div");		//左边图像区
   msg_img.setAttribute("id","msg_img");
   //msg_img.setAttribute("align","right");
   msg_img.style.margin			= "0";
   msg_img.style.padding		= "10px";
   msg_img.style.width			= "100px";
   msg_img.style.height			= "110px";
   msg_img.style.font			= "12px Verdana, Geneva, Arial, Helvetica, sans-serif";
   msg_img.style.color			= msgtxtcolor;
   msg_img.style.styleFloat		= "left";
   msg_img.style.cssFloat		= "left";
   //msg_img.style.border		= "1px solid #f00";
   
   var msg_txt	= document.createElement("div");		//右边文本区
   msg_txt.setAttribute("id","msg_txt");
   msg_txt.setAttribute("align","left");
   msg_txt.style.padding		= "10px";
   msg_txt.style.margin			= "10px 10px 0px 0px";
   msg_txt.style.width			= "350px";
   msg_txt.style.height			= "115px";
   msg_txt.style.lineHeight 	= "26px";
   msg_txt.style.font			= "14px Verdana, Geneva, Arial, Helvetica, sans-serif";
   msg_txt.style.color			= msgtxtcolor;
   msg_txt.style.styleFloat		= "right";
   msg_txt.style.cssFloat		= "right";
   //msg_txt.style.border		= "1px solid #f00";
   
   var msg_bottom	= document.createElement("div");		//底部按纽区
   msg_bottom.setAttribute("id","msg_bottom");
   msg_bottom.setAttribute("align","center");
   msg_bottom.style.margin			= "0";
   msg_bottom.style.padding			= "3px 0px";
   msg_bottom.style.width			= msgw+"px";
   msg_bottom.style.height			= "24px";
   msg_bottom.style.font			= "14px Verdana, Geneva, Arial, Helvetica, sans-serif";
   msg_bottom.style.color			= msgtxtcolor;
   msg_bottom.style.borderBottom	= "3px solid "+titlecolor;
   msg_bottom.style.backgroundColor	= bottomcolor;
   
   //显示一个关闭button
   var button_close		= document.createElement("input");	//创建一个input对象（提示框按钮）
   button_close.setAttribute("type","button");
   button_close.setAttribute("name","test0");
   button_close.setAttribute("value","关闭");
   button_close.style.width			= "75px";
   button_close.style.height		= "22px";
   button_close.style.lineHeight	= "22px";   
   button_close.style.marginLeft	= "10px";
   button_close.style.marginRight	= "auto";
   button_close.style.background	= "white";
   button_close.style.border		= "0px";
   button_close.style.color			= "#061127";
   button_close.style.font			= "14px Verdana, Geneva, Arial, Helvetica, sans-serif";
   button_close.style.background	= "url(skin/"+css_style+"/img/button_green_bg_w4.gif) no-repeat center center";
   button_close.onclick				= remove_obj_false;
   
   
   //显示一个时，button3,错误时，button4
   var button3		= document.createElement("input");	//创建一个input对象（提示框按钮）
   button3.setAttribute("type","button");
   button3.setAttribute("name","button_goback");
   button3.setAttribute("id","button_goback");
   button3.setAttribute("value",show_but1);
   button3.style.width			= "75px";
   button3.style.height			= "22px";
   button3.style.lineHeight		= "22px";   
   button3.style.marginLeft		= "auto";
   button3.style.marginRight	= "10px";
   button3.style.background		= "white";
   button3.style.border			= "0px";
   button3.style.color			= "#061127";
   button3.style.font			= "14px Verdana, Geneva, Arial, Helvetica, sans-serif";
   button3.style.background		= "url(skin/"+css_style+"/img/button_green_bg_w4.gif) no-repeat center center";
   button3.onclick				= remove_obj_true;
 
   var button4	= document.createElement("input");	//创建一个input对象（提示框按钮）
   button4.setAttribute("type","button");
   button4.setAttribute("name","test2");
   button4.setAttribute("value",'错误');
   button4.style.width			= "50px";
   button4.style.height			= "22px";
   button4.style.marginLeft		= "220px";
   button4.style.marginBottom	= "10px";
   button4.style.background		= "white";
   button4.style.border			= "0px";
   button4.style.color			= "#061127";
   button4.style.background		= "url(skin/"+css_style+"/img/button_green_bg_w4.gif) no-repeat center center";
   button4.onclick				=  remove_obj_false;
   
   var txt	= document.createElement("p");					//创建一个p对象（提示框提示信息）
   txt.setAttribute("id","msg_txt");
   txt.style.margin				= "40px auto";	
   
   var msg_image=document.createElement("img");
   msg_image.src					= "skin/green/img/warning_3.gif"; 
   msg_image.style.marginTop		= "30px";
   
   //点击标题栏触发的事件
   function remove_obj_true()
   {
     document.body.removeChild(bg_obj);								//删除背景层Div
     document.getElementById("msg_div").removeChild(title);			//删除提示框的标题栏
     document.body.removeChild(msg_obj);							//删除提示框层
     if (to_url1 != '')
	 {
	     if (to_url1 == '#')
		 {
			 remove_obj_false();
		 }else{
			 window.location.href = to_url1;
		 }
	 }else if(goback_num!=0){
		 window.history.go(0-goback_num);
	 }else{
		 ;
	 }
   }
   //点击标题栏触发的事件
   function remove_obj_false()
   {
     is_show_msg = 1;												//恢复回车提交表单
	 document.body.removeChild(bg_obj);								//删除背景层Div
     document.getElementById("msg_div").removeChild(title);			//删除提示框的标题栏
     document.body.removeChild(msg_obj);							//删除提示框层
	 if (to_url1 != '')
	 {
         window.location.href = to_url1;
	 }else if(goback_num!=0){
		 window.history.go(0-goback_num);
	 }else{
		 ;
	 }
   }

   document.body.appendChild(bg_obj);								//在body内添加该div对象
   document.body.appendChild(msg_obj);								//在body内添加提示框div对象msg_obj
   document.getElementById("msg_div").appendChild(title);			//在提示框div中添加标题栏对象title
   document.getElementById("msg_div").appendChild(msg_img);			//在提示框div中添加图像
   document.getElementById("msg_div").appendChild(msg_txt);			//在提示框div中添加右边文本框
   document.getElementById("msg_div").appendChild(msg_bottom);		//在提示框div中添加提示信息提示框文本区
   document.getElementById("msg_img").appendChild(msg_image);			//在图像div中添加图像
   
   //按钮判断
   if (show_but1 != '')
   {
	   txt.innerHTML	= show_mes;											//来源于函数调用时的参数值
	   document.getElementById("msg_txt").appendChild(txt);					//在提示框div中添加提示信息提示框文本区
	   document.getElementById("msg_bottom").appendChild(button3);			//在提示框div中添加按钮对象button
	   if (show_close==1)
	   {
		   document.getElementById("msg_bottom").appendChild(button_close);		//在提示框div中添加按钮对象button
	   }
   }
}

//显示两个按钮
function msgbox_two(show_mes,to_url1,to_url2,goback_num,show_but1,show_but2,bg_color)
{
   var msgw,msgh,bordercolor;
   msgw					= 400;							//提示窗口的宽度
   msgh					= 200;							//提示窗口的高度
   titleheight			= 25; 							//提示窗口标题高度
   bordercolor			= "#2A87D9";					//提示窗口的边框颜色
   titlecolor			= "#6BBBDF";					//提示窗口的标题颜色
   //如果传入的颜色为空,默认颜色
   if (bg_color == '')
   {
	   bg_color = '#999';   
   }
   //处理传入字符串长度
   var str_length	= show_mes.length - 0;
   if (str_length > 100)
   {
	   show_mes = show_mes.slice(0,92) + '...';   
   }
   var swidth,sheight;
   swidth				= document.body.scrollWidth; 	//网页正文区域宽
   sheight				= document.body.scrollHeight;	//网页正文区域高

   //背景层（大小与窗口有效区域相同，即当弹出对话框时）
   var bg_obj	= document.createElement("div");	//创建一个div对象（背景层）
   bg_obj.setAttribute('id','bg_div');
   bg_obj.style.position		= "absolute";
   bg_obj.style.top				= "0";
   bg_obj.style.background	    = bg_color;
   bg_obj.style.filter			= "progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=50";
   bg_obj.style.opacity			= "0.6";
   bg_obj.style.left			= "0";
   bg_obj.style.width			= swidth + "px";
   bg_obj.style.height			= sheight + "px";
   bg_obj.style.zIndex 			= "10000";
   
   var msg_obj	= document.createElement("div")		//创建一个div对象（提示框层）
   msg_obj.setAttribute("id","msg_div");
   msg_obj.setAttribute("align","center");
   msg_obj.style.background		= "white";
   msg_obj.style.border			= "1px solid " + bordercolor;
   msg_obj.style.position 		= "absolute";
   msg_obj.style.left 			= "50%";
   msg_obj.style.top 			= "50%";
   msg_obj.style.paddingBottom 	= 10+"px";
   msg_obj.style.font			= "12px/1.6em Verdana, Geneva, Arial, Helvetica, sans-serif";
   msg_obj.style.marginLeft 	= "-225px" ;
   msg_obj.style.marginTop 		= -75+document.documentElement.scrollTop+"px";
   msg_obj.style.width 			= msgw + "px";
   //msg_obj.style.height   		= msgh + "px";
   msg_obj.style.textAlign 		= "center";
   msg_obj.style.lineHeight 	= "25px";
   msg_obj.style.zIndex 		= "10001";
  
   var msg_obj_txt	= document.createElement("div")		//创建第二个div对象（提示框层）
   msg_obj_txt.setAttribute("id","msg_div_txt");
   msg_obj_txt.setAttribute("align","center");
   msg_obj_txt.style.background		= "white";
   msg_obj_txt.style.position 		= "relative";
   msg_obj_txt.style.paddingLeft 	= 10+"px";
   msg_obj_txt.style.paddingRight 	= 10+"px";
   msg_obj_txt.style.paddingTop 	= 5+"px";

   msg_obj_txt.style.paddingBottom 	= 20+"px";
   msg_obj_txt.style.font			= "12px/1.6em Verdana, Geneva, Arial, Helvetica, sans-serif";
   msg_obj_txt.style.width 			= msgw-2 + "px";
   msg_obj_txt.style.textAlign 		= "center";
   msg_obj_txt.style.lineHeight 	= "25px";
   msg_obj_txt.style.zIndex 		= "10001";
  
   var title	= document.createElement("h4");		//创建一个h4对象（提示框标题栏）
   title.setAttribute("id","msg_title");
   title.setAttribute("align","right");
   title.style.margin			= "0";
   title.style.padding			= "6px";
   title.style.background		= bordercolor;
   title.style.filter			= "progid:DXImageTransform.Microsoft.Alpha(startX=20, startY=20, finishX=100, finishY=100,style=1,opacity=75,finishOpacity=100);";
   title.style.opacity			= "0.75";
   title.style.border			= "1px solid " + bordercolor;
   title.style.height			= "18px";
   title.style.font				= "12px Verdana, Geneva, Arial, Helvetica, sans-serif";
   title.style.color			= "white";
   title.style.cursor			= "pointer";
   title.innerHTML				= "关闭";
   title.onclick				= remove_obj_false;
   
   //需要显示两个按钮时，为 button1,button2,显示一个时，button3,错误时，button4
   var button1	= document.createElement("input");	//创建一个input对象（提示框按钮）
   button1.setAttribute("type","button");
   button1.setAttribute("name","test1");
   button1.setAttribute("value",show_but1);
   button1.style.width			= "50px";
   button1.style.height			= "22px";
   button1.style.marginLeft		= "220px";
   button1.style.marginBottom	= "10px";
   button1.style.background		= bordercolor;
   button1.style.border			= "1px solid "+ bordercolor;
   button1.style.color			= "white";
   button1.onclick				=  remove_obj_true;
   
   var button2	= document.createElement("input");	//创建一个input对象（提示框按钮）
   button2.setAttribute("type","button");
   button2.setAttribute("name","test2");
   button2.setAttribute("value",show_but2);
   button2.style.width			= "50px";
   button2.style.height			= "22px";
   button2.style.marginLeft		= "50px";
   button2.style.marginBottom	= "10px";
   button2.style.background		= bordercolor;
   button2.style.border			= "1px solid "+ bordercolor;
   button2.style.color			= "white";
   button2.onclick				= remove_obj_false;
 
   var button4	= document.createElement("input");	//创建一个input对象（提示框按钮）
   button4.setAttribute("type","button");
   button4.setAttribute("name","test2");
   button4.setAttribute("value",'错误');
   button4.style.width			= "50px";
   button4.style.height			= "22px";
   button4.style.marginLeft		= "220px";
   button4.style.marginBottom	= "10px";
   button4.style.background		= bordercolor;
   button4.style.border			= "1px solid "+ bordercolor;
   button4.style.color			= "red";
   button4.onclick				= remove_obj_false;
   
   var txt	= document.createElement("p");					//创建一个p对象（提示框提示信息）
   txt.style.margin				= "1em 0"
   txt.setAttribute("id","msg_txt");
   
   //点击标题栏触发的事件,第一个按钮调用
   function remove_obj_true()
   {
     document.body.removeChild(bg_obj);								//删除背景层Div
     document.getElementById("msg_div").removeChild(title);			//删除提示框的标题栏
     document.body.removeChild(msg_obj);							//删除提示框层
	 if (to_url1 != '')
	 {
         window.location.href = to_url1;
	 }
   }
   //点击标题栏触发的事件，关闭弹出层时调用
   function remove_obj_false()
   {
     document.body.removeChild(bg_obj);								//删除背景层Div
     document.getElementById("msg_div").removeChild(title);			//删除提示框的标题栏
     document.body.removeChild(msg_obj);							//删除提示框层
     if (to_url2 != '')
	 {
	     window.location.href = to_url2;	 
	 }else{
		 window.history.go(0-goback_num);
	 }
   }

   document.body.appendChild(bg_obj);								//在body内添加该div对象
   document.body.appendChild(msg_obj);								//在body内添加提示框div对象msg_obj
   document.getElementById("msg_div").appendChild(title);			//在提示框div中添加标题栏对象title
   document.getElementById("msg_div").appendChild(msg_obj_txt);		//在提示框div中添加标题栏对象title
   
   //按钮判断
   if (show_but1 != '' && show_but2 != '')
   {
	   txt.innerHTML	= show_mes;									//来源于函数调用时的参数值
	   document.getElementById("msg_div_txt").appendChild(txt);		//在提示框div中添加提示信息对象txt
   	   document.getElementById("msg_div").appendChild(button1);		//在提示框div中添加按钮对象button
   	   document.getElementById("msg_div").appendChild(button2);		//在提示框div中添加按钮对象button2
   }
   else if (show_but1 == '' || show_but2 == '')
   {
	    txt.innerHTML	= '出错了';									//来源于函数调用时的参数值
	    document.getElementById("msg_div_txt").appendChild(txt);	//在提示框div中添加提示信息对象txt
	    document.getElementById("msg_div").appendChild(button4);
   }
}

