﻿var buttonFunc;
var faderTimer = 0;
var hideFunc;

function showBox(button1_func, button2_func, button3_func) {
	if (faderTimer > 0) {
		clearInterval(faderTimer);
		if (hideFunc)
			hideFunc();
	}
	hideFunc = null;
	buttonFunc = [null, null, null];
	buttonFunc[0] = button1_func;
	buttonFunc[1] = button2_func;
	buttonFunc[2] = button3_func;
 
	var sctop = 0;
	var fw = 0, fh = 0;
	var bb = ge('boxBody'), bgf = ge('boxGoodFrame'), bw = ge('boxWrap'), bf=ge('boxFader');

	show('boxFader');
	bf.style.opacity = 1;
	bf.style.filter = "alpha(opacity=100)";
	
	if (self.innerWidth)
	{
		fw = self.innerWidth;
		fh = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientWidth)
	{
		de = document.documentElement;
		fw = de.clientWidth;
		fh = de.clientHeight;
		bf.style.position = "absolute";
		bf.style.height = bf.clientHeight;		
		sctop = document.documentElement.scrollTop;		
		show('boxGoodFrame');
	}

	bf.style.left = fw / 2 - bb.clientWidth / 2 + "px";
	bf.style.top = sctop + fh / 2 - bb.clientHeight / 2 - 50 + "px";

	mask();
}

function hideBox(hideFunction) {
	hideFunc = hideFunction;
	faderTimer = setInterval(fadeBox(ge('boxFader')), 5);
	fadeBox(ge('boxFader'));
	unmask();
	return false;
}

function fadeBox(boxfader) {
	return function() {
		if (boxfader.style.opacity <= 0.0) {
			hide('boxFader');
			hide('boxGoodFrame');
			clearInterval(faderTimer);
			faderTimer = 0;
			if (hideFunc)
				hideFunc();
		}
		boxfader.style.opacity = boxfader.style.opacity - 0.28;
		boxfader.style.filter = 'alpha(opacity='+boxfader.style.opacity*100+')';			
	}
}


function callBoxFunc(func) {
	if (func == null) {
		return hideBox();
	} else {
		return func();
	}
};


/*
         if (isOnlyNumbers(document.regMe.pass.value)) {
          ge('boxTitle').innerHTML = '';
          ge('boxMessage').innerHTML = '';
          ge('button1').innerHTML = ''; show('button2Cont');
          ge('button2').innerHTML = ''; 
          showBox(function(){ge('email').focus(); hideBox(); return false;}, function(){document.regMe.submit();});
         } 
*/

function showError(body, for_focus) {
         ge('boxTitle').innerHTML = '错误对话框';
         ge('boxMessage').innerHTML = body;
         ge('button1').innerHTML = '确定'; hide('button2Cont'); show('button1Cont');
         showBox(function(){if(for_focus)ge(for_focus).focus();hideBox();});
}

function showSuccess(body, url) {
         ge('boxTitle').innerHTML = '成功对话框';
         ge('boxMessage').innerHTML = body;
         ge('button1').innerHTML = '确定'; hide('button2Cont'); show('button1Cont');
         showBox(function(){hideBox();if(url)window.location=url;});
}

function showLoading(body) {
         ge('boxTitle').innerHTML = '正在操作，请稍候...';
         ge('boxMessage').innerHTML = body;
         ge('button1').innerHTML = '请稍候...'; hide('button2Cont'); show('button1Cont');
         showBox(function(){});
}

function showInfo(body, url) {
         ge('boxTitle').innerHTML = '信息';
         ge('boxMessage').innerHTML = body;
         ge('button1').innerHTML = '确定'; hide('button2Cont'); show('button1Cont');
         showBox(function(){hideBox();if(url)window.location=url;});
}

function showInfo2(body) {
         ge('boxTitle').innerHTML = '信息';
         ge('boxMessage').innerHTML = body;
         ge('button2').innerHTML = '取消'; hide('button1Cont'); show('button2Cont');
         showBox(function(){},function(){hideBox();});
}

function showerror(body, for_focus){
	showError(body,for_focus);
}

function showsuccess(body, url){
	showSuccess(body,url);
}

function showinfo(body, url){
	showInfo(body,url);
}

function showinfo2(body){
	showInfo2(body);
}
