﻿// JavaScript Document
function divAlert(title,str){this.init(title,str);}
$this = divAlert.prototype;
var scrollTop=0;
$this.str = "";//提示框的内容，可以用html代码插入元素，也可以通过appendChild插入
$this.title='';
$this.width =600;//提示框的宽度
$this.height=1000;
//生成半透明的背景层, 并设置样式
$this.bgdiv = document.createElement("div");
$this.bgdiv.style.position = "absolute";
$this.bgdiv.style.top = 0;
$this.bgdiv.style.left = 0;
$this.bgdiv.style.zIndex = 9999;
$this.bgdiv.style.filter = "alpha(opacity=30)";
$this.bgdiv.style.opacity=0.3;
$this.bgdiv.style.backgroundColor = "#000";
$this.bgdiv.style.width = document.documentElement.clientWidth  + "px";
//放到最后设置
$this.outdiv = document.createElement("div");
$this.setWidth = function(w){//给出宽度设置接口, 一并设置宽度关联的css
$this.width = w;
$this.outdiv.style.width = $this.width + "px";
if(document.documentElement&&document.documentElement.scrollTop){
scrollTop=document.documentElement.scrollTop;
}else if(document.body){scrollTop=document.body.scrollTop;}
$this.outdiv.style.marginTop=scrollTop+100+"px"
$this.outdiv.style.marginLeft = (0-$this.width/2) + "px";}
$this.outdiv.style.position = "absolute";
$this.outdiv.style.left = "50%";
$this.outdiv.style.top = "2%";
$this.outdiv.style.border = "1px solid #999";//z-index
$this.outdiv.style.zIndex = 9999;
$this.setWidth($this.width); 
//生成提示框标题
$this.titdiv = document.createElement("div");
$this.titdiv.style.textAlign = "right";
$this.titdiv.style.backgroundColor = "#efefef";
$this.titdiv.style.padding = "5px 15px 5px 5px"
$this.titdiv.style.borderBottom = "1px solid #999";
//$this.titdiv.style.position='relative';
//提示框标题文字
$this.titndiv = document.createElement("div");
$this.titndiv.style.position="absolute";
$this.titndiv.style.top='0px';
$this.titndiv.style.left='0px';
$this.titndiv.style.fontSize = "12px";
$this.titndiv.style.fontWeight = "bold";
$this.titndiv.style.padding = "5px 0px 0px 25px"
$this.titndiv.style.color='#000';
//生成提示框内容
$this.condiv = document.createElement("div");
$this.condiv.style.backgroundColor = "#fff";
$this.condiv.style.height = "680px"; 
//生成关闭按钮
$this.clsbtn = document.createElement("a");//用a,input,span均可
$this.clsbtn.innerHTML = "关闭";
$this.clsbtn.style.cursor = "pointer";
$this.clsbtn.style.fontSize = "12px";
$this.clsbtn.style.color='#ff0000';
$this.clsbtn.onclick = function(){$this.close();} 
$this.init = function(title,str){this.str = str;this.title = title;} 
$this.open = function(){//显示提示框
var winHeight;
if (window.innerHeight){
winHeight = window.innerHeight
}else if((document.body)&&(document.body.clientHeight)){
winHeight = document.body.clientHeight}
if (document.documentElement && document.documentElement.clientHeight){
winHeight = document.documentElement.clientHeight;}
if(winHeight < document.body.clientHeight)
winHeight=document.body.scrollHeight;
this.bgdiv.style.height = winHeight + "px";
//document.body.appendChild(this.bgdiv);
document.body.appendChild(this.outdiv);
this.outdiv.appendChild(this.titdiv);
this.outdiv.appendChild(this.condiv);
this.titdiv.appendChild(this.clsbtn);
this.titdiv.appendChild(this.titndiv);
this.condiv.innerHTML = this.str;
this.titndiv.innerHTML= this.title;}
$this.close = function(){//关闭提示框
this.outdiv.removeChild(this.titdiv);
this.outdiv.removeChild(this.condiv);
this.titdiv.removeChild(this.clsbtn);
this.titdiv.removeChild(this.titndiv);
//document.body.removeChild(this.bgdiv);
document.body.removeChild(this.outdiv);}