// JavaScript Document
function ec_alert_close() {
	if (document.getElementById("bg][div")) {
		document.body.removeChild(document.getElementById("bg][div")); 
	}
	if (document.getElementById("box][title")) {
		document.getElementById("box][div").removeChild(document.getElementById("box][title")); 
	}
	if (document.getElementById("box][div")) {
		document.body.removeChild(document.getElementById("box][div")); 
	}
}

// @para number: delaytime 设置alert自动关闭的时间
function ec_alert_close_delaytime(delaytime) {
	setTimeout(ec_alert_close, delaytime); 
}

function ec_get_page_size() {
	var x_scroll, y_scroll, page_h, page_w;
	if (window.innerHeight && window.scrollMaxY) {	
		x_scroll = document.body.scrollWidth;
		y_scroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		x_scroll = document.body.scrollWidth;
		y_scroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		x_scroll = document.body.offsetWidth;
		y_scroll = document.body.offsetHeight;
	}
	var window_w, window_h;
	if (self.innerHeight) {	// all except Explorer
		window_w = self.innerWidth;
		window_h = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		window_w = document.documentElement.clientWidth;
		window_h = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		window_w = document.body.clientWidth;
		window_h = document.body.clientHeight;
	}	
	// for small pages with total height less then height of the viewport
	if(y_scroll < window_h){
		page_h = window_h;
	} else { 
		page_h = y_scroll;
	}
	// for small pages with total width less then width of the viewport
	if(x_scroll < window_w){	
		page_w = window_w;
	} else {
		page_w = x_scroll;
	}
	var page_window_size = new Array(page_w,page_h,window_w,window_h);
	return page_window_size;
}

/**
* @para string: str, have_title, window_background, border_color, box_background, title_background, title_color number: box_w, box_h, delaytime
* ec_alert(str, box_w=400, box_h=100, delaytime=0, have_title="yes", window_background="#777", border_color="#369", box_background="white", title_background="#369", ="white")
* 不设置相应参数(使用函数默认值)请用 null 或 "" 值, 例: ec_alert("Good work!", null, null, 500, 'no', '', '');
*/
function ec_alert(str) { 
	page_size = new ec_get_page_size();
	var p_width, p_height, s_width, s_height;
	p_width  = page_size[0];
	p_height = page_size[1];
	s_width  = page_size[2];
	s_height = page_size[3];
	
	// if(typeof arguments[1] == "number" || typeof arguments[1] == "string")this.Direction = arguments[1];
	var box_w             = arguments[1] || 400; //提示窗口的宽度,函数的第二个参数,为形参,默认为400px
  var box_h             = arguments[2] || 100; //提示窗口的高度,函数的第三个参数,为形参,默认为100px
	var delaytime         = arguments[3] || 0; //如果需要定时关闭的话,请在调用函数时设置参数delaytime的值为相应时间,默认为不自动关闭
	var have_title        = arguments[4] || "yes"; //默认为有标题栏,如果没有设置自动关闭时间的话,始终都有标题栏
	var window_background = arguments[5] || "#777"; //提示时浏览器的大背景颜色
	var border_color      = arguments[6] || "#369"; //提示窗口的边框颜色
	var box_background    = arguments[7] || "white"; //提示窗口的背景颜色
	var title_background  = arguments[8] || "#369"; //提示标题的背景颜色
	var title_color       = arguments[9] || "white"; //提示窗口的标题(关闭符号)颜色

	var bg_obj = document.createElement("div"); 
	bg_obj.setAttribute("id","bg][div"); 
	bg_obj.style.position = "absolute"; 
	bg_obj.style.top = "0"; 
	bg_obj.style.background = window_background; 
	bg_obj.style.filter = "progid:DXImageTransform.Microsoft.Alpha(style = 3, opacity = 25, finishOpacity = 75);"; 
	bg_obj.style.opacity = "0.6"; 
	bg_obj.style.left = "0"; 
	bg_obj.style.width = p_width + "px"; 
	bg_obj.style.height = p_height + "px"; 
	document.body.appendChild(bg_obj); 
	
	var box_obj = document.createElement("div") 
	box_obj.setAttribute("id", "box][div"); 
	box_obj.setAttribute("align", "center"); 
	box_obj.style.position = "absolute"; 
	box_obj.style.background = box_background; 
	box_obj.style.font = "12px/1.6em Verdana, Geneva, Arial, Helvetica, sans-serif"; 
	box_obj.style.border = "1px solid " + border_color; 
	box_obj.style.width = box_w + "px"; 
	box_obj.style.height = box_h + "px"; 
	box_obj.style.top = (document.documentElement.scrollTop + (s_height-box_h)/2) + "px"; 
	//alert (document.documentElement.scrollTop);
	box_obj.style.left = (s_width-box_w)/2 + "px"; 
	
	document.body.appendChild(box_obj); 

	if (delaytime == 0 || have_title == "yes") {
		var title = document.createElement("h4"); 
		title.setAttribute("id","box][title"); 
		title.setAttribute("align","right"); 
		title.style.margin = "0"; 
		title.style.padding = "3px"; 
		title.style.background = title_background; 
		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 " + border_color; 
		title.style.height = "18px"; 
		title.style.font = "12px Verdana, Geneva, Arial, Helvetica, sans-serif"; 
		title.style.color = title_color; 
		title.style.cursor = "pointer"; 
		title.innerHTML = "<b>×</b>"; 
		
		title.onclick = function(){ 
			document.body.removeChild(bg_obj); 
			document.getElementById("box][div").removeChild(title); 
			document.body.removeChild(box_obj); 
		} 
		
		document.getElementById("box][div").appendChild(title); 	
	} //end if
	
	var txt = document.createElement("p"); 
	txt.style.margin = "1em 0"; 
	txt.setAttribute("id","box][msg"); 
	txt.innerHTML = str; 
	
	document.getElementById("box][div").appendChild(txt); 
	
	if (delaytime !== 0) {
		ec_alert_close_delaytime(delaytime);
	}
} 

