﻿function createTag(tag){return document.createElement(tag);}
/*==半透明透明层==*/
var oWinBg,oAlertWrap,oAlertWrapLeft,winSt,aSelect
var createAlert = function(){
	oWinBg = createTag('div');
	oWinBg.id = 'winBg';
	oWinBg.style.height = (document.body.clientHeight<document.documentElement.clientHeight)?document.documentElement.clientHeight:document.body.clientHeight + 'px';
	document.body.appendChild(oWinBg);
	Element.hide(oWinBg);
	/*==提示对话框==*/
	oAlertWrap = createTag('div');
	oAlertWrap.id = 'alertWrap';
	oAlertWrapLeft = ((document.body.clientWidth<document.documentElement.clientWidth)?document.documentElement.clientWidth:document.body.clientWidth -320)/2 + 'px';
	oAlertWrap.style.left = oAlertWrapLeft;
	winSt = function(){return document.documentElement.scrollTop||document.body.scrollTop;}
	oAlertWrap.style.top = winSt() + 200 + 'px';
	Element.hide(oAlertWrap);
	document.body.appendChild(oAlertWrap);
	aSelect = $A(document.getElementsByTagName('select'));
}
var selectHide = function(){
	if(aSelect){aSelect.each(function(oSelect){Element.hide(oSelect);});}
}
var selectShow = function(){
	if(aSelect){aSelect.each(function(oSelect){Element.show(oSelect);});}
}

var alertIntervalId = null;
var alertFloat = function(){
	if(oAlertWrap){
		oAlertWrap.style.left = oAlertWrapLeft;
		clearInterval(alertIntervalId);
		alertIntervalId = setInterval(alertMove,100);
	}
}
var alertInitSt = 0;
var alertMove = function(){
	var _st = winSt();
	if(alertInitSt!=_st){
		_st = alertInitSt + (_st - alertInitSt)/2;
		alertInitSt = _st;
		oAlertWrap.style.top = alertInitSt + 200 + 'px';
	}else{clearInterval(alertIntervalId);}
}
Event.observe(window,'resize',alertFloat,false);
Event.observe(window,'scroll',alertFloat,false);



var alertError = function(msg,href){
	if(!oWinBg){createAlert();}
	oAlertWrap.innerHTML = '<h2>错误提示！</h2><p>'+ msg +'</p>';
	var oBtn = createTag('input');
	oBtn.type = 'button';
	oBtn.className = 'btn';
	oBtn.value = '确定';
	Event.observe(oBtn,'click',function(){
		oAlertWrap.hide();
		oWinBg.hide();
		selectShow();
		if(href){window.location = href;}
	},false)
	oAlertWrap.appendChild(oBtn);
	oAlertWrap.className = 'alertError';
	selectHide();
	oWinBg.show();
	oAlertWrap.show();
}
var alertSuccess = function(msg,href){
	if(!oWinBg){createAlert();}
	oAlertWrap.innerHTML = '<h2>成功提示！</h2><p>'+ msg +'</p>';
	var oBtn = createTag('input');
	oBtn.type = 'button';
	oBtn.className = 'btn';
	oBtn.value = '确定';
	Event.observe(oBtn,'click',function(){
		oAlertWrap.hide();
		oWinBg.hide();
		selectShow();
		if(href){window.location = href;}
	},false)
	oAlertWrap.appendChild(oBtn);
	oAlertWrap.className = 'alertSuccess';
	selectHide();
	oWinBg.show();
	oAlertWrap.show();
}
var alertTip = function(msg,href){
	if(!oWinBg){createAlert();}
	oAlertWrap.innerHTML = '<h2>提示</h2><p>'+ msg +'</p>';
	var oBtn = createTag('input');
	oBtn.type = 'button';
	oBtn.className = 'btn';
	oBtn.value = '确定';
	Event.observe(oBtn,'click',function(){
		oAlertWrap.hide();
		oWinBg.hide();
		selectShow();
		if(href){window.location = href;}
	},false)
	oAlertWrap.appendChild(oBtn);
	oAlertWrap.className = 'alertTip';
	selectHide();
	oWinBg.show();
	oAlertWrap.show();
}
var jconfirm = function(msg, controlId){
	if(!oWinBg){createAlert();}
	oAlertWrap.innerHTML = '<h2>确认提示</h2><p>'+ msg +'</p>';
	var oBtn = createTag('input');
	oBtn.type = 'button';
	oBtn.className = 'btn';
	oBtn.value = '确定';
	Event.observe(oBtn,'click',function(){
		oAlertWrap.hide();
		oWinBg.hide();
		selectShow();
		__doPostBack(controlId, '');
	},false)
	oAlertWrap.appendChild(oBtn);
	var oBtnCancel = createTag('input');
	oBtnCancel.type = 'button';
	oBtnCancel.className = 'btn';
	oBtnCancel.value = '取消';
	Event.observe(oBtnCancel,'click',function(){
		oAlertWrap.hide();
		oWinBg.hide();
		selectShow();
	},false)
	oAlertWrap.appendChild(oBtnCancel);
	oAlertWrap.className = 'alertConfirm';
	selectHide();
	oWinBg.show();
	oAlertWrap.show();
	return false;
}