/*
* @para string: str, window_background number: box_w, box_h, delaytime
* ec_alert_div(str, box_w, box_h, delaytime="0", window_background="#777")
*/
function ec_alert_div(str, box_w, box_h) { 
	page_size = new ec_get_page_size();
	var p_width, p_height, s_width, s_height;
	p_width  = page_size[0];
	p_height = page_size[1];
	s_width  = page_size[2];
	s_height = page_size[3];
	
	var box_w             = arguments[1] || 400; //提示窗口的宽度,函数的第二个参数,为形参,默认为400px
  var box_h             = arguments[2] || 100; //提示窗口的高度,函数的第三个参数,为形参,默认为100px
	var delaytime         = arguments[3] || 0; //如果需要定时关闭的话,请在调用函数时设置参数delaytime的值为相应时间,默认为不自动关闭
	var window_background = arguments[4] || "#777"; //提示时浏览器的大背景颜色

	var bg_obj = document.createElement("div"); 
	bg_obj.setAttribute("id","bg][div"); 
	bg_obj.style.position = "absolute"; 
	bg_obj.style.top = "0"; 
	bg_obj.style.background = window_background; 
	bg_obj.style.filter = "progid:DXImageTransform.Microsoft.Alpha(style = 3, opacity = 25, finishOpacity = 75);"; 
	bg_obj.style.opacity = "0.6"; 
	bg_obj.style.left = "0"; 
	bg_obj.style.width = p_width + "px"; 
	bg_obj.style.height = p_height + "px"; 
	document.body.appendChild(bg_obj); 
	
	var box_obj = document.createElement("div"); 
	box_obj.setAttribute("id", "box][div"); 
	box_obj.setAttribute("align", "center"); 
	box_obj.style.position = "absolute"; 
	box_obj.innerHTML = str;
	box_obj.style.top = (document.documentElement.scrollTop + (s_height-box_h)/2) + "px"; 
	//alert (document.documentElement.scrollTop);
	box_obj.style.left = (s_width-box_w)/2 + "px";
	document.body.appendChild(box_obj);
	
	if (delaytime !== 0) {
		ec_alert_close_delaytime(delaytime);
	}
} 